difftreelog
Merge pull request #1012 from UniqueNetwork/feature/lookahead-leftovers
in: master
Fix lookahead collator build
11 files changed
Cargo.lockdiffbeforeafterboth6450 "cumulus-pallet-parachain-system",6450 "cumulus-pallet-parachain-system",6451 "cumulus-pallet-xcm",6451 "cumulus-pallet-xcm",6452 "cumulus-pallet-xcmp-queue",6452 "cumulus-pallet-xcmp-queue",6453 "cumulus-primitives-aura",6453 "cumulus-primitives-core",6454 "cumulus-primitives-core",6454 "cumulus-primitives-timestamp",6455 "cumulus-primitives-timestamp",6455 "cumulus-primitives-utility",6456 "cumulus-primitives-utility",8109 "pallet-evm-coder-substrate",8110 "pallet-evm-coder-substrate",8110 "pallet-nonfungible",8111 "pallet-nonfungible",8111 "pallet-refungible",8112 "pallet-refungible",8113 "pallet-structure",8112 "parity-scale-codec",8114 "parity-scale-codec",8113 "scale-info",8115 "scale-info",8114 "sp-core",8116 "sp-core",8115 "sp-io",8117 "sp-io",8116 "sp-runtime",8118 "sp-runtime",8117 "sp-std",8119 "sp-std",8120 "up-common",8118 "up-data-structs",8121 "up-data-structs",8119]8122]8120812314732 "cumulus-client-consensus-proposer",14735 "cumulus-client-consensus-proposer",14733 "cumulus-client-network",14736 "cumulus-client-network",14734 "cumulus-client-service",14737 "cumulus-client-service",14738 "cumulus-primitives-aura",14735 "cumulus-primitives-core",14739 "cumulus-primitives-core",14736 "cumulus-primitives-parachain-inherent",14740 "cumulus-primitives-parachain-inherent",14737 "cumulus-relay-chain-inprocess-interface",14741 "cumulus-relay-chain-inprocess-interface",Cargo.tomldiffbeforeafterboth100cumulus-pallet-parachain-system = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }100cumulus-pallet-parachain-system = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }101cumulus-pallet-xcm = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }101cumulus-pallet-xcm = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }102cumulus-pallet-xcmp-queue = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }102cumulus-pallet-xcmp-queue = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }103cumulus-primitives-aura = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }103cumulus-primitives-core = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }104cumulus-primitives-core = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }104cumulus-primitives-parachain-inherent = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }105cumulus-primitives-parachain-inherent = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }105cumulus-primitives-timestamp = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }106cumulus-primitives-timestamp = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }node/cli/Cargo.tomldiffbeforeafterboth36cumulus-client-consensus-proposer = { workspace = true }36cumulus-client-consensus-proposer = { workspace = true }37cumulus-client-network = { workspace = true }37cumulus-client-network = { workspace = true }38cumulus-client-service = { workspace = true }38cumulus-client-service = { workspace = true }39cumulus-primitives-aura = { workspace = true }39cumulus-primitives-core = { workspace = true }40cumulus-primitives-core = { workspace = true }40cumulus-primitives-parachain-inherent = { features = ["std"], workspace = true }41cumulus-primitives-parachain-inherent = { features = ["std"], workspace = true }41cumulus-relay-chain-inprocess-interface = { workspace = true }42cumulus-relay-chain-inprocess-interface = { workspace = true }114 'unique-runtime?/gov-test-timings',115 'unique-runtime?/gov-test-timings',115]116]116lookahead = []117lookahead = [118 'opal-runtime/lookahead'119]117pov-estimate = [120pov-estimate = [118 'opal-runtime/pov-estimate',121 'opal-runtime/pov-estimate',node/cli/src/command.rsdiffbeforeafterboth396 }396 }397 }397 }398 #[cfg(feature = "try-runtime")]398 #[cfg(feature = "try-runtime")]399 // embedded try-runtime cli will be removed soon.400 #[allow(deprecated)]399 Some(Subcommand::TryRuntime(cmd)) => {401 Some(Subcommand::TryRuntime(cmd)) => {400 use std::{future::Future, pin::Pin};402 use std::{future::Future, pin::Pin};401403node/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.rsdiffbeforeafterboth70 + Mutate<Self::AccountId>;70 + Mutate<Self::AccountId>;71 type TreasuryAccountId: Get<Self::AccountId>;71 type TreasuryAccountId: Get<Self::AccountId>;727273 // The block number provider73 // The block number provider, which should be callable from `on_initialize` hook.74 type BlockNumberProvider: BlockNumberProvider<BlockNumber = BlockNumberFor<Self>>;74 type OnInitializeBlockNumberProvider: BlockNumberProvider<75 BlockNumber = BlockNumberFor<Self>,76 >;757776 /// Number of blocks that pass between treasury balance updates due to inflation78 /// Number of blocks that pass between treasury balance updates due to inflation118 };120 };119121120 let block_interval: u32 = T::InflationBlockInterval::get().try_into().unwrap_or(0);122 let block_interval: u32 = T::InflationBlockInterval::get().try_into().unwrap_or(0);121 let current_relay_block = T::BlockNumberProvider::current_block_number();123 let current_relay_block = T::OnInitializeBlockNumberProvider::current_block_number();122 let next_inflation: BlockNumberFor<T> = <NextInflationBlock<T>>::get();124 let next_inflation: BlockNumberFor<T> = <NextInflationBlock<T>>::get();123 add_weight(1, 0, Weight::from_parts(5_000_000, 0));125 add_weight(1, 0, Weight::from_parts(5_000_000, 0));124126primitives/common/src/constants.rsdiffbeforeafterboth232324use crate::types::{Balance, BlockNumber};24use crate::types::{Balance, BlockNumber};252526#[cfg(not(feature = "lookahead"))]26pub const MILLISECS_PER_BLOCK: u64 = 12000;27pub const MILLISECS_PER_BLOCK: u64 = 12000;28#[cfg(feature = "lookahead")]29pub const MILLISECS_PER_BLOCK: u64 = 3000;27pub const MILLISECS_PER_RELAY_BLOCK: u64 = 6000;30pub const MILLISECS_PER_RELAY_BLOCK: u64 = 6000;283129pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK;32pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK;runtime/common/config/pallets/mod.rsdiffbeforeafterboth21 traits::{ConstU32, ConstU64, Currency},21 traits::{ConstU32, ConstU64, Currency},22};22};23use sp_arithmetic::Perbill;23use sp_arithmetic::Perbill;24use sp_runtime::traits::AccountIdConversion;24use sp_runtime::traits::{AccountIdConversion, BlockNumberProvider};25use up_common::{25use up_common::{26 constants::*,26 constants::*,27 types::{AccountId, Balance, BlockNumber},27 types::{AccountId, Balance, BlockNumber},105 pub const InflationBlockInterval: BlockNumber = 100; // every time per how many blocks inflation is applied105 pub const InflationBlockInterval: BlockNumber = 100; // every time per how many blocks inflation is applied106}106}107108/// Pallet-inflation needs block number in on_initialize, where there is no `validation_data` exists yet109pub struct OnInitializeBlockNumberProvider;110impl BlockNumberProvider for OnInitializeBlockNumberProvider {111 type BlockNumber = BlockNumber;112113 fn current_block_number() -> Self::BlockNumber {114 use hex_literal::hex;115 use parity_scale_codec::Decode;116 use sp_io::storage;117 // TODO: Replace with the following code after https://github.com/paritytech/polkadot-sdk/commit/3ea497b5a0fdda252f9c5a3c257cfaf8685f02fd lands118 // <cumulus_pallet_parachain_system::Pallet<Runtime>>::last_relay_block_number()119120 // ParachainSystem.LastRelayChainBlockNumber121 let Some(encoded) = storage::get(&hex!("45323df7cc47150b3930e2666b0aa313a2bca190d36bd834cc73a38fc213ecbd")) else {122 // First parachain block123 return Default::default()124 };125 BlockNumber::decode(&mut encoded.as_ref())126 .expect("typeof(RelayBlockNumber) == typeof(BlockNumber) == u32; qed")127 }128}107129108/// Used for the pallet inflation130/// Used for the pallet inflation109impl pallet_inflation::Config for Runtime {131impl pallet_inflation::Config for Runtime {110 type Currency = Balances;132 type Currency = Balances;111 type TreasuryAccountId = TreasuryAccountId;133 type TreasuryAccountId = TreasuryAccountId;112 type InflationBlockInterval = InflationBlockInterval;134 type InflationBlockInterval = InflationBlockInterval;113 type BlockNumberProvider = RelayChainBlockNumberProvider<Runtime>;135 type OnInitializeBlockNumberProvider = OnInitializeBlockNumberProvider;114}136}115137116impl pallet_unique::Config for Runtime {138impl pallet_unique::Config for Runtime {runtime/common/config/parachain.rsdiffbeforeafterboth38 type ReservedDmpWeight = ReservedDmpWeight;38 type ReservedDmpWeight = ReservedDmpWeight;39 type ReservedXcmpWeight = ReservedXcmpWeight;39 type ReservedXcmpWeight = ReservedXcmpWeight;40 type XcmpMessageHandler = XcmpQueue;40 type XcmpMessageHandler = XcmpQueue;41 #[cfg(not(feature = "lookahead"))]41 type CheckAssociatedRelayNumber = cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases;42 type CheckAssociatedRelayNumber = cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases;43 #[cfg(feature = "lookahead")]44 type CheckAssociatedRelayNumber =45 cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases;42}46}434744impl parachain_info::Config for Runtime {}48impl parachain_info::Config for Runtime {}454946impl cumulus_pallet_aura_ext::Config for Runtime {}50impl cumulus_pallet_aura_ext::Config for Runtime {}5152/// Maximum number of blocks simultaneously accepted by the Runtime, not yet included53/// into the relay chain.54#[cfg(feature = "lookahead")]55const UNINCLUDED_SEGMENT_CAPACITY: u32 = 3;56/// How many parachain blocks are processed by the relay chain per parent. Limits the57/// number of blocks authored per slot.58#[cfg(feature = "lookahead")]59const BLOCK_PROCESSING_VELOCITY: u32 = 2;60#[cfg(feature = "lookahead")]61pub type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook<62 Runtime,63 { MILLISECS_PER_RELAY_BLOCK as u32 },64 BLOCK_PROCESSING_VELOCITY,65 UNINCLUDED_SEGMENT_CAPACITY,66>;4767runtime/common/runtime_apis.rsdiffbeforeafterboth679 }679 }680 }680 }681682 #[cfg(feature = "lookahead")]683 impl cumulus_primitives_aura::AuraUnincludedSegmentApi<Block> for Runtime {684 fn can_build_upon(685 included_hash: <Block as BlockT>::Hash,686 slot: cumulus_primitives_aura::Slot,687 ) -> bool {688 $crate::config::parachain::ConsensusHook::can_build_upon(included_hash, slot)689 }690 }681691682 /// Should never be used, yet still required because of https://github.com/paritytech/polkadot-sdk/issues/27692 /// Should never be used, yet still required because of https://github.com/paritytech/polkadot-sdk/issues/27683 /// Not allowed to panic, because rpc may be called using native runtime, thus causing thread panic.693 /// Not allowed to panic, because rpc may be called using native runtime, thus causing thread panic.runtime/opal/Cargo.tomldiffbeforeafterboth69 'cumulus-pallet-parachain-system/std',69 'cumulus-pallet-parachain-system/std',70 'cumulus-pallet-xcm/std',70 'cumulus-pallet-xcm/std',71 'cumulus-pallet-xcmp-queue/std',71 'cumulus-pallet-xcmp-queue/std',72 'cumulus-primitives-aura/std',72 'cumulus-primitives-core/std',73 'cumulus-primitives-core/std',73 'cumulus-primitives-utility/std',74 'cumulus-primitives-utility/std',74 'frame-executive/std',75 'frame-executive/std',230preimage = []231preimage = []231refungible = []232refungible = []232session-test-timings = []233session-test-timings = []234lookahead = []233235234################################################################################236################################################################################235# local dependencies237# local dependencies240cumulus-pallet-parachain-system = { workspace = true }242cumulus-pallet-parachain-system = { workspace = true }241cumulus-pallet-xcm = { workspace = true }243cumulus-pallet-xcm = { workspace = true }242cumulus-pallet-xcmp-queue = { workspace = true }244cumulus-pallet-xcmp-queue = { workspace = true }245cumulus-primitives-aura = { workspace = true }243cumulus-primitives-core = { workspace = true }246cumulus-primitives-core = { workspace = true }244cumulus-primitives-timestamp = { workspace = true }247cumulus-primitives-timestamp = { workspace = true }245cumulus-primitives-utility = { workspace = true }248cumulus-primitives-utility = { workspace = true }