Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions polkadot/node/collation-generation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ use polkadot_node_subsystem::{
SubsystemContext, SubsystemError, SubsystemResult, SubsystemSender,
};
use polkadot_node_subsystem_util::{
request_claim_queue, request_persisted_validation_data, request_session_index_for_child,
request_validation_code_hash, request_validators,
runtime::{request_node_features, ClaimQueueSnapshot},
request_claim_queue, request_node_features, request_persisted_validation_data,
request_session_index_for_child, request_validation_code_hash, request_validators,
runtime::ClaimQueueSnapshot,
};
use polkadot_primitives::{
collator_signature_payload,
Expand All @@ -56,8 +56,7 @@ use polkadot_primitives::{
ClaimQueueOffset, CommittedCandidateReceiptV2, TransposedClaimQueue,
},
CandidateCommitments, CandidateDescriptor, CollatorPair, CoreIndex, Hash, Id as ParaId,
NodeFeatures, OccupiedCoreAssumption, PersistedValidationData, SessionIndex,
ValidationCodeHash,
OccupiedCoreAssumption, PersistedValidationData, SessionIndex, ValidationCodeHash,
};
use schnellru::{ByLength, LruMap};
use sp_core::crypto::Pair;
Expand Down Expand Up @@ -510,9 +509,8 @@ impl SessionInfoCache {
let n_validators =
request_validators(relay_parent, &mut sender.clone()).await.await??.len();

let node_features = request_node_features(relay_parent, session_index, sender)
.await?
.unwrap_or(NodeFeatures::EMPTY);
let node_features =
request_node_features(relay_parent, session_index, sender).await.await??;

let info = PerSessionInfo {
v2_receipts: node_features
Expand Down
2 changes: 1 addition & 1 deletion polkadot/node/collation-generation/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use polkadot_node_subsystem_util::TimeoutExt;
use polkadot_primitives::{
node_features,
vstaging::{CandidateDescriptorVersion, CoreSelector, UMPSignal, UMP_SEPARATOR},
CollatorPair, PersistedValidationData,
CollatorPair, NodeFeatures, PersistedValidationData,
};
use polkadot_primitives_test_helpers::dummy_head_data;
use rstest::rstest;
Expand Down
2 changes: 1 addition & 1 deletion polkadot/node/core/av-store/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1329,7 +1329,7 @@ fn store_available_data(
})
.collect();

let chunk_indices = availability_chunk_indices(Some(&node_features), n_validators, core_index)?;
let chunk_indices = availability_chunk_indices(&node_features, n_validators, core_index)?;
for (validator_index, chunk_index) in chunk_indices.into_iter().enumerate() {
write_chunk(
&mut tx,
Expand Down
21 changes: 7 additions & 14 deletions polkadot/node/core/av-store/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,12 +510,8 @@ fn store_pov_and_queries_work() {

let query_all_chunks_res = query_all_chunks(
&mut virtual_overseer,
availability_chunk_indices(
Some(&node_features),
n_validators as usize,
core_index,
)
.unwrap(),
availability_chunk_indices(&node_features, n_validators as usize, core_index)
.unwrap(),
candidate_hash,
)
.await;
Expand Down Expand Up @@ -596,12 +592,8 @@ fn store_pov_and_queries_work() {

let query_all_chunks_res = query_all_chunks(
&mut virtual_overseer,
availability_chunk_indices(
Some(&node_features),
n_validators as usize,
core_index,
)
.unwrap(),
availability_chunk_indices(&node_features, n_validators as usize, core_index)
.unwrap(),
candidate_hash,
)
.await;
Expand All @@ -618,7 +610,7 @@ fn store_pov_and_queries_work() {
.await
.unwrap();
let expected_chunk_index = availability_chunk_index(
Some(&node_features),
&node_features,
n_validators as usize,
core_index,
ValidatorIndex(validator_index),
Expand Down Expand Up @@ -723,7 +715,8 @@ fn query_all_chunks_works() {
}

let chunk_indices =
availability_chunk_indices(None, n_validators as usize, CoreIndex(0)).unwrap();
availability_chunk_indices(&NodeFeatures::EMPTY, n_validators as usize, CoreIndex(0))
.unwrap();

assert_eq!(
query_all_chunks(&mut virtual_overseer, chunk_indices.clone(), candidate_hash_1)
Expand Down
30 changes: 17 additions & 13 deletions polkadot/node/core/backing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,10 @@ use polkadot_node_subsystem::{
use polkadot_node_subsystem_util::{
self as util,
backing_implicit_view::View as ImplicitView,
request_claim_queue, request_disabled_validators, request_session_executor_params,
request_session_index_for_child, request_validator_groups, request_validators,
runtime::{self, request_min_backing_votes, ClaimQueueSnapshot},
request_claim_queue, request_disabled_validators, request_min_backing_votes,
request_node_features, request_session_executor_params, request_session_index_for_child,
request_validator_groups, request_validators,
runtime::{self, ClaimQueueSnapshot},
Validator,
};
use polkadot_parachain_primitives::primitives::IsSystem;
Expand All @@ -125,7 +126,6 @@ use polkadot_statement_table::{
Context as TableContextTrait, Table,
};
use sp_keystore::KeystorePtr;
use util::runtime::request_node_features;

mod error;

Expand Down Expand Up @@ -260,7 +260,7 @@ struct PerSessionCache {
/// Cache for storing validators list, retrieved from the runtime.
validators_cache: LruMap<SessionIndex, Arc<Vec<ValidatorId>>>,
/// Cache for storing node features, retrieved from the runtime.
node_features_cache: LruMap<SessionIndex, Option<NodeFeatures>>,
node_features_cache: LruMap<SessionIndex, NodeFeatures>,
/// Cache for storing executor parameters, retrieved from the runtime.
executor_params_cache: LruMap<SessionIndex, Arc<ExecutorParams>>,
/// Cache for storing the minimum backing votes threshold, retrieved from the runtime.
Expand Down Expand Up @@ -322,15 +322,20 @@ impl PerSessionCache {
session_index: SessionIndex,
parent: Hash,
sender: &mut impl overseer::SubsystemSender<RuntimeApiMessage>,
) -> Result<Option<NodeFeatures>, Error> {
) -> Result<NodeFeatures, RuntimeApiError> {
// Try to get the node features from the cache.
if let Some(node_features) = self.node_features_cache.get(&session_index) {
return Ok(node_features.clone());
}

// Fetch the node features from the runtime since it was not in the cache.
let node_features: Option<NodeFeatures> =
request_node_features(parent, session_index, sender).await?;
let node_features = request_node_features(parent, session_index, sender)
.await
.await
.map_err(|err| RuntimeApiError::Execution {
runtime_api_name: "NodeFeatures",
source: Arc::new(err),
})??;

// Cache the fetched node features for future use.
self.node_features_cache.insert(session_index, node_features.clone());
Expand Down Expand Up @@ -388,11 +393,12 @@ impl PerSessionCache {

// Fetch the value from the runtime since it was not in the cache.
let minimum_backing_votes = request_min_backing_votes(parent, session_index, sender)
.await
.await
.map_err(|err| RuntimeApiError::Execution {
runtime_api_name: "MinimumBackingVotes",
source: Arc::new(err),
})?;
})??;

// Cache the fetched value for future use.
self.minimum_backing_votes_cache.insert(session_index, minimum_backing_votes);
Expand Down Expand Up @@ -1152,10 +1158,8 @@ async fn construct_per_relay_parent_state<Context>(
let validators = per_session_cache.validators(session_index, parent, ctx.sender()).await;
let validators = try_runtime_api!(validators);

let node_features = per_session_cache
.node_features(session_index, parent, ctx.sender())
.await?
.unwrap_or(NodeFeatures::EMPTY);
let node_features = per_session_cache.node_features(session_index, parent, ctx.sender()).await;
let node_features = try_runtime_api!(node_features);

let inject_core_index = node_features
.get(FeatureIndex::ElasticScalingMVP as usize)
Expand Down
16 changes: 0 additions & 16 deletions polkadot/node/core/dispute-coordinator/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,13 +413,6 @@ impl TestState {
)) => {
tx.send(Ok(Vec::new())).unwrap();
},
AllMessages::RuntimeApi(RuntimeApiMessage::Request(
_new_leaf,
RuntimeApiRequest::Version(tx),
)) => {
tx.send(Ok(RuntimeApiRequest::DISABLED_VALIDATORS_RUNTIME_REQUIREMENT))
.unwrap();
},
AllMessages::RuntimeApi(RuntimeApiMessage::Request(
_new_leaf,
RuntimeApiRequest::DisabledValidators(tx),
Expand Down Expand Up @@ -4387,15 +4380,6 @@ async fn handle_disabled_validators_queries(
virtual_overseer: &mut VirtualOverseer,
disabled_validators: Vec<ValidatorIndex>,
) {
assert_matches!(
virtual_overseer.recv().await,
AllMessages::RuntimeApi(RuntimeApiMessage::Request(
_new_leaf,
RuntimeApiRequest::Version(tx),
)) => {
tx.send(Ok(RuntimeApiRequest::DISABLED_VALIDATORS_RUNTIME_REQUIREMENT)).unwrap();
}
);
assert_matches!(
virtual_overseer.recv().await,
AllMessages::RuntimeApi(RuntimeApiMessage::Request(
Expand Down
3 changes: 3 additions & 0 deletions polkadot/node/core/provisioner/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ pub enum Error {
#[error("failed to get session index")]
CanceledSessionIndex(#[source] oneshot::Canceled),

#[error("failed to get node features")]
CanceledNodeFeatures(#[source] oneshot::Canceled),

#[error("failed to get backed candidates")]
CanceledBackedCandidates(#[source] oneshot::Canceled),

Expand Down
12 changes: 6 additions & 6 deletions polkadot/node/core/provisioner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,13 @@ use polkadot_node_subsystem::{
SubsystemError,
};
use polkadot_node_subsystem_util::{
request_availability_cores, request_session_index_for_child, runtime::request_node_features,
TimeoutExt,
request_availability_cores, request_node_features, request_session_index_for_child, TimeoutExt,
};
use polkadot_primitives::{
node_features::FeatureIndex,
vstaging::{BackedCandidate, CoreState},
CandidateHash, CoreIndex, Hash, Id as ParaId, NodeFeatures, SessionIndex,
SignedAvailabilityBitfield, ValidatorIndex,
CandidateHash, CoreIndex, Hash, Id as ParaId, SessionIndex, SignedAvailabilityBitfield,
ValidatorIndex,
};
use std::collections::{BTreeMap, HashMap};

Expand Down Expand Up @@ -203,8 +202,9 @@ async fn handle_active_leaves_update(
.map_err(Error::CanceledSessionIndex)??;
if per_session.get(&session_index).is_none() {
let elastic_scaling_mvp = request_node_features(leaf.hash, session_index, sender)
.await?
.unwrap_or(NodeFeatures::EMPTY)
.await
.await
.map_err(Error::CanceledNodeFeatures)??
.get(FeatureIndex::ElasticScalingMVP as usize)
.map(|b| *b)
.unwrap_or(false);
Expand Down
6 changes: 5 additions & 1 deletion polkadot/node/network/availability-distribution/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use polkadot_primitives::SessionIndex;

use futures::channel::oneshot;

use polkadot_node_subsystem::{ChainApiError, SubsystemError};
use polkadot_node_subsystem::{ChainApiError, RuntimeApiError, SubsystemError};
use polkadot_node_subsystem_util::runtime;

use crate::LOG_TARGET;
Expand Down Expand Up @@ -55,6 +55,9 @@ pub enum Error {
#[error("Retrieving response from Chain API unexpectedly failed with error: {0}")]
ChainApi(#[from] ChainApiError),

#[error("Failed to get node features from the runtime")]
FailedNodeFeatures(#[source] RuntimeApiError),

// av-store will drop the sender on any error that happens.
#[error("Response channel to obtain chunk failed")]
QueryChunkResponseChannel(#[source] oneshot::Canceled),
Expand Down Expand Up @@ -108,6 +111,7 @@ pub fn log_error(
JfyiError::NoSuchCachedSession { .. } |
JfyiError::QueryAvailableDataResponseChannel(_) |
JfyiError::QueryChunkResponseChannel(_) |
JfyiError::FailedNodeFeatures(_) |
JfyiError::ErasureCoding(_) => gum::warn!(target: LOG_TARGET, error = %jfyi, ctx),
JfyiError::FetchPoV(_) |
JfyiError::SendResponse |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use rand::{seq::SliceRandom, thread_rng};
use schnellru::{ByLength, LruMap};

use polkadot_node_subsystem::overseer;
use polkadot_node_subsystem_util::runtime::{request_node_features, RuntimeInfo};
use polkadot_node_subsystem_util::{request_node_features, runtime::RuntimeInfo};
use polkadot_primitives::{
AuthorityDiscoveryId, GroupIndex, Hash, NodeFeatures, SessionIndex, ValidatorIndex,
};
Expand Down Expand Up @@ -66,7 +66,7 @@ pub struct SessionInfo {
pub our_group: Option<GroupIndex>,

/// Node features.
pub node_features: Option<NodeFeatures>,
pub node_features: NodeFeatures,
}

/// Report of bad validators.
Expand Down Expand Up @@ -175,8 +175,10 @@ impl SessionCache {
.get_session_info_by_index(ctx.sender(), relay_parent, session_index)
.await?;

let node_features =
request_node_features(relay_parent, session_index, ctx.sender()).await?;
let node_features = request_node_features(relay_parent, session_index, ctx.sender())
.await
.await?
.map_err(Error::FailedNodeFeatures)?;

let discovery_keys = info.session_info.discovery_keys.clone();
let mut validator_groups = info.session_info.validator_groups.clone();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl TestState {
let session_info = make_session_info();

let our_chunk_index = availability_chunk_index(
Some(&node_features),
&node_features,
session_info.validators.len(),
CoreIndex(1),
ValidatorIndex(0),
Expand Down
2 changes: 1 addition & 1 deletion polkadot/node/network/availability-recovery/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ async fn handle_recover<Context>(
) && chunk_mapping_enabled
{
let chunk_indices =
availability_chunk_indices(Some(node_features), n_validators, core_index)?;
availability_chunk_indices(node_features, n_validators, core_index)?;

let chunk_indices: VecDeque<_> = chunk_indices
.iter()
Expand Down
2 changes: 1 addition & 1 deletion polkadot/node/network/availability-recovery/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ fn map_chunks(
core_index: CoreIndex,
) -> IndexedVec<ValidatorIndex, ErasureChunk> {
let chunk_indices =
availability_chunk_indices(Some(node_features), n_validators, core_index).unwrap();
availability_chunk_indices(node_features, n_validators, core_index).unwrap();

(0..n_validators)
.map(|val_idx| chunks[chunk_indices[val_idx].0 as usize].clone())
Expand Down
3 changes: 3 additions & 0 deletions polkadot/node/network/collator-protocol/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ pub enum Error {
#[error("Response receiver for claim queue request cancelled")]
CancelledClaimQueue(oneshot::Canceled),

#[error("Response receiver for node features request cancelled")]
CancelledNodeFeatures(oneshot::Canceled),

#[error("No state for the relay parent")]
RelayParentStateNotFound,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ use polkadot_node_subsystem::{
use polkadot_node_subsystem_util::{
backing_implicit_view::View as ImplicitView,
reputation::{ReputationAggregator, REPUTATION_CHANGE_INTERVAL},
request_claim_queue, request_session_index_for_child,
runtime::request_node_features,
request_claim_queue, request_node_features, request_session_index_for_child,
};
use polkadot_primitives::{
node_features,
Expand Down Expand Up @@ -1283,8 +1282,9 @@ where
.map_err(Error::CancelledSessionIndex)??;

let v2_receipts = request_node_features(*leaf, session_index, sender)
.await?
.unwrap_or_default()
.await
.await
.map_err(Error::CancelledNodeFeatures)??
.get(node_features::FeatureIndex::CandidateReceiptV2 as usize)
.map(|b| *b)
.unwrap_or(false);
Expand Down
8 changes: 7 additions & 1 deletion polkadot/node/network/statement-distribution/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,20 @@ pub enum Error {
FetchSessionInfo(RuntimeApiError),

#[error("Fetching disabled validators failed {0:?}")]
FetchDisabledValidators(runtime::Error),
FetchDisabledValidators(RuntimeApiError),

#[error("Fetching validator groups failed {0:?}")]
FetchValidatorGroups(RuntimeApiError),

#[error("Fetching claim queue failed {0:?}")]
FetchClaimQueue(RuntimeApiError),

#[error("Fetching minimum backing votes failed {0:?}")]
FetchMinimumBackingVotes(RuntimeApiError),

#[error("Fetching node features failed {0:?}")]
FetchNodeFeatures(RuntimeApiError),

#[error("Attempted to share statement when not a validator or not assigned")]
InvalidShare,

Expand Down
Loading
Loading