From 535819263d6143184608c17ae08a5332ba7af48d Mon Sep 17 00:00:00 2001 From: tersec Date: Wed, 7 Aug 2024 11:14:57 +0000 Subject: [PATCH] clear old electra attestations from attestation pool --- .../consensus_object_pools/attestation_pool.nim | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/beacon_chain/consensus_object_pools/attestation_pool.nim b/beacon_chain/consensus_object_pools/attestation_pool.nim index f4c847e45..fff1949c3 100644 --- a/beacon_chain/consensus_object_pools/attestation_pool.nim +++ b/beacon_chain/consensus_object_pools/attestation_pool.nim @@ -200,6 +200,7 @@ proc addForkChoiceVotes( error "Couldn't add attestation to fork choice, bug?", err = v.error() func candidateIdx(pool: AttestationPool, slot: Slot): Opt[int] = + static: doAssert pool.phase0Candidates.len == pool.electraCandidates.len if slot >= pool.startingSlot and slot < (pool.startingSlot + pool.phase0Candidates.lenu64): Opt.some(int(slot mod pool.phase0Candidates.lenu64)) @@ -210,8 +211,8 @@ proc updateCurrent(pool: var AttestationPool, wallSlot: Slot) = if wallSlot + 1 < pool.phase0Candidates.lenu64: return # Genesis - let - newStartingSlot = wallSlot + 1 - pool.phase0Candidates.lenu64 + static: doAssert pool.phase0Candidates.len == pool.electraCandidates.len + let newStartingSlot = wallSlot + 1 - pool.phase0Candidates.lenu64 if newStartingSlot < pool.startingSlot: error "Current slot older than attestation pool view, clock reset?", @@ -224,10 +225,12 @@ proc updateCurrent(pool: var AttestationPool, wallSlot: Slot) = if newStartingSlot - pool.startingSlot >= pool.phase0Candidates.lenu64(): # In case many slots passed since the last update, avoid iterating over # the same indices over and over - pool.phase0Candidates = default(type(pool.phase0Candidates)) + pool.phase0Candidates.reset() + pool.electraCandidates.reset() else: for i in pool.startingSlot..newStartingSlot: pool.phase0Candidates[i.uint64 mod pool.phase0Candidates.lenu64].reset() + pool.electraCandidates[i.uint64 mod pool.electraCandidates.lenu64].reset() pool.startingSlot = newStartingSlot @@ -507,6 +510,7 @@ func covers*( if candidateIdx.isNone: return false + debugComment "foo" # needs to know more than attestationdata now #let attestation_data_root = hash_tree_root(data) #pool.electraCandidates[candidateIdx.get()].withValue(attestation_data_root, entry): @@ -651,7 +655,8 @@ func score( proc check_attestation_compatible*( dag: ChainDAGRef, state: ForkyHashedBeaconState, - attestation: SomeAttestation | electra.Attestation | electra.TrustedAttestation): Result[void, cstring] = + attestation: SomeAttestation | electra.Attestation | + electra.TrustedAttestation): Result[void, cstring] = let targetEpoch = attestation.data.target.epoch compatibleRoot = state.dependent_root(targetEpoch.get_previous_epoch)