From 65ef193ec8b1356f142ab9b04f580d9056636883 Mon Sep 17 00:00:00 2001 From: Marcio Diaz Date: Sat, 5 Oct 2019 10:43:19 +0200 Subject: [PATCH] Use header metadata in babe verify. (#3756) * Use header_metadata in verify. * Log hash in header_metadata error. * Fix naming, error. --- substrate/core/client/db/src/lib.rs | 4 ++-- substrate/core/client/db/src/light.rs | 2 +- substrate/core/client/src/in_mem.rs | 2 +- substrate/core/consensus/babe/src/lib.rs | 7 +++---- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/substrate/core/client/db/src/lib.rs b/substrate/core/client/db/src/lib.rs index 126622364a..7cc6ef54a0 100644 --- a/substrate/core/client/db/src/lib.rs +++ b/substrate/core/client/db/src/lib.rs @@ -42,7 +42,7 @@ use client::backend::NewBlockState; use client::blockchain::{well_known_cache_keys, HeaderBackend}; use client::{ForkBlocks, ExecutionStrategies}; use client::backend::{StorageCollection, ChildStorageCollection}; -use client::error::Result as ClientResult; +use client::error::{Result as ClientResult, Error as ClientError}; use codec::{Decode, Encode}; use hash_db::{Hasher, Prefix}; use kvdb::{KeyValueDB, DBTransaction}; @@ -417,7 +417,7 @@ impl HeaderMetadata for BlockchainDb { header_metadata.clone(), ); header_metadata - }).ok_or(client::error::Error::UnknownBlock("header not found in db".to_owned())) + }).ok_or(ClientError::UnknownBlock(format!("header not found in db: {}", hash))) }) } diff --git a/substrate/core/client/db/src/light.rs b/substrate/core/client/db/src/light.rs index 111b8e0deb..19fc7fde35 100644 --- a/substrate/core/client/db/src/light.rs +++ b/substrate/core/client/db/src/light.rs @@ -207,7 +207,7 @@ impl HeaderMetadata for LightStorage { header_metadata.clone(), ); header_metadata - }).ok_or(ClientError::UnknownBlock("header not found in db".to_owned())) + }).ok_or(ClientError::UnknownBlock(format!("header not found in db: {}", hash))) }) } diff --git a/substrate/core/client/src/in_mem.rs b/substrate/core/client/src/in_mem.rs index 99dc1b6263..5c35400d77 100644 --- a/substrate/core/client/src/in_mem.rs +++ b/substrate/core/client/src/in_mem.rs @@ -324,7 +324,7 @@ impl HeaderMetadata for Blockchain { fn header_metadata(&self, hash: Block::Hash) -> Result, Self::Error> { self.header(BlockId::hash(hash))?.map(|header| CachedHeaderMetadata::from(&header)) - .ok_or(error::Error::UnknownBlock("header not found".to_owned())) + .ok_or(error::Error::UnknownBlock(format!("header not found: {}", hash))) } fn insert_header_metadata(&self, _hash: Block::Hash, _metadata: CachedHeaderMetadata) { diff --git a/substrate/core/consensus/babe/src/lib.rs b/substrate/core/consensus/babe/src/lib.rs index 683425e815..000c14269f 100644 --- a/substrate/core/consensus/babe/src/lib.rs +++ b/substrate/core/consensus/babe/src/lib.rs @@ -593,9 +593,8 @@ impl Verifier for BabeVerifier(&header)?; let epoch = { @@ -603,7 +602,7 @@ impl Verifier for BabeVerifier