From 2eef454fe764c5779210ffc7fe81986ec3ac5d31 Mon Sep 17 00:00:00 2001 From: Rodrigo Oliveri Date: Tue, 17 Sep 2024 15:56:56 -0300 Subject: [PATCH 1/4] Fix the contribution filter adding the check for the parent_root --- .../validator/block_builder.ex | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/lambda_ethereum_consensus/validator/block_builder.ex b/lib/lambda_ethereum_consensus/validator/block_builder.ex index aeb1042b5..fc1d5edc7 100644 --- a/lib/lambda_ethereum_consensus/validator/block_builder.ex +++ b/lib/lambda_ethereum_consensus/validator/block_builder.ex @@ -90,7 +90,11 @@ defmodule LambdaEthereumConsensus.Validator.BlockBuilder do bls_to_execution_changes: block_request.bls_to_execution_changes, blob_kzg_commitments: block_request.blob_kzg_commitments, sync_aggregate: - get_sync_aggregate(block_request.sync_committee_contributions, block_request.slot), + get_sync_aggregate( + block_request.sync_committee_contributions, + block_request.slot, + block_request.parent_root + ), execution_payload: execution_payload } }} @@ -205,12 +209,15 @@ defmodule LambdaEthereumConsensus.Validator.BlockBuilder do signature end - defp get_sync_aggregate(contributions, slot) do + defp get_sync_aggregate(contributions, slot, parent_root) do # We group by the contributions by subcommittee index, get only the ones related to the previous slot # and pick the one with the most amount of set bits in the aggregation bits. contributions = contributions - |> Enum.filter(&(&1.message.contribution.slot == slot - 1)) + |> Enum.filter( + &(&1.message.contribution.slot == slot - 1 && + &1.message.contribution.beacon_block_root == parent_root) + ) |> Enum.group_by(& &1.message.contribution.subcommittee_index) |> Enum.map(fn {_, contributions} -> Enum.max_by( @@ -221,7 +228,8 @@ defmodule LambdaEthereumConsensus.Validator.BlockBuilder do Logger.debug( "[BlockBuilder] Contributions to aggregate: #{inspect(contributions, pretty: true)}", - slot: slot + slot: slot, + root: parent_root ) aggregate_data = %{ @@ -257,7 +265,8 @@ defmodule LambdaEthereumConsensus.Validator.BlockBuilder do Logger.debug( "[BlockBuilder] SyncAggregate to construct: #{inspect(aggregate_data.signatures, pretty: true)}", bits: aggregate_data.aggregation_bits, - slot: slot + slot: slot, + root: parent_root ) %Types.SyncAggregate{ From 12bdf2a412ad15d581da7a941911fa1f61950c9b Mon Sep 17 00:00:00 2001 From: Rodrigo Oliveri Date: Tue, 17 Sep 2024 16:56:07 -0300 Subject: [PATCH 2/4] Discard old contributions from operations on operations update --- .../p2p/gossip/operations_collector.ex | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/lambda_ethereum_consensus/p2p/gossip/operations_collector.ex b/lib/lambda_ethereum_consensus/p2p/gossip/operations_collector.ex index b144f8a0b..02ec5834f 100644 --- a/lib/lambda_ethereum_consensus/p2p/gossip/operations_collector.ex +++ b/lib/lambda_ethereum_consensus/p2p/gossip/operations_collector.ex @@ -118,6 +118,12 @@ defmodule LambdaEthereumConsensus.P2P.Gossip.OperationsCollector do |> Enum.reject(&old_attestation?(&1, block.slot)) end) + # We only keep the last contributions for each slot, past ones are not needed + # since they are not included in the block when it is built. + update_operation(:sync_committee_contribution, fn values -> + Enum.reject(values, &(&1.message.contribution.slot < block.slot)) + end) + store_slot(block.slot) end From 7bf01a6f78cd3d3c0519fcdc7f4f230d41670913 Mon Sep 17 00:00:00 2001 From: Rodrigo Oliveri Date: Tue, 17 Sep 2024 17:06:03 -0300 Subject: [PATCH 3/4] Added a comment regarding epoch duties lookahead computation --- lib/lambda_ethereum_consensus/validator/duties.ex | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/lambda_ethereum_consensus/validator/duties.ex b/lib/lambda_ethereum_consensus/validator/duties.ex index d61c4bcb7..3a8e4337f 100644 --- a/lib/lambda_ethereum_consensus/validator/duties.ex +++ b/lib/lambda_ethereum_consensus/validator/duties.ex @@ -71,6 +71,9 @@ defmodule LambdaEthereumConsensus.Validator.Duties do ValidatorSet.validators() ) :: duties() def compute_duties_for_epochs(duties_map, epochs_and_start_slots, head_root, validators) do + # TODO: This function needs to be measured and optimized if possible, the main point to look + # at is the beacon fetch and sync committees computation. Also this could be done asynchronusly + # given that except for the first tame it always calculat 1 epoch ahead of time. Logger.debug("[Duties] Computing duties for epochs: #{inspect(epochs_and_start_slots)}") for {epoch, slot} <- epochs_and_start_slots, reduce: duties_map do From 3e2b76ca829f8369aea7bcbcc963736a7e329456 Mon Sep 17 00:00:00 2001 From: Rodrigo Oliveri Date: Thu, 19 Sep 2024 10:43:06 -0300 Subject: [PATCH 4/4] Added issue to TODO comment --- lib/lambda_ethereum_consensus/validator/duties.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/lambda_ethereum_consensus/validator/duties.ex b/lib/lambda_ethereum_consensus/validator/duties.ex index 3a8e4337f..8867ccf97 100644 --- a/lib/lambda_ethereum_consensus/validator/duties.ex +++ b/lib/lambda_ethereum_consensus/validator/duties.ex @@ -71,9 +71,9 @@ defmodule LambdaEthereumConsensus.Validator.Duties do ValidatorSet.validators() ) :: duties() def compute_duties_for_epochs(duties_map, epochs_and_start_slots, head_root, validators) do - # TODO: This function needs to be measured and optimized if possible, the main point to look + # TODO: (#1299) This function needs to be measured and optimized if possible, the main point to look # at is the beacon fetch and sync committees computation. Also this could be done asynchronusly - # given that except for the first tame it always calculat 1 epoch ahead of time. + # given that except for the first time it always calculat 1 epoch ahead of time. Logger.debug("[Duties] Computing duties for epochs: #{inspect(epochs_and_start_slots)}") for {epoch, slot} <- epochs_and_start_slots, reduce: duties_map do