File tree 4 files changed +14
-9
lines changed
lib/lambda_ethereum_consensus
4 files changed +14
-9
lines changed Original file line number Diff line number Diff line change @@ -34,10 +34,9 @@ defmodule LambdaEthereumConsensus.Beacon.PendingBlocks do
34
34
@ spec add_block ( SignedBeaconBlock . t ( ) ) :: :ok
35
35
def add_block ( signed_block ) do
36
36
block_info = BlockInfo . from_block ( signed_block )
37
-
38
- # If the block is new or was to be downloaded, we store it.
39
37
loaded_block = Blocks . get_block_info ( block_info . root )
40
38
39
+ # If the block is new or was to be downloaded, we store it.
41
40
if is_nil ( loaded_block ) or loaded_block . status == :download do
42
41
missing_blobs = missing_blobs ( block_info )
43
42
@@ -130,10 +129,8 @@ defmodule LambdaEthereumConsensus.Beacon.PendingBlocks do
130
129
# To be used when a series of blobs are downloaded. Stores each blob.
131
130
# If there are blocks that can be processed, does so immediately.
132
131
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 )
137
134
|> Enum . uniq ( )
138
135
|> Enum . each ( fn root ->
139
136
with % BlockInfo { } = block_info <- Blocks . get_block_info ( root ) do
Original file line number Diff line number Diff line change @@ -13,7 +13,10 @@ defmodule LambdaEthereumConsensus.Store.BlobDb do
13
13
@ blobdata_prefix "blobdata"
14
14
@ block_root_prefix "block_root"
15
15
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 ( )
17
20
def store_blob ( % BlobSidecar { signed_block_header: % { message: block_header } } = blob ) do
18
21
block_root = Ssz . hash_tree_root! ( block_header )
19
22
{ :ok , encoded_blob } = Ssz . to_ssz ( blob )
@@ -29,6 +32,7 @@ defmodule LambdaEthereumConsensus.Store.BlobDb do
29
32
30
33
block_root_key = block_root_key ( block_header . slot , blob . index )
31
34
Db . put ( block_root_key , block_root )
35
+ block_root
32
36
end
33
37
34
38
# TODO: this is only used for tests
Original file line number Diff line number Diff line change @@ -77,7 +77,11 @@ defmodule LambdaEthereumConsensus.Store.Blocks do
77
77
@ spec new_block_info ( BlockInfo . t ( ) ) :: :ok
78
78
def new_block_info ( block_info ) do
79
79
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 )
81
85
end
82
86
83
87
@ doc """
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ defmodule Unit.P2p.RequestsTest do
10
10
Requests . handle_response ( requests , "some response" , "fake id" )
11
11
end
12
12
13
- test "A requests object should handle a request only once" do
13
+ test "A requests object should handler a request only once" do
14
14
requests = Requests . new ( )
15
15
pid = self ( )
16
16
You can’t perform that action at this time.
0 commit comments