From 3736a8e7048cee969e7dc4db5a66c4e277abd815 Mon Sep 17 00:00:00 2001 From: Andrei Eres Date: Tue, 22 Aug 2023 14:02:28 +0200 Subject: [PATCH] Support new types after the async backing merge --- essentials/src/api/dynamic.rs | 14 ++++++-------- essentials/src/api/subxt_wrapper.rs | 9 +++------ essentials/src/types.rs | 23 ++++++++++++++++++++--- 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/essentials/src/api/dynamic.rs b/essentials/src/api/dynamic.rs index 0b0e5fb7..2244c279 100644 --- a/essentials/src/api/dynamic.rs +++ b/essentials/src/api/dynamic.rs @@ -2,12 +2,11 @@ use super::subxt_wrapper::SubxtWrapperError::{self, DecodeDynamicError}; use crate::{ metadata::{ polkadot::runtime_types::{ - polkadot_parachain::primitives::Id, - polkadot_runtime_parachains::scheduler::{AssignmentKind, CoreAssignment}, + polkadot_parachain::primitives::Id, polkadot_runtime_parachains::scheduler::AssignmentKind, }, - polkadot_primitives::{CoreIndex, GroupIndex, ValidatorIndex}, + polkadot_primitives::{CoreIndex, ValidatorIndex}, }, - types::{Assignment, BlockNumber, ClaimQueue, CoreOccupied, ParasEntry}, + types::{Assignment, BlockNumber, ClaimQueue, CoreAssignment, CoreOccupied, ParasEntry}, }; use log::error; use std::collections::{BTreeMap, VecDeque}; @@ -69,8 +68,7 @@ pub(crate) fn decode_scheduled_paras(raw_paras: &Value) -> Result AssignmentKind::Parachain, name => todo!("Add support for {name}"), }; - let group_idx = GroupIndex(decode_composite_u128_value(value_at("group_idx", para)?)? as u32); - let assignment = CoreAssignment { core, para_id, kind, group_idx }; + let assignment = CoreAssignment { core, para_id, kind }; paras.push(assignment) } @@ -113,10 +111,10 @@ fn decode_paras_entry_option(raw: &Value) -> Result, Sub fn decode_paras_entry(raw: &Value) -> Result { let para_id = decode_composite_u128_value(value_at("para_id", value_at("assignment", raw)?)?)? as u32; let assignment = Assignment { para_id }; - let retries = decode_u128_value(value_at("retries", raw)?)? as u32; + let availability_timeouts = decode_u128_value(value_at("availability_timeouts", raw)?)? as u32; let ttl = decode_u128_value(value_at("ttl", raw)?)? as BlockNumber; - Ok(ParasEntry { assignment, retries, ttl }) + Ok(ParasEntry { assignment, availability_timeouts, ttl }) } fn value_at<'a>(field: &'a str, value: &'a Value) -> Result<&'a Value, SubxtWrapperError> { diff --git a/essentials/src/api/subxt_wrapper.rs b/essentials/src/api/subxt_wrapper.rs index cc00996b..4b776615 100644 --- a/essentials/src/api/subxt_wrapper.rs +++ b/essentials/src/api/subxt_wrapper.rs @@ -19,7 +19,7 @@ use super::dynamic::{decode_claim_queue, decode_validator_groups}; use crate::{ api::dynamic::{decode_availability_cores, decode_scheduled_paras}, metadata::{polkadot, polkadot_primitives}, - types::{AccountId32, BlockNumber, ClaimQueue, CoreOccupied, SessionKeys, Timestamp, H256}, + types::{AccountId32, BlockNumber, ClaimQueue, CoreAssignment, CoreOccupied, SessionKeys, Timestamp, H256}, utils::{Retry, RetryOptions}, }; use log::{error, warn}; @@ -171,7 +171,7 @@ pub enum Response { /// `ParaInherent` data. ParaInherentData(InherentData), /// Availability core assignments for parachains. - ScheduledParas(Vec), + ScheduledParas(Vec), /// Claim queue for parachains. ClaimQueue(ClaimQueue), /// List of the occupied availability cores. @@ -351,10 +351,7 @@ impl RequestExecutor { &mut self, url: &str, block_hash: ::Hash, - ) -> std::result::Result< - Vec, - SubxtWrapperError, - > { + ) -> std::result::Result, SubxtWrapperError> { wrap_subxt_call!(self, GetScheduledParas, ScheduledParas, url, block_hash) } diff --git a/essentials/src/types.rs b/essentials/src/types.rs index e479a380..e4685910 100644 --- a/essentials/src/types.rs +++ b/essentials/src/types.rs @@ -15,7 +15,13 @@ // along with polkadot-introspector. If not, see . // -use crate::metadata::polkadot::runtime_types as subxt_runtime_types; +use crate::metadata::{ + polkadot::{ + runtime_types as subxt_runtime_types, + runtime_types::{polkadot_parachain::primitives::Id, polkadot_runtime_parachains::scheduler::AssignmentKind}, + }, + polkadot_primitives::CoreIndex, +}; use std::collections::{BTreeMap, VecDeque}; use subxt::utils; @@ -35,14 +41,25 @@ pub type SubxtCall = runtime::RuntimeCall; pub type ClaimQueue = BTreeMap>>; +// TODO: Take it from runtime types v5 +/// How a free core is scheduled to be assigned. +pub struct CoreAssignment { + /// The core that is assigned. + pub core: CoreIndex, + /// The unique ID of the para that is assigned to the core. + pub para_id: Id, + /// The kind of the assignment. + pub kind: AssignmentKind, +} + // TODO: Take it from runtime types v5 /// Polkadot v5 ParasEntry type #[derive(Debug)] pub struct ParasEntry { /// The `Assignment` pub assignment: Assignment, - /// Number of times this has been retried. - pub retries: u32, + /// The number of times the entry has timed out in availability. + pub availability_timeouts: u32, /// The block height where this entry becomes invalid. pub ttl: BlockNumber, }