diff --git a/bench/block_processing.exs b/bench/block_processing.exs index bcf2905ae..2b31f0eb2 100644 --- a/bench/block_processing.exs +++ b/bench/block_processing.exs @@ -2,8 +2,8 @@ alias LambdaEthereumConsensus.ForkChoice alias LambdaEthereumConsensus.ForkChoice.Handlers alias LambdaEthereumConsensus.StateTransition.Cache alias LambdaEthereumConsensus.Store -alias LambdaEthereumConsensus.Store.BlockStore -alias LambdaEthereumConsensus.Store.StateStore +alias LambdaEthereumConsensus.Store.BlockDb +alias LambdaEthereumConsensus.Store.StateDb alias Types.{BeaconState, SignedBeaconBlock} Logger.configure(level: :warning) @@ -17,9 +17,9 @@ Cache.initialize_cache() slot = 4_213_280 IO.puts("fetching blocks...") -{:ok, %BeaconState{} = state} = StateStore.get_state_by_slot(slot) -{:ok, %SignedBeaconBlock{} = block} = BlockStore.get_block_by_slot(slot) -{:ok, %SignedBeaconBlock{} = new_block} = BlockStore.get_block_by_slot(slot + 1) +{:ok, %BeaconState{} = state} = StateDb.get_state_by_slot(slot) +{:ok, %SignedBeaconBlock{} = block} = BlockDb.get_block_by_slot(slot) +{:ok, %SignedBeaconBlock{} = new_block} = BlockDb.get_block_by_slot(slot + 1) IO.puts("initializing store...") {:ok, store} = Types.Store.get_forkchoice_store(state, block) @@ -28,7 +28,7 @@ store = Handlers.on_tick(store, store.time + 30) attestations = new_block.message.body.attestations attester_slashings = new_block.message.body.attester_slashings -{:ok, root} = BlockStore.get_block_root_by_slot(slot) +{:ok, root} = BlockDb.get_block_root_by_slot(slot) IO.puts("about to process block: #{slot + 1}, with root: #{Base.encode16(root)}...") IO.puts("#{length(attestations)} attestations ; #{length(attester_slashings)} attester slashings") diff --git a/bench/multiple_blocks_processing.exs b/bench/multiple_blocks_processing.exs index f9a754113..051fc25e2 100644 --- a/bench/multiple_blocks_processing.exs +++ b/bench/multiple_blocks_processing.exs @@ -2,8 +2,8 @@ alias LambdaEthereumConsensus.ForkChoice alias LambdaEthereumConsensus.ForkChoice.Handlers alias LambdaEthereumConsensus.StateTransition.Cache alias LambdaEthereumConsensus.Store -alias LambdaEthereumConsensus.Store.BlockStore -alias LambdaEthereumConsensus.Store.StateStore +alias LambdaEthereumConsensus.Store.BlockDb +alias LambdaEthereumConsensus.Store.StateDb alias Types.{BeaconState, SignedBeaconBlock} Logger.configure(level: :warning) @@ -19,14 +19,14 @@ count = 10 end_slot = start_slot + count IO.puts("fetching blocks...") -{:ok, %BeaconState{} = state} = StateStore.get_state_by_slot(start_slot) -{:ok, %SignedBeaconBlock{} = signed_block} = BlockStore.get_block_by_slot(state.slot) +{:ok, %BeaconState{} = state} = StateDb.get_state_by_slot(start_slot) +{:ok, %SignedBeaconBlock{} = signed_block} = BlockDb.get_block_by_slot(state.slot) blocks = (start_slot + 1)..end_slot # NOTE: we have to consider empty slots |> Enum.flat_map(fn slot -> - case BlockStore.get_block_by_slot(slot) do + case BlockDb.get_block_by_slot(slot) do {:ok, block} -> [block] :not_found -> [] end diff --git a/lib/beacon_api/controllers/v1/beacon_controller.ex b/lib/beacon_api/controllers/v1/beacon_controller.ex index 8145a6f06..f9f346049 100644 --- a/lib/beacon_api/controllers/v1/beacon_controller.ex +++ b/lib/beacon_api/controllers/v1/beacon_controller.ex @@ -3,8 +3,8 @@ defmodule BeaconApi.V1.BeaconController do alias BeaconApi.ErrorController alias LambdaEthereumConsensus.ForkChoice + alias LambdaEthereumConsensus.Store.BlockDb alias LambdaEthereumConsensus.Store.Blocks - alias LambdaEthereumConsensus.Store.BlockStore use BeaconApi, :controller plug(OpenApiSpex.Plug.CastAndValidate, json_render_error_v2: true) @@ -76,7 +76,7 @@ defmodule BeaconApi.V1.BeaconController do def get_block_root(conn, %{block_id: block_id}) do with {slot, ""} when slot >= 0 <- Integer.parse(block_id), - {:ok, block_root} <- BlockStore.get_block_root_by_slot(slot) do + {:ok, block_root} <- BlockDb.get_block_root_by_slot(slot) do conn |> root_response(block_root, true, false) else :not_found -> diff --git a/lib/beacon_api/controllers/v2/beacon_controller.ex b/lib/beacon_api/controllers/v2/beacon_controller.ex index 36782bf78..d33766e62 100644 --- a/lib/beacon_api/controllers/v2/beacon_controller.ex +++ b/lib/beacon_api/controllers/v2/beacon_controller.ex @@ -1,8 +1,8 @@ defmodule BeaconApi.V2.BeaconController do alias BeaconApi.ApiSpec alias BeaconApi.ErrorController + alias LambdaEthereumConsensus.Store.BlockDb alias LambdaEthereumConsensus.Store.Blocks - alias LambdaEthereumConsensus.Store.BlockStore use BeaconApi, :controller plug(OpenApiSpex.Plug.CastAndValidate, json_render_error_v2: true) @@ -48,7 +48,7 @@ defmodule BeaconApi.V2.BeaconController do def get_block(conn, %{block_id: block_id}) do with {slot, ""} when slot >= 0 <- Integer.parse(block_id), - {:ok, block} <- BlockStore.get_block_by_slot(slot) do + {:ok, block} <- BlockDb.get_block_by_slot(slot) do conn |> block_response(block) else :not_found -> diff --git a/lib/lambda_ethereum_consensus/fork_choice/helpers.ex b/lib/lambda_ethereum_consensus/fork_choice/helpers.ex index 2eb226ed7..40b67ee48 100644 --- a/lib/lambda_ethereum_consensus/fork_choice/helpers.ex +++ b/lib/lambda_ethereum_consensus/fork_choice/helpers.ex @@ -6,7 +6,7 @@ defmodule LambdaEthereumConsensus.ForkChoice.Helpers do alias LambdaEthereumConsensus.StateTransition.{Accessors, Misc} alias LambdaEthereumConsensus.Store.Blocks alias LambdaEthereumConsensus.Store.BlockStates - alias LambdaEthereumConsensus.Store.{BlockStore, StateStore} + alias LambdaEthereumConsensus.Store.{BlockDb, StateDb} alias Types.Store @@ -244,7 +244,7 @@ defmodule LambdaEthereumConsensus.ForkChoice.Helpers do def block_root_by_block_id(slot) when is_integer(slot) do with :ok <- check_valid_slot(slot, BeaconChain.get_current_slot()), - {:ok, root} <- BlockStore.get_block_root_by_slot(slot) do + {:ok, root} <- BlockDb.get_block_root_by_slot(slot) do # TODO compute is_optimistic_or_invalid() and is_finalized() execution_optimistic = true finalized = false @@ -259,7 +259,7 @@ defmodule LambdaEthereumConsensus.ForkChoice.Helpers do execution_optimistic = true finalized = false - case StateStore.get_state_by_state_root(hex_root) do + case StateDb.get_state_by_state_root(hex_root) do {:ok, _state} -> {:ok, {hex_root, execution_optimistic, finalized}} _ -> :not_found end @@ -267,7 +267,7 @@ defmodule LambdaEthereumConsensus.ForkChoice.Helpers do def state_root_by_state_id(id) do with {:ok, {block_root, optimistic, finalized}} <- block_root_by_block_id(id), - {:ok, block} <- BlockStore.get_block(block_root) do + {:ok, block} <- BlockDb.get_block(block_root) do %{message: %{state_root: state_root}} = block {:ok, {state_root, optimistic, finalized}} end @@ -281,7 +281,7 @@ defmodule LambdaEthereumConsensus.ForkChoice.Helpers do | :invalid_id def block_by_block_id(block_id) do with {:ok, {root, optimistic, finalized}} <- block_root_by_block_id(block_id), - {:ok, block} <- BlockStore.get_block(root) do + {:ok, block} <- BlockDb.get_block(root) do {:ok, {block, optimistic, finalized}} end end @@ -297,7 +297,7 @@ defmodule LambdaEthereumConsensus.ForkChoice.Helpers do execution_optimistic = true finalized = false - case StateStore.get_state_by_state_root(hex_root) do + case StateDb.get_state_by_state_root(hex_root) do {:ok, state} -> {:ok, {state, execution_optimistic, finalized}} _ -> :not_found end @@ -307,7 +307,7 @@ defmodule LambdaEthereumConsensus.ForkChoice.Helpers do with {:ok, {%{message: %{state_root: state_root}}, optimistic, finalized}} <- block_by_block_id(id), {:ok, state} <- - StateStore.get_state_by_state_root(state_root) do + StateDb.get_state_by_state_root(state_root) do {:ok, {state, optimistic, finalized}} end end diff --git a/lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex b/lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex index 1909b32fb..54c1c7a8e 100644 --- a/lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex +++ b/lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex @@ -6,8 +6,8 @@ defmodule LambdaEthereumConsensus.P2P.IncomingRequests.Handler do alias LambdaEthereumConsensus.Beacon.BeaconChain alias LambdaEthereumConsensus.{Libp2pPort, P2P} + alias LambdaEthereumConsensus.Store.BlockDb alias LambdaEthereumConsensus.Store.Blocks - alias LambdaEthereumConsensus.Store.BlockStore require Logger @@ -113,7 +113,7 @@ defmodule LambdaEthereumConsensus.P2P.IncomingRequests.Handler do blocks = start_slot..slot_coverage - |> Enum.map(&BlockStore.get_block_by_slot/1) + |> Enum.map(&BlockDb.get_block_by_slot/1) response_chunk = blocks diff --git a/lib/lambda_ethereum_consensus/store/block_states.ex b/lib/lambda_ethereum_consensus/store/block_states.ex index 13dc88506..beae2c51d 100644 --- a/lib/lambda_ethereum_consensus/store/block_states.ex +++ b/lib/lambda_ethereum_consensus/store/block_states.ex @@ -3,7 +3,7 @@ defmodule LambdaEthereumConsensus.Store.BlockStates do Interface to `Store.block_states`. """ alias LambdaEthereumConsensus.Store.LRUCache - alias LambdaEthereumConsensus.Store.StateStore + alias LambdaEthereumConsensus.Store.StateDb alias Types.BeaconState @table :states_by_block_hash @@ -20,7 +20,7 @@ defmodule LambdaEthereumConsensus.Store.BlockStates do table: @table, max_entries: @max_entries, batch_prune_size: @batch_prune_size, - store_func: &StateStore.store_state(&2, &1) + store_func: &StateDb.store_state(&2, &1) ) end @@ -50,7 +50,7 @@ defmodule LambdaEthereumConsensus.Store.BlockStates do ########################## defp fetch_state(key) do - case StateStore.get_state_by_block_root(key) do + case StateDb.get_state_by_block_root(key) do {:ok, value} -> value :not_found -> nil # TODO: handle this somehow? diff --git a/lib/lambda_ethereum_consensus/store/block_store.ex b/lib/lambda_ethereum_consensus/store/block_store.ex index 2637085a1..b084c66aa 100644 --- a/lib/lambda_ethereum_consensus/store/block_store.ex +++ b/lib/lambda_ethereum_consensus/store/block_store.ex @@ -1,4 +1,4 @@ -defmodule LambdaEthereumConsensus.Store.BlockStore do +defmodule LambdaEthereumConsensus.Store.BlockDb do @moduledoc """ Storage and retrieval of blocks. """ diff --git a/lib/lambda_ethereum_consensus/store/blocks.ex b/lib/lambda_ethereum_consensus/store/blocks.ex index adf4503d1..259db528c 100644 --- a/lib/lambda_ethereum_consensus/store/blocks.ex +++ b/lib/lambda_ethereum_consensus/store/blocks.ex @@ -2,7 +2,7 @@ defmodule LambdaEthereumConsensus.Store.Blocks do @moduledoc """ Interface to `Store.blocks`. """ - alias LambdaEthereumConsensus.Store.BlockStore + alias LambdaEthereumConsensus.Store.BlockDb alias LambdaEthereumConsensus.Store.LRUCache alias Types.BeaconBlock alias Types.SignedBeaconBlock @@ -21,7 +21,7 @@ defmodule LambdaEthereumConsensus.Store.Blocks do table: @table, max_entries: @max_entries, batch_prune_size: @batch_prune_size, - store_func: &BlockStore.store_block(&2, &1) + store_func: &BlockDb.store_block(&2, &1) ) end @@ -66,7 +66,7 @@ defmodule LambdaEthereumConsensus.Store.Blocks do ########################## defp fetch_block(key) do - case BlockStore.get_block(key) do + case BlockDb.get_block(key) do {:ok, value} -> value :not_found -> nil # TODO: handle this somehow? diff --git a/lib/lambda_ethereum_consensus/store/state_store.ex b/lib/lambda_ethereum_consensus/store/state_store.ex index f7f85ff48..afbaec151 100644 --- a/lib/lambda_ethereum_consensus/store/state_store.ex +++ b/lib/lambda_ethereum_consensus/store/state_store.ex @@ -1,4 +1,4 @@ -defmodule LambdaEthereumConsensus.Store.StateStore do +defmodule LambdaEthereumConsensus.Store.StateDb do @moduledoc """ Beacon node state storage. """ diff --git a/test/integration/fork_choice/handlers_test.exs b/test/integration/fork_choice/handlers_test.exs index c47a7cbbb..6e606b4d3 100644 --- a/test/integration/fork_choice/handlers_test.exs +++ b/test/integration/fork_choice/handlers_test.exs @@ -3,10 +3,10 @@ defmodule Integration.ForkChoice.HandlersTest do alias LambdaEthereumConsensus.ForkChoice.Handlers alias LambdaEthereumConsensus.StateTransition.Cache + alias LambdaEthereumConsensus.Store.BlockDb alias LambdaEthereumConsensus.Store.Blocks - alias LambdaEthereumConsensus.Store.BlockStore alias LambdaEthereumConsensus.Store.Db - alias LambdaEthereumConsensus.Store.StateStore + alias LambdaEthereumConsensus.Store.StateDb setup_all do start_supervised!(Db) @@ -21,10 +21,10 @@ defmodule Integration.ForkChoice.HandlersTest do test "on_block w/data from DB" do # NOTE: this test requires a DB with a state, and blocks for the state's slot and the next slot. # WARN: sometimes fails with "OffsetOutOfBounds" errors. Re-run the test in those cases. - {:ok, state} = StateStore.get_latest_state() + {:ok, state} = StateDb.get_latest_state() - {:ok, signed_block} = BlockStore.get_block_by_slot(state.slot) - {:ok, new_signed_block} = BlockStore.get_block_by_slot(state.slot + 1) + {:ok, signed_block} = BlockDb.get_block_by_slot(state.slot) + {:ok, new_signed_block} = BlockDb.get_block_by_slot(state.slot + 1) assert {:ok, store} = Types.Store.get_forkchoice_store(state, signed_block) new_store = Handlers.on_tick(store, :os.system_time(:second)) diff --git a/test/unit/beacon_api_test.exs b/test/unit/beacon_api_test.exs index 7bf5d237a..6cc24a078 100644 --- a/test/unit/beacon_api_test.exs +++ b/test/unit/beacon_api_test.exs @@ -3,7 +3,7 @@ defmodule BeaconApiTest do use Plug.Test use Patch alias BeaconApi.Router - alias LambdaEthereumConsensus.Store.BlockStore + alias LambdaEthereumConsensus.Store.BlockDb alias LambdaEthereumConsensus.Store.Db @moduletag :beacon_api_case @@ -42,7 +42,7 @@ defmodule BeaconApiTest do 0, 0>> signed_block = Fixtures.Block.signed_beacon_block() - BlockStore.store_block(signed_block, head_root) + BlockDb.store_block(signed_block, head_root) resp_body = %{ data: %{root: "0x" <> Base.encode16(signed_block.message.state_root, case: :lower)}, @@ -86,11 +86,11 @@ defmodule BeaconApiTest do 0, 0>> signed_block = Fixtures.Block.signed_beacon_block() - BlockStore.store_block(signed_block, head_root) + BlockDb.store_block(signed_block, head_root) beacon_state = Fixtures.Block.beacon_state() patch( - LambdaEthereumConsensus.Store.StateStore, + LambdaEthereumConsensus.Store.StateDb, :get_state_by_state_root, {:ok, beacon_state} )