Skip to content

Commit 4e081b4

Browse files
authored
chore: replace BlockStore and StateStore with BlockDb and StateDb (#750)
1 parent 63a9c27 commit 4e081b4

File tree

12 files changed

+41
-41
lines changed

12 files changed

+41
-41
lines changed

bench/block_processing.exs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ alias LambdaEthereumConsensus.ForkChoice
22
alias LambdaEthereumConsensus.ForkChoice.Handlers
33
alias LambdaEthereumConsensus.StateTransition.Cache
44
alias LambdaEthereumConsensus.Store
5-
alias LambdaEthereumConsensus.Store.BlockStore
6-
alias LambdaEthereumConsensus.Store.StateStore
5+
alias LambdaEthereumConsensus.Store.BlockDb
6+
alias LambdaEthereumConsensus.Store.StateDb
77
alias Types.{BeaconState, SignedBeaconBlock}
88

99
Logger.configure(level: :warning)
@@ -17,9 +17,9 @@ Cache.initialize_cache()
1717
slot = 4_213_280
1818

1919
IO.puts("fetching blocks...")
20-
{:ok, %BeaconState{} = state} = StateStore.get_state_by_slot(slot)
21-
{:ok, %SignedBeaconBlock{} = block} = BlockStore.get_block_by_slot(slot)
22-
{:ok, %SignedBeaconBlock{} = new_block} = BlockStore.get_block_by_slot(slot + 1)
20+
{:ok, %BeaconState{} = state} = StateDb.get_state_by_slot(slot)
21+
{:ok, %SignedBeaconBlock{} = block} = BlockDb.get_block_by_slot(slot)
22+
{:ok, %SignedBeaconBlock{} = new_block} = BlockDb.get_block_by_slot(slot + 1)
2323

2424
IO.puts("initializing store...")
2525
{:ok, store} = Types.Store.get_forkchoice_store(state, block)
@@ -28,7 +28,7 @@ store = Handlers.on_tick(store, store.time + 30)
2828
attestations = new_block.message.body.attestations
2929
attester_slashings = new_block.message.body.attester_slashings
3030

31-
{:ok, root} = BlockStore.get_block_root_by_slot(slot)
31+
{:ok, root} = BlockDb.get_block_root_by_slot(slot)
3232

3333
IO.puts("about to process block: #{slot + 1}, with root: #{Base.encode16(root)}...")
3434
IO.puts("#{length(attestations)} attestations ; #{length(attester_slashings)} attester slashings")

bench/multiple_blocks_processing.exs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ alias LambdaEthereumConsensus.ForkChoice
22
alias LambdaEthereumConsensus.ForkChoice.Handlers
33
alias LambdaEthereumConsensus.StateTransition.Cache
44
alias LambdaEthereumConsensus.Store
5-
alias LambdaEthereumConsensus.Store.BlockStore
6-
alias LambdaEthereumConsensus.Store.StateStore
5+
alias LambdaEthereumConsensus.Store.BlockDb
6+
alias LambdaEthereumConsensus.Store.StateDb
77
alias Types.{BeaconState, SignedBeaconBlock}
88

99
Logger.configure(level: :warning)
@@ -19,14 +19,14 @@ count = 10
1919
end_slot = start_slot + count
2020

2121
IO.puts("fetching blocks...")
22-
{:ok, %BeaconState{} = state} = StateStore.get_state_by_slot(start_slot)
23-
{:ok, %SignedBeaconBlock{} = signed_block} = BlockStore.get_block_by_slot(state.slot)
22+
{:ok, %BeaconState{} = state} = StateDb.get_state_by_slot(start_slot)
23+
{:ok, %SignedBeaconBlock{} = signed_block} = BlockDb.get_block_by_slot(state.slot)
2424

2525
blocks =
2626
(start_slot + 1)..end_slot
2727
# NOTE: we have to consider empty slots
2828
|> Enum.flat_map(fn slot ->
29-
case BlockStore.get_block_by_slot(slot) do
29+
case BlockDb.get_block_by_slot(slot) do
3030
{:ok, block} -> [block]
3131
:not_found -> []
3232
end

lib/beacon_api/controllers/v1/beacon_controller.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ defmodule BeaconApi.V1.BeaconController do
33
alias BeaconApi.ErrorController
44

55
alias LambdaEthereumConsensus.ForkChoice
6+
alias LambdaEthereumConsensus.Store.BlockDb
67
alias LambdaEthereumConsensus.Store.Blocks
7-
alias LambdaEthereumConsensus.Store.BlockStore
88
use BeaconApi, :controller
99

1010
plug(OpenApiSpex.Plug.CastAndValidate, json_render_error_v2: true)
@@ -76,7 +76,7 @@ defmodule BeaconApi.V1.BeaconController do
7676

7777
def get_block_root(conn, %{block_id: block_id}) do
7878
with {slot, ""} when slot >= 0 <- Integer.parse(block_id),
79-
{:ok, block_root} <- BlockStore.get_block_root_by_slot(slot) do
79+
{:ok, block_root} <- BlockDb.get_block_root_by_slot(slot) do
8080
conn |> root_response(block_root, true, false)
8181
else
8282
:not_found ->

lib/beacon_api/controllers/v2/beacon_controller.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
defmodule BeaconApi.V2.BeaconController do
22
alias BeaconApi.ApiSpec
33
alias BeaconApi.ErrorController
4+
alias LambdaEthereumConsensus.Store.BlockDb
45
alias LambdaEthereumConsensus.Store.Blocks
5-
alias LambdaEthereumConsensus.Store.BlockStore
66
use BeaconApi, :controller
77

88
plug(OpenApiSpex.Plug.CastAndValidate, json_render_error_v2: true)
@@ -48,7 +48,7 @@ defmodule BeaconApi.V2.BeaconController do
4848

4949
def get_block(conn, %{block_id: block_id}) do
5050
with {slot, ""} when slot >= 0 <- Integer.parse(block_id),
51-
{:ok, block} <- BlockStore.get_block_by_slot(slot) do
51+
{:ok, block} <- BlockDb.get_block_by_slot(slot) do
5252
conn |> block_response(block)
5353
else
5454
:not_found ->

lib/lambda_ethereum_consensus/fork_choice/helpers.ex

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ defmodule LambdaEthereumConsensus.ForkChoice.Helpers do
66
alias LambdaEthereumConsensus.StateTransition.{Accessors, Misc}
77
alias LambdaEthereumConsensus.Store.Blocks
88
alias LambdaEthereumConsensus.Store.BlockStates
9-
alias LambdaEthereumConsensus.Store.{BlockStore, StateStore}
9+
alias LambdaEthereumConsensus.Store.{BlockDb, StateDb}
1010

1111
alias Types.Store
1212

@@ -244,7 +244,7 @@ defmodule LambdaEthereumConsensus.ForkChoice.Helpers do
244244

245245
def block_root_by_block_id(slot) when is_integer(slot) do
246246
with :ok <- check_valid_slot(slot, BeaconChain.get_current_slot()),
247-
{:ok, root} <- BlockStore.get_block_root_by_slot(slot) do
247+
{:ok, root} <- BlockDb.get_block_root_by_slot(slot) do
248248
# TODO compute is_optimistic_or_invalid() and is_finalized()
249249
execution_optimistic = true
250250
finalized = false
@@ -259,15 +259,15 @@ defmodule LambdaEthereumConsensus.ForkChoice.Helpers do
259259
execution_optimistic = true
260260
finalized = false
261261

262-
case StateStore.get_state_by_state_root(hex_root) do
262+
case StateDb.get_state_by_state_root(hex_root) do
263263
{:ok, _state} -> {:ok, {hex_root, execution_optimistic, finalized}}
264264
_ -> :not_found
265265
end
266266
end
267267

268268
def state_root_by_state_id(id) do
269269
with {:ok, {block_root, optimistic, finalized}} <- block_root_by_block_id(id),
270-
{:ok, block} <- BlockStore.get_block(block_root) do
270+
{:ok, block} <- BlockDb.get_block(block_root) do
271271
%{message: %{state_root: state_root}} = block
272272
{:ok, {state_root, optimistic, finalized}}
273273
end
@@ -281,7 +281,7 @@ defmodule LambdaEthereumConsensus.ForkChoice.Helpers do
281281
| :invalid_id
282282
def block_by_block_id(block_id) do
283283
with {:ok, {root, optimistic, finalized}} <- block_root_by_block_id(block_id),
284-
{:ok, block} <- BlockStore.get_block(root) do
284+
{:ok, block} <- BlockDb.get_block(root) do
285285
{:ok, {block, optimistic, finalized}}
286286
end
287287
end
@@ -297,7 +297,7 @@ defmodule LambdaEthereumConsensus.ForkChoice.Helpers do
297297
execution_optimistic = true
298298
finalized = false
299299

300-
case StateStore.get_state_by_state_root(hex_root) do
300+
case StateDb.get_state_by_state_root(hex_root) do
301301
{:ok, state} -> {:ok, {state, execution_optimistic, finalized}}
302302
_ -> :not_found
303303
end
@@ -307,7 +307,7 @@ defmodule LambdaEthereumConsensus.ForkChoice.Helpers do
307307
with {:ok, {%{message: %{state_root: state_root}}, optimistic, finalized}} <-
308308
block_by_block_id(id),
309309
{:ok, state} <-
310-
StateStore.get_state_by_state_root(state_root) do
310+
StateDb.get_state_by_state_root(state_root) do
311311
{:ok, {state, optimistic, finalized}}
312312
end
313313
end

lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ defmodule LambdaEthereumConsensus.P2P.IncomingRequests.Handler do
66

77
alias LambdaEthereumConsensus.Beacon.BeaconChain
88
alias LambdaEthereumConsensus.{Libp2pPort, P2P}
9+
alias LambdaEthereumConsensus.Store.BlockDb
910
alias LambdaEthereumConsensus.Store.Blocks
10-
alias LambdaEthereumConsensus.Store.BlockStore
1111

1212
require Logger
1313

@@ -113,7 +113,7 @@ defmodule LambdaEthereumConsensus.P2P.IncomingRequests.Handler do
113113

114114
blocks =
115115
start_slot..slot_coverage
116-
|> Enum.map(&BlockStore.get_block_by_slot/1)
116+
|> Enum.map(&BlockDb.get_block_by_slot/1)
117117

118118
response_chunk =
119119
blocks

lib/lambda_ethereum_consensus/store/block_states.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ defmodule LambdaEthereumConsensus.Store.BlockStates do
33
Interface to `Store.block_states`.
44
"""
55
alias LambdaEthereumConsensus.Store.LRUCache
6-
alias LambdaEthereumConsensus.Store.StateStore
6+
alias LambdaEthereumConsensus.Store.StateDb
77
alias Types.BeaconState
88

99
@table :states_by_block_hash
@@ -20,7 +20,7 @@ defmodule LambdaEthereumConsensus.Store.BlockStates do
2020
table: @table,
2121
max_entries: @max_entries,
2222
batch_prune_size: @batch_prune_size,
23-
store_func: &StateStore.store_state(&2, &1)
23+
store_func: &StateDb.store_state(&2, &1)
2424
)
2525
end
2626

@@ -50,7 +50,7 @@ defmodule LambdaEthereumConsensus.Store.BlockStates do
5050
##########################
5151

5252
defp fetch_state(key) do
53-
case StateStore.get_state_by_block_root(key) do
53+
case StateDb.get_state_by_block_root(key) do
5454
{:ok, value} -> value
5555
:not_found -> nil
5656
# TODO: handle this somehow?

lib/lambda_ethereum_consensus/store/block_store.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
defmodule LambdaEthereumConsensus.Store.BlockStore do
1+
defmodule LambdaEthereumConsensus.Store.BlockDb do
22
@moduledoc """
33
Storage and retrieval of blocks.
44
"""

lib/lambda_ethereum_consensus/store/blocks.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ defmodule LambdaEthereumConsensus.Store.Blocks do
22
@moduledoc """
33
Interface to `Store.blocks`.
44
"""
5-
alias LambdaEthereumConsensus.Store.BlockStore
5+
alias LambdaEthereumConsensus.Store.BlockDb
66
alias LambdaEthereumConsensus.Store.LRUCache
77
alias Types.BeaconBlock
88
alias Types.SignedBeaconBlock
@@ -21,7 +21,7 @@ defmodule LambdaEthereumConsensus.Store.Blocks do
2121
table: @table,
2222
max_entries: @max_entries,
2323
batch_prune_size: @batch_prune_size,
24-
store_func: &BlockStore.store_block(&2, &1)
24+
store_func: &BlockDb.store_block(&2, &1)
2525
)
2626
end
2727

@@ -66,7 +66,7 @@ defmodule LambdaEthereumConsensus.Store.Blocks do
6666
##########################
6767

6868
defp fetch_block(key) do
69-
case BlockStore.get_block(key) do
69+
case BlockDb.get_block(key) do
7070
{:ok, value} -> value
7171
:not_found -> nil
7272
# TODO: handle this somehow?

lib/lambda_ethereum_consensus/store/state_store.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
defmodule LambdaEthereumConsensus.Store.StateStore do
1+
defmodule LambdaEthereumConsensus.Store.StateDb do
22
@moduledoc """
33
Beacon node state storage.
44
"""

test/integration/fork_choice/handlers_test.exs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ defmodule Integration.ForkChoice.HandlersTest do
33

44
alias LambdaEthereumConsensus.ForkChoice.Handlers
55
alias LambdaEthereumConsensus.StateTransition.Cache
6+
alias LambdaEthereumConsensus.Store.BlockDb
67
alias LambdaEthereumConsensus.Store.Blocks
7-
alias LambdaEthereumConsensus.Store.BlockStore
88
alias LambdaEthereumConsensus.Store.Db
9-
alias LambdaEthereumConsensus.Store.StateStore
9+
alias LambdaEthereumConsensus.Store.StateDb
1010

1111
setup_all do
1212
start_supervised!(Db)
@@ -21,10 +21,10 @@ defmodule Integration.ForkChoice.HandlersTest do
2121
test "on_block w/data from DB" do
2222
# NOTE: this test requires a DB with a state, and blocks for the state's slot and the next slot.
2323
# WARN: sometimes fails with "OffsetOutOfBounds" errors. Re-run the test in those cases.
24-
{:ok, state} = StateStore.get_latest_state()
24+
{:ok, state} = StateDb.get_latest_state()
2525

26-
{:ok, signed_block} = BlockStore.get_block_by_slot(state.slot)
27-
{:ok, new_signed_block} = BlockStore.get_block_by_slot(state.slot + 1)
26+
{:ok, signed_block} = BlockDb.get_block_by_slot(state.slot)
27+
{:ok, new_signed_block} = BlockDb.get_block_by_slot(state.slot + 1)
2828

2929
assert {:ok, store} = Types.Store.get_forkchoice_store(state, signed_block)
3030
new_store = Handlers.on_tick(store, :os.system_time(:second))

test/unit/beacon_api_test.exs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ defmodule BeaconApiTest do
33
use Plug.Test
44
use Patch
55
alias BeaconApi.Router
6-
alias LambdaEthereumConsensus.Store.BlockStore
6+
alias LambdaEthereumConsensus.Store.BlockDb
77
alias LambdaEthereumConsensus.Store.Db
88

99
@moduletag :beacon_api_case
@@ -42,7 +42,7 @@ defmodule BeaconApiTest do
4242
0, 0>>
4343

4444
signed_block = Fixtures.Block.signed_beacon_block()
45-
BlockStore.store_block(signed_block, head_root)
45+
BlockDb.store_block(signed_block, head_root)
4646

4747
resp_body = %{
4848
data: %{root: "0x" <> Base.encode16(signed_block.message.state_root, case: :lower)},
@@ -86,11 +86,11 @@ defmodule BeaconApiTest do
8686
0, 0>>
8787

8888
signed_block = Fixtures.Block.signed_beacon_block()
89-
BlockStore.store_block(signed_block, head_root)
89+
BlockDb.store_block(signed_block, head_root)
9090
beacon_state = Fixtures.Block.beacon_state()
9191

9292
patch(
93-
LambdaEthereumConsensus.Store.StateStore,
93+
LambdaEthereumConsensus.Store.StateDb,
9494
:get_state_by_state_root,
9595
{:ok, beacon_state}
9696
)

0 commit comments

Comments
 (0)