Skip to content

Commit 2bfe826

Browse files
authored
fix: remove genserver behavior from pending blocks (#1200)
1 parent 3e2f78d commit 2bfe826

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

lib/lambda_ethereum_consensus/beacon/pending_blocks.ex

+3-6
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,9 @@ defmodule LambdaEthereumConsensus.Beacon.PendingBlocks do
3434
@spec add_block(SignedBeaconBlock.t()) :: :ok
3535
def add_block(signed_block) do
3636
block_info = BlockInfo.from_block(signed_block)
37-
38-
# If the block is new or was to be downloaded, we store it.
3937
loaded_block = Blocks.get_block_info(block_info.root)
4038

39+
# If the block is new or was to be downloaded, we store it.
4140
if is_nil(loaded_block) or loaded_block.status == :download do
4241
missing_blobs = missing_blobs(block_info)
4342

@@ -130,10 +129,8 @@ defmodule LambdaEthereumConsensus.Beacon.PendingBlocks do
130129
# To be used when a series of blobs are downloaded. Stores each blob.
131130
# If there are blocks that can be processed, does so immediately.
132131
defp add_blobs(blobs) do
133-
Enum.map(blobs, fn blob ->
134-
BlobDb.store_blob(blob)
135-
Ssz.hash_tree_root!(blob.signed_block_header.message)
136-
end)
132+
blobs
133+
|> Enum.map(&BlobDb.store_blob/1)
137134
|> Enum.uniq()
138135
|> Enum.each(fn root ->
139136
with %BlockInfo{} = block_info <- Blocks.get_block_info(root) do

lib/lambda_ethereum_consensus/store/blob_db.ex

+5-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ defmodule LambdaEthereumConsensus.Store.BlobDb do
1313
@blobdata_prefix "blobdata"
1414
@block_root_prefix "block_root"
1515

16-
@spec store_blob(BlobSidecar.t()) :: :ok
16+
@doc """
17+
Stores a blob sidecar for a certain block. Returns the block root.
18+
"""
19+
@spec store_blob(BlobSidecar.t()) :: Types.root()
1720
def store_blob(%BlobSidecar{signed_block_header: %{message: block_header}} = blob) do
1821
block_root = Ssz.hash_tree_root!(block_header)
1922
{:ok, encoded_blob} = Ssz.to_ssz(blob)
@@ -29,6 +32,7 @@ defmodule LambdaEthereumConsensus.Store.BlobDb do
2932

3033
block_root_key = block_root_key(block_header.slot, blob.index)
3134
Db.put(block_root_key, block_root)
35+
block_root
3236
end
3337

3438
# TODO: this is only used for tests

lib/lambda_ethereum_consensus/store/blocks.ex

+5-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@ defmodule LambdaEthereumConsensus.Store.Blocks do
7777
@spec new_block_info(BlockInfo.t()) :: :ok
7878
def new_block_info(block_info) do
7979
store_block_info(block_info)
80-
BlockDb.add_root_to_status(block_info.root, block_info.status)
80+
81+
# We add the root to the status list, but we also make sure we remove it from the downloads
82+
# list. If it's not in the list, the operation is equivalent to only adding it in the correct
83+
# one.
84+
BlockDb.change_root_status(block_info.root, :download, block_info.status)
8185
end
8286

8387
@doc """

test/unit/p2p/requests_test.exs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ defmodule Unit.P2p.RequestsTest do
1010
Requests.handle_response(requests, "some response", "fake id")
1111
end
1212

13-
test "A requests object should handle a request only once" do
13+
test "A requests object should handler a request only once" do
1414
requests = Requests.new()
1515
pid = self()
1616

0 commit comments

Comments
 (0)