From 95b55d71707f5f95007b388b37c3771c758d730c Mon Sep 17 00:00:00 2001 From: divma Date: Tue, 11 Aug 2020 01:30:26 +0000 Subject: [PATCH] Block error display (#1503) ## Issue Addressed #1486 --- beacon_node/beacon_chain/src/beacon_chain.rs | 7 +++---- beacon_node/beacon_chain/src/block_verification.rs | 11 +++++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/beacon_node/beacon_chain/src/beacon_chain.rs b/beacon_node/beacon_chain/src/beacon_chain.rs index bd2601213..1f55af8ae 100644 --- a/beacon_node/beacon_chain/src/beacon_chain.rs +++ b/beacon_node/beacon_chain/src/beacon_chain.rs @@ -70,7 +70,6 @@ pub const ETH1_CACHE_DB_KEY: [u8; 32] = [0; 32]; pub const FORK_CHOICE_DB_KEY: [u8; 32] = [0; 32]; /// The result of a chain segment processing. -#[derive(Debug)] pub enum ChainSegmentResult { /// Processing this chain segment finished successfully. Successful { imported_blocks: usize }, @@ -1310,7 +1309,7 @@ impl BeaconChain { debug!( self.log, "Rejected gossip block"; - "error" => format!("{:?}", e), + "error" => e.to_string(), "graffiti" => graffiti_string, "slot" => slot, ); @@ -1393,11 +1392,11 @@ impl BeaconChain { trace!( self.log, "Beacon block rejected"; - "reason" => format!("{:?}", other), + "reason" => other.to_string(), ); let _ = self.event_handler.register(EventKind::BeaconBlockRejected { - reason: format!("Invalid block: {:?}", other), + reason: format!("Invalid block: {}", other), block: Box::new(block), }); diff --git a/beacon_node/beacon_chain/src/block_verification.rs b/beacon_node/beacon_chain/src/block_verification.rs index f4581d77c..710e7606c 100644 --- a/beacon_node/beacon_chain/src/block_verification.rs +++ b/beacon_node/beacon_chain/src/block_verification.rs @@ -199,6 +199,17 @@ pub enum BlockError { BeaconChainError(BeaconChainError), } +impl std::fmt::Display for BlockError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + BlockError::ParentUnknown(block) => { + write!(f, "ParentUnknown(parent_root:{})", block.parent_root()) + } + other => write!(f, "{:?}", other), + } + } +} + impl From for BlockError { fn from(e: BlockSignatureVerifierError) -> Self { match e {