From 1b4679e5bcac6799a5712ab1c1c29a86625d2ea5 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Tue, 3 Sep 2019 14:18:45 +1000 Subject: [PATCH] Improve block processing outcomes enum --- beacon_node/beacon_chain/src/beacon_chain.rs | 23 ++++++++++++++------ beacon_node/network/src/sync/manager.rs | 8 ++++++- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/beacon_node/beacon_chain/src/beacon_chain.rs b/beacon_node/beacon_chain/src/beacon_chain.rs index 97af437187..72400bd538 100644 --- a/beacon_node/beacon_chain/src/beacon_chain.rs +++ b/beacon_node/beacon_chain/src/beacon_chain.rs @@ -46,11 +46,14 @@ pub enum BlockProcessingOutcome { block_slot: Slot, }, /// The block state_root does not match the generated state. - StateRootMismatch, + StateRootMismatch { block: Hash256, local: Hash256 }, /// The block was a genesis block, these blocks cannot be re-imported. GenesisBlock, /// The slot is finalized, no need to import. - FinalizedSlot, + WouldRevertFinalizedSlot { + block_slot: Slot, + finalized_slot: Slot, + }, /// Block is already known, no need to re-import. BlockIsAlreadyKnown, /// The block could not be applied to the state, it is invalid. @@ -957,14 +960,17 @@ impl BeaconChain { .epoch .start_slot(T::EthSpec::slots_per_epoch()); - if block.slot <= finalized_slot { - return Ok(BlockProcessingOutcome::FinalizedSlot); - } - if block.slot == 0 { return Ok(BlockProcessingOutcome::GenesisBlock); } + if block.slot <= finalized_slot { + return Ok(BlockProcessingOutcome::WouldRevertFinalizedSlot { + block_slot: block.slot, + finalized_slot: finalized_slot, + }); + } + let block_root_timer = metrics::start_timer(&metrics::BLOCK_PROCESSING_BLOCK_ROOT); let block_root = block.canonical_root(); @@ -1062,7 +1068,10 @@ impl BeaconChain { let state_root = state.canonical_root(); if block.state_root != state_root { - return Ok(BlockProcessingOutcome::StateRootMismatch); + return Ok(BlockProcessingOutcome::StateRootMismatch { + block: block.state_root, + local: state_root, + }); } metrics::stop_timer(state_root_timer); diff --git a/beacon_node/network/src/sync/manager.rs b/beacon_node/network/src/sync/manager.rs index b81da0991f..9cce6300df 100644 --- a/beacon_node/network/src/sync/manager.rs +++ b/beacon_node/network/src/sync/manager.rs @@ -682,13 +682,19 @@ impl ImportManager { ); } } - BlockProcessingOutcome::FinalizedSlot => { + BlockProcessingOutcome::WouldRevertFinalizedSlot { .. } => { trace!( self.log, "Finalized or earlier block processed"; "outcome" => format!("{:?}", outcome), ); // block reached our finalized slot or was earlier, move to the next block } + BlockProcessingOutcome::GenesisBlock => { + trace!( + self.log, "Genesis block was processed"; + "outcome" => format!("{:?}", outcome), + ); + } _ => { trace!( self.log, "InvalidBlock";