Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DNM] Use metadata v8 #819

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified essentials/assets/polkadot_metadata.scale
Binary file not shown.
6 changes: 3 additions & 3 deletions essentials/src/chain_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::{
para_inclusion::events::{CandidateBacked, CandidateIncluded, CandidateTimedOut},
paras_disputes::events::{DisputeConcluded, DisputeInitiated},
},
polkadot_primitives::CandidateDescriptor,
polkadot_primitives_staging::CandidateDescriptorV2,
},
types::{Header, OnDemandOrder, H256},
};
Expand Down Expand Up @@ -68,7 +68,7 @@ pub struct SubxtCandidateEvent {
/// Result of candidate receipt hashing
pub candidate_hash: <PolkadotConfig as subxt::Config>::Hash,
/// Full candidate receipt if needed
pub candidate_descriptor: CandidateDescriptor<<PolkadotConfig as subxt::Config>::Hash>,
pub candidate_descriptor: CandidateDescriptorV2<<PolkadotConfig as subxt::Config>::Hash>,
/// The parachain id
pub parachain_id: u32,
/// The event type
Expand Down Expand Up @@ -194,7 +194,7 @@ fn decode_to_specific_event<E: subxt::events::StaticEvent, C: subxt::Config>(

fn create_candidate_event(
commitments_hash: <PolkadotConfig as subxt::Config>::Hash,
candidate_descriptor: CandidateDescriptor<<PolkadotConfig as subxt::Config>::Hash>,
candidate_descriptor: CandidateDescriptorV2<<PolkadotConfig as subxt::Config>::Hash>,
core_idx: u32,
event_type: SubxtCandidateEventType,
) -> SubxtCandidateEvent {
Expand Down
16 changes: 9 additions & 7 deletions essentials/src/collector/candidate_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@
// You should have received a copy of the GNU General Public License
// along with polkadot-introspector. If not, see <http://www.gnu.org/licenses/>.

use crate::{chain_events::SubxtDisputeResult, metadata::polkadot_primitives, types::H256};
use crate::{chain_events::SubxtDisputeResult, metadata::polkadot_primitives_staging, types::H256};
use parity_scale_codec::{Decode, Encode};
use serde::{
ser::{SerializeStruct, Serializer},
Deserialize, Serialize,
};
use serde_bytes::Bytes;
use std::{hash::Hash, time::Duration};

/// Tracks candidate inclusion as seen by a node(s)
Expand Down Expand Up @@ -60,29 +59,32 @@ pub struct CandidateDisputed {
pub concluded: Option<DisputeResult>,
}

impl<T> Serialize for polkadot_primitives::CandidateDescriptor<T>
impl<T> Serialize for polkadot_primitives_staging::CandidateDescriptorV2<T>
where
T: Hash + Serialize + Decode + Encode,
{
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let mut state = serializer.serialize_struct("CandidateDescriptor", 9)?;
let mut state = serializer.serialize_struct("CandidateDescriptorV2", 9)?;
state.serialize_field("para_id", &self.para_id.0)?;
state.serialize_field("relay_parent", &self.relay_parent)?;
state.serialize_field("collator", &self.collator.0)?;
state.serialize_field("version", &self.version.0)?;
state.serialize_field("core_index", &self.core_index)?;
state.serialize_field("session_index", &self.session_index)?;
// Skipped reserved1
state.serialize_field("persisted_validation_data_hash", &self.persisted_validation_data_hash)?;
state.serialize_field("pov_hash", &self.pov_hash)?;
state.serialize_field("erasure_root", &self.erasure_root)?;
state.serialize_field("signature", Bytes::new(&self.signature.0))?;
// Skipped reserved2
state.serialize_field("para_head", &self.para_head)?;
state.serialize_field("validation_code_hash", &self.validation_code_hash.0)?;
state.end()
}
}

impl<T> Serialize for polkadot_primitives::CandidateReceipt<T>
impl<T> Serialize for polkadot_primitives_staging::CandidateReceiptV2<T>
where
T: Hash + Serialize + Decode + Encode,
{
Expand Down
4 changes: 3 additions & 1 deletion essentials/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@
#[subxt::subxt(runtime_metadata_path = "assets/polkadot_metadata.scale")]
pub mod polkadot {}

pub use polkadot::runtime_types::polkadot_primitives::v7 as polkadot_primitives;
pub use polkadot::runtime_types::polkadot_primitives::{
v8 as polkadot_primitives, vstaging as polkadot_primitives_staging,
};
9 changes: 5 additions & 4 deletions essentials/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
// along with polkadot-introspector. If not, see <http://www.gnu.org/licenses/>.
//

use crate::metadata::{polkadot::runtime_types as subxt_runtime_types, polkadot_primitives};
use crate::metadata::{polkadot::runtime_types as subxt_runtime_types, polkadot_primitives_staging};
use parity_scale_codec::{Decode, Encode};
use std::collections::{BTreeMap, VecDeque};
use subxt::{
config::substrate::{BlakeTwo256, SubstrateHeader},
utils,
};
use subxt_runtime_types::polkadot_runtime as runtime;
use subxt_runtime_types::westend_runtime as runtime;

pub type BlockNumber = u32;
pub type H256 = utils::H256;
Expand All @@ -35,8 +35,9 @@ pub type SubxtCall = runtime::RuntimeCall;
pub type ClaimQueue = BTreeMap<u32, VecDeque<Option<ParasEntry>>>;

/// The `InherentData` constructed with the subxt API.
pub type InherentData =
polkadot_primitives::InherentData<subxt_runtime_types::sp_runtime::generic::header::Header<::core::primitive::u32>>;
pub type InherentData = polkadot_primitives_staging::InherentData<
subxt_runtime_types::sp_runtime::generic::header::Header<::core::primitive::u32>,
>;

/// A wrapper over subxt HRMP channel configuration
#[derive(Debug, Clone, Default, Encode, Decode)]
Expand Down
2 changes: 1 addition & 1 deletion parachain-tracer/src/parachain_block_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// along with polkadot-introspector. If not, see <http://www.gnu.org/licenses/>.

use parity_scale_codec::{Decode, Encode};
use polkadot_introspector_essentials::{metadata::polkadot_primitives::BackedCandidate, types::H256};
use polkadot_introspector_essentials::{metadata::polkadot_primitives_staging::BackedCandidate, types::H256};
use subxt::config::{substrate::BlakeTwo256, Hasher};

/// The parachain block tracking information.
Expand Down
5 changes: 4 additions & 1 deletion parachain-tracer/src/tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ use crate::{
use log::{error, info};
use polkadot_introspector_essentials::{
collector::DisputeInfo,
metadata::polkadot_primitives::{AvailabilityBitfield, BackedCandidate, DisputeStatementSet, ValidatorIndex},
metadata::{
polkadot_primitives::{AvailabilityBitfield, DisputeStatementSet, ValidatorIndex},
polkadot_primitives_staging::BackedCandidate,
},
types::{BlockNumber, CoreOccupied, OnDemandOrder, Timestamp, H256},
};
use std::{collections::HashMap, default::Default, time::Duration};
Expand Down
5 changes: 4 additions & 1 deletion parachain-tracer/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
// along with polkadot-introspector. If not, see <http://www.gnu.org/licenses/>.

use polkadot_introspector_essentials::{
metadata::polkadot_primitives::{AvailabilityBitfield, BackedCandidate, DisputeStatement, DisputeStatementSet},
metadata::{
polkadot_primitives::{AvailabilityBitfield, DisputeStatement, DisputeStatementSet},
polkadot_primitives_staging::BackedCandidate,
},
types::{AccountId32, InherentData, Timestamp, H256},
};
use std::time::Duration;
Expand Down
Loading