@@ -69,9 +69,10 @@ defmodule LambdaEthereumConsensus.P2P.Gossip.OperationsCollector do
69
69
get_operation ( :voluntary_exit , count )
70
70
end
71
71
72
- @ spec get_attestations ( non_neg_integer ( ) ) :: list ( Types.Attestation . t ( ) )
73
- def get_attestations ( count ) do
74
- get_operation ( :attestation , count )
72
+ @ spec get_attestations ( non_neg_integer ( ) , Types . slot ( ) ) :: list ( Types.Attestation . t ( ) )
73
+ def get_attestations ( count , slot ) do
74
+ slot = slot || fetch_slot! ( )
75
+ get_operation ( :attestation , count , & ignore? ( & 1 , slot ) )
75
76
end
76
77
77
78
@ spec get_sync_committee_contributions ( ) :: list ( Types.SignedContributionAndProof . t ( ) )
@@ -141,16 +142,22 @@ defmodule LambdaEthereumConsensus.P2P.Gossip.OperationsCollector do
141
142
defp get_operation ( operation , count ) when operation in @ operations do
142
143
# NOTE: we don't remove these from the db, since after a block is built
143
144
# :new_block will be called, and already added messages will be removed
145
+ operation
146
+ |> fetch_operation! ( )
147
+ |> cap_operations ( count )
148
+ end
144
149
145
- slot = fetch_slot! ( )
146
-
147
- operations = fetch_operation! ( operation )
148
-
149
- if count == :all ,
150
- do: operations |> Enum . reject ( & ignore? ( & 1 , slot ) ) ,
151
- else: operations |> Stream . reject ( & ignore? ( & 1 , slot ) ) |> Enum . take ( count )
150
+ defp get_operation ( operation , count , filter ) when operation in @ operations do
151
+ operation
152
+ |> fetch_operation! ( )
153
+ |> Stream . reject ( filter )
154
+ |> cap_operations ( count )
152
155
end
153
156
157
+ defp cap_operations ( % Stream { } = operations , :all ) , do: Enum . to_list ( operations )
158
+ defp cap_operations ( operations , :all ) , do: operations
159
+ defp cap_operations ( operations , count ) , do: Enum . take ( operations , count )
160
+
154
161
@ impl true
155
162
def handle_gossip_message ( store , topic , msg_id , message ) do
156
163
handle_gossip_message ( topic , msg_id , message )
@@ -166,14 +173,10 @@ defmodule LambdaEthereumConsensus.P2P.Gossip.OperationsCollector do
166
173
{ :ok ,
167
174
% Types.SignedAggregateAndProof { message: % Types.AggregateAndProof { aggregate: aggregate } } } <-
168
175
Ssz . from_ssz ( uncompressed , Types.SignedAggregateAndProof ) do
169
- votes = BitField . count ( aggregate . aggregation_bits )
170
- slot = aggregate . data . slot
171
- root = aggregate . data . beacon_block_root |> Base . encode16 ( )
172
-
173
176
Logger . debug (
174
- "[Gossip] Aggregate decoded. Total attestations: #{ votes } " ,
175
- slot: slot ,
176
- root: root
177
+ "[Gossip] Aggregate decoded. Total attestations: #{ BitField . count ( aggregate . aggregation_bits ) } " ,
178
+ slot: aggregate . data . slot ,
179
+ root: aggregate . data . beacon_block_root
177
180
)
178
181
179
182
# We are getting ~500 attestations in half a second. This is overwhelming the store GenServer at the moment.
@@ -271,11 +274,10 @@ defmodule LambdaEthereumConsensus.P2P.Gossip.OperationsCollector do
271
274
defp ignore? ( % Types.Attestation { } , nil ) , do: false
272
275
273
276
defp ignore? ( % Types.Attestation { data: data } , slot ) do
277
+ # Right now this preset is 1, so we add every attestation ASAP, but it could be changed in the future
274
278
data . slot + ChainSpec . get ( "MIN_ATTESTATION_INCLUSION_DELAY" ) > slot
275
279
end
276
280
277
- defp ignore? ( _ , _ ) , do: false
278
-
279
281
defp update_operation ( operation , f ) when is_function ( f ) do
280
282
fetch_operation! ( operation )
281
283
|> f . ( )
0 commit comments