Skip to content

Commit

Permalink
Async, remove council, common pallet config
Browse files Browse the repository at this point in the history
  • Loading branch information
aurexav committed Jun 26, 2024
1 parent 2ed1bca commit aa66038
Show file tree
Hide file tree
Showing 52 changed files with 935 additions and 1,110 deletions.
1,110 changes: 556 additions & 554 deletions Cargo.lock

Large diffs are not rendered by default.

216 changes: 108 additions & 108 deletions Cargo.toml

Large diffs are not rendered by default.

15 changes: 4 additions & 11 deletions core/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,30 +59,23 @@ pub type Header = sp_runtime::generic::Header<BlockNumber, Hashing>;
/// Block type.
pub type Block = sp_runtime::generic::Block<Header, sp_runtime::OpaqueExtrinsic>;

/// This determines the average expected block time that we are targeting.
/// Blocks will be produced at a minimum duration defined by `SLOT_DURATION`.
/// `SLOT_DURATION` is picked up by `pallet_timestamp` which is in turn picked
/// up by `pallet_aura` to implement `fn slot_duration()`.
///
/// Change this to adjust the block time.
pub const MILLISECS_PER_BLOCK: u64 = 12_000;
/// Maximum number of blocks simultaneously accepted by the Runtime, not yet included
/// into the relay chain.
pub const UNINCLUDED_SEGMENT_CAPACITY: u32 = 1;
pub const UNINCLUDED_SEGMENT_CAPACITY: u32 = 3;
/// How many parachain blocks are processed by the relay chain per parent. Limits the
/// number of blocks authored per slot.
pub const BLOCK_PROCESSING_VELOCITY: u32 = 1;
/// Relay chain slot duration, in milliseconds.
pub const RELAY_CHAIN_SLOT_DURATION_MILLIS: u32 = 6000;
pub const RELAY_CHAIN_SLOT_DURATION_MILLIS: u32 = 6_000;

// NOTE: Currently it is not possible to change the slot duration after the chain has started.
// Attempting to do so will brick block production.
/// Slot duration.
pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK;
pub const SLOT_DURATION: u64 = 6_000;

// Time is measured by number of blocks.
/// 10 blocks.
pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber);
pub const MINUTES: BlockNumber = 60_000 / (SLOT_DURATION as BlockNumber);
/// 600 blocks.
pub const HOURS: BlockNumber = MINUTES * 60;
/// 14,400 blocks.
Expand Down
1 change: 1 addition & 0 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ cumulus-client-consensus-common = { workspace = true }
cumulus-client-consensus-proposer = { workspace = true }
cumulus-client-parachain-inherent = { workspace = true }
cumulus-client-service = { workspace = true }
cumulus-primitives-aura = { workspace = true, features = ["std"] }
cumulus-primitives-core = { workspace = true, features = ["std"] }
cumulus-primitives-parachain-inherent = { workspace = true, features = ["std"] }
cumulus-relay-chain-interface = { workspace = true }
Expand Down
3 changes: 3 additions & 0 deletions node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ pub fn run() -> Result<()> {
if chain_spec.is_crab() {
return service::start_dev_node::<CrabRuntimeApi>(
config,
id,
&eth_rpc_config,
)
.map_err(Into::into);
Expand All @@ -517,6 +518,7 @@ pub fn run() -> Result<()> {
if chain_spec.is_darwinia() {
return service::start_dev_node::<DarwiniaRuntimeApi>(
config,
id,
&eth_rpc_config,
)
.map_err(Into::into)
Expand All @@ -526,6 +528,7 @@ pub fn run() -> Result<()> {
if chain_spec.is_koi() {
return service::start_dev_node::<KoiRuntimeApi>(
config,
id,
&eth_rpc_config,
)
.map_err(Into::into)
Expand Down
67 changes: 36 additions & 31 deletions node/src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ use std::{
use futures::FutureExt;
// darwinia
use dc_primitives::*;
// substrate
use sc_client_api::Backend;
// polkadot-sdk
use sc_client_api::{Backend, HeaderBackend};
use sc_consensus::ImportQueue;
use sc_network::NetworkBlock;
use sp_core::Encode;

#[cfg(all(feature = "runtime-benchmarks", feature = "evm-tracing"))]
type HostFunctions = (
Expand Down Expand Up @@ -121,7 +122,8 @@ impl IdentifyVariant for Box<dyn sc_service::ChainSpec> {

/// A set of APIs that darwinia-like runtimes must implement.
pub trait RuntimeApiCollection:
cumulus_primitives_core::CollectCollationInfo<Block>
cumulus_primitives_aura::AuraUnincludedSegmentApi<Block>
+ cumulus_primitives_core::CollectCollationInfo<Block>
+ fp_rpc::ConvertTransactionRuntimeApi<Block>
+ fp_rpc::EthereumRuntimeRPCApi<Block>
+ moonbeam_rpc_primitives_debug::DebugRuntimeApi<Block>
Expand All @@ -137,7 +139,8 @@ pub trait RuntimeApiCollection:
{
}
impl<Api> RuntimeApiCollection for Api where
Api: cumulus_primitives_core::CollectCollationInfo<Block>
Api: cumulus_primitives_aura::AuraUnincludedSegmentApi<Block>
+ cumulus_primitives_core::CollectCollationInfo<Block>
+ fp_rpc::ConvertTransactionRuntimeApi<Block>
+ fp_rpc::EthereumRuntimeRPCApi<Block>
+ moonbeam_rpc_primitives_debug::DebugRuntimeApi<Block>
Expand Down Expand Up @@ -250,6 +253,7 @@ where
RuntimeApi::RuntimeApi: RuntimeApiCollection,
SC: FnOnce(
Arc<FullClient<RuntimeApi>>,
Arc<FullBackend>,
ParachainBlockImport<RuntimeApi>,
Option<&substrate_prometheus_endpoint::Registry>,
Option<sc_telemetry::TelemetryHandle>,
Expand Down Expand Up @@ -285,7 +289,6 @@ where
telemetry_worker_handle,
),
} = new_partial::<RuntimeApi>(&parachain_config, eth_rpc_config)?;

let (relay_chain_interface, collator_key) =
cumulus_client_service::build_relay_chain_interface(
polkadot_config,
Expand All @@ -297,12 +300,10 @@ where
)
.await
.map_err(|e| sc_service::Error::Application(Box::new(e) as Box<_>))?;

let validator = parachain_config.role.is_authority();
let prometheus_registry = parachain_config.prometheus_registry().cloned();
let import_queue_service = import_queue.service();
let net_config = sc_network::config::FullNetworkConfiguration::new(&parachain_config.network);

let (network, system_rpc_tx, tx_handler_controller, start_network, sync_service) =
cumulus_client_service::build_network(cumulus_client_service::BuildNetworkParams {
parachain_config: &parachain_config,
Expand Down Expand Up @@ -380,7 +381,6 @@ where
let collator = parachain_config.role.is_authority();
let eth_rpc_config = eth_rpc_config.clone();
let sync_service = sync_service.clone();

let slot_duration = sc_consensus_aura::slot_duration(&*client)?;
let pending_create_inherent_data_providers = move |_, ()| async move {
let current = sp_timestamp::InherentDataProvider::from_system_time();
Expand Down Expand Up @@ -510,6 +510,7 @@ where
if validator {
start_consensus(
client.clone(),
backend.clone(),
block_import,
prometheus_registry.as_ref(),
telemetry.as_ref().map(|t| t.handle()),
Expand Down Expand Up @@ -588,6 +589,7 @@ where
cumulus_client_service::CollatorSybilResistance::Resistant, // Aura
para_id,
|client,
backend,
block_import,
prometheus_registry,
telemetry,
Expand Down Expand Up @@ -616,11 +618,17 @@ where
announce_block,
client.clone(),
);
let params = cumulus_client_consensus_aura::collators::basic::Params {
let params = cumulus_client_consensus_aura::collators::lookahead::Params {
create_inherent_data_providers: move |_, ()| async move { Ok(()) },
block_import,
para_client: client,
para_client: client.clone(),
para_backend: backend.clone(),
relay_client: relay_chain_interface,
code_hash_provider: move |block_hash| {
client.code_at(block_hash).ok().map(|c| {
cumulus_primitives_core::relay_chain::ValidationCode::from(c).hash()
})
},
sync_oracle,
keystore,
collator_key,
Expand All @@ -631,10 +639,10 @@ where
proposer,
collator_service,
// Very limited proposal time.
authoring_duration: Duration::from_millis(500),
collation_request_receiver: None,
authoring_duration: Duration::from_millis(1_500),
reinitialize: false,
};
let fut = cumulus_client_consensus_aura::collators::basic::run::<
let fut = cumulus_client_consensus_aura::collators::lookahead::run::<
Block,
sp_consensus_aura::sr25519::AuthorityPair,
_,
Expand All @@ -644,6 +652,8 @@ where
_,
_,
_,
_,
_,
>(params);

task_manager.spawn_essential_handle().spawn("aura", None, fut);
Expand All @@ -660,17 +670,15 @@ where
/// !!! WARNING: DO NOT USE ELSEWHERE
pub fn start_dev_node<RuntimeApi>(
mut config: sc_service::Configuration,
para_id: cumulus_primitives_core::ParaId,
eth_rpc_config: &crate::cli::EthRpcConfig,
) -> Result<sc_service::TaskManager, sc_service::error::Error>
where
RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi>> + Send + Sync + 'static,
RuntimeApi: 'static + Send + Sync + sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi>>,
RuntimeApi::RuntimeApi: RuntimeApiCollection,
RuntimeApi::RuntimeApi:
sp_consensus_aura::AuraApi<Block, sp_consensus_aura::sr25519::AuthorityId>,
{
// substrate
use sc_client_api::HeaderBackend;

let sc_service::PartialComponents {
client,
backend,
Expand All @@ -691,7 +699,6 @@ where
),
} = new_partial::<RuntimeApi>(&config, eth_rpc_config)?;
let net_config = sc_network::config::FullNetworkConfiguration::new(&config.network);

let (network, system_rpc_tx, tx_handler_controller, start_network, sync_service) =
sc_service::build_network(sc_service::BuildNetworkParams {
config: &config,
Expand Down Expand Up @@ -729,16 +736,15 @@ where
}

let force_authoring = config.force_authoring;
let backoff_authoring_blocks: Option<()> = None;
let backoff_authoring_blocks = None::<()>;
let slot_duration = sc_consensus_aura::slot_duration(&*client)?;
let proposer_factory = sc_basic_authorship::ProposerFactory::new(
task_manager.spawn_handle(),
client.clone(),
transaction_pool.clone(),
None,
None,
);

let slot_duration = sc_consensus_aura::slot_duration(&*client)?;
let client_for_cidp = client.clone();
if config.role.is_authority() {
let aura = sc_consensus_aura::start_aura::<
Expand All @@ -754,29 +760,31 @@ where
_,
_,
>(sc_consensus_aura::StartAuraParams {
slot_duration: sc_consensus_aura::slot_duration(&*client)?,
slot_duration,
client: client.clone(),
select_chain,
block_import: instant_finalize::InstantFinalizeBlockImport::new(client.clone()),
proposer_factory,
create_inherent_data_providers: move |block: Hash, ()| {
let current_para_block = client_for_cidp
.number(block)
.expect("Header lookup should succeed")
.expect("Header passed in as parent should be present in backend.");
let maybe_current_para_block = client_for_cidp.number(block);
let maybe_current_block_head = client_for_cidp.expect_header(block);
let client_for_xcm = client_for_cidp.clone();

async move {
let current_para_block = maybe_current_para_block?
.ok_or(sp_blockchain::Error::UnknownBlock(block.to_string()))?;
let current_para_block_head =
Some(polkadot_primitives::HeadData(maybe_current_block_head?.encode()));
let timestamp = sp_timestamp::InherentDataProvider::from_system_time();

let slot = sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration(
*timestamp,
slot_duration,
);

let mocked_parachain =
cumulus_client_parachain_inherent::MockValidationDataInherentDataProvider {
current_para_block,
para_id,
current_para_block_head,
relay_offset: 1000,
relay_blocks_per_para_block: 2,
para_blocks_per_relay_epoch: 0,
Expand All @@ -785,7 +793,6 @@ where
&*client_for_xcm,
block,
Default::default(),
Default::default(),
),
raw_downward_messages: Vec::new(),
raw_horizontal_messages: Vec::new(),
Expand Down Expand Up @@ -860,8 +867,6 @@ where
let collator = config.role.is_authority();
let eth_rpc_config = eth_rpc_config.clone();
let sync_service = sync_service.clone();

let slot_duration = sc_consensus_aura::slot_duration(&*client)?;
let pending_create_inherent_data_providers = move |_, ()| async move {
let current = sp_timestamp::InherentDataProvider::from_system_time();
let next_slot = current.timestamp().as_millis() + slot_duration.as_millis();
Expand Down
2 changes: 2 additions & 0 deletions runtime/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ dc-primitives = { workspace = true }

# frontier
fp-account = { workspace = true }
fp-evm = { workspace = true }
pallet-evm = { workspace = true }

# polkadot-sdk
Expand Down Expand Up @@ -51,6 +52,7 @@ std = [

# frontier
"fp-account/std",
"fp-evm/std",
"pallet-evm/std",

# polkadot-sdk
Expand Down
6 changes: 3 additions & 3 deletions runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub mod gov_origin;
pub mod message_queue;
pub mod migration_helper;
pub mod pallet_config;
pub mod xcm_configs;
pub mod xcm_config;

#[cfg(feature = "test")]
pub mod test;
Expand Down Expand Up @@ -171,9 +171,9 @@ impl frame_support::weights::WeightToFeePolynomial for RefTimeToFee {
type Balance = Balance;

fn polynomial() -> frame_support::weights::WeightToFeeCoefficients<Self::Balance> {
// Map base extrinsic weight to 1/200 UNIT.
// Map base extrinsic weight to 1/800 UNIT.
let p = UNIT;
let q = 200
let q = 800
* Balance::from(
frame_support::weights::constants::ExtrinsicBaseWeight::get().ref_time(),
);
Expand Down
Loading

0 comments on commit aa66038

Please sign in to comment.