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:
Robert Habermeier
2022-03-09 14:01:13 -06:00
committed by GitHub
parent 3394cbb142
commit 49f7e5cce4
215 changed files with 2312 additions and 3123 deletions
+25 -7
View File
@@ -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);