Substrate.from() (#426)

* Substrate.from()

* Fix some transaction validation code

* must be more specific for matching now.

* Update `wasm-builder` and add `build-only-wasm` script

* Update to latest service builder interfaces

* ANother substrate update

* Another update
This commit is contained in:
Gavin Wood
2019-09-11 13:14:20 +02:00
committed by GitHub
parent 5590ba2fbe
commit 28e23d07ef
25 changed files with 1471 additions and 1230 deletions
+26 -21
View File
@@ -84,9 +84,8 @@ macro_rules! new_full_start {
let builder = service::ServiceBuilder::new_full::<
Block, RuntimeApi, polkadot_executor::Executor
>($config)?
.with_select_chain(|_config, client| {
#[allow(deprecated)]
Ok(client::LongestChain::new(client.backend().clone()))
.with_select_chain(|_, backend| {
Ok(client::LongestChain::new(backend.clone()))
})?
.with_transaction_pool(|config, client|
Ok(transaction_pool::txpool::Pool::new(config, transaction_pool::ChainApi::new(client)))
@@ -137,12 +136,20 @@ pub fn new_full(config: Configuration<CustomConfiguration, GenesisConfig>)
CallExecutor = impl CallExecutor<Block, Blake2Hasher> + Clone + Send + Sync + 'static,
>, ServiceError>
{
let is_authority = config.roles.is_authority();
let is_collator = config.custom.collating_for.is_some();
let force_authoring = config.force_authoring;
let max_block_data_size = config.custom.max_block_data_size;
let db_path = config.database_path.clone();
let disable_grandpa = config.disable_grandpa;
let name = config.name.clone();
let (builder, mut import_setup, inherent_data_providers, mut tasks_to_spawn) = new_full_start!(config);
let service = builder
.with_network_protocol(|config| Ok(PolkadotProtocol::new(config.custom.collating_for.clone())))?
.with_finality_proof_provider(|client|
Ok(Arc::new(GrandpaFinalityProofProvider::new(client.clone(), client)) as _)
.with_finality_proof_provider(|client, backend|
Ok(Arc::new(GrandpaFinalityProofProvider::new(backend, client)) as _)
)?
.build()?;
@@ -160,7 +167,7 @@ pub fn new_full(config: Configuration<CustomConfiguration, GenesisConfig>)
}
}
if service.config().custom.collating_for.is_some() {
if is_collator {
info!(
"The node cannot start as an authority because it is also configured to run as a collator."
);
@@ -201,11 +208,11 @@ pub fn new_full(config: Configuration<CustomConfiguration, GenesisConfig>)
(is_known, client.clone()),
);
if service.config().roles.is_authority() {
if is_authority {
let availability_store = {
use std::path::PathBuf;
let mut path = PathBuf::from(service.config().database_path.clone());
let mut path = PathBuf::from(db_path);
path.push("availability");
av_store::Store::new(::av_store::Config {
@@ -239,7 +246,7 @@ pub fn new_full(config: Configuration<CustomConfiguration, GenesisConfig>)
service.keystore(),
availability_store,
polkadot_runtime::constants::time::SLOT_DURATION,
service.config().custom.max_block_data_size,
max_block_data_size,
);
let client = service.client();
@@ -254,7 +261,7 @@ pub fn new_full(config: Configuration<CustomConfiguration, GenesisConfig>)
env: proposer,
sync_oracle: service.network(),
inherent_data_providers: inherent_data_providers.clone(),
force_authoring: service.config().force_authoring,
force_authoring: force_authoring,
time_source: babe_link,
};
@@ -269,11 +276,11 @@ pub fn new_full(config: Configuration<CustomConfiguration, GenesisConfig>)
// FIXME substrate#1578 make this available through chainspec
gossip_duration: Duration::from_millis(333),
justification_period: 4096,
name: Some(service.config().name.clone()),
name: Some(name),
keystore: Some(service.keystore()),
};
match (service.config().roles.is_authority(), service.config().disable_grandpa) {
match (is_authority, disable_grandpa) {
(false, false) => {
// start the lightweight GRANDPA observer
service.spawn_task(Box::new(grandpa::run_grandpa_observer(
@@ -319,21 +326,19 @@ pub fn new_light(config: Configuration<CustomConfiguration, GenesisConfig>)
let inherent_data_providers = InherentDataProviders::new();
ServiceBuilder::new_light::<Block, RuntimeApi, polkadot_executor::Executor>(config)?
.with_select_chain(|_config, client| {
#[allow(deprecated)]
Ok(LongestChain::new(client.backend().clone()))
.with_select_chain(|_, backend| {
Ok(LongestChain::new(backend.clone()))
})?
.with_transaction_pool(|config, client|
Ok(TransactionPool::new(config, transaction_pool::ChainApi::new(client)))
)?
.with_import_queue_and_fprb(|_config, client, _select_chain, transaction_pool| {
#[allow(deprecated)]
let fetch_checker = client.backend().blockchain().fetcher()
.with_import_queue_and_fprb(|_config, client, backend, _select_chain, transaction_pool| {
let fetch_checker = backend.blockchain().fetcher()
.upgrade()
.map(|fetcher| fetcher.checker().clone())
.ok_or_else(|| "Trying to start light import queue without active fetch checker")?;
let block_import = grandpa::light_block_import::<_, _, _, RuntimeApi, _>(
client.clone(), Arc::new(fetch_checker), client.clone()
client.clone(), backend, Arc::new(fetch_checker), client.clone()
)?;
let finality_proof_import = block_import.clone();
@@ -355,8 +360,8 @@ pub fn new_light(config: Configuration<CustomConfiguration, GenesisConfig>)
Ok((import_queue, finality_proof_request_builder))
})?
.with_network_protocol(|config| Ok(PolkadotProtocol::new(config.custom.collating_for.clone())))?
.with_finality_proof_provider(|client|
Ok(Arc::new(GrandpaFinalityProofProvider::new(client.clone(), client)) as _)
.with_finality_proof_provider(|client, backend|
Ok(Arc::new(GrandpaFinalityProofProvider::new(backend, client)) as _)
)?
.build()
}