From dbcc0686ff32621408c06c22250b812bc0865275 Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Fri, 20 Nov 2020 15:16:04 +0100 Subject: [PATCH] delay pruning of cache for finalized epoch (fixes #2049) --- beacon_chain/block_pools/chain_dag.nim | 3 ++- beacon_chain/validator_duties.nim | 8 +++----- tests/test_block_pool.nim | 10 ++++++++-- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/beacon_chain/block_pools/chain_dag.nim b/beacon_chain/block_pools/chain_dag.nim index 12a023fd1..301441ae4 100644 --- a/beacon_chain/block_pools/chain_dag.nim +++ b/beacon_chain/block_pools/chain_dag.nim @@ -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 diff --git a/beacon_chain/validator_duties.nim b/beacon_chain/validator_duties.nim index b4d0efad5..b0471f9d6 100644 --- a/beacon_chain/validator_duties.nim +++ b/beacon_chain/validator_duties.nim @@ -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(): diff --git a/tests/test_block_pool.nim b/tests/test_block_pool.nim index 29f30d8b3..6a4658f08 100644 --- a/tests/test_block_pool.nim +++ b/tests/test_block_pool.nim @@ -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: