Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

past-session validator discovery APIs #2009

Merged
43 commits merged into from
Nov 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
4fecb64
guide: fix formatting for SessionInfo module
ordian Nov 5, 2020
f3b5430
primitives: SessionInfo type
ordian Nov 6, 2020
62843e9
punt on approval keys
ordian Nov 9, 2020
1f720aa
ah, revert the type alias
ordian Nov 9, 2020
25dd0c9
session info runtime module skeleton
ordian Nov 10, 2020
f1dd12a
update the guide
ordian Nov 13, 2020
b2ef662
runtime/configuration: sync with the guide
ordian Nov 17, 2020
c2512be
runtime/configuration: setters for newly added fields
ordian Nov 17, 2020
a6432bf
runtime/configuration: set codec indexes
ordian Nov 17, 2020
d350875
runtime/configuration: update test
ordian Nov 17, 2020
93e29b2
primitives: fix SessionInfo definition
ordian Nov 17, 2020
4a5ca12
runtime/session_info: initial impl
ordian Nov 17, 2020
e594e5d
runtime/session_info: use initializer for session handling (wip)
ordian Nov 17, 2020
c9f4e7c
Merge branch 'master' into ao-session-info
ordian Nov 18, 2020
d308491
Merge branch 'master' into ao-session-info
ordian Nov 19, 2020
b01341a
runtime/session_info: mock authority discovery trait
ordian Nov 19, 2020
2e563d3
guide: update the initializer's order
ordian Nov 19, 2020
532429e
runtime/session_info: tests skeleton
ordian Nov 19, 2020
b0dd493
runtime/session_info: store n_delay_tranches in Configuration
ordian Nov 19, 2020
ca9dd13
runtime/session_info: punt on approval keys
ordian Nov 19, 2020
088efb3
runtime/session_info: add some basic tests
ordian Nov 19, 2020
4599423
Merge branch 'master' into ao-session-info
ordian Nov 19, 2020
76ec9ab
Update primitives/src/v1.rs
ordian Nov 19, 2020
f8a11cb
small fixes
ordian Nov 19, 2020
2f6905a
remove codec index annotation on structs
ordian Nov 19, 2020
d50073b
Merge branch 'master' into ao-session-info
ordian Nov 23, 2020
612c170
Merge branch 'master' into ao-session-info
ordian Nov 23, 2020
35cb563
fix off-by-one error
ordian Nov 23, 2020
3d22556
validator_discovery: accept a session index
ordian Nov 24, 2020
5304563
runtime: replace validator_discovery api with session_info
ordian Nov 24, 2020
60aede3
Merge branch 'master' into ao-validator-discovery-previous-sessions
ordian Nov 24, 2020
21eb2a4
Update runtime/parachains/src/session_info.rs
ordian Nov 25, 2020
25e13e1
runtime/session_info: add a comment about missing entries
ordian Nov 25, 2020
158a5fa
runtime/session_info: define the keys
ordian Nov 25, 2020
8c32d84
Merge branch 'ao-session-info' into ao-validator-discovery-previous-s…
ordian Nov 25, 2020
09c9359
util: expose connect_to_past_session_validators
ordian Nov 25, 2020
1d7ad3b
util: allow session_info requests for jobs
ordian Nov 25, 2020
992ed07
runtime-api: add mock test for session_info
ordian Nov 25, 2020
835ae2f
collator-protocol: add session_index to test state
ordian Nov 25, 2020
f1cc838
Merge branch 'master' into ao-validator-discovery-previous-sessions
ordian Nov 25, 2020
248fd37
util: fix error message for runtime error
ordian Nov 25, 2020
1a16356
fix compilation
ordian Nov 25, 2020
947a4fc
fix tests after merge with master
ordian Nov 25, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 35 additions & 7 deletions node/core/runtime-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ fn make_runtime_api_request<Client>(
Request::CandidatePendingAvailability(para, sender) =>
query!(candidate_pending_availability(para), sender),
Request::CandidateEvents(sender) => query!(candidate_events(), sender),
Request::ValidatorDiscovery(ids, sender) => query!(validator_discovery(ids), sender),
Request::SessionInfo(index, sender) => query!(session_info(index), sender),
Request::DmqContents(id, sender) => query!(dmq_contents(id), sender),
Request::InboundHrmpChannelsContents(id, sender) => query!(inbound_hrmp_channels_contents(id), sender),
}
Expand Down Expand Up @@ -201,8 +201,8 @@ mod tests {
use polkadot_primitives::v1::{
ValidatorId, ValidatorIndex, GroupRotationInfo, CoreState, PersistedValidationData,
Id as ParaId, OccupiedCoreAssumption, ValidationData, SessionIndex, ValidationCode,
CommittedCandidateReceipt, CandidateEvent, AuthorityDiscoveryId, InboundDownwardMessage,
BlockNumber, InboundHrmpMessage,
CommittedCandidateReceipt, CandidateEvent, InboundDownwardMessage,
BlockNumber, InboundHrmpMessage, SessionInfo,
};
use polkadot_node_subsystem_test_helpers as test_helpers;
use sp_core::testing::TaskExecutor;
Expand All @@ -216,6 +216,7 @@ mod tests {
availability_cores: Vec<CoreState>,
validation_data: HashMap<ParaId, ValidationData>,
session_index_for_child: SessionIndex,
session_info: HashMap<SessionIndex, SessionInfo>,
validation_code: HashMap<ParaId, ValidationCode>,
historical_validation_code: HashMap<ParaId, Vec<(BlockNumber, ValidationCode)>>,
validation_outputs_results: HashMap<ParaId, bool>,
Expand Down Expand Up @@ -289,6 +290,10 @@ mod tests {
self.session_index_for_child.clone()
}

fn session_info(&self, index: SessionIndex) -> Option<SessionInfo> {
self.session_info.get(&index).cloned()
}

fn validation_code(
&self,
para: ParaId,
Expand Down Expand Up @@ -321,10 +326,6 @@ mod tests {
self.candidate_events.clone()
}

fn validator_discovery(ids: Vec<ValidatorId>) -> Vec<Option<AuthorityDiscoveryId>> {
vec![None; ids.len()]
}

fn dmq_contents(
&self,
recipient: ParaId,
Expand Down Expand Up @@ -569,6 +570,33 @@ mod tests {
futures::executor::block_on(future::join(subsystem_task, test_task));
}

#[test]
fn requests_session_info() {
let (ctx, mut ctx_handle) = test_helpers::make_subsystem_context(TaskExecutor::new());
let mut runtime_api = MockRuntimeApi::default();
let session_index = 1;
runtime_api.session_info.insert(session_index, Default::default());
let runtime_api = Arc::new(runtime_api);

let relay_parent = [1; 32].into();

let subsystem = RuntimeApiSubsystem::new(runtime_api.clone(), Metrics(None));
let subsystem_task = run(ctx, subsystem).map(|x| x.unwrap());
let test_task = async move {
let (tx, rx) = oneshot::channel();

ctx_handle.send(FromOverseer::Communication {
msg: RuntimeApiMessage::Request(relay_parent, Request::SessionInfo(session_index, tx))
}).await;

assert_eq!(rx.await.unwrap().unwrap(), Some(Default::default()));

ctx_handle.send(FromOverseer::Signal(OverseerSignal::Conclude)).await;
};

futures::executor::block_on(future::join(subsystem_task, test_task));
}

#[test]
fn requests_validation_code() {
let (ctx, mut ctx_handle) = test_helpers::make_subsystem_context(TaskExecutor::new());
Expand Down
50 changes: 28 additions & 22 deletions node/network/collator-protocol/src/collator_side.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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> {
Expand Down Expand Up @@ -832,6 +834,7 @@ mod tests {
relay_parent,
availability_core,
our_collator_pair,
session_index: 1,
}
}
}
Expand All @@ -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()
}
Expand Down Expand Up @@ -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`
Expand Down Expand Up @@ -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 = [&current_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();
}
);

Expand Down
10 changes: 0 additions & 10 deletions node/network/collator-protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions node/network/pov-distribution/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ pub enum Error {
#[error(transparent)]
Runtime(#[from] polkadot_subsystem::errors::RuntimeApiError),
#[error(transparent)]
ValidatorDiscovery(#[from] polkadot_node_subsystem_util::validator_discovery::Error),
#[error(transparent)]
Util(#[from] polkadot_node_subsystem_util::Error),
}

Expand Down
Loading