Skip to content

Commit

Permalink
Revert "Async backing (#1492)" (#1505)
Browse files Browse the repository at this point in the history
This reverts commit 48f10ed.
  • Loading branch information
AurevoirXavier authored May 29, 2024
1 parent 8384846 commit 4fce0cc
Show file tree
Hide file tree
Showing 37 changed files with 902 additions and 1,244 deletions.
1,690 changes: 737 additions & 953 deletions Cargo.lock

Large diffs are not rendered by default.

171 changes: 32 additions & 139 deletions Cargo.toml

Large diffs are not rendered by default.

15 changes: 11 additions & 4 deletions core/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,30 @@ 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 = 3;
pub const UNINCLUDED_SEGMENT_CAPACITY: u32 = 1;
/// 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 = 6_000;
pub const RELAY_CHAIN_SLOT_DURATION_MILLIS: u32 = 6000;

// 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 = 6_000;
pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK;

// Time is measured by number of blocks.
/// 10 blocks.
pub const MINUTES: BlockNumber = 60_000 / (SLOT_DURATION as BlockNumber);
pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber);
/// 600 blocks.
pub const HOURS: BlockNumber = MINUTES * 60;
/// 14,400 blocks.
Expand Down
1 change: 0 additions & 1 deletion node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ cumulus-client-consensus-aura = { workspace = true }
cumulus-client-consensus-common = { workspace = true }
cumulus-client-consensus-proposer = { 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: 0 additions & 3 deletions node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,6 @@ pub fn run() -> Result<()> {
if chain_spec.is_crab() {
return service::start_dev_node::<CrabRuntimeApi, CrabRuntimeExecutor>(
config,
id,
&eth_rpc_config,
)
.map_err(Into::into);
Expand All @@ -516,7 +515,6 @@ pub fn run() -> Result<()> {
if chain_spec.is_darwinia() {
return service::start_dev_node::<DarwiniaRuntimeApi, DarwiniaRuntimeExecutor>(
config,
id,
&eth_rpc_config,
)
.map_err(Into::into)
Expand All @@ -526,7 +524,6 @@ pub fn run() -> Result<()> {
if chain_spec.is_pangolin() {
return service::start_dev_node::<PangolinRuntimeApi, PangolinRuntimeExecutor>(
config,
id,
&eth_rpc_config,
)
.map_err(Into::into)
Expand Down
77 changes: 29 additions & 48 deletions node/src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,9 @@ use futures::FutureExt;
// darwinia
use dc_primitives::*;
// substrate
use sc_client_api::{Backend, HeaderBackend};
use sc_client_api::Backend;
use sc_consensus::ImportQueue;
use sc_network::NetworkBlock;
use sp_core::Encode;

/// Full client backend type.
type FullBackend = sc_service::TFullBackend<Block>;
Expand Down Expand Up @@ -95,8 +94,7 @@ impl IdentifyVariant for Box<dyn sc_service::ChainSpec> {

/// A set of APIs that darwinia-like runtimes must implement.
pub trait RuntimeApiCollection:
cumulus_primitives_aura::AuraUnincludedSegmentApi<Block>
+ cumulus_primitives_core::CollectCollationInfo<Block>
cumulus_primitives_core::CollectCollationInfo<Block>
+ fp_rpc::ConvertTransactionRuntimeApi<Block>
+ fp_rpc::EthereumRuntimeRPCApi<Block>
+ moonbeam_rpc_primitives_debug::DebugRuntimeApi<Block>
Expand All @@ -112,8 +110,7 @@ pub trait RuntimeApiCollection:
{
}
impl<Api> RuntimeApiCollection for Api where
Api: cumulus_primitives_aura::AuraUnincludedSegmentApi<Block>
+ cumulus_primitives_core::CollectCollationInfo<Block>
Api: cumulus_primitives_core::CollectCollationInfo<Block>
+ fp_rpc::ConvertTransactionRuntimeApi<Block>
+ fp_rpc::EthereumRuntimeRPCApi<Block>
+ moonbeam_rpc_primitives_debug::DebugRuntimeApi<Block>
Expand Down Expand Up @@ -264,7 +261,6 @@ where
Executor: 'static + sc_executor::NativeExecutionDispatch,
SC: FnOnce(
Arc<FullClient<RuntimeApi, Executor>>,
Arc<FullBackend>,
ParachainBlockImport<RuntimeApi, Executor>,
Option<&substrate_prometheus_endpoint::Registry>,
Option<sc_telemetry::TelemetryHandle>,
Expand Down Expand Up @@ -300,6 +296,7 @@ where
telemetry_worker_handle,
),
} = new_partial::<RuntimeApi, Executor>(&parachain_config, eth_rpc_config)?;

let (relay_chain_interface, collator_key) =
cumulus_client_service::build_relay_chain_interface(
polkadot_config,
Expand All @@ -311,10 +308,12 @@ 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 @@ -522,7 +521,6 @@ 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 @@ -616,7 +614,6 @@ where
cumulus_client_service::CollatorSybilResistance::Resistant, // Aura
para_id,
|client,
backend,
block_import,
prometheus_registry,
telemetry,
Expand Down Expand Up @@ -645,17 +642,11 @@ where
announce_block,
client.clone(),
);
let params = cumulus_client_consensus_aura::collators::lookahead::Params {
let params = cumulus_client_consensus_aura::collators::basic::Params {
create_inherent_data_providers: move |_, ()| async move { Ok(()) },
block_import,
para_client: client.clone(),
para_backend: backend.clone(),
para_client: client,
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 @@ -666,9 +657,9 @@ where
proposer,
collator_service,
// Very limited proposal time.
authoring_duration: Duration::from_millis(1_500),
authoring_duration: Duration::from_millis(500),
};
let fut = cumulus_client_consensus_aura::collators::lookahead::run::<
let fut = cumulus_client_consensus_aura::collators::basic::run::<
Block,
sp_consensus_aura::sr25519::AuthorityPair,
_,
Expand All @@ -678,8 +669,6 @@ where
_,
_,
_,
_,
_,
>(params);

task_manager.spawn_essential_handle().spawn("aura", None, fut);
Expand All @@ -696,19 +685,21 @@ where
/// !!! WARNING: DO NOT USE ELSEWHERE
pub fn start_dev_node<RuntimeApi, Executor>(
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: 'static
RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, Executor>>
+ Send
+ Sync
+ sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, Executor>>,
+ 'static,
RuntimeApi::RuntimeApi: RuntimeApiCollection,
RuntimeApi::RuntimeApi:
sp_consensus_aura::AuraApi<Block, sp_consensus_aura::sr25519::AuthorityId>,
Executor: 'static + sc_executor::NativeExecutionDispatch,
{
// substrate
use sc_client_api::HeaderBackend;

let sc_service::PartialComponents {
client,
backend,
Expand All @@ -729,6 +720,7 @@ where
),
} = new_partial::<RuntimeApi, Executor>(&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 @@ -765,17 +757,17 @@ where
}

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

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::<
sp_consensus_aura::sr25519::AuthorityPair,
Expand All @@ -790,54 +782,41 @@ where
_,
_,
>(sc_consensus_aura::StartAuraParams {
slot_duration,
slot_duration: sc_consensus_aura::slot_duration(&*client)?,
client: client.clone(),
select_chain,
block_import: instant_finalize::InstantFinalizeBlockImport::new(client.clone()),
proposer_factory,
create_inherent_data_providers: move |block: Hash, ()| {
let maybe_current_para_block = client_for_cidp.number(block);
let maybe_current_block_head = client_for_cidp.expect_header(block);
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 client_for_xcm = client_for_cidp.clone();
// TODO: hack for now.
let additional_key_values = Some(vec![(
array_bytes::hex2bytes_unchecked(
"1cb6f36e027abb2091cfb5110ab5087f06155b3cd9a8c9e5e9a23fd5dc13a5ed",
),
cumulus_primitives_aura::Slot::from_timestamp(
sp_timestamp::Timestamp::current(),
slot_duration,
)
.encode(),
)]);

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_primitives_parachain_inherent::MockValidationDataInherentDataProvider {
current_para_block,
current_para_block_head,
relay_offset: 1000,
relay_blocks_per_para_block: 2,
para_blocks_per_relay_epoch: 0,
relay_randomness_config: (),
xcm_config: cumulus_primitives_parachain_inherent::MockXcmConfig::new(
&*client_for_xcm,
block,
para_id,
Default::default(),
Default::default(),
),
raw_downward_messages: Vec::new(),
raw_horizontal_messages: Vec::new(),
additional_key_values,
};

Ok((slot, timestamp, mocked_parachain))
Expand Down Expand Up @@ -908,6 +887,8 @@ 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
4 changes: 2 additions & 2 deletions pallet/staking/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `574`
// Estimated: `4543`
// Minimum execution time: 6_000 nanoseconds.
// Minimum execution time: 12_000 nanoseconds.
Weight::from_parts(12_000_000, 0)
.saturating_add(Weight::from_parts(4543, 0))
.saturating_add(T::DbWeight::get().reads(3_u64))
Expand Down Expand Up @@ -265,7 +265,7 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `574`
// Estimated: `4543`
// Minimum execution time: 6_000 nanoseconds.
// Minimum execution time: 12_000 nanoseconds.
Weight::from_parts(12_000_000, 0)
.saturating_add(Weight::from_parts(4543, 0))
.saturating_add(RocksDbWeight::get().reads(3_u64))
Expand Down
4 changes: 2 additions & 2 deletions runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@ impl WeightToFeePolynomial for RefTimeToFee {
type Balance = Balance;

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

smallvec::smallvec![WeightToFeeCoefficient {
degree: 1,
Expand Down
2 changes: 1 addition & 1 deletion runtime/common/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ macro_rules! impl_evm_tests {
#[test]
fn evm_constants_are_correctly() {
assert_eq!(BlockGasLimit::get(), U256::from(20_000_000));
assert_eq!(WeightPerGas::get().ref_time(), 75000);
assert_eq!(WeightPerGas::get().ref_time(), 18750);
}

#[test]
Expand Down
2 changes: 0 additions & 2 deletions runtime/crab/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ cumulus-pallet-dmp-queue = { workspace = true }
cumulus-pallet-parachain-system = { workspace = true }
cumulus-pallet-xcm = { workspace = true }
cumulus-pallet-xcmp-queue = { workspace = true }
cumulus-primitives-aura = { workspace = true }
cumulus-primitives-core = { workspace = true }
cumulus-primitives-utility = { workspace = true }
parachain-info = { workspace = true }
Expand Down Expand Up @@ -142,7 +141,6 @@ std = [
"cumulus-pallet-parachain-system/std",
"cumulus-pallet-xcm/std",
"cumulus-pallet-xcmp-queue/std",
"cumulus-primitives-aura/std",
"cumulus-primitives-core/std",
"cumulus-primitives-utility/std",
"parachain-info/std",
Expand Down
9 changes: 0 additions & 9 deletions runtime/crab/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,15 +325,6 @@ sp_api::impl_runtime_apis! {
}
}

impl cumulus_primitives_aura::AuraUnincludedSegmentApi<Block> for Runtime {
fn can_build_upon(
included_hash: <Block as sp_runtime::traits::Block>::Hash,
slot: cumulus_primitives_aura::Slot,
) -> bool {
ConsensusHook::can_build_upon(included_hash, slot)
}
}

impl cumulus_primitives_core::CollectCollationInfo<Block> for Runtime {
fn collect_collation_info(header: &<Block as sp_runtime::traits::Block>::Header) -> cumulus_primitives_core::CollationInfo {
ParachainSystem::collect_collation_info(header)
Expand Down
3 changes: 2 additions & 1 deletion runtime/crab/src/pallets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ mod session;
pub use session::*;

mod aura;
pub use aura::*;

mod aura_ext;

// Governance stuff.
mod governance;
Expand Down
Loading

0 comments on commit 4fce0cc

Please sign in to comment.