Block error display (#1503)

## Issue Addressed

#1486
This commit is contained in:
divma 2020-08-11 01:30:26 +00:00
parent 134676fd6f
commit 95b55d7170
2 changed files with 14 additions and 4 deletions

View File

@ -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<T: EthSpec> {
/// Processing this chain segment finished successfully.
Successful { imported_blocks: usize },
@ -1310,7 +1309,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
debug!(
self.log,
"Rejected gossip block";
"error" => format!("{:?}", e),
"error" => e.to_string(),
"graffiti" => graffiti_string,
"slot" => slot,
);
@ -1393,11 +1392,11 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
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),
});

View File

@ -199,6 +199,17 @@ pub enum BlockError<T: EthSpec> {
BeaconChainError(BeaconChainError),
}
impl<T: EthSpec> std::fmt::Display for BlockError<T> {
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<T: EthSpec> From<BlockSignatureVerifierError> for BlockError<T> {
fn from(e: BlockSignatureVerifierError) -> Self {
match e {