Skip to content

Commit

Permalink
Feature/rust fmt (#62)
Browse files Browse the repository at this point in the history
* add rustfomt toml

* use rust fmt

* update rustfmt

* run rustfmt

* prune deps
  • Loading branch information
Satoshi-Kusumoto authored Aug 3, 2021
1 parent 0be7306 commit d9c7402
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 138 deletions.
42 changes: 14 additions & 28 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ impl Extensions {
type AccountPublic = <Signature as Verify>::Signer;

/// Helper function to generate an account ID from seed
pub fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId where
pub fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId
where
AccountPublic: From<<TPublic::Pair as Pair>::Public>,
{
AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()
Expand All @@ -51,10 +52,7 @@ pub fn get_chain_spec(id: ParaId) -> ChainSpec {
move || {
testnet_genesis(
get_account_id_from_seed::<sr25519::Public>("Alice"),
vec![
get_from_seed::<AuraId>("Alice"),
get_from_seed::<AuraId>("Bob"),
],
vec![get_from_seed::<AuraId>("Alice"), get_from_seed::<AuraId>("Bob")],
vec![
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_account_id_from_seed::<sr25519::Public>("Bob"),
Expand All @@ -76,10 +74,7 @@ pub fn get_chain_spec(id: ParaId) -> ChainSpec {
None,
None,
None,
Extensions {
relay_chain: "westend".into(),
para_id: id.into(),
},
Extensions { relay_chain: "westend".into(), para_id: id.into() },
)
}

Expand All @@ -100,7 +95,7 @@ pub fn staging_test_net(id: ParaId) -> ChainSpec {
.unchecked_into(),
],
vec![
hex!["9ed7705e3c7da027ba0583a22a3212042f7e715d3c168ba14f1424e2bc111d00"].into(),
hex!["9ed7705e3c7da027ba0583a22a3212042f7e715d3c168ba14f1424e2bc111d00"].into()
],
id,
)
Expand All @@ -109,10 +104,7 @@ pub fn staging_test_net(id: ParaId) -> ChainSpec {
None,
None,
None,
Extensions {
relay_chain: "westend".into(),
para_id: id.into(),
},
Extensions { relay_chain: "westend".into(), para_id: id.into() },
)
}

Expand All @@ -122,7 +114,6 @@ fn testnet_genesis(
endowed_accounts: Vec<AccountId>,
id: ParaId,
) -> parachain_runtime::GenesisConfig {

let num_endowed_accounts = endowed_accounts.len();

parachain_runtime::GenesisConfig {
Expand All @@ -133,29 +124,24 @@ fn testnet_genesis(
changes_trie_config: Default::default(),
},
balances: parachain_runtime::BalancesConfig {
balances: endowed_accounts
.iter()
.cloned()
.map(|k| (k, 1 << 60))
.collect(),
balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(),
},
sudo: parachain_runtime::SudoConfig { key: root_key },
orml_nft: Default::default(),
parachain_info: parachain_runtime::ParachainInfoConfig { parachain_id: id },
democracy: parachain_runtime::DemocracyConfig::default(),
council: parachain_runtime::CouncilConfig::default(),
technical_committee: parachain_runtime::TechnicalCommitteeConfig {
members: endowed_accounts.iter()
.take((num_endowed_accounts + 1) / 2)
.cloned()
.collect(),
members: endowed_accounts
.iter()
.take((num_endowed_accounts + 1) / 2)
.cloned()
.collect(),
phantom: Default::default(),
},
treasury: Default::default(),
aura: parachain_runtime::AuraConfig {
authorities: initial_authorities,
},
aura: parachain_runtime::AuraConfig { authorities: initial_authorities },
aura_ext: Default::default(),
parachain_system: Default::default(),
}
}
}
13 changes: 3 additions & 10 deletions node/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,7 @@ impl RelayChainCli {
) -> Self {
let extension = chain_spec::Extensions::try_get(&*para_config.chain_spec);
let chain_id = extension.map(|e| e.relay_chain.clone());
let base_path = para_config
.base_path
.as_ref()
.map(|x| x.path().join("polkadot"));
Self {
base_path,
chain_id,
base: polkadot_cli::RunCmd::from_iter(relay_chain_args),
}
let base_path = para_config.base_path.as_ref().map(|x| x.path().join("polkadot"));
Self { base_path, chain_id, base: polkadot_cli::RunCmd::from_iter(relay_chain_args) }
}
}
}
40 changes: 13 additions & 27 deletions node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn load_spec(
path => {
let chain_spec = chain_spec::ChainSpec::from_json_file(path.into())?;
Box::new(chain_spec)
}
},
})
}

Expand Down Expand Up @@ -149,27 +149,27 @@ pub fn run() -> Result<()> {
Some(Subcommand::BuildSpec(cmd)) => {
let runner = cli.create_runner(cmd)?;
runner.sync_run(|config| cmd.run(config.chain_spec, config.network))
}
},
Some(Subcommand::CheckBlock(cmd)) => {
construct_async_run!(|components, cli, cmd, config| {
Ok(cmd.run(components.client, components.import_queue))
})
}
},
Some(Subcommand::ExportBlocks(cmd)) => {
construct_async_run!(|components, cli, cmd, config| {
Ok(cmd.run(components.client, config.database))
})
}
},
Some(Subcommand::ExportState(cmd)) => {
construct_async_run!(|components, cli, cmd, config| {
Ok(cmd.run(components.client, config.chain_spec))
})
}
},
Some(Subcommand::ImportBlocks(cmd)) => {
construct_async_run!(|components, cli, cmd, config| {
Ok(cmd.run(components.client, components.import_queue))
})
}
},
Some(Subcommand::PurgeChain(cmd)) => {
let runner = cli.create_runner(cmd)?;

Expand All @@ -190,7 +190,7 @@ pub fn run() -> Result<()> {

cmd.run(config, polkadot_config)
})
}
},
Some(Subcommand::Revert(cmd)) => construct_async_run!(|components, cli, cmd, config| {
Ok(cmd.run(components.client, components.backend))
}),
Expand All @@ -217,7 +217,7 @@ pub fn run() -> Result<()> {
}

Ok(())
}
},
Some(Subcommand::ExportGenesisWasm(params)) => {
let mut builder = sc_cli::LoggerBuilder::new("");
builder.with_profiling(sc_tracing::TracingReceiver::Log, "");
Expand All @@ -238,12 +238,11 @@ pub fn run() -> Result<()> {
}

Ok(())
}
},
None => {
let runner = cli.create_runner(&cli.run.normalize())?;

runner.run_node_until_exit(|config| async move {

let para_id =
chain_spec::Extensions::try_get(&*config.chain_spec).map(|e| e.para_id);

Expand Down Expand Up @@ -271,23 +270,14 @@ pub fn run() -> Result<()> {
info!("Parachain id: {:?}", id);
info!("Parachain Account: {}", parachain_account);
info!("Parachain genesis state: {}", genesis_state);
info!(
"Is collating: {}",
if config.role.is_authority() {
"yes"
} else {
"no"
}
);

info!("Is collating: {}", if config.role.is_authority() { "yes" } else { "no" });

crate::service::start_rococo_parachain_node(config, polkadot_config, id)
.await
.map(|r| r.0)
.map_err(Into::into)

})
}
},
}
}

Expand Down Expand Up @@ -356,11 +346,7 @@ impl CliConfiguration<Self> for RelayChainCli {
fn chain_id(&self, is_dev: bool) -> Result<String> {
let chain_id = self.base.base.chain_id(is_dev)?;

Ok(if chain_id.is_empty() {
self.chain_id.clone().unwrap_or_default()
} else {
chain_id
})
Ok(if chain_id.is_empty() { self.chain_id.clone().unwrap_or_default() } else { chain_id })
}

fn role(&self, is_dev: bool) -> Result<sc_service::Role> {
Expand Down Expand Up @@ -417,4 +403,4 @@ impl CliConfiguration<Self> for RelayChainCli {
) -> Result<Option<sc_telemetry::TelemetryEndpoints>> {
self.base.base.telemetry_endpoints(chain_spec)
}
}
}
2 changes: 1 addition & 1 deletion node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ mod command;

fn main() -> sc_cli::Result<()> {
command::run()
}
}
69 changes: 36 additions & 33 deletions node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,22 +186,20 @@ where
) -> Result<Box<dyn ParachainConsensus<Block>>, sc_service::Error>,
{
if matches!(parachain_config.role, Role::Light) {
return Err("Light client not supported!".into());
return Err("Light client not supported!".into())
}

let parachain_config = prepare_node_config(parachain_config);

let params = new_partial::<RuntimeApi, Executor, BIQ>(&parachain_config, build_import_queue)?;
let (mut telemetry, telemetry_worker_handle) = params.other;

let relay_chain_full_node = cumulus_client_service::build_polkadot_full_node(
polkadot_config,
telemetry_worker_handle,
)
.map_err(|e| match e {
polkadot_service::Error::Sub(x) => x,
s => format!("{}", s).into(),
})?;
let relay_chain_full_node =
cumulus_client_service::build_polkadot_full_node(polkadot_config, telemetry_worker_handle)
.map_err(|e| match e {
polkadot_service::Error::Sub(x) => x,
s => format!("{}", s).into(),
})?;

let client = params.client.clone();
let backend = params.backend.clone();
Expand Down Expand Up @@ -234,7 +232,10 @@ where

if parachain_config.offchain_worker.enabled {
sc_service::build_offchain_workers(
&parachain_config, task_manager.spawn_handle(), client.clone(), network.clone(),
&parachain_config,
task_manager.spawn_handle(),
client.clone(),
network.clone(),
);
};

Expand Down Expand Up @@ -305,9 +306,7 @@ where

/// Build the import queue for the rococo parachain runtime.
pub fn rococo_parachain_build_import_queue(
client: Arc<
TFullClient<Block, parachain_runtime::RuntimeApi, RococoParachainRuntimeExecutor>,
>,
client: Arc<TFullClient<Block, parachain_runtime::RuntimeApi, RococoParachainRuntimeExecutor>>,
config: &Configuration,
telemetry: Option<TelemetryHandle>,
task_manager: &TaskManager,
Expand All @@ -320,29 +319,33 @@ pub fn rococo_parachain_build_import_queue(
> {
let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;

cumulus_client_consensus_aura::import_queue::<sp_consensus_aura::sr25519::AuthorityPair, _, _, _, _, _, _>(
cumulus_client_consensus_aura::ImportQueueParams {
block_import: client.clone(),
client: client.clone(),
create_inherent_data_providers: move |_, _| async move {
let time = sp_timestamp::InherentDataProvider::from_system_time();
cumulus_client_consensus_aura::import_queue::<
sp_consensus_aura::sr25519::AuthorityPair,
_,
_,
_,
_,
_,
_,
>(cumulus_client_consensus_aura::ImportQueueParams {
block_import: client.clone(),
client: client.clone(),
create_inherent_data_providers: move |_, _| async move {
let time = sp_timestamp::InherentDataProvider::from_system_time();

let slot =
sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_duration(
*time,
slot_duration.slot_duration(),
);
let slot =
sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_duration(
*time,
slot_duration.slot_duration(),
);

Ok((time, slot))
},
registry: config.prometheus_registry().clone(),
can_author_with: sp_consensus::CanAuthorWithNativeVersion::new(
client.executor().clone(),
),
spawner: &task_manager.spawn_essential_handle(),
telemetry,
Ok((time, slot))
},
)
registry: config.prometheus_registry().clone(),
can_author_with: sp_consensus::CanAuthorWithNativeVersion::new(client.executor().clone()),
spawner: &task_manager.spawn_essential_handle(),
telemetry,
})
.map_err(Into::into)
}

Expand Down
2 changes: 1 addition & 1 deletion runtime/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ fn main() {
.export_heap_base()
.import_memory()
.build()
}
}
Loading

0 comments on commit d9c7402

Please sign in to comment.