mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 14:37:57 +00:00
Finish migration to v2 primitives (#5037)
* remove v0 primitives from polkadot-primitives * first pass: remove v0 * fix fallout in erasure-coding * remove v1 primitives, consolidate to v2 * the great import update * update runtime_api_impl_v1 to v2 as well * guide: add `Version` request for runtime API * add version query to runtime API * reintroduce OldV1SessionInfo in a limited way
This commit is contained in:
committed by
GitHub
parent
3394cbb142
commit
49f7e5cce4
@@ -20,15 +20,12 @@ 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, ScrapedOnChainVotes, SessionIndex, ValidationCode,
|
||||
ValidationCodeHash, ValidatorId, ValidatorIndex, ValidatorSignature,
|
||||
},
|
||||
v2::{PvfCheckStatement, SessionInfo},
|
||||
use polkadot_primitives::v2::{
|
||||
AuthorityDiscoveryId, BlockNumber, CandidateCommitments, CandidateEvent,
|
||||
CommittedCandidateReceipt, CoreState, GroupRotationInfo, Hash, Id as ParaId,
|
||||
InboundDownwardMessage, InboundHrmpMessage, OccupiedCoreAssumption, PersistedValidationData,
|
||||
PvfCheckStatement, ScrapedOnChainVotes, SessionIndex, SessionInfo, ValidationCode,
|
||||
ValidationCodeHash, ValidatorId, ValidatorIndex, ValidatorSignature,
|
||||
};
|
||||
|
||||
const AUTHORITIES_CACHE_SIZE: usize = 128 * 1024;
|
||||
@@ -49,6 +46,7 @@ const CURRENT_BABE_EPOCH_CACHE_SIZE: usize = 64 * 1024;
|
||||
const ON_CHAIN_VOTES_CACHE_SIZE: usize = 3 * 1024;
|
||||
const PVFS_REQUIRE_PRECHECK_SIZE: usize = 1024;
|
||||
const VALIDATION_CODE_HASH_CACHE_SIZE: usize = 64 * 1024;
|
||||
const VERSION_CACHE_SIZE: usize = 4 * 1024;
|
||||
|
||||
struct ResidentSizeOf<T>(T);
|
||||
|
||||
@@ -116,6 +114,7 @@ pub(crate) struct RequestResultCache {
|
||||
(Hash, ParaId, OccupiedCoreAssumption),
|
||||
ResidentSizeOf<Option<ValidationCodeHash>>,
|
||||
>,
|
||||
version: MemoryLruCache<Hash, ResidentSizeOf<u32>>,
|
||||
}
|
||||
|
||||
impl Default for RequestResultCache {
|
||||
@@ -142,6 +141,7 @@ impl Default for RequestResultCache {
|
||||
on_chain_votes: MemoryLruCache::new(ON_CHAIN_VOTES_CACHE_SIZE),
|
||||
pvfs_require_precheck: MemoryLruCache::new(PVFS_REQUIRE_PRECHECK_SIZE),
|
||||
validation_code_hash: MemoryLruCache::new(VALIDATION_CODE_HASH_CACHE_SIZE),
|
||||
version: MemoryLruCache::new(VERSION_CACHE_SIZE),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -399,6 +399,14 @@ impl RequestResultCache {
|
||||
) {
|
||||
self.validation_code_hash.insert(key, ResidentSizeOf(value));
|
||||
}
|
||||
|
||||
pub(crate) fn version(&mut self, relay_parent: &Hash) -> Option<&u32> {
|
||||
self.version.get(&relay_parent).map(|v| &v.0)
|
||||
}
|
||||
|
||||
pub(crate) fn cache_version(&mut self, key: Hash, value: u32) {
|
||||
self.version.insert(key, ResidentSizeOf(value));
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) enum RequestResult {
|
||||
@@ -433,4 +441,5 @@ pub(crate) enum RequestResult {
|
||||
// This is a request with side-effects and no result, hence ().
|
||||
SubmitPvfCheckStatement(Hash, PvfCheckStatement, ValidatorSignature, ()),
|
||||
ValidationCodeHash(Hash, ParaId, OccupiedCoreAssumption, Option<ValidationCodeHash>),
|
||||
Version(Hash, u32),
|
||||
}
|
||||
|
||||
@@ -23,10 +23,7 @@
|
||||
#![warn(missing_docs)]
|
||||
|
||||
use polkadot_node_subsystem_util::metrics::{self, prometheus};
|
||||
use polkadot_primitives::{
|
||||
v1::{Block, BlockId, Hash},
|
||||
v2::ParachainHost,
|
||||
};
|
||||
use polkadot_primitives::v2::{Block, BlockId, Hash, ParachainHost};
|
||||
use polkadot_subsystem::{
|
||||
errors::RuntimeApiError,
|
||||
messages::{RuntimeApiMessage, RuntimeApiRequest as Request},
|
||||
@@ -165,6 +162,8 @@ where
|
||||
ValidationCodeHash(relay_parent, para_id, assumption, hash) => self
|
||||
.requests_cache
|
||||
.cache_validation_code_hash((relay_parent, para_id, assumption), hash),
|
||||
Version(relay_parent, version) =>
|
||||
self.requests_cache.cache_version(relay_parent, version),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,6 +194,8 @@ where
|
||||
}
|
||||
|
||||
match request {
|
||||
Request::Version(sender) =>
|
||||
query!(version(), sender).map(|sender| Request::Version(sender)),
|
||||
Request::Authorities(sender) =>
|
||||
query!(authorities(), sender).map(|sender| Request::Authorities(sender)),
|
||||
Request::Validators(sender) =>
|
||||
@@ -360,6 +361,8 @@ where
|
||||
Client: ProvideRuntimeApi<Block>,
|
||||
Client::Api: ParachainHost<Block> + BabeApi<Block> + AuthorityDiscoveryApi<Block>,
|
||||
{
|
||||
use sp_api::ApiExt;
|
||||
|
||||
let _timer = metrics.time_make_runtime_api_request();
|
||||
|
||||
macro_rules! query {
|
||||
@@ -367,7 +370,6 @@ where
|
||||
let sender = $sender;
|
||||
let api = client.runtime_api();
|
||||
|
||||
use sp_api::ApiExt;
|
||||
let runtime_version = api.api_version::<dyn ParachainHost<Block>>(&BlockId::Hash(relay_parent))
|
||||
.unwrap_or_else(|e| {
|
||||
tracing::warn!(
|
||||
@@ -404,6 +406,24 @@ where
|
||||
}
|
||||
|
||||
match request {
|
||||
Request::Version(sender) => {
|
||||
let api = client.runtime_api();
|
||||
|
||||
let runtime_version = match api
|
||||
.api_version::<dyn ParachainHost<Block>>(&BlockId::Hash(relay_parent))
|
||||
{
|
||||
Ok(Some(v)) => Ok(v),
|
||||
Ok(None) => Err(RuntimeApiError::NotSupported { runtime_api_name: "api_version" }),
|
||||
Err(e) => Err(RuntimeApiError::Execution {
|
||||
runtime_api_name: "api_version",
|
||||
source: std::sync::Arc::new(e),
|
||||
}),
|
||||
};
|
||||
|
||||
let _ = sender.send(runtime_version.clone());
|
||||
runtime_version.ok().map(|v| RequestResult::Version(relay_parent, v))
|
||||
},
|
||||
|
||||
Request::Authorities(sender) => query!(Authorities, authorities(), ver = 1, sender),
|
||||
Request::Validators(sender) => query!(Validators, validators(), ver = 1, sender),
|
||||
Request::ValidatorGroups(sender) =>
|
||||
@@ -448,8 +468,6 @@ where
|
||||
Request::CandidateEvents(sender) =>
|
||||
query!(CandidateEvents, candidate_events(), ver = 1, sender),
|
||||
Request::SessionInfo(index, sender) => {
|
||||
use sp_api::ApiExt;
|
||||
|
||||
let api = client.runtime_api();
|
||||
let block_id = BlockId::Hash(relay_parent);
|
||||
|
||||
|
||||
@@ -20,14 +20,11 @@ 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, ScrapedOnChainVotes, SessionIndex,
|
||||
ValidationCode, ValidationCodeHash, ValidatorId, ValidatorIndex, ValidatorSignature,
|
||||
},
|
||||
v2::{PvfCheckStatement, SessionInfo},
|
||||
use polkadot_primitives::v2::{
|
||||
AuthorityDiscoveryId, CandidateEvent, CommittedCandidateReceipt, CoreState, GroupRotationInfo,
|
||||
Id as ParaId, InboundDownwardMessage, InboundHrmpMessage, OccupiedCoreAssumption,
|
||||
PersistedValidationData, PvfCheckStatement, ScrapedOnChainVotes, SessionIndex, SessionInfo,
|
||||
ValidationCode, ValidationCodeHash, ValidatorId, ValidatorIndex, ValidatorSignature,
|
||||
};
|
||||
use sp_core::testing::TaskExecutor;
|
||||
use std::{
|
||||
@@ -111,7 +108,7 @@ sp_api::mock_impl_runtime_apis! {
|
||||
fn check_validation_outputs(
|
||||
&self,
|
||||
para_id: ParaId,
|
||||
_commitments: polkadot_primitives::v1::CandidateCommitments,
|
||||
_commitments: polkadot_primitives::v2::CandidateCommitments,
|
||||
) -> bool {
|
||||
self.validation_outputs_results
|
||||
.get(¶_id)
|
||||
@@ -219,7 +216,7 @@ sp_api::mock_impl_runtime_apis! {
|
||||
}
|
||||
|
||||
fn submit_report_equivocation_unsigned_extrinsic(
|
||||
_equivocation_proof: sp_consensus_babe::EquivocationProof<polkadot_primitives::v1::Header>,
|
||||
_equivocation_proof: sp_consensus_babe::EquivocationProof<polkadot_primitives::v2::Header>,
|
||||
_key_owner_proof: sp_consensus_babe::OpaqueKeyOwnershipProof,
|
||||
) -> Option<()> {
|
||||
None
|
||||
@@ -442,7 +439,7 @@ fn requests_check_validation_outputs() {
|
||||
let relay_parent = [1; 32].into();
|
||||
let para_a = 5.into();
|
||||
let para_b = 6.into();
|
||||
let commitments = polkadot_primitives::v1::CandidateCommitments::default();
|
||||
let commitments = polkadot_primitives::v2::CandidateCommitments::default();
|
||||
let spawner = sp_core::testing::TaskExecutor::new();
|
||||
|
||||
runtime_api.validation_outputs_results.insert(para_a, false);
|
||||
|
||||
Reference in New Issue
Block a user