diff --git a/essentials/src/api/api_client.rs b/essentials/src/api/api_client.rs index 3c3f4e72..df8d3a17 100644 --- a/essentials/src/api/api_client.rs +++ b/essentials/src/api/api_client.rs @@ -141,7 +141,7 @@ impl> ApiClientT for ApiClient { block_hash: H256, para_id: u32, ) -> Result, subxt::Error> { - use polkadot::runtime_types::polkadot_parachain::primitives::{HrmpChannelId, Id}; + use polkadot::runtime_types::polkadot_parachain_primitives::primitives::{HrmpChannelId, Id}; let addr = polkadot::storage().hrmp().hrmp_ingress_channels_index(&Id(para_id)); let hrmp_channels = self.storage().at(block_hash).fetch(&addr).await?.unwrap_or_default(); let mut channels_configuration: BTreeMap = BTreeMap::new(); @@ -164,7 +164,7 @@ impl> ApiClientT for ApiClient { block_hash: H256, para_id: u32, ) -> Result, subxt::Error> { - use polkadot::runtime_types::polkadot_parachain::primitives::{HrmpChannelId, Id}; + use polkadot::runtime_types::polkadot_parachain_primitives::primitives::{HrmpChannelId, Id}; let addr = polkadot::storage().hrmp().hrmp_egress_channels_index(&Id(para_id)); let hrmp_channels = self.storage().at(block_hash).fetch(&addr).await?.unwrap_or_default(); diff --git a/essentials/src/api/dynamic.rs b/essentials/src/api/dynamic.rs index 4e48f92e..8dc74bff 100644 --- a/essentials/src/api/dynamic.rs +++ b/essentials/src/api/dynamic.rs @@ -1,12 +1,7 @@ use super::subxt_wrapper::SubxtWrapperError::{self, DecodeDynamicError}; use crate::{ - metadata::{ - polkadot::runtime_types::{ - polkadot_parachain::primitives::Id, polkadot_runtime_parachains::scheduler::AssignmentKind, - }, - polkadot_primitives::{CoreIndex, ValidatorIndex}, - }, - types::{Assignment, BlockNumber, ClaimQueue, CoreAssignment, CoreOccupied, OnDemandOrder, ParasEntry}, + metadata::polkadot_primitives::ValidatorIndex, + types::{Assignment, BlockNumber, ClaimQueue, CoreOccupied, OnDemandOrder, ParasEntry}, }; use log::error; use std::collections::{BTreeMap, VecDeque}; @@ -58,24 +53,6 @@ pub(crate) fn decode_availability_cores(raw_cores: &Value) -> Result) -> Result, SubxtWrapperError> { - let decoded_paras = decode_unnamed_composite(raw_paras)?; - let mut paras = Vec::with_capacity(decoded_paras.len()); - for para in decoded_paras.iter() { - let core = CoreIndex(decode_composite_u128_value(value_at("core", para)?)? as u32); - let para_id = Id(decode_composite_u128_value(value_at("para_id", para)?)? as u32); - let kind = match decode_variant(value_at("kind", para)?)?.name.as_str() { - "Parachain" => AssignmentKind::Parachain, - name => todo!("Add support for {name}"), - }; - let assignment = CoreAssignment { core, para_id, kind }; - - paras.push(assignment) - } - - Ok(paras) -} - pub(crate) fn decode_claim_queue(raw: &Value) -> Result { let decoded_btree_map = decode_unnamed_composite(raw)?; let decoded_btree_map_inner = decoded_btree_map diff --git a/essentials/src/api/mod.rs b/essentials/src/api/mod.rs index b0d43127..97425064 100644 --- a/essentials/src/api/mod.rs +++ b/essentials/src/api/mod.rs @@ -149,21 +149,6 @@ mod tests { .expect("Inherent data must be present"); } - #[tokio::test] - async fn get_scheduled_paras() { - let api = ApiService::::new_with_storage( - RecordsStorageConfig { max_blocks: 1 }, - ApiClientMode::RPC, - RetryOptions::default(), - ); - let mut subxt = api.subxt(); - - let head = subxt.get_block_head(rpc_node_url(), None).await.unwrap().unwrap(); - let paras = subxt.get_scheduled_paras(rpc_node_url(), head.hash()).await; - - assert!(paras.is_ok()); - } - #[tokio::test] async fn get_occupied_cores() { let api = ApiService::::new_with_storage( diff --git a/essentials/src/api/subxt_wrapper.rs b/essentials/src/api/subxt_wrapper.rs index 08c5f953..34831508 100644 --- a/essentials/src/api/subxt_wrapper.rs +++ b/essentials/src/api/subxt_wrapper.rs @@ -18,12 +18,12 @@ use crate::{ api::{ api_client::{build_light_client, build_online_client, ApiClientT, HeaderStream}, - dynamic::{decode_availability_cores, decode_claim_queue, decode_scheduled_paras, decode_validator_groups}, + dynamic::{decode_availability_cores, decode_claim_queue, decode_validator_groups}, }, metadata::polkadot_primitives, types::{ - AccountId32, BlockNumber, ClaimQueue, CoreAssignment, CoreOccupied, InherentData, SessionKeys, - SubxtHrmpChannel, Timestamp, H256, + AccountId32, BlockNumber, ClaimQueue, CoreOccupied, InherentData, SessionKeys, SubxtHrmpChannel, Timestamp, + H256, }, utils::{Retry, RetryOptions}, }; @@ -54,8 +54,6 @@ pub enum RequestType { GetEvents(::Hash), /// Extract the `ParaInherentData` from a given block. ExtractParaInherent(Option<::Hash>), - /// Get the availability core scheduling information at a given block. - GetScheduledParas(::Hash), /// Get the claim queue scheduling information at a given block. GetClaimQueue(::Hash), /// Get occupied core information at a given block. @@ -102,9 +100,6 @@ impl Debug for RequestType { RequestType::ExtractParaInherent(h) => { format!("get inherent for block: {:?}", h) }, - RequestType::GetScheduledParas(h) => { - format!("get scheduled paras: {:?}", h) - }, RequestType::GetClaimQueue(h) => { format!("get claim queue: {:?}", h) }, @@ -151,8 +146,6 @@ pub enum Response { MaybeEvents(Option>), /// `ParaInherent` data. ParaInherentData(InherentData), - /// Availability core assignments for parachains. - ScheduledParas(Vec), /// Claim queue for parachains. ClaimQueue(ClaimQueue), /// List of the occupied availability cores. @@ -236,7 +229,6 @@ impl RequestExecutor { RequestType::GetBlockHash(maybe_block_number) => subxt_get_block_hash(api, maybe_block_number).await, RequestType::GetEvents(hash) => subxt_get_events(api, hash).await, RequestType::ExtractParaInherent(maybe_hash) => subxt_extract_parainherent(api, maybe_hash).await, - RequestType::GetScheduledParas(hash) => subxt_get_sheduled_paras(api, hash).await, RequestType::GetClaimQueue(hash) => subxt_get_claim_queue(api, hash).await, RequestType::GetOccupiedCores(hash) => subxt_get_occupied_cores(api, hash).await, RequestType::GetBackingGroups(hash) => subxt_get_validator_groups(api, hash).await, @@ -321,14 +313,6 @@ impl RequestExecutor { wrap_subxt_call!(self, ExtractParaInherent, ParaInherentData, url, maybe_hash) } - pub async fn get_scheduled_paras( - &mut self, - url: &str, - block_hash: ::Hash, - ) -> std::result::Result, SubxtWrapperError> { - wrap_subxt_call!(self, GetScheduledParas, ScheduledParas, url, block_hash) - } - pub async fn get_claim_queue( &mut self, url: &str, @@ -501,13 +485,6 @@ async fn fetch_dynamic_storage( .ok_or(SubxtWrapperError::EmptyResponseFromDynamicStorage(format!("{pallet_name}.{entry_name}"))) } -async fn subxt_get_sheduled_paras(api: Box, block_hash: H256) -> Result { - let value = fetch_dynamic_storage(api, Some(block_hash), "ParaScheduler", "Scheduled").await?; - let paras = decode_scheduled_paras(&value)?; - - Ok(Response::ScheduledParas(paras)) -} - async fn subxt_get_claim_queue(api: Box, block_hash: H256) -> Result { let value = fetch_dynamic_storage(api, Some(block_hash), "ParaScheduler", "ClaimQueue").await?; let queue = decode_claim_queue(&value)?; diff --git a/essentials/src/collector/mod.rs b/essentials/src/collector/mod.rs index 0642919b..b0a51e3a 100644 --- a/essentials/src/collector/mod.rs +++ b/essentials/src/collector/mod.rs @@ -671,41 +671,23 @@ impl Collector { block_number: u32, ts: Timestamp, ) -> color_eyre::Result<(), CollectorError> { - // After adding On-demand Parachains, `ParaScheduler.Scheduled` API call will be removed - let mut assignments = self.core_assignments_via_scheduled_paras(block_hash).await; - // `ParaScheduler,Scheduled` not found, try to fetch `ParaScheduler.ClaimQueue` - if let Err(SubxtWrapperError::SubxtError(subxt::error::Error::Metadata( - subxt::error::MetadataError::StorageEntryNotFound(_), - ))) = assignments - { - assignments = self.core_assignments_via_claim_queue(block_hash).await; - } - if let Err(SubxtWrapperError::EmptyResponseFromDynamicStorage(reason)) = assignments { - info!("{}. Nothing to process, used empty value", reason); - assignments = Ok(BTreeMap::default()); - } - + let assignments = match self.core_assignments_via_claim_queue(block_hash).await { + Err(SubxtWrapperError::EmptyResponseFromDynamicStorage(reason)) => { + info!("{}. Nothing to process, used empty value", reason); + BTreeMap::default() + }, + v => v?, + }; self.storage_write_prefixed( CollectorPrefixType::CoreAssignments, block_hash, - StorageEntry::new_onchain(RecordTime::with_ts(block_number, Duration::from_secs(ts)), assignments?), + StorageEntry::new_onchain(RecordTime::with_ts(block_number, Duration::from_secs(ts)), assignments), ) .await?; Ok(()) } - async fn core_assignments_via_scheduled_paras( - &mut self, - block_hash: H256, - ) -> color_eyre::Result>, SubxtWrapperError> { - let core_assignments = self.executor.get_scheduled_paras(self.endpoint.as_str(), block_hash).await?; - Ok(core_assignments - .iter() - .map(|v| (v.core.0, vec![v.para_id.0])) - .collect::>()) - } - async fn core_assignments_via_claim_queue( &mut self, block_hash: H256, diff --git a/essentials/src/metadata.rs b/essentials/src/metadata.rs index 957945b3..b835e6a3 100644 --- a/essentials/src/metadata.rs +++ b/essentials/src/metadata.rs @@ -18,4 +18,4 @@ #[subxt::subxt(runtime_metadata_path = "assets/polkadot_metadata.scale")] pub mod polkadot {} -pub use polkadot::runtime_types::polkadot_primitives::v4 as polkadot_primitives; +pub use polkadot::runtime_types::polkadot_primitives::v5 as polkadot_primitives; diff --git a/essentials/src/types.rs b/essentials/src/types.rs index 7039148a..ccd98d33 100644 --- a/essentials/src/types.rs +++ b/essentials/src/types.rs @@ -15,13 +15,7 @@ // along with polkadot-introspector. If not, see . // -use crate::metadata::{ - polkadot::{ - runtime_types as subxt_runtime_types, - runtime_types::{polkadot_parachain::primitives::Id, polkadot_runtime_parachains::scheduler::AssignmentKind}, - }, - polkadot_primitives, -}; +use crate::metadata::{polkadot::runtime_types as subxt_runtime_types, polkadot_primitives}; use parity_scale_codec::{Decode, Encode}; use std::collections::{BTreeMap, VecDeque}; use subxt::{ @@ -40,12 +34,8 @@ pub type SubxtCall = runtime::RuntimeCall; pub type ClaimQueue = BTreeMap>>; /// The `InherentData` constructed with the subxt API. -pub type InherentData = polkadot_primitives::InherentData< - subxt_runtime_types::sp_runtime::generic::header::Header< - ::core::primitive::u32, - subxt_runtime_types::sp_runtime::traits::BlakeTwo256, - >, ->; +pub type InherentData = + polkadot_primitives::InherentData>; /// A wrapper over subxt HRMP channel configuration #[derive(Debug, Clone, Default)] @@ -75,17 +65,6 @@ impl From f } } -// 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: polkadot_primitives::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)] diff --git a/parachain-tracer/src/test_utils.rs b/parachain-tracer/src/test_utils.rs index 57007f44..72234680 100644 --- a/parachain-tracer/src/test_utils.rs +++ b/parachain-tracer/src/test_utils.rs @@ -25,12 +25,9 @@ use polkadot_introspector_essentials::{ polkadot::runtime_types::{ bounded_collections::bounded_vec::BoundedVec, polkadot_core_primitives::CandidateHash, - polkadot_parachain::primitives::{HeadData, Id, ValidationCodeHash}, + polkadot_parachain_primitives::primitives::{HeadData, Id, ValidationCodeHash}, sp_core::sr25519::{Public, Signature}, - sp_runtime::{ - generic::{digest::Digest, header::Header}, - traits::BlakeTwo256, - }, + sp_runtime::generic::{digest::Digest, header::Header}, }, polkadot_primitives::{ collator_app, signed::UncheckedSigned, validator_app, AvailabilityBitfield, BackedCandidate, @@ -106,7 +103,7 @@ pub fn create_dispute_statement_set() -> DisputeStatementSet { } } -pub fn create_inherent_data(para_id: u32) -> InherentData> { +pub fn create_inherent_data(para_id: u32) -> InherentData> { InherentData { bitfields: vec![UncheckedSigned { payload: AvailabilityBitfield(DecodedBits::from_iter([true])), @@ -122,7 +119,6 @@ pub fn create_inherent_data(para_id: u32) -> InherentData