difftreelog
Merge pull request #1012 from UniqueNetwork/feature/lookahead-leftovers
in: master
Fix lookahead collator build
11 files changed
Cargo.lockdiffbeforeafterboth--- a/Cargo.lock
+++ b/Cargo.lock
@@ -6450,6 +6450,7 @@
"cumulus-pallet-parachain-system",
"cumulus-pallet-xcm",
"cumulus-pallet-xcmp-queue",
+ "cumulus-primitives-aura",
"cumulus-primitives-core",
"cumulus-primitives-timestamp",
"cumulus-primitives-utility",
@@ -8109,12 +8110,14 @@
"pallet-evm-coder-substrate",
"pallet-nonfungible",
"pallet-refungible",
+ "pallet-structure",
"parity-scale-codec",
"scale-info",
"sp-core",
"sp-io",
"sp-runtime",
"sp-std",
+ "up-common",
"up-data-structs",
]
@@ -14732,6 +14735,7 @@
"cumulus-client-consensus-proposer",
"cumulus-client-network",
"cumulus-client-service",
+ "cumulus-primitives-aura",
"cumulus-primitives-core",
"cumulus-primitives-parachain-inherent",
"cumulus-relay-chain-inprocess-interface",
Cargo.tomldiffbeforeafterboth--- a/Cargo.toml
+++ b/Cargo.toml
@@ -100,6 +100,7 @@
cumulus-pallet-parachain-system = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
cumulus-pallet-xcm = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
cumulus-pallet-xcmp-queue = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
+cumulus-primitives-aura = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
cumulus-primitives-core = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
cumulus-primitives-parachain-inherent = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
cumulus-primitives-timestamp = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
node/cli/Cargo.tomldiffbeforeafterboth--- a/node/cli/Cargo.toml
+++ b/node/cli/Cargo.toml
@@ -36,6 +36,7 @@
cumulus-client-consensus-proposer = { workspace = true }
cumulus-client-network = { workspace = true }
cumulus-client-service = { workspace = true }
+cumulus-primitives-aura = { workspace = true }
cumulus-primitives-core = { workspace = true }
cumulus-primitives-parachain-inherent = { features = ["std"], workspace = true }
cumulus-relay-chain-inprocess-interface = { workspace = true }
@@ -113,7 +114,9 @@
'quartz-runtime?/gov-test-timings',
'unique-runtime?/gov-test-timings',
]
-lookahead = []
+lookahead = [
+ 'opal-runtime/lookahead'
+]
pov-estimate = [
'opal-runtime/pov-estimate',
'quartz-runtime?/pov-estimate',
node/cli/src/command.rsdiffbeforeafterboth--- a/node/cli/src/command.rs
+++ b/node/cli/src/command.rs
@@ -396,6 +396,8 @@
}
}
#[cfg(feature = "try-runtime")]
+ // embedded try-runtime cli will be removed soon.
+ #[allow(deprecated)]
Some(Subcommand::TryRuntime(cmd)) => {
use std::{future::Future, pin::Pin};
node/cli/src/service.rsdiffbeforeafterboth221 {221 {222 }222 }223);223);224#[cfg(not(feature = "lookahead"))]225ez_bounds!(226 pub trait LookaheadApiDep {}227);228#[cfg(feature = "lookahead")]229ez_bounds!(230 pub trait LookaheadApiDep: cumulus_primitives_aura::AuraUnincludedSegmentApi<Block> {}231);224232225/// Starts a `ServiceBuilder` for a full service.233/// Starts a `ServiceBuilder` for a full service.226///234///358 + Sync366 + Sync359 + 'static,367 + 'static,360 RuntimeApi::RuntimeApi: RuntimeApiDep<Runtime> + 'static,368 RuntimeApi::RuntimeApi: RuntimeApiDep<Runtime> + 'static,369 RuntimeApi::RuntimeApi: LookaheadApiDep,361 Runtime: RuntimeInstance,370 Runtime: RuntimeInstance,362 ExecutorDispatch: NativeExecutionDispatch + 'static,371 ExecutorDispatch: NativeExecutionDispatch + 'static,363{372{687 announce_block: Arc<dyn Fn(Hash, Option<Vec<u8>>) + Send + Sync>,696 announce_block: Arc<dyn Fn(Hash, Option<Vec<u8>>) + Send + Sync>,688}697}689698699// Clones ignored for optional lookahead collator700#[allow(clippy::redundant_clone)]690pub fn start_consensus<ExecutorDispatch, RuntimeApi, Runtime>(701pub fn start_consensus<ExecutorDispatch, RuntimeApi, Runtime>(691 client: Arc<FullClient<RuntimeApi, ExecutorDispatch>>,702 client: Arc<FullClient<RuntimeApi, ExecutorDispatch>>,692 transaction_pool: Arc<703 transaction_pool: Arc<701 + Sync712 + Sync702 + 'static,713 + 'static,703 RuntimeApi::RuntimeApi: RuntimeApiDep<Runtime> + 'static,714 RuntimeApi::RuntimeApi: RuntimeApiDep<Runtime> + 'static,715 RuntimeApi::RuntimeApi: LookaheadApiDep,704 Runtime: RuntimeInstance,716 Runtime: RuntimeInstance,705{717{706 let StartConsensusParameters {718 let StartConsensusParameters {735 client.clone(),747 client.clone(),736 );748 );737749738 let block_import = ParachainBlockImport::new(client.clone(), backend);750 let block_import = ParachainBlockImport::new(client.clone(), backend.clone());739751740 let params = BuildAuraConsensusParams {752 let params = BuildAuraConsensusParams {741 create_inherent_data_providers: move |_, ()| async move { Ok(()) },753 create_inherent_data_providers: move |_, ()| async move { Ok(()) },742 block_import,754 block_import,743 para_client: client,755 para_client: client.clone(),744 #[cfg(feature = "lookahead")]756 #[cfg(feature = "lookahead")]745 para_backend: backend,757 para_backend: backend,746 para_id,758 para_id,751 proposer,763 proposer,752 collator_service,764 collator_service,753 // With async-baking, we allowed to be both slower (longer authoring) and faster (multiple para blocks per relay block)765 // With async-baking, we allowed to be both slower (longer authoring) and faster (multiple para blocks per relay block)766 #[cfg(not(feature = "lookahead"))]754 authoring_duration: Duration::from_millis(500),767 authoring_duration: Duration::from_millis(500),768 #[cfg(feature = "lookahead")]769 authoring_duration: Duration::from_millis(1500),755 overseer_handle,770 overseer_handle,756 #[cfg(feature = "lookahead")]771 #[cfg(feature = "lookahead")]757 code_hash_provider: || {},772 code_hash_provider: move |block_hash| {773 client774 .code_at(block_hash)775 .ok()776 .map(cumulus_primitives_core::relay_chain::ValidationCode)777 .map(|c| c.hash())778 },758 collator_key,779 collator_key,759 relay_chain_slot_duration,780 relay_chain_slot_duration,762 task_manager.spawn_essential_handle().spawn(783 task_manager.spawn_essential_handle().spawn(763 "aura",784 "aura",764 None,785 None,786 #[cfg(not(feature = "lookahead"))]765 run_aura::<_, AuraAuthorityPair, _, _, _, _, _, _, _>(params),787 run_aura::<_, AuraAuthorityPair, _, _, _, _, _, _, _>(params),788 #[cfg(feature = "lookahead")]789 run_aura::<_, AuraAuthorityPair, _, _, _, _, _, _, _, _, _>(params),766 );790 );767 Ok(())791 Ok(())768}792}pallets/inflation/src/lib.rsdiffbeforeafterboth--- a/pallets/inflation/src/lib.rs
+++ b/pallets/inflation/src/lib.rs
@@ -70,8 +70,10 @@
+ Mutate<Self::AccountId>;
type TreasuryAccountId: Get<Self::AccountId>;
- // The block number provider
- type BlockNumberProvider: BlockNumberProvider<BlockNumber = BlockNumberFor<Self>>;
+ // The block number provider, which should be callable from `on_initialize` hook.
+ type OnInitializeBlockNumberProvider: BlockNumberProvider<
+ BlockNumber = BlockNumberFor<Self>,
+ >;
/// Number of blocks that pass between treasury balance updates due to inflation
#[pallet::constant]
@@ -118,7 +120,7 @@
};
let block_interval: u32 = T::InflationBlockInterval::get().try_into().unwrap_or(0);
- let current_relay_block = T::BlockNumberProvider::current_block_number();
+ let current_relay_block = T::OnInitializeBlockNumberProvider::current_block_number();
let next_inflation: BlockNumberFor<T> = <NextInflationBlock<T>>::get();
add_weight(1, 0, Weight::from_parts(5_000_000, 0));
primitives/common/src/constants.rsdiffbeforeafterboth--- a/primitives/common/src/constants.rs
+++ b/primitives/common/src/constants.rs
@@ -23,7 +23,10 @@
use crate::types::{Balance, BlockNumber};
+#[cfg(not(feature = "lookahead"))]
pub const MILLISECS_PER_BLOCK: u64 = 12000;
+#[cfg(feature = "lookahead")]
+pub const MILLISECS_PER_BLOCK: u64 = 3000;
pub const MILLISECS_PER_RELAY_BLOCK: u64 = 6000;
pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK;
runtime/common/config/pallets/mod.rsdiffbeforeafterboth--- a/runtime/common/config/pallets/mod.rs
+++ b/runtime/common/config/pallets/mod.rs
@@ -21,7 +21,7 @@
traits::{ConstU32, ConstU64, Currency},
};
use sp_arithmetic::Perbill;
-use sp_runtime::traits::AccountIdConversion;
+use sp_runtime::traits::{AccountIdConversion, BlockNumberProvider};
use up_common::{
constants::*,
types::{AccountId, Balance, BlockNumber},
@@ -105,12 +105,34 @@
pub const InflationBlockInterval: BlockNumber = 100; // every time per how many blocks inflation is applied
}
+/// Pallet-inflation needs block number in on_initialize, where there is no `validation_data` exists yet
+pub struct OnInitializeBlockNumberProvider;
+impl BlockNumberProvider for OnInitializeBlockNumberProvider {
+ type BlockNumber = BlockNumber;
+
+ fn current_block_number() -> Self::BlockNumber {
+ use hex_literal::hex;
+ use parity_scale_codec::Decode;
+ use sp_io::storage;
+ // TODO: Replace with the following code after https://github.com/paritytech/polkadot-sdk/commit/3ea497b5a0fdda252f9c5a3c257cfaf8685f02fd lands
+ // <cumulus_pallet_parachain_system::Pallet<Runtime>>::last_relay_block_number()
+
+ // ParachainSystem.LastRelayChainBlockNumber
+ let Some(encoded) = storage::get(&hex!("45323df7cc47150b3930e2666b0aa313a2bca190d36bd834cc73a38fc213ecbd")) else {
+ // First parachain block
+ return Default::default()
+ };
+ BlockNumber::decode(&mut encoded.as_ref())
+ .expect("typeof(RelayBlockNumber) == typeof(BlockNumber) == u32; qed")
+ }
+}
+
/// Used for the pallet inflation
impl pallet_inflation::Config for Runtime {
type Currency = Balances;
type TreasuryAccountId = TreasuryAccountId;
type InflationBlockInterval = InflationBlockInterval;
- type BlockNumberProvider = RelayChainBlockNumberProvider<Runtime>;
+ type OnInitializeBlockNumberProvider = OnInitializeBlockNumberProvider;
}
impl pallet_unique::Config for Runtime {
runtime/common/config/parachain.rsdiffbeforeafterboth--- a/runtime/common/config/parachain.rs
+++ b/runtime/common/config/parachain.rs
@@ -38,9 +38,29 @@
type ReservedDmpWeight = ReservedDmpWeight;
type ReservedXcmpWeight = ReservedXcmpWeight;
type XcmpMessageHandler = XcmpQueue;
+ #[cfg(not(feature = "lookahead"))]
type CheckAssociatedRelayNumber = cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases;
+ #[cfg(feature = "lookahead")]
+ type CheckAssociatedRelayNumber =
+ cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases;
}
impl parachain_info::Config for Runtime {}
impl cumulus_pallet_aura_ext::Config for Runtime {}
+
+/// Maximum number of blocks simultaneously accepted by the Runtime, not yet included
+/// into the relay chain.
+#[cfg(feature = "lookahead")]
+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.
+#[cfg(feature = "lookahead")]
+const BLOCK_PROCESSING_VELOCITY: u32 = 2;
+#[cfg(feature = "lookahead")]
+pub type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook<
+ Runtime,
+ { MILLISECS_PER_RELAY_BLOCK as u32 },
+ BLOCK_PROCESSING_VELOCITY,
+ UNINCLUDED_SEGMENT_CAPACITY,
+>;
runtime/common/runtime_apis.rsdiffbeforeafterboth--- a/runtime/common/runtime_apis.rs
+++ b/runtime/common/runtime_apis.rs
@@ -679,6 +679,16 @@
}
}
+ #[cfg(feature = "lookahead")]
+ impl cumulus_primitives_aura::AuraUnincludedSegmentApi<Block> for Runtime {
+ fn can_build_upon(
+ included_hash: <Block as BlockT>::Hash,
+ slot: cumulus_primitives_aura::Slot,
+ ) -> bool {
+ $crate::config::parachain::ConsensusHook::can_build_upon(included_hash, slot)
+ }
+ }
+
/// Should never be used, yet still required because of https://github.com/paritytech/polkadot-sdk/issues/27
/// Not allowed to panic, because rpc may be called using native runtime, thus causing thread panic.
impl fp_rpc::ConvertTransactionRuntimeApi<Block> for Runtime {
runtime/opal/Cargo.tomldiffbeforeafterboth--- a/runtime/opal/Cargo.toml
+++ b/runtime/opal/Cargo.toml
@@ -69,6 +69,7 @@
'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',
'frame-executive/std',
@@ -230,6 +231,7 @@
preimage = []
refungible = []
session-test-timings = []
+lookahead = []
################################################################################
# local dependencies
@@ -240,6 +242,7 @@
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-timestamp = { workspace = true }
cumulus-primitives-utility = { workspace = true }