mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-19 20:25:40 +00:00
session-info: add new fields + migration (#4545)
* session_info: v2 + migration * use primitives::v2 * use polkadot_primitives::v2 * impl primitives::v2 * fix approval-voting tests * fix other tests * hook storage migration up * backwards compat (1) * backwards compat (2) * fmt * fix tests * FMT * do not reexport v1 in v2 * fmt * set storage version to 1 Co-authored-by: Javier Viola <javier@parity.io>
This commit is contained in:
@@ -20,8 +20,9 @@ use parity_scale_codec::{Decode, Encode};
|
||||
use polkadot_node_primitives::approval::{
|
||||
self as approval_types, AssignmentCert, AssignmentCertKind, DelayTranche, RelayVRFStory,
|
||||
};
|
||||
use polkadot_primitives::v1::{
|
||||
AssignmentId, AssignmentPair, CandidateHash, CoreIndex, GroupIndex, SessionInfo, ValidatorIndex,
|
||||
use polkadot_primitives::{
|
||||
v1::{AssignmentId, AssignmentPair, CandidateHash, CoreIndex, GroupIndex, ValidatorIndex},
|
||||
v2::SessionInfo,
|
||||
};
|
||||
use sc_keystore::LocalKeystore;
|
||||
use sp_application_crypto::ByteArray;
|
||||
|
||||
@@ -582,7 +582,7 @@ pub(crate) mod tests {
|
||||
use polkadot_node_primitives::approval::{VRFOutput, VRFProof};
|
||||
use polkadot_node_subsystem::messages::AllMessages;
|
||||
use polkadot_node_subsystem_test_helpers::make_subsystem_context;
|
||||
use polkadot_primitives::v1::{SessionInfo, ValidatorIndex};
|
||||
use polkadot_primitives::{v1::ValidatorIndex, v2::SessionInfo};
|
||||
pub(crate) use sp_consensus_babe::{
|
||||
digests::{CompatibleDigestItem, PreDigest, SecondaryVRFPreDigest},
|
||||
AllowedSlots, BabeEpochConfiguration, Epoch as BabeEpoch,
|
||||
@@ -685,6 +685,7 @@ pub(crate) mod tests {
|
||||
n_delay_tranches: index as _,
|
||||
no_show_slots: index as _,
|
||||
needed_approvals: index as _,
|
||||
active_validator_indices: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1140,6 +1141,7 @@ pub(crate) mod tests {
|
||||
relay_vrf_modulo_samples: irrelevant,
|
||||
n_delay_tranches: irrelevant,
|
||||
no_show_slots: irrelevant,
|
||||
active_validator_indices: Vec::new(),
|
||||
};
|
||||
|
||||
let slot = Slot::from(10);
|
||||
|
||||
@@ -50,10 +50,13 @@ use polkadot_node_subsystem_util::{
|
||||
},
|
||||
TimeoutExt,
|
||||
};
|
||||
use polkadot_primitives::v1::{
|
||||
ApprovalVote, BlockNumber, CandidateHash, CandidateIndex, CandidateReceipt, DisputeStatement,
|
||||
GroupIndex, Hash, SessionIndex, SessionInfo, ValidDisputeStatementKind, ValidatorId,
|
||||
ValidatorIndex, ValidatorPair, ValidatorSignature,
|
||||
use polkadot_primitives::{
|
||||
v1::{
|
||||
ApprovalVote, BlockNumber, CandidateHash, CandidateIndex, CandidateReceipt,
|
||||
DisputeStatement, GroupIndex, Hash, SessionIndex, ValidDisputeStatementKind, ValidatorId,
|
||||
ValidatorIndex, ValidatorPair, ValidatorSignature,
|
||||
},
|
||||
v2::SessionInfo,
|
||||
};
|
||||
use sc_keystore::LocalKeystore;
|
||||
use sp_application_crypto::Pair;
|
||||
|
||||
@@ -740,6 +740,22 @@ impl ChainBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
fn session_info(keys: &[Sr25519Keyring]) -> SessionInfo {
|
||||
SessionInfo {
|
||||
validators: keys.iter().map(|v| v.public().into()).collect(),
|
||||
discovery_keys: keys.iter().map(|v| v.public().into()).collect(),
|
||||
assignment_keys: keys.iter().map(|v| v.public().into()).collect(),
|
||||
validator_groups: vec![vec![ValidatorIndex(0)], vec![ValidatorIndex(1)]],
|
||||
n_cores: keys.len() as _,
|
||||
needed_approvals: 2,
|
||||
zeroth_delay_tranche_width: 5,
|
||||
relay_vrf_modulo_samples: 3,
|
||||
n_delay_tranches: 50,
|
||||
no_show_slots: 2,
|
||||
active_validator_indices: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
async fn import_block(
|
||||
overseer: &mut VirtualOverseer,
|
||||
hashes: &[(Hash, Header)],
|
||||
@@ -757,18 +773,7 @@ async fn import_block(
|
||||
|
||||
let session_info = config.session_info.clone().unwrap_or({
|
||||
let validators = vec![Sr25519Keyring::Alice, Sr25519Keyring::Bob];
|
||||
SessionInfo {
|
||||
validators: validators.iter().map(|v| v.public().into()).collect(),
|
||||
discovery_keys: validators.iter().map(|v| v.public().into()).collect(),
|
||||
assignment_keys: validators.iter().map(|v| v.public().into()).collect(),
|
||||
validator_groups: vec![vec![ValidatorIndex(0)], vec![ValidatorIndex(1)]],
|
||||
n_cores: validators.len() as _,
|
||||
needed_approvals: 1,
|
||||
zeroth_delay_tranche_width: 5,
|
||||
relay_vrf_modulo_samples: 3,
|
||||
n_delay_tranches: 50,
|
||||
no_show_slots: 2,
|
||||
}
|
||||
SessionInfo { needed_approvals: 1, ..session_info(&validators) }
|
||||
});
|
||||
|
||||
overseer_send(
|
||||
@@ -1452,20 +1457,13 @@ fn subsystem_second_approval_import_only_schedules_wakeups() {
|
||||
Sr25519Keyring::Eve,
|
||||
];
|
||||
let session_info = SessionInfo {
|
||||
validators: validators.iter().map(|v| v.public().into()).collect(),
|
||||
validator_groups: vec![
|
||||
vec![ValidatorIndex(0), ValidatorIndex(1)],
|
||||
vec![ValidatorIndex(2)],
|
||||
vec![ValidatorIndex(3), ValidatorIndex(4)],
|
||||
],
|
||||
needed_approvals: 1,
|
||||
discovery_keys: validators.iter().map(|v| v.public().into()).collect(),
|
||||
assignment_keys: validators.iter().map(|v| v.public().into()).collect(),
|
||||
n_cores: validators.len() as _,
|
||||
zeroth_delay_tranche_width: 5,
|
||||
relay_vrf_modulo_samples: 3,
|
||||
n_delay_tranches: 50,
|
||||
no_show_slots: 2,
|
||||
..session_info(&validators)
|
||||
};
|
||||
|
||||
// Add block hash 0x01...
|
||||
@@ -1763,20 +1761,12 @@ fn import_checked_approval_updates_entries_and_schedules() {
|
||||
Sr25519Keyring::Eve,
|
||||
];
|
||||
let session_info = SessionInfo {
|
||||
validators: validators.iter().map(|v| v.public().into()).collect(),
|
||||
validator_groups: vec![
|
||||
vec![ValidatorIndex(0), ValidatorIndex(1)],
|
||||
vec![ValidatorIndex(2)],
|
||||
vec![ValidatorIndex(3), ValidatorIndex(4)],
|
||||
],
|
||||
needed_approvals: 2,
|
||||
discovery_keys: validators.iter().map(|v| v.public().into()).collect(),
|
||||
assignment_keys: validators.iter().map(|v| v.public().into()).collect(),
|
||||
n_cores: validators.len() as _,
|
||||
zeroth_delay_tranche_width: 5,
|
||||
relay_vrf_modulo_samples: 3,
|
||||
n_delay_tranches: 50,
|
||||
no_show_slots: 2,
|
||||
..session_info(&validators)
|
||||
};
|
||||
|
||||
let candidate_descriptor = make_candidate(1.into(), &block_hash);
|
||||
@@ -1923,20 +1913,12 @@ fn subsystem_import_checked_approval_sets_one_block_bit_at_a_time() {
|
||||
Sr25519Keyring::Eve,
|
||||
];
|
||||
let session_info = SessionInfo {
|
||||
validators: validators.iter().map(|v| v.public().into()).collect(),
|
||||
validator_groups: vec![
|
||||
vec![ValidatorIndex(0), ValidatorIndex(1)],
|
||||
vec![ValidatorIndex(2)],
|
||||
vec![ValidatorIndex(3), ValidatorIndex(4)],
|
||||
],
|
||||
needed_approvals: 2,
|
||||
discovery_keys: validators.iter().map(|v| v.public().into()).collect(),
|
||||
assignment_keys: validators.iter().map(|v| v.public().into()).collect(),
|
||||
n_cores: validators.len() as _,
|
||||
zeroth_delay_tranche_width: 5,
|
||||
relay_vrf_modulo_samples: 3,
|
||||
n_delay_tranches: 50,
|
||||
no_show_slots: 2,
|
||||
..session_info(&validators)
|
||||
};
|
||||
|
||||
ChainBuilder::new()
|
||||
@@ -2209,20 +2191,12 @@ fn subsystem_validate_approvals_cache() {
|
||||
Sr25519Keyring::Eve,
|
||||
];
|
||||
let session_info = SessionInfo {
|
||||
validators: validators.iter().map(|v| v.public().into()).collect(),
|
||||
validator_groups: vec![
|
||||
vec![ValidatorIndex(0), ValidatorIndex(1)],
|
||||
vec![ValidatorIndex(2)],
|
||||
vec![ValidatorIndex(3), ValidatorIndex(4)],
|
||||
],
|
||||
needed_approvals: 2,
|
||||
discovery_keys: validators.iter().map(|v| v.public().into()).collect(),
|
||||
assignment_keys: validators.iter().map(|v| v.public().into()).collect(),
|
||||
n_cores: validators.len() as _,
|
||||
zeroth_delay_tranche_width: 5,
|
||||
relay_vrf_modulo_samples: 3,
|
||||
n_delay_tranches: 50,
|
||||
no_show_slots: 2,
|
||||
..session_info(&validators)
|
||||
};
|
||||
|
||||
let candidates = Some(vec![(candidate_receipt.clone(), CoreIndex(0), GroupIndex(0))]);
|
||||
@@ -2422,20 +2396,14 @@ where
|
||||
Sr25519Keyring::Ferdie,
|
||||
];
|
||||
let session_info = SessionInfo {
|
||||
validators: validators.iter().map(|v| v.public().into()).collect(),
|
||||
validator_groups: vec![
|
||||
vec![ValidatorIndex(0), ValidatorIndex(1)],
|
||||
vec![ValidatorIndex(2), ValidatorIndex(3)],
|
||||
vec![ValidatorIndex(4), ValidatorIndex(5)],
|
||||
],
|
||||
needed_approvals: 2,
|
||||
discovery_keys: validators.iter().map(|v| v.public().into()).collect(),
|
||||
assignment_keys: validators.iter().map(|v| v.public().into()).collect(),
|
||||
n_cores: validators.len() as _,
|
||||
zeroth_delay_tranche_width: 5,
|
||||
relay_vrf_modulo_samples: 2,
|
||||
n_delay_tranches: 50,
|
||||
no_show_slots,
|
||||
..session_info(&validators)
|
||||
};
|
||||
|
||||
ChainBuilder::new()
|
||||
@@ -2740,20 +2708,12 @@ fn pre_covers_dont_stall_approval() {
|
||||
Sr25519Keyring::One,
|
||||
];
|
||||
let session_info = SessionInfo {
|
||||
validators: validators.iter().map(|v| v.public().into()).collect(),
|
||||
validator_groups: vec![
|
||||
vec![ValidatorIndex(0), ValidatorIndex(1)],
|
||||
vec![ValidatorIndex(2), ValidatorIndex(5)],
|
||||
vec![ValidatorIndex(3), ValidatorIndex(4)],
|
||||
],
|
||||
needed_approvals: 2,
|
||||
discovery_keys: validators.iter().map(|v| v.public().into()).collect(),
|
||||
assignment_keys: validators.iter().map(|v| v.public().into()).collect(),
|
||||
n_cores: validators.len() as _,
|
||||
zeroth_delay_tranche_width: 5,
|
||||
relay_vrf_modulo_samples: 3,
|
||||
n_delay_tranches: 50,
|
||||
no_show_slots: 2,
|
||||
..session_info(&validators)
|
||||
};
|
||||
|
||||
let candidate_descriptor = make_candidate(1.into(), &block_hash);
|
||||
@@ -2920,20 +2880,12 @@ fn waits_until_approving_assignments_are_old_enough() {
|
||||
Sr25519Keyring::One,
|
||||
];
|
||||
let session_info = SessionInfo {
|
||||
validators: validators.iter().map(|v| v.public().into()).collect(),
|
||||
validator_groups: vec![
|
||||
vec![ValidatorIndex(0), ValidatorIndex(1)],
|
||||
vec![ValidatorIndex(2), ValidatorIndex(5)],
|
||||
vec![ValidatorIndex(3), ValidatorIndex(4)],
|
||||
],
|
||||
needed_approvals: 2,
|
||||
discovery_keys: validators.iter().map(|v| v.public().into()).collect(),
|
||||
assignment_keys: validators.iter().map(|v| v.public().into()).collect(),
|
||||
n_cores: validators.len() as _,
|
||||
zeroth_delay_tranche_width: 5,
|
||||
relay_vrf_modulo_samples: 3,
|
||||
n_delay_tranches: 50,
|
||||
no_show_slots: 2,
|
||||
..session_info(&validators)
|
||||
};
|
||||
|
||||
let candidate_descriptor = make_candidate(1.into(), &block_hash);
|
||||
|
||||
@@ -39,10 +39,13 @@ use polkadot_node_subsystem::{
|
||||
use polkadot_node_subsystem_util::rolling_session_window::{
|
||||
RollingSessionWindow, SessionWindowUpdate,
|
||||
};
|
||||
use polkadot_primitives::v1::{
|
||||
byzantine_threshold, BlockNumber, CandidateHash, CandidateReceipt, CompactStatement,
|
||||
DisputeStatement, DisputeStatementSet, Hash, ScrapedOnChainVotes, SessionIndex, SessionInfo,
|
||||
ValidDisputeStatementKind, ValidatorId, ValidatorIndex, ValidatorPair, ValidatorSignature,
|
||||
use polkadot_primitives::{
|
||||
v1::{
|
||||
byzantine_threshold, BlockNumber, CandidateHash, CandidateReceipt, CompactStatement,
|
||||
DisputeStatement, DisputeStatementSet, Hash, ScrapedOnChainVotes, SessionIndex,
|
||||
ValidDisputeStatementKind, ValidatorId, ValidatorIndex, ValidatorPair, ValidatorSignature,
|
||||
},
|
||||
v2::SessionInfo,
|
||||
};
|
||||
|
||||
use crate::{metrics::Metrics, real::DisputeCoordinatorSubsystem, LOG_TARGET};
|
||||
|
||||
@@ -54,10 +54,13 @@ use polkadot_node_subsystem::{
|
||||
ActivatedLeaf, ActiveLeavesUpdate, LeafStatus,
|
||||
};
|
||||
use polkadot_node_subsystem_test_helpers::{make_subsystem_context, TestSubsystemContextHandle};
|
||||
use polkadot_primitives::v1::{
|
||||
BlakeTwo256, BlockNumber, CandidateCommitments, CandidateHash, CandidateReceipt, Hash, HashT,
|
||||
Header, MultiDisputeStatementSet, ScrapedOnChainVotes, SessionIndex, SessionInfo, ValidatorId,
|
||||
ValidatorIndex,
|
||||
use polkadot_primitives::{
|
||||
v1::{
|
||||
BlakeTwo256, BlockNumber, CandidateCommitments, CandidateHash, CandidateReceipt, Hash,
|
||||
HashT, Header, MultiDisputeStatementSet, ScrapedOnChainVotes, SessionIndex, ValidatorId,
|
||||
ValidatorIndex,
|
||||
},
|
||||
v2::SessionInfo,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
@@ -313,6 +316,7 @@ impl TestState {
|
||||
n_delay_tranches: 100,
|
||||
no_show_slots: 1,
|
||||
needed_approvals: 10,
|
||||
active_validator_indices: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,12 +20,15 @@ use memory_lru::{MemoryLruCache, ResidentSize};
|
||||
use parity_util_mem::{MallocSizeOf, MallocSizeOfExt};
|
||||
use sp_consensus_babe::Epoch;
|
||||
|
||||
use polkadot_primitives::v1::{
|
||||
AuthorityDiscoveryId, BlockNumber, CandidateCommitments, CandidateEvent,
|
||||
CommittedCandidateReceipt, CoreState, GroupRotationInfo, Hash, Id as ParaId,
|
||||
InboundDownwardMessage, InboundHrmpMessage, OccupiedCoreAssumption, PersistedValidationData,
|
||||
PvfCheckStatement, ScrapedOnChainVotes, SessionIndex, SessionInfo, ValidationCode,
|
||||
ValidationCodeHash, ValidatorId, ValidatorIndex, ValidatorSignature,
|
||||
use polkadot_primitives::{
|
||||
v1::{
|
||||
AuthorityDiscoveryId, BlockNumber, CandidateCommitments, CandidateEvent,
|
||||
CommittedCandidateReceipt, CoreState, GroupRotationInfo, Hash, Id as ParaId,
|
||||
InboundDownwardMessage, InboundHrmpMessage, OccupiedCoreAssumption,
|
||||
PersistedValidationData, ScrapedOnChainVotes, SessionIndex, ValidationCode,
|
||||
ValidationCodeHash, ValidatorId, ValidatorIndex, ValidatorSignature,
|
||||
},
|
||||
v2::{PvfCheckStatement, SessionInfo},
|
||||
};
|
||||
|
||||
const AUTHORITIES_CACHE_SIZE: usize = 128 * 1024;
|
||||
|
||||
@@ -23,7 +23,10 @@
|
||||
#![warn(missing_docs)]
|
||||
|
||||
use polkadot_node_subsystem_util::metrics::{self, prometheus};
|
||||
use polkadot_primitives::v1::{Block, BlockId, Hash, ParachainHost};
|
||||
use polkadot_primitives::{
|
||||
v1::{Block, BlockId, Hash},
|
||||
v2::ParachainHost,
|
||||
};
|
||||
use polkadot_subsystem::{
|
||||
errors::RuntimeApiError,
|
||||
messages::{RuntimeApiMessage, RuntimeApiRequest as Request},
|
||||
@@ -429,8 +432,42 @@ where
|
||||
),
|
||||
Request::CandidateEvents(sender) =>
|
||||
query!(CandidateEvents, candidate_events(), ver = 1, sender),
|
||||
Request::SessionInfo(index, sender) =>
|
||||
query!(SessionInfo, session_info(index), ver = 1, sender),
|
||||
Request::SessionInfo(index, sender) => {
|
||||
use sp_api::ApiExt;
|
||||
|
||||
let api = client.runtime_api();
|
||||
let block_id = BlockId::Hash(relay_parent);
|
||||
|
||||
let api_version = api
|
||||
.api_version::<dyn ParachainHost<Block>>(&BlockId::Hash(relay_parent))
|
||||
.unwrap_or_default()
|
||||
.unwrap_or_default();
|
||||
|
||||
let res = if api_version >= 2 {
|
||||
let res =
|
||||
api.session_info(&block_id, index).map_err(|e| RuntimeApiError::Execution {
|
||||
runtime_api_name: "SessionInfo",
|
||||
source: std::sync::Arc::new(e),
|
||||
});
|
||||
metrics.on_request(res.is_ok());
|
||||
res
|
||||
} else {
|
||||
#[allow(deprecated)]
|
||||
let res = api.session_info_before_version_2(&block_id, index).map_err(|e| {
|
||||
RuntimeApiError::Execution {
|
||||
runtime_api_name: "SessionInfo",
|
||||
source: std::sync::Arc::new(e),
|
||||
}
|
||||
});
|
||||
metrics.on_request(res.is_ok());
|
||||
|
||||
res.map(|r| r.map(|old| old.into()))
|
||||
};
|
||||
|
||||
let _ = sender.send(res.clone());
|
||||
|
||||
res.ok().map(|res| RequestResult::SessionInfo(relay_parent, index, res))
|
||||
},
|
||||
Request::DmqContents(id, sender) => query!(DmqContents, dmq_contents(id), ver = 1, sender),
|
||||
Request::InboundHrmpChannelsContents(id, sender) =>
|
||||
query!(InboundHrmpChannelsContents, inbound_hrmp_channels_contents(id), ver = 1, sender),
|
||||
|
||||
@@ -20,11 +20,14 @@ use ::test_helpers::{dummy_committed_candidate_receipt, dummy_validation_code};
|
||||
use futures::channel::oneshot;
|
||||
use polkadot_node_primitives::{BabeAllowedSlots, BabeEpoch, BabeEpochConfiguration};
|
||||
use polkadot_node_subsystem_test_helpers::make_subsystem_context;
|
||||
use polkadot_primitives::v1::{
|
||||
AuthorityDiscoveryId, CandidateEvent, CommittedCandidateReceipt, CoreState, GroupRotationInfo,
|
||||
Id as ParaId, InboundDownwardMessage, InboundHrmpMessage, OccupiedCoreAssumption,
|
||||
PersistedValidationData, PvfCheckStatement, ScrapedOnChainVotes, SessionIndex, SessionInfo,
|
||||
ValidationCode, ValidationCodeHash, ValidatorId, ValidatorIndex, ValidatorSignature,
|
||||
use polkadot_primitives::{
|
||||
v1::{
|
||||
AuthorityDiscoveryId, CandidateEvent, CommittedCandidateReceipt, CoreState,
|
||||
GroupRotationInfo, Id as ParaId, InboundDownwardMessage, InboundHrmpMessage,
|
||||
OccupiedCoreAssumption, PersistedValidationData, ScrapedOnChainVotes, SessionIndex,
|
||||
ValidationCode, ValidationCodeHash, ValidatorId, ValidatorIndex, ValidatorSignature,
|
||||
},
|
||||
v2::{PvfCheckStatement, SessionInfo},
|
||||
};
|
||||
use sp_core::testing::TaskExecutor;
|
||||
use std::{
|
||||
@@ -508,6 +511,7 @@ fn dummy_session_info() -> SessionInfo {
|
||||
n_delay_tranches: 2u32,
|
||||
no_show_slots: 0u32,
|
||||
needed_approvals: 1u32,
|
||||
active_validator_indices: vec![],
|
||||
}
|
||||
}
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user