mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 09:21:04 +00:00
past-session validator discovery APIs (#2009)
* guide: fix formatting for SessionInfo module * primitives: SessionInfo type * punt on approval keys * ah, revert the type alias * session info runtime module skeleton * update the guide * runtime/configuration: sync with the guide * runtime/configuration: setters for newly added fields * runtime/configuration: set codec indexes * runtime/configuration: update test * primitives: fix SessionInfo definition * runtime/session_info: initial impl * runtime/session_info: use initializer for session handling (wip) * runtime/session_info: mock authority discovery trait * guide: update the initializer's order * runtime/session_info: tests skeleton * runtime/session_info: store n_delay_tranches in Configuration * runtime/session_info: punt on approval keys * runtime/session_info: add some basic tests * Update primitives/src/v1.rs * small fixes * remove codec index annotation on structs * fix off-by-one error * validator_discovery: accept a session index * runtime: replace validator_discovery api with session_info * Update runtime/parachains/src/session_info.rs Co-authored-by: Sergei Shulepov <sergei@parity.io> * runtime/session_info: add a comment about missing entries * runtime/session_info: define the keys * util: expose connect_to_past_session_validators * util: allow session_info requests for jobs * runtime-api: add mock test for session_info * collator-protocol: add session_index to test state * util: fix error message for runtime error * fix compilation * fix tests after merge with master Co-authored-by: Sergei Shulepov <sergei@parity.io>
This commit is contained in:
@@ -25,6 +25,7 @@ use primitives::RuntimeDebug;
|
||||
use runtime_primitives::traits::AppVerify;
|
||||
use inherents::InherentIdentifier;
|
||||
use sp_arithmetic::traits::{BaseArithmetic, Saturating, Zero};
|
||||
use application_crypto::KeyTypeId;
|
||||
|
||||
pub use runtime_primitives::traits::{BlakeTwo256, Hash as HashT};
|
||||
|
||||
@@ -57,6 +58,34 @@ pub use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId;
|
||||
/// Unique identifier for the Inclusion Inherent
|
||||
pub const INCLUSION_INHERENT_IDENTIFIER: InherentIdentifier = *b"inclusn0";
|
||||
|
||||
|
||||
/// The key type ID for a parachain approval voting key.
|
||||
pub const APPROVAL_KEY_TYPE_ID: KeyTypeId = KeyTypeId(*b"aprv");
|
||||
|
||||
mod approval_app {
|
||||
use application_crypto::{app_crypto, sr25519};
|
||||
app_crypto!(sr25519, super::APPROVAL_KEY_TYPE_ID);
|
||||
}
|
||||
|
||||
/// The public key of a keypair used by a validator for approval voting
|
||||
/// on included parachain candidates.
|
||||
pub type ApprovalId = approval_app::Public;
|
||||
|
||||
/// The key type ID for parachain assignment key.
|
||||
pub const ASSIGNMENT_KEY_TYPE_ID: KeyTypeId = KeyTypeId(*b"asgn");
|
||||
|
||||
// The public key of a keypair used by a validator for determining assignments
|
||||
/// to approve included parachain candidates.
|
||||
mod assigment_app {
|
||||
use application_crypto::{app_crypto, sr25519};
|
||||
app_crypto!(sr25519, super::ASSIGNMENT_KEY_TYPE_ID);
|
||||
}
|
||||
|
||||
/// The public key of a keypair used by a validator for determining assignments
|
||||
/// to approve included parachain candidates.
|
||||
pub type AssignmentId = assigment_app::Public;
|
||||
|
||||
|
||||
/// Get a collator signature payload on a relay-parent, block-data combo.
|
||||
pub fn collator_signature_payload<H: AsRef<[u8]>>(
|
||||
relay_parent: &H,
|
||||
@@ -671,6 +700,35 @@ pub enum CandidateEvent<H = Hash> {
|
||||
CandidateTimedOut(CandidateReceipt<H>, HeadData),
|
||||
}
|
||||
|
||||
/// Information about validator sets of a session.
|
||||
#[derive(Clone, Encode, Decode, RuntimeDebug)]
|
||||
#[cfg_attr(feature = "std", derive(PartialEq, Default))]
|
||||
pub struct SessionInfo {
|
||||
/// Validators in canonical ordering.
|
||||
pub validators: Vec<ValidatorId>,
|
||||
/// Validators' authority discovery keys for the session in canonical ordering.
|
||||
pub discovery_keys: Vec<AuthorityDiscoveryId>,
|
||||
/// The assignment and approval keys for validators.
|
||||
pub approval_keys: Vec<(ApprovalId, AssignmentId)>,
|
||||
/// Validators in shuffled ordering - these are the validator groups as produced
|
||||
/// by the `Scheduler` module for the session and are typically referred to by
|
||||
/// `GroupIndex`.
|
||||
pub validator_groups: Vec<Vec<ValidatorIndex>>,
|
||||
/// The number of availability cores used by the protocol during this session.
|
||||
pub n_cores: u32,
|
||||
/// The zeroth delay tranche width.
|
||||
pub zeroth_delay_tranche_width: u32,
|
||||
/// The number of samples we do of relay_vrf_modulo.
|
||||
pub relay_vrf_modulo_samples: u32,
|
||||
/// The number of delay tranches in total.
|
||||
pub n_delay_tranches: u32,
|
||||
/// How many slots (BABE / SASSAFRAS) must pass before an assignment is considered a
|
||||
/// no-show.
|
||||
pub no_show_slots: u32,
|
||||
/// The number of validators needed to approve a block.
|
||||
pub needed_approvals: u32,
|
||||
}
|
||||
|
||||
sp_api::decl_runtime_apis! {
|
||||
/// The API for querying the state of parachains on-chain.
|
||||
pub trait ParachainHost<H: Decode = Hash, N: Encode + Decode = BlockNumber> {
|
||||
@@ -710,6 +768,9 @@ sp_api::decl_runtime_apis! {
|
||||
/// This can be used to instantiate a `SigningContext`.
|
||||
fn session_index_for_child() -> SessionIndex;
|
||||
|
||||
/// Get the session info for the given session, if stored.
|
||||
fn session_info(index: SessionIndex) -> Option<SessionInfo>;
|
||||
|
||||
/// Fetch the validation code used by a para, making the given `OccupiedCoreAssumption`.
|
||||
///
|
||||
/// Returns `None` if either the para is not registered or the assumption is `Freed`
|
||||
@@ -735,13 +796,6 @@ sp_api::decl_runtime_apis! {
|
||||
#[skip_initialize_block]
|
||||
fn candidate_events() -> Vec<CandidateEvent<H>>;
|
||||
|
||||
/// Get the `AuthorityDiscoveryId`s corresponding to the given `ValidatorId`s.
|
||||
/// Currently this request is limited to validators in the current session.
|
||||
///
|
||||
/// We assume that every validator runs authority discovery,
|
||||
/// which would allow us to establish point-to-point connection to given validators.
|
||||
fn validator_discovery(validators: Vec<ValidatorId>) -> Vec<Option<AuthorityDiscoveryId>>;
|
||||
|
||||
/// Get all the pending inbound messages in the downward message queue for a para.
|
||||
fn dmq_contents(
|
||||
recipient: Id,
|
||||
|
||||
Reference in New Issue
Block a user