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:
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user