mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 15:47:58 +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,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