Skip to content

Commit

Permalink
refac: saner formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
saiintbrisson committed Feb 29, 2024
1 parent 5eaf1fa commit c27b049
Show file tree
Hide file tree
Showing 30 changed files with 955 additions and 382 deletions.
13 changes: 10 additions & 3 deletions node/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ pub struct TransferKeepAliveBuilder {
impl TransferKeepAliveBuilder {
// Creates a new [`Self`] from the given client.
pub fn new(client: Arc<FullClient>, dest: AccountId, value: Balance) -> Self {
Self { client, dest, value }
Self {
client,
dest,
value,
}
}
}

Expand All @@ -82,8 +86,11 @@ impl frame_benchmarking_cli::ExtrinsicBuilder for TransferKeepAliveBuilder {
let extrinsic: OpaqueExtrinsic = create_benchmark_extrinsic(
self.client.as_ref(),
acc,
BalancesCall::transfer_keep_alive { dest: self.dest.clone().into(), value: self.value }
.into(),
BalancesCall::transfer_keep_alive {
dest: self.dest.clone().into(),
value: self.value,
}
.into(),
nonce,
)
.into();
Expand Down
13 changes: 11 additions & 2 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,17 @@ pub fn generate_config(network: String) -> Result<ChainSpec, String> {
let block: u32 = state.block;
// (name, tempo, immunity_period, min_allowed_weights, max_allowed_weights, max_allowed_uids,
// founder)
let mut subnets: Vec<(Vec<u8>, u16, u16, u16, u16, u16, u16, u64, sp_runtime::AccountId32)> =
Vec::new();
let mut subnets: Vec<(
Vec<u8>,
u16,
u16,
u16,
u16,
u16,
u16,
u64,
sp_runtime::AccountId32,
)> = Vec::new();
let mut modules: Vec<Vec<(sp_runtime::AccountId32, Vec<u8>, Vec<u8>, Vec<(u16, u16)>)>> =
Vec::new();
let mut stake_to: Vec<Vec<(sp_runtime::AccountId32, Vec<(sp_runtime::AccountId32, u64)>)>> =
Expand Down
85 changes: 54 additions & 31 deletions node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ impl SubstrateCli for Cli {
"test" => Box::new(chain_spec::testnet_config()?),
"main" => Box::new(chain_spec::mainnet_config()?),
"dev" => Box::new(chain_spec::mainnet_config()?),
path =>
Box::new(chain_spec::ChainSpec::from_json_file(std::path::PathBuf::from(path))?),
path => Box::new(chain_spec::ChainSpec::from_json_file(
std::path::PathBuf::from(path),
)?),
})
}
}
Expand All @@ -55,53 +56,73 @@ pub fn run() -> sc_cli::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)) => {
let runner = cli.create_runner(cmd)?;
runner.async_run(|config| {
let PartialComponents { client, task_manager, import_queue, .. } =
service::new_partial(&config)?;
let PartialComponents {
client,
task_manager,
import_queue,
..
} = service::new_partial(&config)?;
Ok((cmd.run(client, import_queue), task_manager))
})
},
}
Some(Subcommand::ExportBlocks(cmd)) => {
let runner = cli.create_runner(cmd)?;
runner.async_run(|config| {
let PartialComponents { client, task_manager, .. } = service::new_partial(&config)?;
let PartialComponents {
client,
task_manager,
..
} = service::new_partial(&config)?;
Ok((cmd.run(client, config.database), task_manager))
})
},
}
Some(Subcommand::ExportState(cmd)) => {
let runner = cli.create_runner(cmd)?;
runner.async_run(|config| {
let PartialComponents { client, task_manager, .. } = service::new_partial(&config)?;
let PartialComponents {
client,
task_manager,
..
} = service::new_partial(&config)?;
Ok((cmd.run(client, config.chain_spec), task_manager))
})
},
}
Some(Subcommand::ImportBlocks(cmd)) => {
let runner = cli.create_runner(cmd)?;
runner.async_run(|config| {
let PartialComponents { client, task_manager, import_queue, .. } =
service::new_partial(&config)?;
let PartialComponents {
client,
task_manager,
import_queue,
..
} = service::new_partial(&config)?;
Ok((cmd.run(client, import_queue), task_manager))
})
},
}
Some(Subcommand::PurgeChain(cmd)) => {
let runner = cli.create_runner(cmd)?;
runner.sync_run(|config| cmd.run(config.database))
},
}
Some(Subcommand::Revert(cmd)) => {
let runner = cli.create_runner(cmd)?;
runner.async_run(|config| {
let PartialComponents { client, task_manager, backend, .. } =
service::new_partial(&config)?;
let PartialComponents {
client,
task_manager,
backend,
..
} = service::new_partial(&config)?;
let aux_revert = Box::new(|client, _, blocks| {
sc_consensus_grandpa::revert(client, blocks)?;
Ok(())
});
Ok((cmd.run(client, backend, Some(aux_revert)), task_manager))
})
},
}
Some(Subcommand::Benchmark(cmd)) => {
let runner = cli.create_runner(cmd)?;

Expand All @@ -117,29 +138,30 @@ pub fn run() -> sc_cli::Result<()> {
"Runtime benchmarking wasn't enabled when building the node. \
You can enable it with `--features runtime-benchmarks`."
.into(),
)
);
}

cmd.run::<Block, SubstrateHostFunctions>(config)
},
}
BenchmarkCmd::Block(cmd) => {
let PartialComponents { client, .. } = service::new_partial(&config)?;
cmd.run(client)
},
}
#[cfg(not(feature = "runtime-benchmarks"))]
BenchmarkCmd::Storage(_) => Err(
"Storage benchmarking can be enabled with `--features runtime-benchmarks`."
.into(),
),
#[cfg(feature = "runtime-benchmarks")]
BenchmarkCmd::Storage(cmd) => {
let PartialComponents { client, backend, .. } =
service::new_partial(&config)?;
let PartialComponents {
client, backend, ..
} = service::new_partial(&config)?;
let db = backend.expose_db();
let storage = backend.expose_storage();

cmd.run(config, client, db, storage)
},
}
BenchmarkCmd::Overhead(cmd) => {
let PartialComponents { client, .. } = service::new_partial(&config)?;
let ext_builder = RemarkBuilder::new(client.clone());
Expand All @@ -151,7 +173,7 @@ pub fn run() -> sc_cli::Result<()> {
Vec::new(),
&ext_builder,
)
},
}
BenchmarkCmd::Extrinsic(cmd) => {
let PartialComponents { client, .. } = service::new_partial(&config)?;
// Register the *Remark* and *TKA* builders.
Expand All @@ -165,12 +187,13 @@ pub fn run() -> sc_cli::Result<()> {
]);

cmd.run(client, inherent_benchmark_data()?, Vec::new(), &ext_factory)
},
BenchmarkCmd::Machine(cmd) =>
cmd.run(&config, SUBSTRATE_REFERENCE_HARDWARE.clone()),
}
BenchmarkCmd::Machine(cmd) => {
cmd.run(&config, SUBSTRATE_REFERENCE_HARDWARE.clone())
}
}
})
},
}
#[cfg(feature = "try-runtime")]
Some(Subcommand::TryRuntime(cmd)) => {
use crate::service::ExecutorDispatch;
Expand All @@ -191,20 +214,20 @@ pub fn run() -> sc_cli::Result<()> {
task_manager,
))
})
},
}
#[cfg(not(feature = "try-runtime"))]
Some(Subcommand::TryRuntime) => Err("TryRuntime wasn't enabled when building the node. \
You can enable it with `--features try-runtime`."
.into()),
Some(Subcommand::ChainInfo(cmd)) => {
let runner = cli.create_runner(cmd)?;
runner.sync_run(|config| cmd.run::<Block>(&config))
},
}
None => {
let runner = cli.create_runner(&cli.run)?;
runner.run_node_until_exit(|config| async move {
service::new_full(config).map_err(sc_cli::Error::Service)
})
},
}
}
}
6 changes: 5 additions & 1 deletion node/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ where
use substrate_frame_rpc_system::{System, SystemApiServer};

let mut module = RpcModule::new(());
let FullDeps { client, pool, deny_unsafe } = deps;
let FullDeps {
client,
pool,
deny_unsafe,
} = deps;

module.merge(System::new(client.clone(), pool, deny_unsafe).into_rpc())?;
module.merge(TransactionPayment::new(client.clone()).into_rpc())?;
Expand Down
13 changes: 10 additions & 3 deletions node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,11 @@ pub fn new_full(config: Configuration) -> Result<TaskManager, ServiceError> {
let pool = transaction_pool.clone();

Box::new(move |deny_unsafe, _| {
let deps =
crate::rpc::FullDeps { client: client.clone(), pool: pool.clone(), deny_unsafe };
let deps = crate::rpc::FullDeps {
client: client.clone(),
pool: pool.clone(),
deny_unsafe,
};
crate::rpc::create_full(deps).map_err(Into::into)
})
};
Expand Down Expand Up @@ -285,7 +288,11 @@ pub fn new_full(config: Configuration) -> Result<TaskManager, ServiceError> {
if enable_grandpa {
// if the node isn't actively participating in consensus then it doesn't
// need a keystore, regardless of which protocol we use below.
let keystore = if role.is_authority() { Some(keystore_container.keystore()) } else { None };
let keystore = if role.is_authority() {
Some(keystore_container.keystore())
} else {
None
};

let grandpa_config = sc_consensus_grandpa::Config {
// FIXME #1578 make this available through chainspec
Expand Down
10 changes: 8 additions & 2 deletions pallets/subspace/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ pub struct SubspacePallet<C, Block> {

impl<C, Block> SubspacePallet<C, Block> {
pub fn new(client: Arc<C>) -> Self {
Self { client, _marker: Default::default() }
Self {
client,
_marker: Default::default(),
}
}
}

Expand All @@ -58,7 +61,10 @@ where
let at = at.unwrap_or_else(|| self.client.info().best_hash);

let value = api.get_burn_rate(at).map_err(runtime_error_into_rpc_err);
Ok(Custom { code: 200, burn_rate: value.unwrap() })
Ok(Custom {
code: 200,
burn_rate: value.unwrap(),
})
}

fn get_module_info(
Expand Down
40 changes: 33 additions & 7 deletions pallets/subspace/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ fn default_register_helper<T: Config>() -> (Vec<u8>, Vec<u8>, Vec<u8>, T::Accoun
let address: Vec<u8> = b"address".to_vec();
let module_key: T::AccountId = account("key", 0, SEED);

let netuid =
register_helper::<T>(network.clone(), name.clone(), address.clone(), module_key.clone());
let netuid = register_helper::<T>(
network.clone(),
name.clone(),
address.clone(),
module_key.clone(),
);

(network, name, address, module_key, netuid)
}
Expand Down Expand Up @@ -120,7 +124,10 @@ mod benchmarks {

let netuid = <Pallet<T>>::get_netuid_for_name(network).unwrap_or(u16::MAX);

assert!(<Pallet<T>>::is_registered(netuid, &module_key), "Register failed");
assert!(
<Pallet<T>>::is_registered(netuid, &module_key),
"Register failed"
);

Ok(())
}
Expand Down Expand Up @@ -160,7 +167,12 @@ mod benchmarks {
let (network, name, address, module_key, netuid) = default_register_helper::<T>();

#[extrinsic_call]
add_stake(RawOrigin::Signed(module_key.clone()), netuid, module_key.clone(), MIN_STAKE);
add_stake(
RawOrigin::Signed(module_key.clone()),
netuid,
module_key.clone(),
MIN_STAKE,
);

Ok(())
}
Expand Down Expand Up @@ -254,7 +266,11 @@ mod benchmarks {
}

#[extrinsic_call]
transfer_multiple(RawOrigin::Signed(module_key.clone()), new_module_keys, amounts);
transfer_multiple(
RawOrigin::Signed(module_key.clone()),
new_module_keys,
amounts,
);

Ok(())
}
Expand All @@ -275,7 +291,12 @@ mod benchmarks {
);

#[extrinsic_call]
remove_stake(RawOrigin::Signed(module_key.clone()), netuid, module_key.clone(), MIN_STAKE);
remove_stake(
RawOrigin::Signed(module_key.clone()),
netuid,
module_key.clone(),
MIN_STAKE,
);

Ok(())
}
Expand All @@ -287,7 +308,12 @@ mod benchmarks {
let (netuid, module_keys, amounts) = add_stake_multiple_helper::<T>(caller.clone());

#[extrinsic_call]
remove_stake_multiple(RawOrigin::Signed(caller.clone()), netuid, module_keys, amounts);
remove_stake_multiple(
RawOrigin::Signed(caller.clone()),
netuid,
module_keys,
amounts,
);

Ok(())
}
Expand Down
Loading

0 comments on commit c27b049

Please sign in to comment.