diff --git a/substrate/client/api/src/client.rs b/substrate/client/api/src/client.rs index d941b9d906..ceb3601085 100644 --- a/substrate/client/api/src/client.rs +++ b/substrate/client/api/src/client.rs @@ -16,12 +16,11 @@ //! A set of APIs supported by the client along with their primitives. -use std::collections::HashMap; use futures::channel::mpsc; use sp_core::storage::StorageKey; use sp_runtime::{ - traits::{Block as BlockT, NumberFor}, - generic::BlockId + traits::{Block as BlockT, NumberFor}, + generic::BlockId }; use sp_consensus::BlockOrigin; @@ -38,7 +37,7 @@ pub type FinalityNotifications = mpsc::UnboundedReceiver = Option, ::Hash>>; +pub type ForkBlocks = Option, ::Hash)>>; /// Figure out the block type for a given type (for now, just a `Client`). pub trait BlockOf { diff --git a/substrate/client/src/client.rs b/substrate/client/src/client.rs index 0bd08548be..349cd816b2 100644 --- a/substrate/client/src/client.rs +++ b/substrate/client/src/client.rs @@ -1472,7 +1472,10 @@ impl<'a, B, E, Block, RA> sp_consensus::BlockImport for &'a Client Result { let BlockCheckParams { hash, number, parent_hash, allow_missing_state, import_existing } = block; - if let Some(h) = self.fork_blocks.as_ref().and_then(|x| x.get(&number)) { + let fork_block = self.fork_blocks.as_ref() + .and_then(|fs| fs.iter().find(|(n, _)| *n == number)); + + if let Some((_, h)) = fork_block { if &hash != h { trace!( "Rejecting block from known invalid fork. Got {:?}, expected: {:?} at height {}",