Skip to content

Commit

Permalink
Merge pull request #509 from paritytech/AndreiEres/async-backing-types
Browse files Browse the repository at this point in the history
Support new types after the async backing merge
  • Loading branch information
AndreiEres authored Aug 23, 2023
2 parents e0a06c7 + 3736a8e commit 638029f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
14 changes: 6 additions & 8 deletions essentials/src/api/dynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -69,8 +68,7 @@ pub(crate) fn decode_scheduled_paras(raw_paras: &Value<u32>) -> Result<Vec<CoreA
"Parachain" => 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)
}
Expand Down Expand Up @@ -113,10 +111,10 @@ fn decode_paras_entry_option(raw: &Value<u32>) -> Result<Option<ParasEntry>, Sub
fn decode_paras_entry(raw: &Value<u32>) -> Result<ParasEntry, SubxtWrapperError> {
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<u32>) -> Result<&'a Value<u32>, SubxtWrapperError> {
Expand Down
9 changes: 3 additions & 6 deletions essentials/src/api/subxt_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -171,7 +171,7 @@ pub enum Response {
/// `ParaInherent` data.
ParaInherentData(InherentData),
/// Availability core assignments for parachains.
ScheduledParas(Vec<polkadot::runtime_types::polkadot_runtime_parachains::scheduler::CoreAssignment>),
ScheduledParas(Vec<CoreAssignment>),
/// Claim queue for parachains.
ClaimQueue(ClaimQueue),
/// List of the occupied availability cores.
Expand Down Expand Up @@ -351,10 +351,7 @@ impl RequestExecutor {
&mut self,
url: &str,
block_hash: <PolkadotConfig as subxt::Config>::Hash,
) -> std::result::Result<
Vec<polkadot::runtime_types::polkadot_runtime_parachains::scheduler::CoreAssignment>,
SubxtWrapperError,
> {
) -> std::result::Result<Vec<CoreAssignment>, SubxtWrapperError> {
wrap_subxt_call!(self, GetScheduledParas, ScheduledParas, url, block_hash)
}

Expand Down
23 changes: 20 additions & 3 deletions essentials/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@
// along with polkadot-introspector. If not, see <http://www.gnu.org/licenses/>.
//

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;

Expand All @@ -35,14 +41,25 @@ pub type SubxtCall = runtime::RuntimeCall;

pub type ClaimQueue = BTreeMap<u32, VecDeque<Option<ParasEntry>>>;

// 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,
}
Expand Down

0 comments on commit 638029f

Please sign in to comment.