Change the import queue traits to take &mut self instead of &self (#3058)

* SharedFinalityProofRequestBuilder -> BoxFinalityProofRequestBuilder

* SharedThings -> BoxThings

* Fix tests

* build_request_data now takes &mut self

* The other traits now also take &mut self

* More or less fix tests

* Fix tests

* Fix more tests

* Moar tests

* Don't call make_block_import multiple time

* Fix doctest
This commit is contained in:
Pierre Krieger
2019-07-09 17:11:25 +02:00
committed by Gavin Wood
parent e729dbabbe
commit d7b6720663
21 changed files with 268 additions and 150 deletions
+21 -6
View File
@@ -63,6 +63,21 @@ pub struct GrandpaBlockImport<B, E, Block: BlockT<Hash=H256>, RA, PRA, SC> {
api: Arc<PRA>,
}
impl<B, E, Block: BlockT<Hash=H256>, RA, PRA, SC: Clone> Clone for
GrandpaBlockImport<B, E, Block, RA, PRA, SC>
{
fn clone(&self) -> Self {
GrandpaBlockImport {
inner: self.inner.clone(),
select_chain: self.select_chain.clone(),
authority_set: self.authority_set.clone(),
send_voter_commands: self.send_voter_commands.clone(),
consensus_changes: self.consensus_changes.clone(),
api: self.api.clone(),
}
}
}
impl<B, E, Block: BlockT<Hash=H256>, RA, PRA, SC> JustificationImport<Block>
for GrandpaBlockImport<B, E, Block, RA, PRA, SC> where
NumberFor<Block>: grandpa::BlockNumberOps,
@@ -76,7 +91,7 @@ impl<B, E, Block: BlockT<Hash=H256>, RA, PRA, SC> JustificationImport<Block>
{
type Error = ConsensusError;
fn on_start(&self) -> Vec<(Block::Hash, NumberFor<Block>)> {
fn on_start(&mut self) -> Vec<(Block::Hash, NumberFor<Block>)> {
let mut out = Vec::new();
let chain_info = self.inner.info().chain;
@@ -106,7 +121,7 @@ impl<B, E, Block: BlockT<Hash=H256>, RA, PRA, SC> JustificationImport<Block>
}
fn import_justification(
&self,
&mut self,
hash: Block::Hash,
number: NumberFor<Block>,
justification: Justification,
@@ -390,7 +405,7 @@ impl<B, E, Block: BlockT<Hash=H256>, RA, PRA, SC> BlockImport<Block>
{
type Error = ConsensusError;
fn import_block(&self, mut block: ImportBlock<Block>, new_cache: HashMap<well_known_cache_keys::Id, Vec<u8>>)
fn import_block(&mut self, mut block: ImportBlock<Block>, new_cache: HashMap<well_known_cache_keys::Id, Vec<u8>>)
-> Result<ImportResult, Self::Error>
{
let hash = block.post_header().hash();
@@ -410,7 +425,7 @@ impl<B, E, Block: BlockT<Hash=H256>, RA, PRA, SC> BlockImport<Block>
// we don't want to finalize on `inner.import_block`
let mut justification = block.justification.take();
let enacts_consensus_change = !new_cache.is_empty();
let import_result = self.inner.import_block(block, new_cache);
let import_result = (&*self.inner).import_block(block, new_cache);
let mut imported_aux = {
match import_result {
@@ -504,7 +519,7 @@ impl<B, E, Block: BlockT<Hash=H256>, RA, PRA, SC> BlockImport<Block>
}
fn check_block(
&self,
&mut self,
hash: Block::Hash,
parent_hash: Block::Hash,
) -> Result<ImportResult, Self::Error> {
@@ -548,7 +563,7 @@ where
/// If `enacts_change` is set to true, then finalizing this block *must*
/// enact an authority set change, the function will panic otherwise.
fn import_justification(
&self,
&mut self,
hash: Block::Hash,
number: NumberFor<Block>,
justification: Justification,