mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 03:01:07 +00:00
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:
committed by
Gavin Wood
parent
c555b9bf88
commit
667ee95f5d
@@ -39,12 +39,12 @@ use sr_primitives::{generic::BlockId, traits::Block as BlockT};
|
||||
/// Maximum duration of single wait call.
|
||||
const MAX_WAIT_TIME: Duration = Duration::from_secs(60 * 3);
|
||||
|
||||
struct TestNet<G, F, L, U> {
|
||||
struct TestNet<G, E, F, L, U> {
|
||||
runtime: Runtime,
|
||||
authority_nodes: Vec<(usize, SyncService<F>, U, Multiaddr)>,
|
||||
full_nodes: Vec<(usize, SyncService<F>, U, Multiaddr)>,
|
||||
light_nodes: Vec<(usize, SyncService<L>, Multiaddr)>,
|
||||
chain_spec: ChainSpec<G>,
|
||||
chain_spec: ChainSpec<G, E>,
|
||||
base_port: u16,
|
||||
nodes: usize,
|
||||
}
|
||||
@@ -79,7 +79,7 @@ impl<T: Future<Item=(), Error=service::Error>> Future for SyncService<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<G, F, L, U> TestNet<G, F, L, U>
|
||||
impl<G, E, F, L, U> TestNet<G, E, F, L, U>
|
||||
where F: Send + 'static, L: Send +'static, U: Clone + Send + 'static
|
||||
{
|
||||
pub fn run_until_all_full<FP, LP>(
|
||||
@@ -124,14 +124,14 @@ where F: Send + 'static, L: Send +'static, U: Clone + Send + 'static
|
||||
}
|
||||
}
|
||||
|
||||
fn node_config<G> (
|
||||
fn node_config<G, E: Clone> (
|
||||
index: usize,
|
||||
spec: &ChainSpec<G>,
|
||||
spec: &ChainSpec<G, E>,
|
||||
role: Roles,
|
||||
key_seed: Option<String>,
|
||||
base_port: u16,
|
||||
root: &TempDir,
|
||||
) -> Configuration<(), G>
|
||||
) -> Configuration<(), G, E>
|
||||
{
|
||||
let root = root.path().join(format!("node-{}", index));
|
||||
|
||||
@@ -193,18 +193,22 @@ fn node_config<G> (
|
||||
}
|
||||
}
|
||||
|
||||
impl<G, F, L, U> TestNet<G, F, L, U> where
|
||||
impl<G, E, F, L, U> TestNet<G, E, F, L, U> where
|
||||
F: AbstractService,
|
||||
L: AbstractService,
|
||||
E: Clone,
|
||||
{
|
||||
fn new(
|
||||
temp: &TempDir,
|
||||
spec: ChainSpec<G>,
|
||||
full: impl Iterator<Item = impl FnOnce(Configuration<(), G>) -> Result<(F, U), Error>>,
|
||||
light: impl Iterator<Item = impl FnOnce(Configuration<(), G>) -> Result<L, Error>>,
|
||||
authorities: impl Iterator<Item = (String, impl FnOnce(Configuration<(), G>) -> Result<(F, U), Error>)>,
|
||||
spec: ChainSpec<G, E>,
|
||||
full: impl Iterator<Item = impl FnOnce(Configuration<(), G, E>) -> Result<(F, U), Error>>,
|
||||
light: impl Iterator<Item = impl FnOnce(Configuration<(), G, E>) -> Result<L, Error>>,
|
||||
authorities: impl Iterator<Item = (
|
||||
String,
|
||||
impl FnOnce(Configuration<(), G, E>) -> Result<(F, U), Error>
|
||||
)>,
|
||||
base_port: u16
|
||||
) -> TestNet<G, F, L, U> {
|
||||
) -> TestNet<G, E, F, L, U> {
|
||||
let _ = env_logger::try_init();
|
||||
fdlimit::raise_fd_limit();
|
||||
let runtime = Runtime::new().expect("Error creating tokio runtime");
|
||||
@@ -224,9 +228,9 @@ impl<G, F, L, U> TestNet<G, F, L, U> where
|
||||
fn insert_nodes(
|
||||
&mut self,
|
||||
temp: &TempDir,
|
||||
full: impl Iterator<Item = impl FnOnce(Configuration<(), G>) -> Result<(F, U), Error>>,
|
||||
light: impl Iterator<Item = impl FnOnce(Configuration<(), G>) -> Result<L, Error>>,
|
||||
authorities: impl Iterator<Item = (String, impl FnOnce(Configuration<(), G>) -> Result<(F, U), Error>)>
|
||||
full: impl Iterator<Item = impl FnOnce(Configuration<(), G, E>) -> Result<(F, U), Error>>,
|
||||
light: impl Iterator<Item = impl FnOnce(Configuration<(), G, E>) -> Result<L, Error>>,
|
||||
authorities: impl Iterator<Item = (String, impl FnOnce(Configuration<(), G, E>) -> Result<(F, U), Error>)>
|
||||
) {
|
||||
let executor = self.runtime.executor();
|
||||
|
||||
@@ -274,16 +278,17 @@ impl<G, F, L, U> TestNet<G, F, L, U> where
|
||||
}
|
||||
}
|
||||
|
||||
pub fn connectivity<G, Fb, F, Lb, L>(
|
||||
spec: ChainSpec<G>,
|
||||
pub fn connectivity<G, E, Fb, F, Lb, L>(
|
||||
spec: ChainSpec<G, E>,
|
||||
full_builder: Fb,
|
||||
light_builder: Lb,
|
||||
light_node_interconnectivity: bool, // should normally be false, unless the light nodes
|
||||
// aren't actually light.
|
||||
) where
|
||||
Fb: Fn(Configuration<(), G>) -> Result<F, Error>,
|
||||
E: Clone,
|
||||
Fb: Fn(Configuration<(), G, E>) -> Result<F, Error>,
|
||||
F: AbstractService,
|
||||
Lb: Fn(Configuration<(), G>) -> Result<L, Error>,
|
||||
Lb: Fn(Configuration<(), G, E>) -> Result<L, Error>,
|
||||
L: AbstractService,
|
||||
{
|
||||
const NUM_FULL_NODES: usize = 5;
|
||||
@@ -377,20 +382,21 @@ pub fn connectivity<G, Fb, F, Lb, L>(
|
||||
}
|
||||
}
|
||||
|
||||
pub fn sync<G, Fb, F, Lb, L, B, E, U>(
|
||||
spec: ChainSpec<G>,
|
||||
pub fn sync<G, E, Fb, F, Lb, L, B, ExF, U>(
|
||||
spec: ChainSpec<G, E>,
|
||||
full_builder: Fb,
|
||||
light_builder: Lb,
|
||||
mut make_block_and_import: B,
|
||||
mut extrinsic_factory: E
|
||||
mut extrinsic_factory: ExF
|
||||
) where
|
||||
Fb: Fn(Configuration<(), G>) -> Result<(F, U), Error>,
|
||||
Fb: Fn(Configuration<(), G, E>) -> Result<(F, U), Error>,
|
||||
F: AbstractService,
|
||||
Lb: Fn(Configuration<(), G>) -> Result<L, Error>,
|
||||
Lb: Fn(Configuration<(), G, E>) -> Result<L, Error>,
|
||||
L: AbstractService,
|
||||
B: FnMut(&F, &mut U),
|
||||
E: FnMut(&F, &U) -> <F::Block as BlockT>::Extrinsic,
|
||||
ExF: FnMut(&F, &U) -> <F::Block as BlockT>::Extrinsic,
|
||||
U: Clone + Send + 'static,
|
||||
E: Clone,
|
||||
{
|
||||
const NUM_FULL_NODES: usize = 10;
|
||||
// FIXME: BABE light client support is currently not working.
|
||||
@@ -446,16 +452,17 @@ pub fn sync<G, Fb, F, Lb, L, B, E, U>(
|
||||
);
|
||||
}
|
||||
|
||||
pub fn consensus<G, Fb, F, Lb, L>(
|
||||
spec: ChainSpec<G>,
|
||||
pub fn consensus<G, E, Fb, F, Lb, L>(
|
||||
spec: ChainSpec<G, E>,
|
||||
full_builder: Fb,
|
||||
light_builder: Lb,
|
||||
authorities: impl IntoIterator<Item = String>
|
||||
) where
|
||||
Fb: Fn(Configuration<(), G>) -> Result<F, Error>,
|
||||
Fb: Fn(Configuration<(), G, E>) -> Result<F, Error>,
|
||||
F: AbstractService,
|
||||
Lb: Fn(Configuration<(), G>) -> Result<L, Error>,
|
||||
Lb: Fn(Configuration<(), G, E>) -> Result<L, Error>,
|
||||
L: AbstractService,
|
||||
E: Clone,
|
||||
{
|
||||
const NUM_FULL_NODES: usize = 10;
|
||||
const NUM_LIGHT_NODES: usize = 10;
|
||||
|
||||
Reference in New Issue
Block a user