Companion PR for Add a build-sync-spec subcommand and remove the CHT roots from the light sync state. (#1670)

* Add BuildSyncSpec

* Remove accidental whitespace

* Update substrate

* Update substrate

* Fix wasm compilation
This commit is contained in:
Ashley
2020-09-11 17:08:03 +02:00
committed by GitHub
parent 84f2ab3d7f
commit 5c1553be27
6 changed files with 309 additions and 181 deletions
+45
View File
@@ -349,3 +349,48 @@ impl sc_client_api::StorageProvider<Block, crate::FullBackend> for Client {
}
}
}
impl sp_blockchain::HeaderBackend<Block> for Client {
fn header(&self, id: BlockId<Block>) -> sp_blockchain::Result<Option<<Block as BlockT>::Header>> {
match self {
Self::Polkadot(client) => client.header(&id),
Self::Westend(client) => client.header(&id),
Self::Kusama(client) => client.header(&id),
}
}
fn info(&self) -> sp_blockchain::Info<Block> {
match self {
Self::Polkadot(client) => client.info(),
Self::Westend(client) => client.info(),
Self::Kusama(client) => client.info(),
}
}
fn status(&self, id: BlockId<Block>) -> sp_blockchain::Result<sp_blockchain::BlockStatus> {
match self {
Self::Polkadot(client) => client.status(id),
Self::Westend(client) => client.status(id),
Self::Kusama(client) => client.status(id),
}
}
fn number(
&self,
hash: <Block as BlockT>::Hash
) -> sp_blockchain::Result<Option<NumberFor<Block>>> {
match self {
Self::Polkadot(client) => client.number(hash),
Self::Westend(client) => client.number(hash),
Self::Kusama(client) => client.number(hash),
}
}
fn hash(&self, number: NumberFor<Block>) -> sp_blockchain::Result<Option<<Block as BlockT>::Hash>> {
match self {
Self::Polkadot(client) => client.hash(number),
Self::Westend(client) => client.hash(number),
Self::Kusama(client) => client.hash(number),
}
}
}
+85 -40
View File
@@ -243,6 +243,30 @@ pub fn new_partial<RuntimeApi, Executor>(config: &mut Configuration, test: bool)
})
}
#[cfg(feature = "full-node")]
pub struct NewFull<C> {
pub task_manager: TaskManager,
pub client: C,
pub node_handles: FullNodeHandles,
pub network: Arc<sc_network::NetworkService<Block, <Block as BlockT>::Hash>>,
pub network_status_sinks: service::NetworkStatusSinks<Block>,
pub rpc_handlers: RpcHandlers,
}
#[cfg(feature = "full-node")]
impl<C> NewFull<C> {
fn with_client(self, func: impl FnOnce(C) -> Client) -> NewFull<Client> {
NewFull {
client: func(self.client),
task_manager: self.task_manager,
node_handles: self.node_handles,
network: self.network,
network_status_sinks: self.network_status_sinks,
rpc_handlers: self.rpc_handlers,
}
}
}
#[cfg(feature = "full-node")]
pub fn new_full<RuntimeApi, Executor>(
mut config: Configuration,
@@ -250,13 +274,7 @@ pub fn new_full<RuntimeApi, Executor>(
authority_discovery_enabled: bool,
grandpa_pause: Option<(u32, u32)>,
test: bool,
) -> Result<(
TaskManager,
Arc<FullClient<RuntimeApi, Executor>>,
FullNodeHandles,
Arc<sc_network::NetworkService<Block, <Block as BlockT>::Hash>>,
RpcHandlers,
), Error>
) -> Result<NewFull<Arc<FullClient<RuntimeApi, Executor>>>, Error>
where
RuntimeApi: ConstructRuntimeApi<Block, FullClient<RuntimeApi, Executor>> + Send + Sync + 'static,
RuntimeApi::RuntimeApi:
@@ -318,7 +336,8 @@ pub fn new_full<RuntimeApi, Executor>(
on_demand: None,
remote_blockchain: None,
telemetry_connection_sinks: telemetry_connection_sinks.clone(),
network_status_sinks, system_rpc_tx,
network_status_sinks: network_status_sinks.clone(),
system_rpc_tx,
})?;
let (block_import, link_half, babe_link) = import_setup;
@@ -457,7 +476,45 @@ pub fn new_full<RuntimeApi, Executor>(
network_starter.start_network();
Ok((task_manager, client, FullNodeHandles, network, rpc_handlers))
Ok(NewFull {
task_manager, client, node_handles: FullNodeHandles, network, network_status_sinks,
rpc_handlers,
})
}
#[cfg(feature = "full-node")]
pub fn new_full_nongeneric(
config: Configuration,
collating_for: Option<(CollatorId, parachain::Id)>,
authority_discovery_enabled: bool,
grandpa_pause: Option<(u32, u32)>,
test: bool,
) -> Result<NewFull<Client>, Error> {
if config.chain_spec.is_kusama() {
new_full::<kusama_runtime::RuntimeApi, KusamaExecutor>(
config,
collating_for,
authority_discovery_enabled,
grandpa_pause,
test,
).map(|full| full.with_client(Client::Kusama))
} else if config.chain_spec.is_westend() {
new_full::<westend_runtime::RuntimeApi, WestendExecutor>(
config,
collating_for,
authority_discovery_enabled,
grandpa_pause,
false,
).map(|full| full.with_client(Client::Westend))
} else {
new_full::<polkadot_runtime::RuntimeApi, PolkadotExecutor>(
config,
collating_for,
authority_discovery_enabled,
grandpa_pause,
false,
).map(|full| full.with_client(Client::Polkadot))
}
}
/// Builds a new service for a light client.
@@ -607,7 +664,9 @@ pub fn polkadot_new_full(
FullNodeHandles,
), ServiceError>
{
let (service, client, handles, _, _) = new_full::<polkadot_runtime::RuntimeApi, PolkadotExecutor>(
let NewFull {
task_manager, client, node_handles, ..
} = new_full::<polkadot_runtime::RuntimeApi, PolkadotExecutor>(
config,
collating_for,
authority_discovery_enabled,
@@ -615,7 +674,7 @@ pub fn polkadot_new_full(
false,
)?;
Ok((service, client, handles))
Ok((task_manager, client, node_handles))
}
/// Create a new Kusama service for a full node.
@@ -631,7 +690,9 @@ pub fn kusama_new_full(
FullNodeHandles
), ServiceError>
{
let (service, client, handles, _, _) = new_full::<kusama_runtime::RuntimeApi, KusamaExecutor>(
let NewFull {
task_manager, client, node_handles, ..
} = new_full::<kusama_runtime::RuntimeApi, KusamaExecutor>(
config,
collating_for,
authority_discovery_enabled,
@@ -639,7 +700,7 @@ pub fn kusama_new_full(
false,
)?;
Ok((service, client, handles))
Ok((task_manager, client, node_handles))
}
/// Create a new Westend service for a full node.
@@ -656,7 +717,9 @@ pub fn westend_new_full(
FullNodeHandles,
), ServiceError>
{
let (service, client, handles, _, _) = new_full::<westend_runtime::RuntimeApi, WestendExecutor>(
let NewFull {
task_manager, client, node_handles, ..
} = new_full::<westend_runtime::RuntimeApi, WestendExecutor>(
config,
collating_for,
authority_discovery_enabled,
@@ -664,7 +727,7 @@ pub fn westend_new_full(
false,
)?;
Ok((service, client, handles))
Ok((task_manager, client, node_handles))
}
/// Handles to other sub-services that full nodes instantiate, which consumers
@@ -692,29 +755,11 @@ pub fn build_full(
authority_discovery_enabled: bool,
grandpa_pause: Option<(u32, u32)>,
) -> Result<(TaskManager, Client, FullNodeHandles), ServiceError> {
if config.chain_spec.is_kusama() {
new_full::<kusama_runtime::RuntimeApi, KusamaExecutor>(
config,
collating_for,
authority_discovery_enabled,
grandpa_pause,
false,
).map(|(task_manager, client, handles, _, _)| (task_manager, Client::Kusama(client), handles))
} else if config.chain_spec.is_westend() {
new_full::<westend_runtime::RuntimeApi, WestendExecutor>(
config,
collating_for,
authority_discovery_enabled,
grandpa_pause,
false,
).map(|(task_manager, client, handles, _, _)| (task_manager, Client::Westend(client), handles))
} else {
new_full::<polkadot_runtime::RuntimeApi, PolkadotExecutor>(
config,
collating_for,
authority_discovery_enabled,
grandpa_pause,
false,
).map(|(task_manager, client, handles, _, _)| (task_manager, Client::Polkadot(client), handles))
}
new_full_nongeneric(
config,
collating_for,
authority_discovery_enabled,
grandpa_pause,
false,
).map(|NewFull { task_manager, client, node_handles, .. }| (task_manager, client, node_handles))
}