Set uncles inherent (#3317)

* Include uncles

* Filter missing uncles

* Moved inherent registration to a new crate

* Ignore invalid inherent encoding
This commit is contained in:
Arkadiy Paronyan
2019-08-08 00:56:29 +02:00
committed by GitHub
parent ea58b7c92a
commit 58bd0d4c05
12 changed files with 319 additions and 82 deletions
+22 -1
View File
@@ -170,6 +170,13 @@ pub trait BlockBody<Block: BlockT> {
) -> error::Result<Option<Vec<<Block as BlockT>::Extrinsic>>>;
}
/// Provide a list of potential uncle headers for a given block.
pub trait ProvideUncles<Block: BlockT> {
/// Gets the uncles of the block with `target_hash` going back `max_generation` ancestors.
fn uncles(&self, target_hash: Block::Hash, max_generation: NumberFor<Block>)
-> error::Result<Vec<Block::Header>>;
}
/// Client info
#[derive(Debug)]
pub struct ClientInfo<Block: BlockT> {
@@ -1329,7 +1336,7 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
ancestor_hash = *current.parent_hash();
ancestor = load_header(ancestor_hash)?;
}
trace!("Collected {} uncles", uncles.len());
Ok(uncles)
}
@@ -1353,6 +1360,20 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
}
}
impl<B, E, Block, RA> ProvideUncles<Block> for Client<B, E, Block, RA> where
B: backend::Backend<Block, Blake2Hasher>,
E: CallExecutor<Block, Blake2Hasher>,
Block: BlockT<Hash=H256>,
{
fn uncles(&self, target_hash: Block::Hash, max_generation: NumberFor<Block>) -> error::Result<Vec<Block::Header>> {
Ok(Client::uncles(self, target_hash, max_generation)?
.into_iter()
.filter_map(|hash| Client::header(self, &BlockId::Hash(hash)).unwrap_or(None))
.collect()
)
}
}
impl<B, E, Block, RA> ChainHeaderBackend<Block> for Client<B, E, Block, RA> where
B: backend::Backend<Block, Blake2Hasher>,
E: CallExecutor<Block, Blake2Hasher> + Send + Sync,
+1 -1
View File
@@ -115,7 +115,7 @@ pub use crate::client::{
new_in_mem,
BlockBody, BlockStatus, ImportNotifications, FinalityNotifications, BlockchainEvents,
BlockImportNotification, Client, ClientInfo, ExecutionStrategies, FinalityNotification,
LongestChain, BlockOf,
LongestChain, BlockOf, ProvideUncles,
utils,
};
#[cfg(feature = "std")]