ChainSpec extensions (#3692)

* Add some chainspec tests and make sure we validate it.

* Manual implementation of Extension + Forks definitions.

* Move chain spec to separate crate.

* Allow using ChainSpec with extensions.

* Renames.

* Implement Extension derive.

* Implement Extension for Forks.

* Support specifying fork blocks.

* make for_blocks work

* Support forks correctly.

* Add a bunch of docs.

* Make fork blocks optional.

* Add missing docs.

* Fix build.

* Use struct for check_block params.

* Fix tests?

* Clean up.
This commit is contained in:
Tomasz Drwięga
2019-09-28 19:05:36 +02:00
committed by Gavin Wood
parent c555b9bf88
commit 667ee95f5d
39 changed files with 1368 additions and 336 deletions
@@ -27,7 +27,7 @@ use client::backend::Backend;
use client::utils::is_descendent_of;
use consensus_common::{
BlockImport, Error as ConsensusError,
BlockImportParams, ImportResult, JustificationImport,
BlockCheckParams, BlockImportParams, ImportResult, JustificationImport,
SelectChain,
};
use fg_primitives::{GRANDPA_ENGINE_ID, ScheduledChange, ConsensusLog};
@@ -386,9 +386,11 @@ impl<B, E, Block: BlockT<Hash=H256>, RA, SC> BlockImport<Block>
{
type Error = ConsensusError;
fn import_block(&mut self, mut block: BlockImportParams<Block>, new_cache: HashMap<well_known_cache_keys::Id, Vec<u8>>)
-> Result<ImportResult, Self::Error>
{
fn import_block(
&mut self,
mut block: BlockImportParams<Block>,
new_cache: HashMap<well_known_cache_keys::Id, Vec<u8>>,
) -> Result<ImportResult, Self::Error> {
let hash = block.post_header().hash();
let number = block.header.number().clone();
@@ -500,10 +502,9 @@ impl<B, E, Block: BlockT<Hash=H256>, RA, SC> BlockImport<Block>
fn check_block(
&mut self,
hash: Block::Hash,
parent_hash: Block::Hash,
block: BlockCheckParams<Block>,
) -> Result<ImportResult, Self::Error> {
self.inner.check_block(hash, parent_hash)
self.inner.check_block(block)
}
}
@@ -30,7 +30,7 @@ use codec::{Encode, Decode};
use consensus_common::{
import_queue::Verifier,
BlockOrigin, BlockImport, FinalityProofImport, BlockImportParams, ImportResult, ImportedAux,
Error as ConsensusError,
BlockCheckParams, Error as ConsensusError,
};
use network::config::{BoxFinalityProofRequestBuilder, FinalityProofRequestBuilder};
use sr_primitives::Justification;
@@ -142,10 +142,9 @@ impl<B, E, Block: BlockT<Hash=H256>, RA> BlockImport<Block>
fn check_block(
&mut self,
hash: Block::Hash,
parent_hash: Block::Hash,
block: BlockCheckParams<Block>,
) -> Result<ImportResult, Self::Error> {
self.client.check_block(hash, parent_hash)
self.client.check_block(block)
}
}
@@ -591,10 +590,9 @@ pub mod tests {
fn check_block(
&mut self,
hash: Block::Hash,
parent_hash: Block::Hash,
block: BlockCheckParams<Block>,
) -> Result<ImportResult, Self::Error> {
self.0.check_block(hash, parent_hash)
self.0.check_block(block)
}
}