avoid needlessly rescoring aggregates during block attestation packing (#5471)

This commit is contained in:
tersec 2023-10-04 22:38:10 +00:00 committed by GitHub
parent 672fc33586
commit 89686fa274
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)