Skip to content

Commit

Permalink
clear old electra attestations from attestation pool
Browse files Browse the repository at this point in the history
  • Loading branch information
tersec committed Aug 7, 2024
1 parent 053f78d commit 5358192
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions beacon_chain/consensus_object_pools/attestation_pool.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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?",
Expand All @@ -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

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 5358192

Please sign in to comment.