delay pruning of cache for finalized epoch (fixes #2049)

This commit is contained in:
Jacek Sieka 2020-11-20 15:16:04 +01:00 committed by zah
parent 316a19af5f
commit dbcc0686ff
3 changed files with 13 additions and 8 deletions

View File

@ -902,7 +902,8 @@ proc updateHead*(
while tmp != dag.finalizedHead.blck:
# leave the epoch cache in the last block of the epoch..
tmp = tmp.parent
tmp.epochRefs = @[]
if tmp.parent != nil:
tmp.parent.epochRefs = @[]
dag.finalizedHead = finalizedHead

View File

@ -405,11 +405,9 @@ proc handleAttestations(node: BeaconNode, head: BlockRef, slot: Slot) =
proc handleProposal(node: BeaconNode, head: BlockRef, slot: Slot):
Future[BlockRef] {.async.} =
## Perform the proposal for the given slot, iff we have a validator attached
## that is supposed to do so, given the shuffling in head
# TODO here we advance the state to the new slot, but later we'll be
# proposing for it - basically, we're selecting proposer based on an
# empty slot
## that is supposed to do so, given the shuffling at that slot for the given
## head - to compute the proposer, we need to advance a state to the given
## slot
let proposer = node.chainDag.getProposer(head, slot)
if proposer.isNone():

View File

@ -373,7 +373,9 @@ suiteReport "chain DAG finalization tests" & preset():
check:
dag.heads.len() == 1
let headER = dag.heads[0].findEpochRef(dag.heads[0].slot.epoch)
let
headER = dag.heads[0].findEpochRef(dag.heads[0].slot.epoch)
finalER = dag.finalizedHead.blck.findEpochRef(dag.finalizedHead.slot.epoch)
check:
# Epochrefs should share validator key set when the validator set is
@ -385,10 +387,14 @@ suiteReport "chain DAG finalization tests" & preset():
headER.validator_key_store[1] ==
dag.heads[0].findEpochRef(dag.heads[0].slot.epoch - 1).validator_key_store[1]
# The EpochRef for the finalized block is needed for eth1 voting, so we
# should never drop it!
not finalER.isNil
block:
var cur = dag.heads[0]
while cur != nil:
if cur.slot < dag.finalizedHead.blck.slot:
if cur.slot < dag.finalizedHead.blck.parent.slot:
# Cache should be cleaned on finalization
check: cur.epochRefs.len == 0
else: