Skip to content

Commit 4fce0cc

Browse files
authored
Revert "Async backing (#1492)" (#1505)
This reverts commit 48f10ed.
1 parent 8384846 commit 4fce0cc

37 files changed

+902
-1244
lines changed

Cargo.lock

Lines changed: 737 additions & 953 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 32 additions & 139 deletions
Large diffs are not rendered by default.

core/primitives/src/lib.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,23 +60,30 @@ pub type Header = sp_runtime::generic::Header<BlockNumber, Hashing>;
6060
/// Block type.
6161
pub type Block = sp_runtime::generic::Block<Header, sp_runtime::OpaqueExtrinsic>;
6262

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

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

7784
// Time is measured by number of blocks.
7885
/// 10 blocks.
79-
pub const MINUTES: BlockNumber = 60_000 / (SLOT_DURATION as BlockNumber);
86+
pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber);
8087
/// 600 blocks.
8188
pub const HOURS: BlockNumber = MINUTES * 60;
8289
/// 14,400 blocks.

node/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ cumulus-client-consensus-aura = { workspace = true }
2828
cumulus-client-consensus-common = { workspace = true }
2929
cumulus-client-consensus-proposer = { workspace = true }
3030
cumulus-client-service = { workspace = true }
31-
cumulus-primitives-aura = { workspace = true, features = ["std"] }
3231
cumulus-primitives-core = { workspace = true, features = ["std"] }
3332
cumulus-primitives-parachain-inherent = { workspace = true, features = ["std"] }
3433
cumulus-relay-chain-interface = { workspace = true }

node/src/command.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,6 @@ pub fn run() -> Result<()> {
506506
if chain_spec.is_crab() {
507507
return service::start_dev_node::<CrabRuntimeApi, CrabRuntimeExecutor>(
508508
config,
509-
id,
510509
&eth_rpc_config,
511510
)
512511
.map_err(Into::into);
@@ -516,7 +515,6 @@ pub fn run() -> Result<()> {
516515
if chain_spec.is_darwinia() {
517516
return service::start_dev_node::<DarwiniaRuntimeApi, DarwiniaRuntimeExecutor>(
518517
config,
519-
id,
520518
&eth_rpc_config,
521519
)
522520
.map_err(Into::into)
@@ -526,7 +524,6 @@ pub fn run() -> Result<()> {
526524
if chain_spec.is_pangolin() {
527525
return service::start_dev_node::<PangolinRuntimeApi, PangolinRuntimeExecutor>(
528526
config,
529-
id,
530527
&eth_rpc_config,
531528
)
532529
.map_err(Into::into)

node/src/service/mod.rs

Lines changed: 29 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,9 @@ use futures::FutureExt;
4343
// darwinia
4444
use dc_primitives::*;
4545
// substrate
46-
use sc_client_api::{Backend, HeaderBackend};
46+
use sc_client_api::Backend;
4747
use sc_consensus::ImportQueue;
4848
use sc_network::NetworkBlock;
49-
use sp_core::Encode;
5049

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

9695
/// A set of APIs that darwinia-like runtimes must implement.
9796
pub trait RuntimeApiCollection:
98-
cumulus_primitives_aura::AuraUnincludedSegmentApi<Block>
99-
+ cumulus_primitives_core::CollectCollationInfo<Block>
97+
cumulus_primitives_core::CollectCollationInfo<Block>
10098
+ fp_rpc::ConvertTransactionRuntimeApi<Block>
10199
+ fp_rpc::EthereumRuntimeRPCApi<Block>
102100
+ moonbeam_rpc_primitives_debug::DebugRuntimeApi<Block>
@@ -112,8 +110,7 @@ pub trait RuntimeApiCollection:
112110
{
113111
}
114112
impl<Api> RuntimeApiCollection for Api where
115-
Api: cumulus_primitives_aura::AuraUnincludedSegmentApi<Block>
116-
+ cumulus_primitives_core::CollectCollationInfo<Block>
113+
Api: cumulus_primitives_core::CollectCollationInfo<Block>
117114
+ fp_rpc::ConvertTransactionRuntimeApi<Block>
118115
+ fp_rpc::EthereumRuntimeRPCApi<Block>
119116
+ moonbeam_rpc_primitives_debug::DebugRuntimeApi<Block>
@@ -264,7 +261,6 @@ where
264261
Executor: 'static + sc_executor::NativeExecutionDispatch,
265262
SC: FnOnce(
266263
Arc<FullClient<RuntimeApi, Executor>>,
267-
Arc<FullBackend>,
268264
ParachainBlockImport<RuntimeApi, Executor>,
269265
Option<&substrate_prometheus_endpoint::Registry>,
270266
Option<sc_telemetry::TelemetryHandle>,
@@ -300,6 +296,7 @@ where
300296
telemetry_worker_handle,
301297
),
302298
} = new_partial::<RuntimeApi, Executor>(&parachain_config, eth_rpc_config)?;
299+
303300
let (relay_chain_interface, collator_key) =
304301
cumulus_client_service::build_relay_chain_interface(
305302
polkadot_config,
@@ -311,10 +308,12 @@ where
311308
)
312309
.await
313310
.map_err(|e| sc_service::Error::Application(Box::new(e) as Box<_>))?;
311+
314312
let validator = parachain_config.role.is_authority();
315313
let prometheus_registry = parachain_config.prometheus_registry().cloned();
316314
let import_queue_service = import_queue.service();
317315
let net_config = sc_network::config::FullNetworkConfiguration::new(&parachain_config.network);
316+
318317
let (network, system_rpc_tx, tx_handler_controller, start_network, sync_service) =
319318
cumulus_client_service::build_network(cumulus_client_service::BuildNetworkParams {
320319
parachain_config: &parachain_config,
@@ -522,7 +521,6 @@ where
522521
if validator {
523522
start_consensus(
524523
client.clone(),
525-
backend.clone(),
526524
block_import,
527525
prometheus_registry.as_ref(),
528526
telemetry.as_ref().map(|t| t.handle()),
@@ -616,7 +614,6 @@ where
616614
cumulus_client_service::CollatorSybilResistance::Resistant, // Aura
617615
para_id,
618616
|client,
619-
backend,
620617
block_import,
621618
prometheus_registry,
622619
telemetry,
@@ -645,17 +642,11 @@ where
645642
announce_block,
646643
client.clone(),
647644
);
648-
let params = cumulus_client_consensus_aura::collators::lookahead::Params {
645+
let params = cumulus_client_consensus_aura::collators::basic::Params {
649646
create_inherent_data_providers: move |_, ()| async move { Ok(()) },
650647
block_import,
651-
para_client: client.clone(),
652-
para_backend: backend.clone(),
648+
para_client: client,
653649
relay_client: relay_chain_interface,
654-
code_hash_provider: move |block_hash| {
655-
client.code_at(block_hash).ok().map(|c| {
656-
cumulus_primitives_core::relay_chain::ValidationCode::from(c).hash()
657-
})
658-
},
659650
sync_oracle,
660651
keystore,
661652
collator_key,
@@ -666,9 +657,9 @@ where
666657
proposer,
667658
collator_service,
668659
// Very limited proposal time.
669-
authoring_duration: Duration::from_millis(1_500),
660+
authoring_duration: Duration::from_millis(500),
670661
};
671-
let fut = cumulus_client_consensus_aura::collators::lookahead::run::<
662+
let fut = cumulus_client_consensus_aura::collators::basic::run::<
672663
Block,
673664
sp_consensus_aura::sr25519::AuthorityPair,
674665
_,
@@ -678,8 +669,6 @@ where
678669
_,
679670
_,
680671
_,
681-
_,
682-
_,
683672
>(params);
684673

685674
task_manager.spawn_essential_handle().spawn("aura", None, fut);
@@ -696,19 +685,21 @@ where
696685
/// !!! WARNING: DO NOT USE ELSEWHERE
697686
pub fn start_dev_node<RuntimeApi, Executor>(
698687
mut config: sc_service::Configuration,
699-
para_id: cumulus_primitives_core::ParaId,
700688
eth_rpc_config: &crate::cli::EthRpcConfig,
701689
) -> Result<sc_service::TaskManager, sc_service::error::Error>
702690
where
703-
RuntimeApi: 'static
691+
RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, Executor>>
704692
+ Send
705693
+ Sync
706-
+ sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, Executor>>,
694+
+ 'static,
707695
RuntimeApi::RuntimeApi: RuntimeApiCollection,
708696
RuntimeApi::RuntimeApi:
709697
sp_consensus_aura::AuraApi<Block, sp_consensus_aura::sr25519::AuthorityId>,
710698
Executor: 'static + sc_executor::NativeExecutionDispatch,
711699
{
700+
// substrate
701+
use sc_client_api::HeaderBackend;
702+
712703
let sc_service::PartialComponents {
713704
client,
714705
backend,
@@ -729,6 +720,7 @@ where
729720
),
730721
} = new_partial::<RuntimeApi, Executor>(&config, eth_rpc_config)?;
731722
let net_config = sc_network::config::FullNetworkConfiguration::new(&config.network);
723+
732724
let (network, system_rpc_tx, tx_handler_controller, start_network, sync_service) =
733725
sc_service::build_network(sc_service::BuildNetworkParams {
734726
config: &config,
@@ -765,17 +757,17 @@ where
765757
}
766758

767759
let force_authoring = config.force_authoring;
768-
let backoff_authoring_blocks = <Option<()>>::None;
769-
let slot_duration = sc_consensus_aura::slot_duration(&*client)?;
760+
let backoff_authoring_blocks: Option<()> = None;
770761
let proposer_factory = sc_basic_authorship::ProposerFactory::new(
771762
task_manager.spawn_handle(),
772763
client.clone(),
773764
transaction_pool.clone(),
774765
None,
775766
None,
776767
);
777-
let client_for_cidp = client.clone();
778768

769+
let slot_duration = sc_consensus_aura::slot_duration(&*client)?;
770+
let client_for_cidp = client.clone();
779771
if config.role.is_authority() {
780772
let aura = sc_consensus_aura::start_aura::<
781773
sp_consensus_aura::sr25519::AuthorityPair,
@@ -790,54 +782,41 @@ where
790782
_,
791783
_,
792784
>(sc_consensus_aura::StartAuraParams {
793-
slot_duration,
785+
slot_duration: sc_consensus_aura::slot_duration(&*client)?,
794786
client: client.clone(),
795787
select_chain,
796788
block_import: instant_finalize::InstantFinalizeBlockImport::new(client.clone()),
797789
proposer_factory,
798790
create_inherent_data_providers: move |block: Hash, ()| {
799-
let maybe_current_para_block = client_for_cidp.number(block);
800-
let maybe_current_block_head = client_for_cidp.expect_header(block);
791+
let current_para_block = client_for_cidp
792+
.number(block)
793+
.expect("Header lookup should succeed")
794+
.expect("Header passed in as parent should be present in backend.");
801795
let client_for_xcm = client_for_cidp.clone();
802-
// TODO: hack for now.
803-
let additional_key_values = Some(vec![(
804-
array_bytes::hex2bytes_unchecked(
805-
"1cb6f36e027abb2091cfb5110ab5087f06155b3cd9a8c9e5e9a23fd5dc13a5ed",
806-
),
807-
cumulus_primitives_aura::Slot::from_timestamp(
808-
sp_timestamp::Timestamp::current(),
809-
slot_duration,
810-
)
811-
.encode(),
812-
)]);
813796

814797
async move {
815-
let current_para_block = maybe_current_para_block?
816-
.ok_or(sp_blockchain::Error::UnknownBlock(block.to_string()))?;
817-
let current_para_block_head =
818-
Some(polkadot_primitives::HeadData(maybe_current_block_head?.encode()));
819798
let timestamp = sp_timestamp::InherentDataProvider::from_system_time();
799+
820800
let slot = sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration(
821801
*timestamp,
822802
slot_duration,
823803
);
804+
824805
let mocked_parachain =
825806
cumulus_primitives_parachain_inherent::MockValidationDataInherentDataProvider {
826807
current_para_block,
827-
current_para_block_head,
828808
relay_offset: 1000,
829809
relay_blocks_per_para_block: 2,
830810
para_blocks_per_relay_epoch: 0,
831811
relay_randomness_config: (),
832812
xcm_config: cumulus_primitives_parachain_inherent::MockXcmConfig::new(
833813
&*client_for_xcm,
834814
block,
835-
para_id,
815+
Default::default(),
836816
Default::default(),
837817
),
838818
raw_downward_messages: Vec::new(),
839819
raw_horizontal_messages: Vec::new(),
840-
additional_key_values,
841820
};
842821

843822
Ok((slot, timestamp, mocked_parachain))
@@ -908,6 +887,8 @@ where
908887
let collator = config.role.is_authority();
909888
let eth_rpc_config = eth_rpc_config.clone();
910889
let sync_service = sync_service.clone();
890+
891+
let slot_duration = sc_consensus_aura::slot_duration(&*client)?;
911892
let pending_create_inherent_data_providers = move |_, ()| async move {
912893
let current = sp_timestamp::InherentDataProvider::from_system_time();
913894
let next_slot = current.timestamp().as_millis() + slot_duration.as_millis();

pallet/staking/src/weights.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
134134
// Proof Size summary in bytes:
135135
// Measured: `574`
136136
// Estimated: `4543`
137-
// Minimum execution time: 6_000 nanoseconds.
137+
// Minimum execution time: 12_000 nanoseconds.
138138
Weight::from_parts(12_000_000, 0)
139139
.saturating_add(Weight::from_parts(4543, 0))
140140
.saturating_add(T::DbWeight::get().reads(3_u64))
@@ -265,7 +265,7 @@ impl WeightInfo for () {
265265
// Proof Size summary in bytes:
266266
// Measured: `574`
267267
// Estimated: `4543`
268-
// Minimum execution time: 6_000 nanoseconds.
268+
// Minimum execution time: 12_000 nanoseconds.
269269
Weight::from_parts(12_000_000, 0)
270270
.saturating_add(Weight::from_parts(4543, 0))
271271
.saturating_add(RocksDbWeight::get().reads(3_u64))

runtime/common/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,9 @@ impl WeightToFeePolynomial for RefTimeToFee {
174174
type Balance = Balance;
175175

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

181181
smallvec::smallvec![WeightToFeeCoefficient {
182182
degree: 1,

runtime/common/src/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ macro_rules! impl_evm_tests {
421421
#[test]
422422
fn evm_constants_are_correctly() {
423423
assert_eq!(BlockGasLimit::get(), U256::from(20_000_000));
424-
assert_eq!(WeightPerGas::get().ref_time(), 75000);
424+
assert_eq!(WeightPerGas::get().ref_time(), 18750);
425425
}
426426

427427
#[test]

runtime/crab/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ cumulus-pallet-dmp-queue = { workspace = true }
2727
cumulus-pallet-parachain-system = { workspace = true }
2828
cumulus-pallet-xcm = { workspace = true }
2929
cumulus-pallet-xcmp-queue = { workspace = true }
30-
cumulus-primitives-aura = { workspace = true }
3130
cumulus-primitives-core = { workspace = true }
3231
cumulus-primitives-utility = { workspace = true }
3332
parachain-info = { workspace = true }
@@ -142,7 +141,6 @@ std = [
142141
"cumulus-pallet-parachain-system/std",
143142
"cumulus-pallet-xcm/std",
144143
"cumulus-pallet-xcmp-queue/std",
145-
"cumulus-primitives-aura/std",
146144
"cumulus-primitives-core/std",
147145
"cumulus-primitives-utility/std",
148146
"parachain-info/std",

0 commit comments

Comments
 (0)