Skip to content

Commit 59eec20

Browse files
authored
fix: 2% blocks missed after sync aggregate addition (#1297)
1 parent 3ae84fc commit 59eec20

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

lib/lambda_ethereum_consensus/p2p/gossip/operations_collector.ex

+6
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ defmodule LambdaEthereumConsensus.P2P.Gossip.OperationsCollector do
118118
|> Enum.reject(&old_attestation?(&1, block.slot))
119119
end)
120120

121+
# We only keep the last contributions for each slot, past ones are not needed
122+
# since they are not included in the block when it is built.
123+
update_operation(:sync_committee_contribution, fn values ->
124+
Enum.reject(values, &(&1.message.contribution.slot < block.slot))
125+
end)
126+
121127
store_slot(block.slot)
122128
end
123129

lib/lambda_ethereum_consensus/validator/block_builder.ex

+14-5
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,11 @@ defmodule LambdaEthereumConsensus.Validator.BlockBuilder do
9090
bls_to_execution_changes: block_request.bls_to_execution_changes,
9191
blob_kzg_commitments: block_request.blob_kzg_commitments,
9292
sync_aggregate:
93-
get_sync_aggregate(block_request.sync_committee_contributions, block_request.slot),
93+
get_sync_aggregate(
94+
block_request.sync_committee_contributions,
95+
block_request.slot,
96+
block_request.parent_root
97+
),
9498
execution_payload: execution_payload
9599
}
96100
}}
@@ -205,12 +209,15 @@ defmodule LambdaEthereumConsensus.Validator.BlockBuilder do
205209
signature
206210
end
207211

208-
defp get_sync_aggregate(contributions, slot) do
212+
defp get_sync_aggregate(contributions, slot, parent_root) do
209213
# We group by the contributions by subcommittee index, get only the ones related to the previous slot
210214
# and pick the one with the most amount of set bits in the aggregation bits.
211215
contributions =
212216
contributions
213-
|> Enum.filter(&(&1.message.contribution.slot == slot - 1))
217+
|> Enum.filter(
218+
&(&1.message.contribution.slot == slot - 1 &&
219+
&1.message.contribution.beacon_block_root == parent_root)
220+
)
214221
|> Enum.group_by(& &1.message.contribution.subcommittee_index)
215222
|> Enum.map(fn {_, contributions} ->
216223
Enum.max_by(
@@ -221,7 +228,8 @@ defmodule LambdaEthereumConsensus.Validator.BlockBuilder do
221228

222229
Logger.debug(
223230
"[BlockBuilder] Contributions to aggregate: #{inspect(contributions, pretty: true)}",
224-
slot: slot
231+
slot: slot,
232+
root: parent_root
225233
)
226234

227235
aggregate_data = %{
@@ -257,7 +265,8 @@ defmodule LambdaEthereumConsensus.Validator.BlockBuilder do
257265
Logger.debug(
258266
"[BlockBuilder] SyncAggregate to construct: #{inspect(aggregate_data.signatures, pretty: true)}",
259267
bits: aggregate_data.aggregation_bits,
260-
slot: slot
268+
slot: slot,
269+
root: parent_root
261270
)
262271

263272
%Types.SyncAggregate{

lib/lambda_ethereum_consensus/validator/duties.ex

+3
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ defmodule LambdaEthereumConsensus.Validator.Duties do
7171
ValidatorSet.validators()
7272
) :: duties()
7373
def compute_duties_for_epochs(duties_map, epochs_and_start_slots, head_root, validators) do
74+
# TODO: (#1299) This function needs to be measured and optimized if possible, the main point to look
75+
# at is the beacon fetch and sync committees computation. Also this could be done asynchronusly
76+
# given that except for the first time it always calculat 1 epoch ahead of time.
7477
Logger.debug("[Duties] Computing duties for epochs: #{inspect(epochs_and_start_slots)}")
7578

7679
for {epoch, slot} <- epochs_and_start_slots, reduce: duties_map do

0 commit comments

Comments
 (0)