From 89686fa274ebf7d312b0f229ce51d56e0bc02a94 Mon Sep 17 00:00:00 2001 From: tersec Date: Wed, 4 Oct 2023 22:38:10 +0000 Subject: [PATCH] avoid needlessly rescoring aggregates during block attestation packing (#5471) --- beacon_chain/consensus_object_pools/attestation_pool.nim | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/beacon_chain/consensus_object_pools/attestation_pool.nim b/beacon_chain/consensus_object_pools/attestation_pool.nim index 8d37a51d7..19b801049 100644 --- a/beacon_chain/consensus_object_pools/attestation_pool.nim +++ b/beacon_chain/consensus_object_pools/attestation_pool.nim @@ -643,7 +643,7 @@ proc getAttestationsForBlock*(pool: var AttestationPool, var res: seq[Attestation] let totalCandidates = candidates.len() while candidates.len > 0 and res.lenu64() < MAX_ATTESTATIONS: - block: + let entryCacheKey = block: # Find the candidate with the highest score - slot is used as a # tie-breaker so that more recent attestations are added first let @@ -667,10 +667,16 @@ proc getAttestationsForBlock*(pool: var AttestationPool, # the score below attCache.add(entry[].data, entry[].aggregates[j].aggregation_bits) + entry[].data.getAttestationCacheKey + block: # Because we added some votes, it's quite possible that some candidates # are no longer interesting - update the scores of the existing candidates for it in candidates.mitems(): + # Aggregates not on the same (slot, committee) pair don't change scores + if it.entry[].data.getAttestationCacheKey != entryCacheKey: + continue + it.score = attCache.score( it.entry[].data, it.entry[].aggregates[it.validation].aggregation_bits)