Skip to content

Commit dbcc068

Browse files
arnetheduckzah
authored andcommitted
delay pruning of cache for finalized epoch (fixes #2049)
1 parent 316a19a commit dbcc068

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

beacon_chain/block_pools/chain_dag.nim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,8 @@ proc updateHead*(
902902
while tmp != dag.finalizedHead.blck:
903903
# leave the epoch cache in the last block of the epoch..
904904
tmp = tmp.parent
905-
tmp.epochRefs = @[]
905+
if tmp.parent != nil:
906+
tmp.parent.epochRefs = @[]
906907

907908
dag.finalizedHead = finalizedHead
908909

beacon_chain/validator_duties.nim

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -405,11 +405,9 @@ proc handleAttestations(node: BeaconNode, head: BlockRef, slot: Slot) =
405405
proc handleProposal(node: BeaconNode, head: BlockRef, slot: Slot):
406406
Future[BlockRef] {.async.} =
407407
## Perform the proposal for the given slot, iff we have a validator attached
408-
## that is supposed to do so, given the shuffling in head
409-
410-
# TODO here we advance the state to the new slot, but later we'll be
411-
# proposing for it - basically, we're selecting proposer based on an
412-
# empty slot
408+
## that is supposed to do so, given the shuffling at that slot for the given
409+
## head - to compute the proposer, we need to advance a state to the given
410+
## slot
413411

414412
let proposer = node.chainDag.getProposer(head, slot)
415413
if proposer.isNone():

tests/test_block_pool.nim

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,9 @@ suiteReport "chain DAG finalization tests" & preset():
373373
check:
374374
dag.heads.len() == 1
375375

376-
let headER = dag.heads[0].findEpochRef(dag.heads[0].slot.epoch)
376+
let
377+
headER = dag.heads[0].findEpochRef(dag.heads[0].slot.epoch)
378+
finalER = dag.finalizedHead.blck.findEpochRef(dag.finalizedHead.slot.epoch)
377379
check:
378380

379381
# Epochrefs should share validator key set when the validator set is
@@ -385,10 +387,14 @@ suiteReport "chain DAG finalization tests" & preset():
385387
headER.validator_key_store[1] ==
386388
dag.heads[0].findEpochRef(dag.heads[0].slot.epoch - 1).validator_key_store[1]
387389

390+
# The EpochRef for the finalized block is needed for eth1 voting, so we
391+
# should never drop it!
392+
not finalER.isNil
393+
388394
block:
389395
var cur = dag.heads[0]
390396
while cur != nil:
391-
if cur.slot < dag.finalizedHead.blck.slot:
397+
if cur.slot < dag.finalizedHead.blck.parent.slot:
392398
# Cache should be cleaned on finalization
393399
check: cur.epochRefs.len == 0
394400
else:

0 commit comments

Comments
 (0)