Skip to content

Commit

Permalink
Unify Consensus state id for the relaychain (#392)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wizdave97 authored Mar 4, 2025
1 parent 3c1a7e1 commit a441a70
Show file tree
Hide file tree
Showing 13 changed files with 75 additions and 35 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ serde-hex-utils = { version = "0.1.0", path = "modules/utils/serde", default-fea
grandpa-verifier-primitives = { version = "0.2.0", path = "./modules/consensus/grandpa/primitives", default-features = false }
grandpa-verifier = { version = "0.2.0", path = "./modules/consensus/grandpa/verifier", default-features = false }
ismp-grandpa = { version = "16.0.0", path = "./modules/ismp/clients/grandpa", default-features = false }
ismp-parachain = { version = "16.0.0", path = "./modules/ismp/clients/parachain/client", default-features = false }
ismp-parachain-inherent = { version = "16.0.0", path = "./modules/ismp/clients/parachain/inherent" }
ismp-parachain = { version = "16.1.0", path = "./modules/ismp/clients/parachain/client", default-features = false }
ismp-parachain-inherent = { version = "16.1.0", path = "./modules/ismp/clients/parachain/inherent" }
ismp-parachain-runtime-api = { version = "16.0.0", path = "./modules/ismp/clients/parachain/runtime-api", default-features = false }
pallet-ismp = { version = "16.1.0", path = "modules/pallets/ismp", default-features = false }
pallet-ismp-rpc = { version = "16.0.0", path = "modules/pallets/ismp/rpc" }
Expand Down
2 changes: 1 addition & 1 deletion modules/ismp/clients/parachain/client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ismp-parachain"
version = "16.0.0"
version = "16.1.0"
edition = "2021"
authors = ["Polytope Labs <hello@polytope.technology>"]
license = "Apache-2.0"
Expand Down
5 changes: 4 additions & 1 deletion modules/ismp/clients/parachain/client/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,12 @@ mod benchmarks {
/// afterward proceed to update the parachain consensus.
#[benchmark]
fn update_parachain_consensus() -> Result<(), BenchmarkError> {
let host = T::IsmpHost::default();

let host_state_machine = host.host_state_machine();
let consensus_message = ConsensusMessage {
consensus_proof: hex::decode("825343001cb036004131e62a7368ee07000037803937450aba30ede02c0df7ca997ec9000e89fb68bd32e01097975eadc3ff55054d05a562fce78ebc2a99bdc809124eea7a220517e57ac517a5dc804e251d785c3c51ee293a00638b15d26969a945491f035648a811ef6d6c1d84864891b8ad8990c89f8aa27b7c11fbb62a93db8c10b4f79b5bcb838330340bd1e92342247c8c6f02ec74449314066175726120fe4f9e0800000000045250535290db6f2927773c5e1103907d99844d0626453a5b2987a4e31d5a7dec0c015cb545024e0d010466726f6e8801640c2728044dbb747004ccd03ca02b6e8bef4fa0bde33aea8bbe90716858134f000449534d5001010000000000000000000000000000000000000000000000000000000000000000471985d4945bc6c8f3e23fd146e1d24170624024afa2f37f0201a113c8ed76c705617572610101008e484c50e614d075f0972602a9c96145d33b480c161d1ce79fae577d27ac6647d4f6dae51b6c1485ce68f52f6d29fb0196d2269ea45989af1236d85192f98a250380029d80224a52f114ab1a88145a96d316f019bd92042c383a6683ba8c65fff6152dfe20807016a756665964a1c18722c71dc2a88b61a2170e370bede79faf3aeae794b06980d4860999463a8d9e4e1f544d10bf596569efff6f7065dcf0de0cb72be6032fc880828a9f395e1bb0f79aaab17e6f610b3c235b1a7e466505d82164ab2581b36d3e80739c15f45dcbf244ae9ff6f4916222923564c1488582b421ac88ebc137734d91803fe7f37b6bc215f7b755b0b62237e926dd1e35cacb43c78adc762b0dd88d797e250380546480805b68d75c109f29b589a2e933d3add750b832ab14118b0a47172a1295a00d028063fa3443f4e8b71a14886166ad03f5747914d180a4f9766ef2f500531e14c60880911e015f455657fe02ab564bf226adfe0e0e93969e95c8f397eb78b2b950d2e380f6f6801e4b41e2e6d8ec194dba122bfb9eb33feb2545ef5144cea79551f7cc528072ef2653224e6f7bf59a1181469f9d02f2ec2c34501b2e28c368f43e3b669b8880faebd742d9a812ad819a7711c13059b1f2935e1205a4be45dc1a1c4615b493a54d0880ffff80ef834bee8b63ba8e8421c76f0763441b585cd8fe6bfa585a4043b811be43dd4e8008a3ea5a26aae30824f158c904d9684299b656d5a7d53cf5f15ccd5ca9b9c1c48044be9dff9da3546926d6e0b20f98ec609bc946970d7de805d6f3303db479957e806e6c423ca9c6f1e78b810f8c099d8aa2f7baea14b7b369621fdb1932bf88807e80d2c5f53b89e4e7a674312d0748a86d57eb58b67fdf9dedf9ae9f5c33171aa0d880bf6de02e054df87c04079fef2ff587704ce08c1b500a4b5679932b4d28f8db6d8034f3837bf803d3e07f7b03050cc2253cb9098c591377380eae894dcabec596c680928c7aeef0329500c4d687a62ae81057c17275e80b557c71634915348cb1caa080d9abbab39a3f73d9c44bd6b56b120485807306537c2df7f2e3a8401d5ca5c32180e2134710da0547dc7680141c08754dbc001fcbaec563eac6db500f24da61691f80f8917b0e3e0e427dbe722050be4ce1ad98c4aa04aa4a2e3f73550e5c661d72da807e664e0a08c5369a06b24c3039af5e0eed4c37cb070f180012a1751e9d10a71480e0f820145eaa4a95faad6f3b5394865e986d0a3b64b2898c2b28516cb1fa9f5780bf56c7d6af42a099a109d994cb94c75b948f631ce3033d163864a8ec93f8773580bf479f4f4ac201e91cceb1b80befce19798a70ed572e5f4c40129120b4e45a72801251547e9228098a010647a0b22e580236a9a7ec52d96190f1e0b97956ef027fd9049e710b30bd2eab0352ddcc26417aa1945fc380df23617fe84624ee3a237f090565501628c634ab465cdaf2cebe390e88949f578005b66a1717fa59769d977e6d1e82c7cd39ccf06601a95c477ce3a98b0cce657580dffa5030e4d00bbb5ec8e94fd84c1f849e1d747a7c0b1cee3e4594c20e3ebf358039183678fbf0917679e88304ea4d576455847f85ba3019b62146a76fdcded5c4505f0e7b9012096b41c4eb3aaf947f6ea4290800004c5f03c716fb8fff3de61a883bb76adb34a2040080ffabf0036468f09381d8388a0a228b5a20ef364292d8a08f6563ef0df5aceb8b4c5f0f4993f016e2d2f8e5f43be7bb259486040080bcbcd3e31c129afddb25dc7c6b6fa05ab9456897d4bff9740db5b54dab7847dc8084e4102db06857917315d395e1bba01496489df5c65ef1144a08081e60fab0488d089f0b3c252fcb29d88eff4f3de5de4476c3ffff80889ed5e0c08c9d3c179bc7a389c4a06f884d1b11255720fc99408feef530992f80c8c97dd0a133cae1cc139da9fad4b7608eec2a285615b54df938314ed2d61519809399f4484a565428bd2e157c4b50bbe2b8062a6bed251ecd9075be2fae13014f80cf1ad2da790e25108a23dce568bf85b07024c1d6a0cd9901aca2ae54d7857fed8067b4da94af41d1439b7c82bfe2626fa2f175e6bcb936dca137891e623cd3083680eabd62d710962690f51ddeac0845b0debf5b047033ebdaf61ad9c8bc1a78d7e68023ae4ac98f3e4e4da887153440a36a28c864e2e727a77bec702fa50a1b00637a8065a82c283839f68d533a3dc5a77fe4b1dcaab35cfa8c68c68bcc788a43b3e4f280f8594eec587bfef5b35e96e5b05d46edda21d499dcb0659326335fd57d8fc8d58012035bd14aa2c5ffd0b1baa28b515884808b2cd73aa97fc7075d8154596fe432801128f943a07fd2692adfa15df9b9fb4c374161b4b9da11d0c7a0851f524794aa80de0c1d5a68a34f6d6ae6f03effd9a761dfef83c97c2b50bc7b6130734fa36aa58061ae531244939ee9211cf6b24156cd2ae4f6f3324b025eefd8d55aae423035f8809f2ff8e9f7a13866525d3de985d1bc1646a798e05314f0a0d9bf414cf0eaa963807e5f808ca32a79d5dfbc58970fe6720ece7f3f41d62f69ec929175c8f70a7f088030ffbafb038ce795acca0ed1eb852161a7a8ed46113f443f7501532a39572642").expect("Decoding failed"),
consensus_state_id: *b"PARA",
consensus_state_id: parachain_consensus_state_id(host_state_machine),
signer: vec![],
};

Expand Down
6 changes: 6 additions & 0 deletions modules/ismp/clients/parachain/client/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ pub struct ParachainConsensusProof {
/// [`ConsensusClientId`] for [`ParachainConsensusClient`]
pub const PARACHAIN_CONSENSUS_ID: ConsensusClientId = *b"PARA";

/// [`ConsensusClientId`] for [`ParachainConsensusClient`] on Polkadot
pub const POLKADOT_CONSENSUS_ID: ConsensusStateId = *b"DOT0";

/// [`ConsensusClientId`] for [`ParachainConsensusClient`] on Paseo
pub const PASEO_CONSENSUS_ID: ConsensusStateId = *b"PAS0";

impl<T, R, S> ConsensusClient for ParachainConsensusClient<T, R, S>
where
R: RelayChainOracle,
Expand Down
40 changes: 33 additions & 7 deletions modules/ismp/clients/parachain/client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ use cumulus_pallet_parachain_system::{
RelayChainState, RelaychainDataProvider, RelaychainStateProvider,
};
use cumulus_primitives_core::relay_chain;
use ismp::{handlers, messaging::CreateConsensusState};
use ismp::{
consensus::ConsensusStateId,
handlers,
host::{IsmpHost, StateMachine},
messaging::CreateConsensusState,
};
pub use pallet::*;
pub use weights::WeightInfo;

Expand All @@ -49,7 +54,7 @@ pub mod pallet {
use frame_system::pallet_prelude::*;
use ismp::{
consensus::StateMachineId,
host::{IsmpHost, StateMachine},
host::StateMachine,
messaging::{ConsensusMessage, Message},
};
use migration::StorageV0;
Expand Down Expand Up @@ -123,9 +128,11 @@ pub mod pallet {
!ConsensusUpdated::<T>::exists(),
"ValidationData must be updated only once in a block",
);
let host = <T::IsmpHost>::default();

assert_eq!(
data.consensus_state_id, PARACHAIN_CONSENSUS_ID,
data.consensus_state_id,
parachain_consensus_state_id(host.host_state_machine()),
"Only parachain consensus updates should be passed in the inherents!"
);

Expand Down Expand Up @@ -154,7 +161,10 @@ pub mod pallet {
};
Parachains::<T>::insert(para.id, para.slot_duration);
let _ = host.store_challenge_period(
StateMachineId { state_id, consensus_state_id: PARACHAIN_CONSENSUS_ID },
StateMachineId {
state_id,
consensus_state_id: parachain_consensus_state_id(host.host_state_machine()),
},
0,
);
}
Expand Down Expand Up @@ -193,7 +203,9 @@ pub mod pallet {
// kill the storage, since this is the beginning of a new block.
ConsensusUpdated::<T>::kill();
let host = T::IsmpHost::default();
if let Err(_) = host.consensus_state(PARACHAIN_CONSENSUS_ID) {
if let Err(_) =
host.consensus_state(parachain_consensus_state_id(host.host_state_machine()))
{
Pallet::<T>::initialize();
}

Expand Down Expand Up @@ -242,6 +254,7 @@ pub mod pallet {
fn build(&self) {
Pallet::<T>::initialize();
let host = <T::IsmpHost>::default();
let host_state_machine = host.host_state_machine();

// insert the parachain ids
for para in &self.parachains {
Expand All @@ -252,7 +265,10 @@ pub mod pallet {
_ => continue,
};
let _ = host.store_challenge_period(
StateMachineId { state_id, consensus_state_id: PARACHAIN_CONSENSUS_ID },
StateMachineId {
state_id,
consensus_state_id: parachain_consensus_state_id(host_state_machine),
},
0,
);
}
Expand All @@ -277,12 +293,13 @@ impl<T: Config> Pallet<T> {
/// ismp parachain client consensus state, either through `genesis_build` or `on_initialize`.
pub fn initialize() {
let host = T::IsmpHost::default();
let host_state_machine = host.host_state_machine();
let message = CreateConsensusState {
// insert empty bytes
consensus_state: vec![],
unbonding_period: u64::MAX,
challenge_periods: Default::default(),
consensus_state_id: PARACHAIN_CONSENSUS_ID,
consensus_state_id: parachain_consensus_state_id(host_state_machine),
consensus_client_id: PARACHAIN_CONSENSUS_ID,
state_machine_commitments: vec![],
};
Expand Down Expand Up @@ -324,3 +341,12 @@ pub struct ParachainData {
/// parachain slot duration type
pub slot_duration: u64,
}

/// Returns the consensus state id for The relay chain
pub fn parachain_consensus_state_id(host: StateMachine) -> ConsensusStateId {
match host {
StateMachine::Kusama(_) => PASEO_CONSENSUS_ID,
StateMachine::Polkadot(_) => POLKADOT_CONSENSUS_ID,
_ => POLKADOT_CONSENSUS_ID,
}
}
2 changes: 1 addition & 1 deletion modules/ismp/clients/parachain/inherent/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ismp-parachain-inherent"
version = "16.0.0"
version = "16.1.0"
edition = "2021"
authors = ["Polytope Labs <hello@polytope.technology>"]
license = "Apache-2.0"
Expand Down
12 changes: 8 additions & 4 deletions modules/ismp/clients/parachain/inherent/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use std::sync::Arc;
use ismp::{consensus::StateMachineId, host::StateMachine, messaging::ConsensusMessage};
use ismp_parachain::{
consensus::{parachain_header_storage_key, ParachainConsensusProof},
PARACHAIN_CONSENSUS_ID,
parachain_consensus_state_id,
};
use ismp_parachain_runtime_api::IsmpParachainApi;
use pallet_ismp_runtime_api::IsmpRuntimeApi;
Expand Down Expand Up @@ -83,6 +83,7 @@ impl ConsensusInherentProvider {
return Ok(ConsensusInherentProvider(None));
};

let host_state_machine = client.runtime_api().host_state_machine(parent)?;
let mut para_ids_to_fetch = vec![];
for id in para_ids {
let Some(head) = relay_chain_interface
Expand All @@ -101,7 +102,7 @@ impl ConsensusInherentProvider {
continue;
};

let state_id = match client.runtime_api().host_state_machine(parent)? {
let state_id = match host_state_machine {
StateMachine::Polkadot(_) => StateMachine::Polkadot(id),
StateMachine::Kusama(_) => StateMachine::Kusama(id),
id => Err(anyhow!("Unsupported state machine: {id:?}"))?,
Expand All @@ -110,7 +111,10 @@ impl ConsensusInherentProvider {
.runtime_api()
.latest_state_machine_height(
parent,
StateMachineId { consensus_state_id: PARACHAIN_CONSENSUS_ID, state_id },
StateMachineId {
consensus_state_id: parachain_consensus_state_id(host_state_machine),
state_id,
},
)?
.unwrap_or_default();

Expand All @@ -135,7 +139,7 @@ impl ConsensusInherentProvider {

let consensus_proof = ParachainConsensusProof { relay_height: state.number, storage_proof };
let message = ConsensusMessage {
consensus_state_id: PARACHAIN_CONSENSUS_ID,
consensus_state_id: parachain_consensus_state_id(host_state_machine),
consensus_proof: consensus_proof.encode(),
signer: Default::default(),
};
Expand Down
2 changes: 1 addition & 1 deletion parachain/runtimes/gargantua/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("gargantua"),
impl_name: create_runtime_str!("gargantua"),
authoring_version: 1,
spec_version: 2_300,
spec_version: 2_400,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down
23 changes: 12 additions & 11 deletions parachain/runtimes/nexus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("nexus"),
impl_name: create_runtime_str!("nexus"),
authoring_version: 1,
spec_version: 2_700,
spec_version: 2_800,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down Expand Up @@ -337,8 +337,8 @@ impl Contains<RuntimeCall> for IsTreasurySpend {
fn contains(c: &RuntimeCall) -> bool {
matches!(
c,
RuntimeCall::Treasury(pallet_treasury::Call::spend { .. }) |
RuntimeCall::Treasury(pallet_treasury::Call::spend_local { .. })
RuntimeCall::Treasury(pallet_treasury::Call::spend { .. })
| RuntimeCall::Treasury(pallet_treasury::Call::spend_local { .. })
)
}
}
Expand Down Expand Up @@ -766,19 +766,20 @@ impl InstanceFilter<RuntimeCall> for ProxyType {
fn filter(&self, c: &RuntimeCall) -> bool {
match self {
ProxyType::Any => true,
ProxyType::NonTransfer =>
!matches!(c, RuntimeCall::Balances { .. } | RuntimeCall::Assets { .. }),
ProxyType::NonTransfer => {
!matches!(c, RuntimeCall::Balances { .. } | RuntimeCall::Assets { .. })
},
ProxyType::CancelProxy => matches!(
c,
RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. }) |
RuntimeCall::Utility { .. } |
RuntimeCall::Multisig { .. }
RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. })
| RuntimeCall::Utility { .. }
| RuntimeCall::Multisig { .. }
),
ProxyType::Collator => matches!(
c,
RuntimeCall::CollatorSelection { .. } |
RuntimeCall::Utility { .. } |
RuntimeCall::Multisig { .. }
RuntimeCall::CollatorSelection { .. }
| RuntimeCall::Utility { .. }
| RuntimeCall::Multisig { .. }
),
}
}
Expand Down
6 changes: 3 additions & 3 deletions parachain/simtests/src/hyperbridge_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ async fn test_will_accept_paid_requests() -> Result<(), anyhow::Error> {
let height = StateMachineHeight {
id: StateMachineId {
state_id: StateMachine::Kusama(para_id).into(),
consensus_state_id: *b"PARA",
consensus_state_id: *b"PAS0",
},
height: 200,
};
Expand Down Expand Up @@ -338,7 +338,7 @@ async fn test_will_reject_unpaid_requests() -> Result<(), anyhow::Error> {
let height = StateMachineHeight {
id: StateMachineId {
state_id: StateMachine::Kusama(para_id).into(),
consensus_state_id: *b"PARA",
consensus_state_id: *b"PAS0",
},
height: 200,
};
Expand Down Expand Up @@ -521,7 +521,7 @@ async fn test_will_reject_partially_paid_requests() -> Result<(), anyhow::Error>
let height = StateMachineHeight {
id: StateMachineId {
state_id: StateMachine::Kusama(para_id).into(),
consensus_state_id: *b"PARA",
consensus_state_id: *b"PAS0",
},
height: 200,
};
Expand Down
2 changes: 1 addition & 1 deletion parachain/simtests/src/pallet_ismp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ async fn test_txpool_should_reject_duplicate_requests() -> Result<(), anyhow::Er
let height = StateMachineHeight {
id: StateMachineId {
state_id: StateMachine::Kusama(para_id).into(),
consensus_state_id: *b"PARA",
consensus_state_id: *b"PAS0",
},
height: 200,
};
Expand Down
2 changes: 1 addition & 1 deletion tesseract/substrate/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ where
let signer = sr25519::Pair::from_seed_slice(&bytes)?;
let mut consensus_state_id: ConsensusStateId = Default::default();
consensus_state_id
.copy_from_slice(config.consensus_state_id.clone().unwrap_or("PARA".into()).as_bytes());
.copy_from_slice(config.consensus_state_id.clone().unwrap_or("DOT0".into()).as_bytes());
let address = signer.public().0.to_vec();
Ok(Self {
client,
Expand Down

0 comments on commit a441a70

Please sign in to comment.