backing: move the min votes threshold to the runtime (#1200)

* move min backing votes const to runtime

also cache it per-session in the backing subsystem

Signed-off-by: alindima <alin@parity.io>

* add runtime migration

* introduce api versioning for min_backing votes

also enable it for rococo/versi for testing

* also add min_backing_votes runtime calls to statement-distribution

this dependency has been recently introduced by async backing

* remove explicit version runtime API call

this is not needed, as the RuntimeAPISubsystem already takes care
of versioning and will return NotSupported if the version is not
right.

* address review comments

- parametrise backing votes runtime API with session index
- remove RuntimeInfo usage in backing subsystem, as runtime API
caches the min backing votes by session index anyway.
- move the logic for adjusting the configured needed backing votes with the size of the backing group
to a primitives helper.
- move the legacy min backing votes value to a primitives helper.
- mark JoinMultiple error as fatal, since the Canceled (non-multiple) counterpart is also fatal.
- make backing subsystem handle fatal errors for new leaves update.
- add HostConfiguration consistency check for zeroed backing votes threshold
- add cumulus accompanying change

* fix cumulus test compilation

* fix tests

* more small fixes

* fix merge

* bump runtime api version for westend and rollback version for rococo

---------

Signed-off-by: alindima <alin@parity.io>
Co-authored-by: Javier Viola <javier@parity.io>
This commit is contained in:
Alin Dima
2023-08-31 14:01:36 +03:00
committed by GitHub
parent f1845f725d
commit d6af073aa5
37 changed files with 920 additions and 255 deletions
@@ -33,7 +33,7 @@ pub enum Error {
/// Some request to the runtime failed.
/// For example if we prune a block we're requesting info about.
#[error("Runtime API error {0}")]
RuntimeRequest(RuntimeApiError),
RuntimeRequest(#[from] RuntimeApiError),
/// We tried fetching a session info which was not available.
#[error("There was no session with the given index {0}")]
@@ -43,7 +43,7 @@ pub enum Error {
pub type Result<T> = std::result::Result<T, Error>;
/// Receive a response from a runtime request and convert errors.
pub(crate) async fn recv_runtime<V>(
pub async fn recv_runtime<V>(
r: oneshot::Receiver<std::result::Result<V, RuntimeApiError>>,
) -> Result<V> {
let result = r
@@ -24,27 +24,29 @@ use sp_core::crypto::ByteArray;
use sp_keystore::{Keystore, KeystorePtr};
use polkadot_node_subsystem::{
errors::RuntimeApiError, messages::RuntimeApiMessage, overseer, SubsystemSender,
errors::RuntimeApiError,
messages::{RuntimeApiMessage, RuntimeApiRequest},
overseer, SubsystemSender,
};
use polkadot_primitives::{
vstaging, CandidateEvent, CandidateHash, CoreState, EncodeAs, GroupIndex, GroupRotationInfo,
Hash, IndexedVec, OccupiedCore, ScrapedOnChainVotes, SessionIndex, SessionInfo, Signed,
SigningContext, UncheckedSigned, ValidationCode, ValidationCodeHash, ValidatorId,
ValidatorIndex,
ValidatorIndex, LEGACY_MIN_BACKING_VOTES,
};
use crate::{
request_availability_cores, request_candidate_events, request_key_ownership_proof,
request_on_chain_votes, request_session_index_for_child, request_session_info,
request_staging_async_backing_params, request_submit_report_dispute_lost,
request_availability_cores, request_candidate_events, request_from_runtime,
request_key_ownership_proof, request_on_chain_votes, request_session_index_for_child,
request_session_info, request_staging_async_backing_params, request_submit_report_dispute_lost,
request_unapplied_slashes, request_validation_code_by_hash, request_validator_groups,
};
/// Errors that can happen on runtime fetches.
mod error;
use error::{recv_runtime, Result};
pub use error::{Error, FatalError, JfyiError};
use error::Result;
pub use error::{recv_runtime, Error, FatalError, JfyiError};
const LOG_TARGET: &'static str = "parachain::runtime-info";
@@ -451,3 +453,32 @@ where
})
}
}
/// Request the min backing votes value.
/// Prior to runtime API version 6, just return a hardcoded constant.
pub async fn request_min_backing_votes(
parent: Hash,
session_index: SessionIndex,
sender: &mut impl overseer::SubsystemSender<RuntimeApiMessage>,
) -> Result<u32> {
let min_backing_votes_res = recv_runtime(
request_from_runtime(parent, sender, |tx| {
RuntimeApiRequest::MinimumBackingVotes(session_index, tx)
})
.await,
)
.await;
if let Err(Error::RuntimeRequest(RuntimeApiError::NotSupported { .. })) = min_backing_votes_res
{
gum::trace!(
target: LOG_TARGET,
?parent,
"Querying the backing threshold from the runtime is not supported by the current Runtime API",
);
Ok(LEGACY_MIN_BACKING_VOTES)
} else {
min_backing_votes_res
}
}