Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: deprecate AsyncBackingParams #7254

Draft
wants to merge 15 commits into
base: master
Choose a base branch
from
57 changes: 37 additions & 20 deletions cumulus/client/consensus/aura/src/collators/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,18 @@

use crate::collator::SlotClaim;
use codec::Codec;
use cumulus_client_consensus_common::{
self as consensus_common, load_abridged_host_configuration, ParentSearchParams,
};
use cumulus_client_consensus_common::{self as consensus_common, ParentSearchParams};
use cumulus_primitives_aura::{AuraUnincludedSegmentApi, Slot};
use cumulus_primitives_core::{relay_chain::Hash as ParaHash, BlockT, ClaimQueueOffset};
use cumulus_relay_chain_interface::RelayChainInterface;
use polkadot_node_subsystem::messages::RuntimeApiRequest;
use polkadot_node_subsystem_util::runtime::ClaimQueueSnapshot;
use polkadot_primitives::{
AsyncBackingParams, CoreIndex, Hash as RelayHash, Id as ParaId, OccupiedCoreAssumption,
ValidationCodeHash,
CoreIndex, Hash as RelayHash, Id as ParaId, OccupiedCoreAssumption, ValidationCodeHash,
DEFAULT_SCHEDULING_LOOKAHEAD,
};
use sc_consensus_aura::{standalone as aura_internal, AuraApi};
use sp_api::{ApiExt, ProvideRuntimeApi};
use sp_api::{ApiExt, ProvideRuntimeApi, RuntimeApiInfo};
use sp_core::Pair;
use sp_keystore::KeystorePtr;
use sp_timestamp::Timestamp;
Expand Down Expand Up @@ -101,26 +100,43 @@ async fn check_validation_code_or_log(
}
}

/// Reads async backing parameters from the relay chain storage at the given relay parent.
async fn async_backing_params(
/// Fetch scheduling lookahead at given relay parent.
async fn scheduling_lookahead(
relay_parent: RelayHash,
relay_client: &impl RelayChainInterface,
) -> Option<AsyncBackingParams> {
match load_abridged_host_configuration(relay_parent, relay_client).await {
Ok(Some(config)) => Some(config.async_backing_params),
Ok(None) => {
) -> Option<u32> {
let runtime_api_version = relay_client
.version(relay_parent)
.await
.map_err(|e| {
tracing::error!(
target: crate::LOG_TARGET,
"Active config is missing in relay chain storage",
);
None
},
target: super::LOG_TARGET,
error = ?e,
"Failed to fetch relay chain runtime version.",
)
})
.ok()?;

let parachain_host_runtime_api_version = runtime_api_version
.api_version(
&<dyn polkadot_primitives::runtime_api::ParachainHost<polkadot_primitives::Block>>::ID,
)
.unwrap_or_default();

if parachain_host_runtime_api_version <
RuntimeApiRequest::SCHEDULING_LOOKAHEAD_RUNTIME_REQUIREMENT
{
return None
}

match relay_client.scheduling_lookahead(relay_parent).await {
Ok(scheduling_lookahead) => Some(scheduling_lookahead),
Err(err) => {
tracing::error!(
target: crate::LOG_TARGET,
?err,
?relay_parent,
"Failed to read active config from relay chain client",
"Failed to fetch scheduling lookahead from relay chain",
);
None
},
Expand Down Expand Up @@ -216,9 +232,10 @@ where
let parent_search_params = ParentSearchParams {
relay_parent,
para_id,
ancestry_lookback: crate::collators::async_backing_params(relay_parent, relay_client)
ancestry_lookback: scheduling_lookahead(relay_parent, relay_client)
.await
.map_or(0, |params| params.allowed_ancestry_len as usize),
.unwrap_or(DEFAULT_SCHEDULING_LOOKAHEAD)
.saturating_sub(1) as usize,
max_depth: PARENT_SEARCH_DEPTH,
ignore_alternative_branches: true,
};
Expand Down
4 changes: 4 additions & 0 deletions cumulus/client/relay-chain-inprocess-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,10 @@ impl RelayChainInterface for RelayChainInProcessInterface {
) -> RelayChainResult<BTreeMap<CoreIndex, VecDeque<ParaId>>> {
Ok(self.full_client.runtime_api().claim_queue(hash)?)
}

async fn scheduling_lookahead(&self, hash: PHash) -> RelayChainResult<u32> {
Ok(self.full_client.runtime_api().scheduling_lookahead(hash)?)
}
}

pub enum BlockCheckStatus {
Expand Down
7 changes: 7 additions & 0 deletions cumulus/client/relay-chain-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,9 @@ pub trait RelayChainInterface: Send + Sync {
&self,
relay_parent: PHash,
) -> RelayChainResult<BTreeMap<CoreIndex, VecDeque<ParaId>>>;

/// Fetch the scheduling lookahead value.
async fn scheduling_lookahead(&self, relay_parent: PHash) -> RelayChainResult<u32>;
}

#[async_trait]
Expand Down Expand Up @@ -398,6 +401,10 @@ where
) -> RelayChainResult<BTreeMap<CoreIndex, VecDeque<ParaId>>> {
(**self).claim_queue(relay_parent).await
}

async fn scheduling_lookahead(&self, relay_parent: PHash) -> RelayChainResult<u32> {
(**self).scheduling_lookahead(relay_parent).await
}
}

/// Helper function to call an arbitrary runtime API using a `RelayChainInterface` client.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,10 @@ impl RuntimeApiSubsystemClient for BlockChainRpcClient {
.parachain_host_candidates_pending_availability(at, para_id)
.await?)
}

async fn scheduling_lookahead(&self, at: Hash) -> Result<u32, sp_api::ApiError> {
Ok(self.rpc_client.parachain_host_scheduling_lookahead(at).await?)
}
}

#[async_trait::async_trait]
Expand Down
4 changes: 4 additions & 0 deletions cumulus/client/relay-chain-rpc-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,4 +282,8 @@ impl RelayChainInterface for RelayChainRpcInterface {
> {
self.rpc_client.parachain_host_claim_queue(relay_parent).await
}

async fn scheduling_lookahead(&self, relay_parent: RelayHash) -> RelayChainResult<u32> {
self.rpc_client.parachain_host_scheduling_lookahead(relay_parent).await
}
}
8 changes: 8 additions & 0 deletions cumulus/client/relay-chain-rpc-interface/src/rpc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,14 @@ impl RelayChainRpcClient {
.await
}

pub async fn parachain_host_scheduling_lookahead(
&self,
at: RelayHash,
) -> Result<u32, RelayChainError> {
self.call_remote_runtime_function("ParachainHost_scheduling_lookahead", at, None::<()>)
.await
}

pub async fn validation_code_hash(
&self,
at: RelayHash,
Expand Down
4 changes: 0 additions & 4 deletions cumulus/zombienet/tests/0008-elastic_authoring.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
[settings]
timeout = 1000

[relaychain.genesis.runtimeGenesis.patch.configuration.config.async_backing_params]
max_candidate_depth = 6
allowed_ancestry_len = 3

[relaychain.genesis.runtimeGenesis.patch.configuration.config.scheduler_params]
max_validators_per_core = 1
num_cores = 4
Expand Down
4 changes: 0 additions & 4 deletions cumulus/zombienet/tests/0009-elastic_pov_recovery.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ requests = { memory = "2G", cpu = "1" }
limits = { memory = "4G", cpu = "2" }
requests = { memory = "2G", cpu = "1" }

[relaychain.genesis.runtimeGenesis.patch.configuration.config.async_backing_params]
max_candidate_depth = 6
allowed_ancestry_len = 3

[relaychain.genesis.runtimeGenesis.patch.configuration.config.scheduler_params]
max_validators_per_core = 1
num_cores = 4
Expand Down
Loading
Loading