Skip to content

Commit

Permalink
Style: format rust file
Browse files Browse the repository at this point in the history
* Format rust file use cargo rustfmt
  • Loading branch information
toints committed Oct 11, 2023
1 parent d34e546 commit 33fdd96
Show file tree
Hide file tree
Showing 11 changed files with 142 additions and 109 deletions.
24 changes: 24 additions & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Basic
edition = "2021"
hard_tabs = true
max_width = 100
use_small_heuristics = "Max"
# Imports
imports_granularity = "Crate"
reorder_imports = true
# Consistency
newline_style = "Unix"
# Misc
chain_width = 80
spaces_around_ranges = false
binop_separator = "Back"
reorder_impl_items = false
match_arm_leading_pipes = "Preserve"
match_arm_blocks = false
match_block_trailing_comma = true
trailing_comma = "Vertical"
trailing_semicolon = false
use_field_init_shorthand = true
# Format comments
comment_width = 100
wrap_comments = true
7 changes: 4 additions & 3 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use cumulus_primitives_core::ParaId;
use parachain_magnet_runtime::{AccountId, AuraId, Signature, EXISTENTIAL_DEPOSIT, };
use parachain_magnet_runtime::{AccountId, AuraId, Signature, EXISTENTIAL_DEPOSIT};
use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup};
use sc_service::ChainType;
use serde::{Deserialize, Serialize};
use sp_core::{sr25519, Pair, Public, H160, U256};
use sp_runtime::traits::{IdentifyAccount, Verify};
use sp_std::marker::PhantomData;
use std::{collections::BTreeMap, str::FromStr};
use sp_std::{marker::PhantomData};

/// Specialized `ChainSpec` for the normal parachain runtime.
pub type ChainSpec =
Expand Down Expand Up @@ -252,7 +252,8 @@ fn testnet_genesis(
// Derived from SS58 (42 prefix) address
// SS58: 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY
// hex: 0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d
// Using the full hex key, truncating to the first 20 bytes (the first 40 hex chars)
// Using the full hex key, truncating to the first 20 bytes (the first 40 hex
// chars)
H160::from_str("d43593c715fdd31c61141abd04a99fd6822c8558")
.expect("internal H160 is valid; qed"),
fp_evm::GenesisAccount {
Expand Down
2 changes: 1 addition & 1 deletion node/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::path::PathBuf;
use crate::service::EthConfiguration;
use std::path::PathBuf;

/// Sub-commands supported by the collator.
#[derive(Debug, clap::Subcommand)]
Expand Down
11 changes: 3 additions & 8 deletions node/src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ pub async fn spawn_frontier_tasks<RuntimeApi, Executor>(
)
.for_each(|()| future::ready(())),
);
}
},
fc_db::Backend::Sql(b) => {
task_manager.spawn_essential_handle().spawn_blocking(
"frontier-mapping-sync-worker",
Expand All @@ -183,7 +183,7 @@ pub async fn spawn_frontier_tasks<RuntimeApi, Executor>(
pubsub_notification_sinks,
),
);
}
},
}

// Spawn Frontier EthFilterApi maintenance task.
Expand All @@ -201,11 +201,6 @@ pub async fn spawn_frontier_tasks<RuntimeApi, Executor>(
task_manager.spawn_essential_handle().spawn(
"frontier-fee-history",
Some("frontier"),
EthTask::fee_history_task(
client,
overrides,
fee_history_cache,
fee_history_cache_limit,
),
EthTask::fee_history_task(client, overrides, fee_history_cache, fee_history_cache_limit),
);
}
4 changes: 2 additions & 2 deletions node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ mod chain_spec;
#[macro_use]
mod service;
mod cli;
mod client;
mod command;
mod rpc;
mod eth;
mod client;
mod rpc;

fn main() -> sc_cli::Result<()> {
command::run()
Expand Down
8 changes: 5 additions & 3 deletions node/src/rpc/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ pub struct EthDeps<B: BlockT, C, P, A: ChainApi, CT, CIDP> {
pub pending_create_inherent_data_providers: CIDP,
}

impl <B: BlockT, C, P, A: ChainApi, CT: Clone, CIDP: Clone >Clone for EthDeps<B, C, P, A, CT, CIDP> {
impl<B: BlockT, C, P, A: ChainApi, CT: Clone, CIDP: Clone> Clone for EthDeps<B, C, P, A, CT, CIDP> {
fn clone(&self) -> Self {
Self{
Self {
client: self.client.clone(),
pool: self.pool.clone(),
graph: self.graph.clone(),
Expand All @@ -87,7 +87,9 @@ impl <B: BlockT, C, P, A: ChainApi, CT: Clone, CIDP: Clone >Clone for EthDeps<B,
fee_history_cache_limit: self.fee_history_cache_limit,
execute_gas_limit_multiplier: self.execute_gas_limit_multiplier,
forced_parent_hashes: self.forced_parent_hashes.clone(),
pending_create_inherent_data_providers: self.pending_create_inherent_data_providers.clone(),
pending_create_inherent_data_providers: self
.pending_create_inherent_data_providers
.clone(),
}
}
}
Expand Down
8 changes: 1 addition & 7 deletions node/src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,7 @@ where
use substrate_frame_rpc_system::{System, SystemApiServer};

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

io.merge(System::new(client.clone(), pool, deny_unsafe).into_rpc())?;
io.merge(TransactionPayment::new(client).into_rpc())?;
Expand Down
86 changes: 55 additions & 31 deletions node/src/service.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
//! Service and ServiceFactory implementation. Specialized wrapper over substrate service.
// std
use std::{sync::Arc, path::Path, time::Duration};
use sp_core::U256;
use std::{path::Path, sync::Arc, time::Duration};

use cumulus_client_cli::CollatorOptions;
// Local Runtime Types
use parachain_magnet_runtime::{
opaque::{Block, Hash},
RuntimeApi,
TransactionConverter,
RuntimeApi, TransactionConverter,
};

// Cumulus Imports
Expand Down Expand Up @@ -38,14 +37,14 @@ use sc_transaction_pool_api::OffchainTransactionPoolFactory;
use sp_keystore::KeystorePtr;
use substrate_prometheus_endpoint::Registry;

use crate::{
eth::{
new_frontier_partial, spawn_frontier_tasks, BackendType, //EthCompatRuntimeApiCollection,
FrontierBackend, FrontierBlockImport as TFrontierBlockImport, FrontierPartialComponents,
},
};
pub use crate::{
eth::{db_config_dir, EthConfiguration},
pub use crate::eth::{db_config_dir, EthConfiguration};
use crate::eth::{
new_frontier_partial,
spawn_frontier_tasks,
BackendType, //EthCompatRuntimeApiCollection,
FrontierBackend,
FrontierBlockImport as TFrontierBlockImport,
FrontierPartialComponents,
};

/// Native executor type.
Expand Down Expand Up @@ -88,9 +87,13 @@ pub fn new_partial(
(),
sc_consensus::DefaultImportQueue<Block>,
sc_transaction_pool::FullPool<Block, ParachainClient>,
(ParachainBlockImport, Option<Telemetry>, Option<TelemetryWorkerHandle>,
FrontierBackend,
Arc<fc_rpc::OverrideHandle<Block>>,),
(
ParachainBlockImport,
Option<Telemetry>,
Option<TelemetryWorkerHandle>,
FrontierBackend,
Arc<fc_rpc::OverrideHandle<Block>>,
),
>,
sc_service::Error,
> {
Expand Down Expand Up @@ -167,9 +170,9 @@ pub fn new_partial(
std::num::NonZeroU32::new(eth_config.frontier_sql_backend_num_ops_timeout),
overrides.clone(),
))
.unwrap_or_else(|err| panic!("failed creating sql backend: {:?}", err));
.unwrap_or_else(|err| panic!("failed creating sql backend: {:?}", err));
FrontierBackend::Sql(backend)
}
},
};

let frontier_block_import = FrontierBlockImport::new(client.clone(), client.clone());
Expand All @@ -192,7 +195,13 @@ pub fn new_partial(
task_manager,
transaction_pool,
select_chain: (),
other: (parachain_block_import, telemetry, telemetry_worker_handle, frontier_backend, overrides,),
other: (
parachain_block_import,
telemetry,
telemetry_worker_handle,
frontier_backend,
overrides,
),
})
}

Expand All @@ -213,7 +222,8 @@ async fn start_node_impl(
parachain_config.rpc_id_provider = Some(Box::new(fc_rpc::EthereumSubIdProvider));

let params = new_partial(&parachain_config, &eth_config)?;
let (block_import, mut telemetry, telemetry_worker_handle, frontier_backend, overrides) = params.other;
let (block_import, mut telemetry, telemetry_worker_handle, frontier_backend, overrides) =
params.other;
let net_config = sc_network::config::FullNetworkConfiguration::new(&parachain_config.network);

let FrontierPartialComponents { filter_pool, fee_history_cache, fee_history_cache_limit } =
Expand Down Expand Up @@ -279,8 +289,9 @@ async fn start_node_impl(

// Sinks for pubsub notifications.
// Everytime a new subscription is created, a new mpsc channel is added to the sink pool.
// The MappingSyncWorker sends through the channel on block import and the subscription emits a notification to the subscriber on receiving a message through this channel.
// This way we avoid race conditions when using native substrate block import notification stream.
// The MappingSyncWorker sends through the channel on block import and the subscription emits a
// notification to the subscriber on receiving a message through this channel. This way we avoid
// race conditions when using native substrate block import notification stream.
let pubsub_notification_sinks: fc_mapping_sync::EthereumBlockNotificationSinks<
fc_mapping_sync::EthereumBlockNotification<Block>,
> = Default::default();
Expand All @@ -293,10 +304,11 @@ async fn start_node_impl(
let current = sp_timestamp::InherentDataProvider::from_system_time();
let next_slot = current.timestamp().as_millis() + slot_duration.as_millis();
let timestamp = sp_timestamp::InherentDataProvider::new(next_slot.into());
let slot = sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration(
*timestamp,
slot_duration,
);
let slot =
sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration(
*timestamp,
slot_duration,
);
let dynamic_fee = fp_dynamic_fee::InherentDataProvider(U256::from(target_gas_price));
Ok((slot, timestamp, dynamic_fee))
};
Expand Down Expand Up @@ -344,10 +356,12 @@ async fn start_node_impl(
eth: eth_rpc_params.clone(),
};

crate::rpc::create_full(deps,
subscription_task_executor,
pubsub_notification_sinks.clone(),
).map_err(Into::into)
crate::rpc::create_full(
deps,
subscription_task_executor,
pubsub_notification_sinks.clone(),
)
.map_err(Into::into)
})
};

Expand Down Expand Up @@ -377,7 +391,8 @@ async fn start_node_impl(
fee_history_cache_limit,
sync_service.clone(),
pubsub_notification_sinks_frontier,
).await;
)
.await;

if let Some(hwbench) = hwbench {
sc_sysinfo::print_hwbench(&hwbench);
Expand Down Expand Up @@ -471,7 +486,8 @@ fn build_import_queue(
>(
client,
block_import,
move |_, _| async move { //TODO: add create_inherent_data_providers
move |_, _| async move {
//TODO: add create_inherent_data_providers
let timestamp = sp_timestamp::InherentDataProvider::from_system_time();
Ok(timestamp)
},
Expand Down Expand Up @@ -560,5 +576,13 @@ pub async fn start_parachain_node(
para_id: ParaId,
hwbench: Option<sc_sysinfo::HwBench>,
) -> sc_service::error::Result<(TaskManager, Arc<ParachainClient>)> {
start_node_impl(parachain_config, polkadot_config, eth_config, collator_options, para_id, hwbench).await
start_node_impl(
parachain_config,
polkadot_config,
eth_config,
collator_options,
para_id,
hwbench,
)
.await
}
15 changes: 6 additions & 9 deletions pallets/motion/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,12 @@ fn setup_proposal(threshold: u32, motion_type: MotionType) -> Proposal {

// Setup motion with specified origin type
let motion = match motion_type {
MotionType::SimpleMajority => {
RuntimeCall::Motion(pallet_motion::Call::simple_majority { call: Box::new(inner_call) })
},
MotionType::SuperMajority => {
RuntimeCall::Motion(pallet_motion::Call::super_majority { call: Box::new(inner_call) })
},
MotionType::Unanimous => {
RuntimeCall::Motion(pallet_motion::Call::unanimous { call: Box::new(inner_call) })
},
MotionType::SimpleMajority =>
RuntimeCall::Motion(pallet_motion::Call::simple_majority { call: Box::new(inner_call) }),
MotionType::SuperMajority =>
RuntimeCall::Motion(pallet_motion::Call::super_majority { call: Box::new(inner_call) }),
MotionType::Unanimous =>
RuntimeCall::Motion(pallet_motion::Call::unanimous { call: Box::new(inner_call) }),
};

let proposal_len: u32 = motion.using_encoded(|p| p.len() as u32);
Expand Down
Loading

0 comments on commit 33fdd96

Please sign in to comment.