dispute-coordinator: disabling in participation (#2637)

Closes #2225.

- [x] tests
- [x] fix todos
- [x] fix duplicates
- [x] make the check part of `potential_spam` 
- [x] fix a bug with votes insertion
- [x] guide changes
- [x] docs

---------

Co-authored-by: Tsvetomir Dimitrov <tsvetomir@parity.io>
This commit is contained in:
ordian
2024-01-09 07:44:19 +01:00
committed by GitHub
parent a02b53475b
commit 0ff3f4d3af
12 changed files with 1013 additions and 48 deletions
+17 -1
View File
@@ -141,6 +141,20 @@ impl From<OverseerError> for Error {
}
}
impl TryFrom<crate::runtime::Error> for Error {
type Error = ();
fn try_from(e: crate::runtime::Error) -> Result<Self, ()> {
use crate::runtime::Error;
match e {
Error::RuntimeRequestCanceled(e) => Ok(Self::Oneshot(e)),
Error::RuntimeRequest(e) => Ok(Self::RuntimeApi(e)),
Error::NoSuchSession(_) | Error::NoExecutorParams(_) => Err(()),
}
}
}
/// A type alias for Runtime API receivers.
pub type RuntimeApiReceiver<T> = oneshot::Receiver<Result<T, RuntimeApiError>>;
@@ -465,7 +479,9 @@ impl Validator {
// TODO: https://github.com/paritytech/polkadot-sdk/issues/1940
// When `DisabledValidators` is released remove this and add a
// `request_disabled_validators` call here
let disabled_validators = get_disabled_validators_with_fallback(sender, parent).await?;
let disabled_validators = get_disabled_validators_with_fallback(sender, parent)
.await
.map_err(|e| Error::try_from(e).expect("the conversion is infallible; qed"))?;
Self::construct(&validators, &disabled_validators, signing_context, keystore)
}
@@ -43,7 +43,7 @@ use crate::{
request_from_runtime, request_key_ownership_proof, request_on_chain_votes,
request_session_executor_params, request_session_index_for_child, request_session_info,
request_submit_report_dispute_lost, request_unapplied_slashes, request_validation_code_by_hash,
request_validator_groups,
request_validator_groups, vstaging::get_disabled_validators_with_fallback,
};
/// Errors that can happen on runtime fetches.
@@ -75,6 +75,11 @@ pub struct RuntimeInfo {
/// overseer seems sensible.
session_index_cache: LruMap<Hash, SessionIndex>,
/// In the happy case, we do not query disabled validators at all. In the worst case, we can
/// query it order of `n_cores` times `n_validators` per block, so caching it here seems
/// sensible.
disabled_validators_cache: LruMap<Hash, Vec<ValidatorIndex>>,
/// Look up cached sessions by `SessionIndex`.
session_info_cache: LruMap<SessionIndex, ExtendedSessionInfo>,
@@ -129,6 +134,7 @@ impl RuntimeInfo {
Self {
session_index_cache: LruMap::new(ByLength::new(cfg.session_cache_lru_size.max(10))),
session_info_cache: LruMap::new(ByLength::new(cfg.session_cache_lru_size)),
disabled_validators_cache: LruMap::new(ByLength::new(100)),
pinned_blocks: LruMap::new(ByLength::new(cfg.session_cache_lru_size)),
keystore: cfg.keystore,
}
@@ -180,6 +186,26 @@ impl RuntimeInfo {
self.get_session_info_by_index(sender, relay_parent, session_index).await
}
/// Get the list of disabled validators at the relay parent.
pub async fn get_disabled_validators<Sender>(
&mut self,
sender: &mut Sender,
relay_parent: Hash,
) -> Result<Vec<ValidatorIndex>>
where
Sender: SubsystemSender<RuntimeApiMessage>,
{
match self.disabled_validators_cache.get(&relay_parent).cloned() {
Some(result) => Ok(result),
None => {
let disabled_validators =
get_disabled_validators_with_fallback(sender, relay_parent).await?;
self.disabled_validators_cache.insert(relay_parent, disabled_validators.clone());
Ok(disabled_validators)
},
}
}
/// Get `ExtendedSessionInfo` by session index.
///
/// `request_session_info` still requires the parent to be passed in, so we take the parent
+3 -3
View File
@@ -23,7 +23,7 @@ use polkadot_node_subsystem_types::messages::{RuntimeApiMessage, RuntimeApiReque
use polkadot_overseer::SubsystemSender;
use polkadot_primitives::{Hash, ValidatorIndex};
use crate::{has_required_runtime, request_disabled_validators, Error};
use crate::{has_required_runtime, request_disabled_validators, runtime};
const LOG_TARGET: &'static str = "parachain::subsystem-util-vstaging";
@@ -35,7 +35,7 @@ const LOG_TARGET: &'static str = "parachain::subsystem-util-vstaging";
pub async fn get_disabled_validators_with_fallback<Sender: SubsystemSender<RuntimeApiMessage>>(
sender: &mut Sender,
relay_parent: Hash,
) -> Result<Vec<ValidatorIndex>, Error> {
) -> Result<Vec<ValidatorIndex>, runtime::Error> {
let disabled_validators = if has_required_runtime(
sender,
relay_parent,
@@ -46,7 +46,7 @@ pub async fn get_disabled_validators_with_fallback<Sender: SubsystemSender<Runti
request_disabled_validators(relay_parent, sender)
.await
.await
.map_err(Error::Oneshot)??
.map_err(runtime::Error::RuntimeRequestCanceled)??
} else {
gum::debug!(target: LOG_TARGET, "Runtime doesn't support `DisabledValidators` - continuing with an empty disabled validators set");
vec![]