mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 12:17:58 +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:
@@ -738,6 +738,7 @@ mod tests {
|
||||
use polkadot_primitives::v1::{
|
||||
BlockData, CandidateDescriptor, CollatorPair, ScheduledCore,
|
||||
ValidatorIndex, GroupRotationInfo, AuthorityDiscoveryId,
|
||||
SessionIndex, SessionInfo,
|
||||
};
|
||||
use polkadot_subsystem::{ActiveLeavesUpdate, messages::{RuntimeApiMessage, RuntimeApiRequest}};
|
||||
use polkadot_node_subsystem_util::TimeoutExt;
|
||||
@@ -776,6 +777,7 @@ mod tests {
|
||||
relay_parent: Hash,
|
||||
availability_core: CoreState,
|
||||
our_collator_pair: CollatorPair,
|
||||
session_index: SessionIndex,
|
||||
}
|
||||
|
||||
fn validator_pubkeys(val_ids: &[Sr25519Keyring]) -> Vec<ValidatorId> {
|
||||
@@ -832,6 +834,7 @@ mod tests {
|
||||
relay_parent,
|
||||
availability_core,
|
||||
our_collator_pair,
|
||||
session_index: 1,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -841,6 +844,10 @@ mod tests {
|
||||
&self.validator_groups.0[0]
|
||||
}
|
||||
|
||||
fn current_session_index(&self) -> SessionIndex {
|
||||
self.session_index
|
||||
}
|
||||
|
||||
fn current_group_validator_peer_ids(&self) -> Vec<PeerId> {
|
||||
self.current_group_validator_indices().iter().map(|i| self.validator_peer_id[*i as usize].clone()).collect()
|
||||
}
|
||||
@@ -870,20 +877,6 @@ mod tests {
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn next_group_validator_ids(&self) -> Vec<ValidatorId> {
|
||||
self.next_group_validator_indices()
|
||||
.iter()
|
||||
.map(|i| self.validator_public[*i as usize].clone())
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Returns the unique count of validators in the current and next group.
|
||||
fn current_and_next_group_unique_validator_count(&self) -> usize {
|
||||
let mut indices = self.next_group_validator_indices().iter().collect::<HashSet<_>>();
|
||||
indices.extend(self.current_group_validator_indices());
|
||||
indices.len()
|
||||
}
|
||||
|
||||
/// Generate a new relay parent and inform the subsystem about the new view.
|
||||
///
|
||||
/// If `merge_views == true` it means the subsystem will be informed that we working on the old `relay_parent`
|
||||
@@ -1090,20 +1083,33 @@ mod tests {
|
||||
overseer_recv(virtual_overseer).await,
|
||||
AllMessages::RuntimeApi(RuntimeApiMessage::Request(
|
||||
relay_parent,
|
||||
RuntimeApiRequest::ValidatorDiscovery(validators, tx),
|
||||
RuntimeApiRequest::SessionIndexForChild(tx),
|
||||
)) => {
|
||||
assert_eq!(relay_parent, test_state.relay_parent);
|
||||
assert_eq!(validators.len(), test_state.current_and_next_group_unique_validator_count());
|
||||
tx.send(Ok(test_state.current_session_index())).unwrap();
|
||||
}
|
||||
);
|
||||
|
||||
let current_validators = test_state.current_group_validator_ids();
|
||||
let next_validators = test_state.next_group_validator_ids();
|
||||
assert_matches!(
|
||||
overseer_recv(virtual_overseer).await,
|
||||
AllMessages::RuntimeApi(RuntimeApiMessage::Request(
|
||||
relay_parent,
|
||||
RuntimeApiRequest::SessionInfo(index, tx),
|
||||
)) => {
|
||||
assert_eq!(relay_parent, test_state.relay_parent);
|
||||
assert_eq!(index, test_state.current_session_index());
|
||||
|
||||
assert!(validators.iter().all(|v| current_validators.contains(&v) || next_validators.contains(&v)));
|
||||
let validators = test_state.current_group_validator_ids();
|
||||
let current_discovery_keys = test_state.current_group_validator_authority_ids();
|
||||
let next_discovery_keys = test_state.next_group_validator_authority_ids();
|
||||
|
||||
let current_validators = test_state.current_group_validator_authority_ids();
|
||||
let next_validators = test_state.next_group_validator_authority_ids();
|
||||
let discovery_keys = [¤t_discovery_keys[..], &next_discovery_keys[..]].concat();
|
||||
|
||||
tx.send(Ok(current_validators.into_iter().chain(next_validators).map(Some).collect())).unwrap();
|
||||
tx.send(Ok(Some(SessionInfo {
|
||||
validators,
|
||||
discovery_keys,
|
||||
..Default::default()
|
||||
}))).unwrap();
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@@ -60,16 +60,6 @@ enum Error {
|
||||
Prometheus(#[from] prometheus::PrometheusError),
|
||||
}
|
||||
|
||||
impl From<util::validator_discovery::Error> for Error {
|
||||
fn from(me: util::validator_discovery::Error) -> Self {
|
||||
match me {
|
||||
util::validator_discovery::Error::Subsystem(s) => Error::Subsystem(s),
|
||||
util::validator_discovery::Error::RuntimeApi(ra) => Error::RuntimeApi(ra),
|
||||
util::validator_discovery::Error::Oneshot(c) => Error::Oneshot(c),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
/// What side of the collator protocol is being engaged
|
||||
|
||||
Reference in New Issue
Block a user