Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 2% blocks missed after sync aggregate addition #1297

Merged
merged 4 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
19 changes: 14 additions & 5 deletions lib/lambda_ethereum_consensus/validator/block_builder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}}
Expand Down Expand Up @@ -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(
Expand All @@ -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 = %{
Expand Down Expand Up @@ -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{
Expand Down
3 changes: 3 additions & 0 deletions lib/lambda_ethereum_consensus/validator/duties.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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: (#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 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
Expand Down
Loading