Skip to content

Commit 29dc4a0

Browse files
author
Stephane Gurgenidze
committed
refactor(runtime-api): remove redundant version checks
1 parent fd72d58 commit 29dc4a0

File tree

4 files changed

+20
-78
lines changed

4 files changed

+20
-78
lines changed

polkadot/node/network/statement-distribution/src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ pub enum Error {
7373
FetchSessionInfo(RuntimeApiError),
7474

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

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

polkadot/node/network/statement-distribution/src/v2/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -586,11 +586,13 @@ pub(crate) async fn handle_active_leaves_update<Context>(
586586

587587
for new_relay_parent in new_relay_parents.iter().cloned() {
588588
let disabled_validators: HashSet<_> =
589-
polkadot_node_subsystem_util::runtime::get_disabled_validators_with_fallback(
590-
ctx.sender(),
589+
polkadot_node_subsystem_util::request_disabled_validators(
591590
new_relay_parent,
591+
ctx.sender(),
592592
)
593593
.await
594+
.await
595+
.map_err(JfyiError::RuntimeApiUnavailable)?
594596
.map_err(JfyiError::FetchDisabledValidators)?
595597
.into_iter()
596598
.collect();

polkadot/node/subsystem-util/src/lib.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ use polkadot_primitives::{
5353
ValidationCodeHash, ValidatorId, ValidatorIndex, ValidatorSignature,
5454
};
5555
pub use rand;
56-
use runtime::get_disabled_validators_with_fallback;
5756
use sp_application_crypto::AppCrypto;
5857
use sp_core::ByteArray;
5958
use sp_keystore::{Error as KeystoreError, KeystorePtr};
@@ -488,12 +487,7 @@ impl Validator {
488487

489488
let validators = validators?;
490489

491-
// TODO: https://github.com/paritytech/polkadot-sdk/issues/1940
492-
// When `DisabledValidators` is released remove this and add a
493-
// `request_disabled_validators` call here
494-
let disabled_validators = get_disabled_validators_with_fallback(sender, parent)
495-
.await
496-
.map_err(|e| Error::try_from(e).expect("the conversion is infallible; qed"))?;
490+
let disabled_validators = request_disabled_validators(parent, sender).await.await??;
497491

498492
Self::construct(&validators, &disabled_validators, signing_context, keystore)
499493
}

polkadot/node/subsystem-util/src/runtime/mod.rs

Lines changed: 14 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,17 @@ use polkadot_primitives::{
3636
CandidateHash, CoreIndex, EncodeAs, ExecutorParams, GroupIndex, GroupRotationInfo, Hash,
3737
Id as ParaId, IndexedVec, NodeFeatures, SessionIndex, SessionInfo, Signed, SigningContext,
3838
UncheckedSigned, ValidationCode, ValidationCodeHash, ValidatorId, ValidatorIndex,
39-
DEFAULT_SCHEDULING_LOOKAHEAD, LEGACY_MIN_BACKING_VOTES,
39+
DEFAULT_SCHEDULING_LOOKAHEAD,
4040
};
4141

4242
use std::collections::{BTreeMap, VecDeque};
4343

4444
use crate::{
45-
has_required_runtime, request_availability_cores, request_candidate_events,
46-
request_claim_queue, request_disabled_validators, request_from_runtime,
47-
request_key_ownership_proof, request_on_chain_votes, request_session_executor_params,
48-
request_session_index_for_child, request_session_info, request_submit_report_dispute_lost,
49-
request_unapplied_slashes, request_validation_code_by_hash, request_validator_groups,
45+
request_availability_cores, request_candidate_events, request_claim_queue,
46+
request_disabled_validators, request_from_runtime, request_key_ownership_proof,
47+
request_on_chain_votes, request_session_executor_params, request_session_index_for_child,
48+
request_session_info, request_submit_report_dispute_lost, request_unapplied_slashes,
49+
request_validation_code_by_hash, request_validator_groups,
5050
};
5151

5252
/// Errors that can happen on runtime fetches.
@@ -202,7 +202,7 @@ impl RuntimeInfo {
202202
Some(result) => Ok(result),
203203
None => {
204204
let disabled_validators =
205-
get_disabled_validators_with_fallback(sender, relay_parent).await?;
205+
request_disabled_validators(relay_parent, sender).await.await??;
206206
self.disabled_validators_cache.insert(relay_parent, disabled_validators.clone());
207207
Ok(disabled_validators)
208208
},
@@ -469,61 +469,35 @@ where
469469
}
470470

471471
/// Request the min backing votes value.
472-
/// Prior to runtime API version 6, just return a hardcoded constant.
473472
pub async fn request_min_backing_votes(
474473
parent: Hash,
475474
session_index: SessionIndex,
476475
sender: &mut impl overseer::SubsystemSender<RuntimeApiMessage>,
477476
) -> Result<u32> {
478-
let min_backing_votes_res = recv_runtime(
477+
recv_runtime(
479478
request_from_runtime(parent, sender, |tx| {
480479
RuntimeApiRequest::MinimumBackingVotes(session_index, tx)
481480
})
482481
.await,
483482
)
484-
.await;
485-
486-
if let Err(Error::RuntimeRequest(RuntimeApiError::NotSupported { .. })) = min_backing_votes_res
487-
{
488-
gum::trace!(
489-
target: LOG_TARGET,
490-
?parent,
491-
"Querying the backing threshold from the runtime is not supported by the current Runtime API",
492-
);
493-
494-
Ok(LEGACY_MIN_BACKING_VOTES)
495-
} else {
496-
min_backing_votes_res
497-
}
483+
.await
498484
}
499485

500486
/// Request the node features enabled in the runtime.
501487
/// Pass in the session index for caching purposes, as it should only change on session boundaries.
502-
/// Prior to runtime API version 9, just return `None`.
503488
pub async fn request_node_features(
504489
parent: Hash,
505490
session_index: SessionIndex,
506491
sender: &mut impl overseer::SubsystemSender<RuntimeApiMessage>,
507492
) -> Result<Option<NodeFeatures>> {
508-
let res = recv_runtime(
493+
recv_runtime(
509494
request_from_runtime(parent, sender, |tx| {
510495
RuntimeApiRequest::NodeFeatures(session_index, tx)
511496
})
512497
.await,
513498
)
514-
.await;
515-
516-
if let Err(Error::RuntimeRequest(RuntimeApiError::NotSupported { .. })) = res {
517-
gum::trace!(
518-
target: LOG_TARGET,
519-
?parent,
520-
"Querying the node features from the runtime is not supported by the current Runtime API",
521-
);
522-
523-
Ok(None)
524-
} else {
525-
res.map(Some)
526-
}
499+
.await
500+
.map(Some)
527501
}
528502

529503
/// A snapshot of the runtime claim queue at an arbitrary relay chain block.
@@ -568,34 +542,6 @@ impl ClaimQueueSnapshot {
568542
}
569543
}
570544

571-
// TODO: https://github.com/paritytech/polkadot-sdk/issues/1940
572-
/// Returns disabled validators list if the runtime supports it. Otherwise logs a debug messages and
573-
/// returns an empty vec.
574-
/// Once runtime ver `DISABLED_VALIDATORS_RUNTIME_REQUIREMENT` is released remove this function and
575-
/// replace all usages with `request_disabled_validators`
576-
pub async fn get_disabled_validators_with_fallback<Sender: SubsystemSender<RuntimeApiMessage>>(
577-
sender: &mut Sender,
578-
relay_parent: Hash,
579-
) -> Result<Vec<ValidatorIndex>> {
580-
let disabled_validators = if has_required_runtime(
581-
sender,
582-
relay_parent,
583-
RuntimeApiRequest::DISABLED_VALIDATORS_RUNTIME_REQUIREMENT,
584-
)
585-
.await
586-
{
587-
request_disabled_validators(relay_parent, sender)
588-
.await
589-
.await
590-
.map_err(Error::RuntimeRequestCanceled)??
591-
} else {
592-
gum::debug!(target: LOG_TARGET, "Runtime doesn't support `DisabledValidators` - continuing with an empty disabled validators set");
593-
vec![]
594-
};
595-
596-
Ok(disabled_validators)
597-
}
598-
599545
/// Fetch the claim queue and wrap it into a helpful `ClaimQueueSnapshot`
600546
pub async fn fetch_claim_queue(
601547
sender: &mut impl SubsystemSender<RuntimeApiMessage>,
@@ -609,8 +555,8 @@ pub async fn fetch_claim_queue(
609555
Ok(cq.into())
610556
}
611557

612-
/// Checks if the runtime supports `request_claim_queue` and attempts to fetch the claim queue.
613-
/// Returns `ClaimQueueSnapshot` or `None` if claim queue API is not supported by runtime.
558+
/// Returns the lookahead from the scheduler params if the runtime supports it,
559+
/// or default value if scheduling lookahead API is not supported by runtime.
614560
pub async fn fetch_scheduling_lookahead(
615561
parent: Hash,
616562
session_index: SessionIndex,

0 commit comments

Comments
 (0)