From 84c552df999a61d83da4b5daae22be44b4ae9277 Mon Sep 17 00:00:00 2001 From: Ayush Kumar Mishra Date: Thu, 9 Jan 2025 09:41:56 +0530 Subject: [PATCH] Integrated hyperbridge with 2407 --- Cargo.lock | 368 ++++++++++++++++++- Cargo.toml | 10 + node/client/Cargo.toml | 6 +- node/client/src/lib.rs | 3 + node/rpc/Cargo.toml | 4 + node/rpc/src/lib.rs | 21 +- node/service/src/chain_spec.rs | 2 +- node/service/src/lib.rs | 1 + pallets/chainbridge/src/lib.rs | 2 +- pallets/ddc-clusters-gov/src/lib.rs | 2 +- pallets/ddc-clusters/src/lib.rs | 2 +- pallets/ddc-customers/src/lib.rs | 2 +- pallets/ddc-nodes/src/lib.rs | 2 +- pallets/ddc-payouts/src/lib.rs | 2 +- pallets/ddc-staking/src/lib.rs | 2 +- pallets/origins/src/lib.rs | 2 +- runtime/cere-dev/Cargo.toml | 22 +- runtime/cere-dev/src/lib.rs | 134 ++++++- runtime/cere-dev/src/weights/ismp_grandpa.rs | 62 ++++ runtime/cere-dev/src/weights/mod.rs | 1 + runtime/cere/Cargo.toml | 22 +- runtime/cere/src/lib.rs | 133 ++++++- runtime/cere/src/weights/ismp_grandpa.rs | 62 ++++ runtime/cere/src/weights/mod.rs | 1 + runtime/common/Cargo.toml | 2 +- 25 files changed, 837 insertions(+), 33 deletions(-) create mode 100644 runtime/cere-dev/src/weights/ismp_grandpa.rs create mode 100644 runtime/cere-dev/src/weights/mod.rs create mode 100644 runtime/cere/src/weights/ismp_grandpa.rs create mode 100644 runtime/cere/src/weights/mod.rs diff --git a/Cargo.lock b/Cargo.lock index b2a6ab255..8c1302ef8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -646,6 +646,7 @@ checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" dependencies = [ "funty", "radium", + "serde", "tap", "wyz", ] @@ -904,6 +905,8 @@ dependencies = [ "frame-system", "frame-system-rpc-runtime-api", "futures 0.3.31", + "pallet-ismp", + "pallet-ismp-runtime-api", "pallet-transaction-payment", "pallet-transaction-payment-rpc-runtime-api", "sc-client-api", @@ -916,6 +919,7 @@ dependencies = [ "sp-consensus", "sp-consensus-babe", "sp-consensus-grandpa", + "sp-core", "sp-inherents", "sp-offchain", "sp-runtime", @@ -929,17 +933,21 @@ dependencies = [ name = "cere-dev-runtime" version = "7.0.0" dependencies = [ + "anyhow", "cere-runtime-common", "ddc-primitives", "frame-benchmarking", "frame-election-provider-support", "frame-executive", + "frame-metadata-hash-extension", "frame-support", "frame-system", "frame-system-benchmarking", "frame-system-rpc-runtime-api", "frame-try-runtime", "hex-literal 0.4.1", + "ismp", + "ismp-grandpa", "log", "pallet-authority-discovery", "pallet-authorship", @@ -966,10 +974,13 @@ dependencies = [ "pallet-erc721", "pallet-fast-unstake", "pallet-grandpa", + "pallet-hyperbridge", "pallet-identity", "pallet-im-online", "pallet-indices", "pallet-insecure-randomness-collective-flip", + "pallet-ismp", + "pallet-ismp-runtime-api", "pallet-membership", "pallet-multisig", "pallet-nomination-pools", @@ -1007,6 +1018,7 @@ dependencies = [ "sp-genesis-builder", "sp-inherents", "sp-io", + "sp-mmr-primitives", "sp-offchain", "sp-runtime", "sp-session", @@ -1025,6 +1037,8 @@ version = "7.0.0" dependencies = [ "ddc-primitives", "jsonrpsee", + "pallet-ismp-rpc", + "pallet-ismp-runtime-api", "pallet-transaction-payment-rpc", "sc-chain-spec", "sc-client-api", @@ -1042,6 +1056,7 @@ dependencies = [ "sp-blockchain", "sp-consensus", "sp-consensus-babe", + "sp-core", "sp-keystore", "sp-runtime", "substrate-frame-rpc-system", @@ -1052,17 +1067,21 @@ dependencies = [ name = "cere-runtime" version = "7.0.0" dependencies = [ + "anyhow", "cere-runtime-common", "ddc-primitives", "frame-benchmarking", "frame-election-provider-support", "frame-executive", + "frame-metadata-hash-extension", "frame-support", "frame-system", "frame-system-benchmarking", "frame-system-rpc-runtime-api", "frame-try-runtime", "hex-literal 0.3.4", + "ismp", + "ismp-grandpa", "log", "pallet-authority-discovery", "pallet-authorship", @@ -1089,10 +1108,13 @@ dependencies = [ "pallet-erc721", "pallet-fast-unstake", "pallet-grandpa", + "pallet-hyperbridge", "pallet-identity", "pallet-im-online", "pallet-indices", "pallet-insecure-randomness-collective-flip", + "pallet-ismp", + "pallet-ismp-runtime-api", "pallet-membership", "pallet-multisig", "pallet-nomination-pools", @@ -1130,6 +1152,7 @@ dependencies = [ "sp-genesis-builder", "sp-inherents", "sp-io", + "sp-mmr-primitives", "sp-offchain", "sp-runtime", "sp-session", @@ -1333,6 +1356,15 @@ dependencies = [ "zeroize", ] +[[package]] +name = "ckb-merkle-mountain-range" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56ccb671c5921be8a84686e6212ca184cb1d7c51cadcdbfcbd1cc3f042f5dfb8" +dependencies = [ + "cfg-if", +] + [[package]] name = "clang-sys" version = "1.8.1" @@ -1742,6 +1774,23 @@ dependencies = [ "cipher 0.4.4", ] +[[package]] +name = "cumulus-primitives-core" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "114859ea473b98046ba46eab82a1830329294015673def6fbadcf34662df4e6f" +dependencies = [ + "parity-scale-codec", + "polkadot-core-primitives", + "polkadot-parachain-primitives", + "polkadot-primitives", + "scale-info", + "sp-api", + "sp-runtime", + "sp-trie", + "staging-xcm", +] + [[package]] name = "curve25519-dalek" version = "4.1.3" @@ -1981,6 +2030,7 @@ dependencies = [ "proc-macro2", "quote", "syn 2.0.94", + "unicode-xid", ] [[package]] @@ -2307,7 +2357,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d" dependencies = [ "libc", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -2525,6 +2575,17 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "fortuples" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87630a8087e9cac4b7edfb6ee5e250ddca9112b57b6b17d8f5107375a3a8eace" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "forwarded-header-value" version = "0.1.1" @@ -2677,6 +2738,22 @@ dependencies = [ "serde", ] +[[package]] +name = "frame-metadata-hash-extension" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4033a2b473472e7ad29ff501d3cedff36f8eaa26f61654d19b6b5cf3e1885296" +dependencies = [ + "array-bytes", + "docify", + "frame-support", + "frame-system", + "log", + "parity-scale-codec", + "scale-info", + "sp-runtime", +] + [[package]] name = "frame-support" version = "37.0.1" @@ -3103,6 +3180,50 @@ dependencies = [ "spinning_top", ] +[[package]] +name = "grandpa-verifier" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d00fddb62ec7e429d283c9d17dd83346df9a0c012d554f3fb8a47958921b2716" +dependencies = [ + "anyhow", + "derive_more 0.99.18", + "finality-grandpa", + "frame-support", + "grandpa-verifier-primitives", + "parity-scale-codec", + "serde", + "sp-consensus-grandpa", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", + "sp-storage", + "sp-trie", + "substrate-state-machine", +] + +[[package]] +name = "grandpa-verifier-primitives" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "011cd8f7019cc3141794e2fcebbc8f1a2137d7580711f5a27d8f8d965b1fb6d8" +dependencies = [ + "anyhow", + "finality-grandpa", + "frame-support", + "ismp", + "log", + "parity-scale-codec", + "sp-consensus-grandpa", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", + "sp-storage", + "sp-trie", +] + [[package]] name = "group" version = "0.13.0" @@ -3872,6 +3993,53 @@ version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" +[[package]] +name = "ismp" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3bc8967dc96f847dc8c4a39e0c48d174a6be8add82f9f79199fc2c7a689bab5a" +dependencies = [ + "anyhow", + "derive_more 1.0.0", + "displaydoc", + "hex", + "parity-scale-codec", + "primitive-types", + "scale-info", + "serde", + "serde-hex-utils", + "serde_json", + "thiserror 2.0.9", +] + +[[package]] +name = "ismp-grandpa" +version = "1.15.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59f5e2e015bb26669935194b79c68dc375df5771b77bf6abd02df931de9e9726" +dependencies = [ + "anyhow", + "ckb-merkle-mountain-range", + "cumulus-primitives-core", + "finality-grandpa", + "frame-support", + "frame-system", + "grandpa-verifier", + "grandpa-verifier-primitives", + "ismp", + "pallet-ismp", + "parity-scale-codec", + "primitive-types", + "scale-info", + "sp-consensus-aura", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", + "sp-trie", + "substrate-state-machine", +] + [[package]] name = "itertools" version = "0.10.5" @@ -4104,7 +4272,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34" dependencies = [ "cfg-if", - "windows-targets 0.48.5", + "windows-targets 0.52.6", ] [[package]] @@ -6136,6 +6304,23 @@ dependencies = [ "sp-staking", ] +[[package]] +name = "pallet-hyperbridge" +version = "1.15.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19ded5664b3a75c9e1211827905bde6e8e9f62a37bfdd3162c0a615a295eec3a" +dependencies = [ + "anyhow", + "frame-support", + "frame-system", + "ismp", + "pallet-ismp", + "parity-scale-codec", + "primitive-types", + "scale-info", + "sp-std", +] + [[package]] name = "pallet-identity" version = "37.0.0" @@ -6204,6 +6389,76 @@ dependencies = [ "sp-runtime", ] +[[package]] +name = "pallet-ismp" +version = "1.15.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1427602a5b78a0fe76f51bd216d6ad8b95a7c7cc36970fbbcfbc8053197ad859" +dependencies = [ + "anyhow", + "fortuples", + "frame-benchmarking", + "frame-support", + "frame-system", + "ismp", + "log", + "parity-scale-codec", + "scale-info", + "serde", + "sp-api", + "sp-core", + "sp-io", + "sp-mmr-primitives", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-ismp-rpc" +version = "1.15.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11b9e1e7bb5644808055ee75d0b927e3f70fccb7e7cafd7b791090f29f0bf4e9" +dependencies = [ + "anyhow", + "frame-system", + "hash-db", + "hex", + "hex-literal 0.4.1", + "ismp", + "jsonrpsee", + "pallet-ismp", + "pallet-ismp-runtime-api", + "parity-scale-codec", + "sc-client-api", + "sc-rpc", + "serde", + "serde_json", + "sp-api", + "sp-blockchain", + "sp-core", + "sp-mmr-primitives", + "sp-runtime", + "sp-storage", + "sp-trie", + "tower", + "trie-db", +] + +[[package]] +name = "pallet-ismp-runtime-api" +version = "1.15.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "086c4b66f03b4e373afbf5c644113254173b181385f88399ae75920f46c7eae7" +dependencies = [ + "ismp", + "pallet-ismp", + "parity-scale-codec", + "primitive-types", + "serde", + "sp-api", + "sp-mmr-primitives", +] + [[package]] name = "pallet-membership" version = "37.0.0" @@ -6953,6 +7208,16 @@ version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" +[[package]] +name = "polkadot-ckb-merkle-mountain-range" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4b44320e5f7ce2c18227537a3032ae5b2c476a7e8eddba45333e1011fc31b92" +dependencies = [ + "cfg-if", + "itertools 0.10.5", +] + [[package]] name = "polkadot-core-primitives" version = "15.0.0" @@ -6982,6 +7247,33 @@ dependencies = [ "sp-weights", ] +[[package]] +name = "polkadot-primitives" +version = "15.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b57bc055fa389372ec5fc0001b99aeffd50f3fd379280ce572d935189bb58dd8" +dependencies = [ + "bitvec", + "hex-literal 0.4.1", + "log", + "parity-scale-codec", + "polkadot-core-primitives", + "polkadot-parachain-primitives", + "scale-info", + "serde", + "sp-api", + "sp-application-crypto", + "sp-arithmetic", + "sp-authority-discovery", + "sp-consensus-slots", + "sp-core", + "sp-inherents", + "sp-io", + "sp-keystore", + "sp-runtime", + "sp-staking", +] + [[package]] name = "polkavm" version = "0.9.3" @@ -7976,7 +8268,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys 0.4.14", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -9425,6 +9717,17 @@ dependencies = [ "serde_derive", ] +[[package]] +name = "serde-hex-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e3d83ec090e617054c5425d2eddd4358a251104c9fba51d71bd997d05cf4915" +dependencies = [ + "anyhow", + "hex", + "serde", +] + [[package]] name = "serde_bytes" version = "0.11.15" @@ -9817,6 +10120,23 @@ dependencies = [ "thiserror 1.0.69", ] +[[package]] +name = "sp-consensus-aura" +version = "0.40.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a8faaa05bbcb9c41f0cc535c4c1315abf6df472b53eae018678d1b4d811ac47" +dependencies = [ + "async-trait", + "parity-scale-codec", + "scale-info", + "sp-api", + "sp-application-crypto", + "sp-consensus-slots", + "sp-inherents", + "sp-runtime", + "sp-timestamp", +] + [[package]] name = "sp-consensus-babe" version = "0.40.0" @@ -10080,6 +10400,24 @@ dependencies = [ "sp-application-crypto", ] +[[package]] +name = "sp-mmr-primitives" +version = "34.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a12dd76e368f1e48144a84b4735218b712f84b3f976970e2f25a29b30440e10" +dependencies = [ + "log", + "parity-scale-codec", + "polkadot-ckb-merkle-mountain-range", + "scale-info", + "serde", + "sp-api", + "sp-core", + "sp-debug-derive", + "sp-runtime", + "thiserror 1.0.69", +] + [[package]] name = "sp-npos-elections" version = "34.0.0" @@ -10696,6 +11034,26 @@ dependencies = [ "tokio 1.42.0", ] +[[package]] +name = "substrate-state-machine" +version = "1.15.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a470df0c4cfd5c7498aaededa6a3d6327e817db5713f9899d1ecd7efe2cc192" +dependencies = [ + "frame-support", + "hash-db", + "ismp", + "pallet-ismp", + "parity-scale-codec", + "primitive-types", + "scale-info", + "serde", + "sp-consensus-aura", + "sp-consensus-babe", + "sp-runtime", + "sp-trie", +] + [[package]] name = "substrate-state-trie-migration-rpc" version = "37.0.0" @@ -10858,7 +11216,7 @@ dependencies = [ "getrandom", "once_cell", "rustix 0.38.42", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -12107,7 +12465,7 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "windows-sys 0.48.0", + "windows-sys 0.59.0", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index ec524e575..c06395192 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -192,5 +192,15 @@ pallet-erc20 = { path = "pallets/erc20", default-features = false } pallet-erc721 = { path = "pallets/erc721", default-features = false } pallet-origins = { path = "pallets/origins", default-features = false } +ismp = { default-features = false, version = "0.2.2" } +pallet-ismp = { default-features = false, version = "1.15.3" } +pallet-ismp-rpc = { default-features = false, version = "1.15.3" } +pallet-ismp-runtime-api = { default-features = false, version = "1.15.3" } +pallet-hyperbridge = { default-features = false, version = "1.15.3" } +ismp-grandpa = { default-features = false, version = "1.15.4" } +frame-metadata-hash-extension = { default-features = false, version = "0.5.0" } +sp-mmr-primitives = { default-features = false, version = "34.0.0" } +anyhow = { version = "1.0", default-features = false } + [profile.release] panic = "unwind" diff --git a/node/client/Cargo.toml b/node/client/Cargo.toml index 438b48578..c68089a62 100644 --- a/node/client/Cargo.toml +++ b/node/client/Cargo.toml @@ -13,10 +13,10 @@ repository.workspace = true futures = { workspace = true } # Substrate dependencies +ddc-primitives = { workspace = true, default-features = true } frame-benchmarking = { workspace = true, default-features = true } frame-system = { workspace = true, default-features = true } frame-system-rpc-runtime-api = { workspace = true, default-features = true } -ddc-primitives = { workspace = true, default-features = true } pallet-transaction-payment = { workspace = true, default-features = true } pallet-transaction-payment-rpc-runtime-api = { workspace = true, default-features = true } sc-client-api = { workspace = true, default-features = true } @@ -29,6 +29,7 @@ sp-blockchain = { workspace = true, default-features = true } sp-consensus = { workspace = true, default-features = true } sp-consensus-babe = { workspace = true, default-features = true } sp-consensus-grandpa = { workspace = true, default-features = true } +sp-core = { workspace = true, default-features = true } sp-inherents = { workspace = true, default-features = true } sp-offchain = { workspace = true, default-features = true } sp-runtime = { workspace = true, default-features = true } @@ -40,7 +41,8 @@ sp-transaction-pool = { workspace = true, default-features = true } # Local cere-dev-runtime = { workspace = true, optional = true } cere-runtime = { workspace = true, optional = true } - +pallet-ismp = { workspace = true, default-features = true } +pallet-ismp-runtime-api = { workspace = true, default-features = true } [features] default = ["cere"] cere = ["cere-runtime"] diff --git a/node/client/src/lib.rs b/node/client/src/lib.rs index 1a051c9ca..1e0bf152f 100644 --- a/node/client/src/lib.rs +++ b/node/client/src/lib.rs @@ -11,6 +11,7 @@ pub use sc_executor::NativeElseWasmExecutor; use sp_api::{CallApiAt, ProvideRuntimeApi}; use sp_blockchain::{HeaderBackend, HeaderMetadata}; use sp_consensus::BlockStatus; +use sp_core::H256; use sp_runtime::{ generic::SignedBlock, traits::{BlakeTwo256, Block as BlockT, NumberFor}, @@ -512,6 +513,7 @@ pub trait RuntimeApiCollection: + sp_block_builder::BlockBuilder + frame_system_rpc_runtime_api::AccountNonceApi + pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi + + pallet_ismp_runtime_api::IsmpRuntimeApi + sp_api::Metadata + sp_offchain::OffchainWorkerApi + sp_session::SessionKeys @@ -527,6 +529,7 @@ impl RuntimeApiCollection for Api where + sp_block_builder::BlockBuilder + frame_system_rpc_runtime_api::AccountNonceApi + pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi + + pallet_ismp_runtime_api::IsmpRuntimeApi + sp_api::Metadata + sp_offchain::OffchainWorkerApi + sp_session::SessionKeys diff --git a/node/rpc/Cargo.toml b/node/rpc/Cargo.toml index 06043165c..65f3d3507 100644 --- a/node/rpc/Cargo.toml +++ b/node/rpc/Cargo.toml @@ -31,7 +31,11 @@ sp-block-builder = { workspace = true, default-features = true } sp-blockchain = { workspace = true, default-features = true } sp-consensus = { workspace = true, default-features = true } sp-consensus-babe = { workspace = true, default-features = true } +sp-core = { workspace = true, default-features = true } sp-keystore = { workspace = true, default-features = true } sp-runtime = { workspace = true, default-features = true } substrate-frame-rpc-system = { workspace = true, default-features = true } substrate-state-trie-migration-rpc = { workspace = true, default-features = true } + +pallet-ismp-rpc = { workspace = true, default-features = true } +pallet-ismp-runtime-api = { workspace = true, default-features = true } diff --git a/node/rpc/src/lib.rs b/node/rpc/src/lib.rs index 014fd6876..95e549cf0 100644 --- a/node/rpc/src/lib.rs +++ b/node/rpc/src/lib.rs @@ -7,9 +7,10 @@ use std::sync::Arc; -use jsonrpsee::RpcModule; use ddc_primitives::{AccountId, Balance, Block, BlockNumber, Hash, Nonce}; -use sc_client_api::AuxStore; +use jsonrpsee::RpcModule; +use pallet_ismp_rpc::{IsmpApiServer, IsmpRpcHandler}; +use sc_client_api::{AuxStore, BlockBackend, ProofProvider}; use sc_consensus_grandpa::{ FinalityProofProvider, GrandpaJustificationStream, SharedAuthoritySet, SharedVoterState, }; @@ -22,6 +23,7 @@ use sp_block_builder::BlockBuilder; use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata}; use sp_consensus::SelectChain; use sp_consensus_babe::BabeApi; +use sp_core::H256; use sp_keystore::KeystorePtr; /// Extra dependencies for BABE. @@ -61,12 +63,14 @@ pub struct FullDeps { pub babe: BabeDeps, /// GRANDPA specific dependencies. pub grandpa: GrandpaDeps, + /// Backend used by the node. + pub backend: Arc, } /// Instantiate all full RPC extensions. pub fn create_full( deps: FullDeps, - backend: Arc, + _backend: Arc, ) -> Result, Box> where C: ProvideRuntimeApi @@ -77,10 +81,13 @@ where + Sync + Send + 'static, + C: BlockBackend, + C: ProofProvider, C::Api: substrate_frame_rpc_system::AccountNonceApi, C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi, C::Api: BabeApi, C::Api: BlockBuilder, + C::Api: pallet_ismp_runtime_api::IsmpRuntimeApi, P: TransactionPool + 'static, SC: SelectChain + 'static, B: sc_client_api::Backend + Send + Sync + 'static, @@ -95,7 +102,8 @@ where use substrate_state_trie_migration_rpc::StateMigrationApiServer; let mut io = RpcModule::new(()); - let FullDeps { client, pool, select_chain, chain_spec, deny_unsafe, babe, grandpa } = deps; + let FullDeps { client, pool, select_chain, chain_spec, deny_unsafe, babe, grandpa, backend } = + deps; let BabeDeps { babe_worker_handle, keystore } = babe; let GrandpaDeps { @@ -134,12 +142,13 @@ where io.merge( substrate_state_trie_migration_rpc::StateMigration::new( client.clone(), - backend, + backend.clone(), deny_unsafe, ) .into_rpc(), )?; - io.merge(Dev::new(client, deny_unsafe).into_rpc())?; + io.merge(Dev::new(client.clone(), deny_unsafe).into_rpc())?; + io.merge(IsmpRpcHandler::new(client, backend)?.into_rpc())?; Ok(io) } diff --git a/node/service/src/chain_spec.rs b/node/service/src/chain_spec.rs index 6f79ca0a6..811fd1bed 100644 --- a/node/service/src/chain_spec.rs +++ b/node/service/src/chain_spec.rs @@ -2,8 +2,8 @@ use cere_dev_runtime as cere_dev; #[cfg(feature = "cere-dev-native")] use cere_runtime_common::constants::currency::DOLLARS as TEST_UNITS; -use jsonrpsee::core::__reexports::serde_json; pub use ddc_primitives::{AccountId, Balance, Block, Signature}; +use jsonrpsee::core::__reexports::serde_json; use pallet_im_online::sr25519::AuthorityId as ImOnlineId; use sc_chain_spec::ChainSpecExtension; use sc_service::ChainType; diff --git a/node/service/src/lib.rs b/node/service/src/lib.rs index 998d44df0..b223519ac 100644 --- a/node/service/src/lib.rs +++ b/node/service/src/lib.rs @@ -257,6 +257,7 @@ where subscription_executor, finality_provider: finality_proof_provider.clone(), }, + backend: rpc_backend.clone(), }; cere_rpc::create_full(deps, rpc_backend.clone()).map_err(Into::into) diff --git a/pallets/chainbridge/src/lib.rs b/pallets/chainbridge/src/lib.rs index ce71d06ea..9ec72baa2 100644 --- a/pallets/chainbridge/src/lib.rs +++ b/pallets/chainbridge/src/lib.rs @@ -1,7 +1,7 @@ #![allow(clippy::all)] // Ensure we're `no_std` when compiling for Wasm. #![cfg_attr(not(feature = "std"), no_std)] - +#![allow(clippy::manual_inspect)] pub mod weights; use crate::weights::WeightInfo; diff --git a/pallets/ddc-clusters-gov/src/lib.rs b/pallets/ddc-clusters-gov/src/lib.rs index 788ee0656..65957ecb6 100644 --- a/pallets/ddc-clusters-gov/src/lib.rs +++ b/pallets/ddc-clusters-gov/src/lib.rs @@ -13,7 +13,7 @@ #![cfg_attr(not(feature = "std"), no_std)] #![recursion_limit = "256"] - +#![allow(clippy::manual_inspect)] use codec::{Decode, Encode}; #[cfg(feature = "runtime-benchmarks")] use ddc_primitives::traits::{node::NodeCreator, staking::StakerCreator}; diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs index e9c1cd123..be5815547 100644 --- a/pallets/ddc-clusters/src/lib.rs +++ b/pallets/ddc-clusters/src/lib.rs @@ -12,7 +12,7 @@ //! `GenesisConfig` is optional and allow to set some initial nodes in DDC. #![cfg_attr(not(feature = "std"), no_std)] #![recursion_limit = "256"] - +#![allow(clippy::manual_inspect)] pub mod weights; use crate::weights::WeightInfo; diff --git a/pallets/ddc-customers/src/lib.rs b/pallets/ddc-customers/src/lib.rs index 35fbfb4e5..41c3af03c 100644 --- a/pallets/ddc-customers/src/lib.rs +++ b/pallets/ddc-customers/src/lib.rs @@ -1,6 +1,6 @@ #![cfg_attr(not(feature = "std"), no_std)] #![recursion_limit = "256"] - +#![allow(clippy::manual_inspect)] pub mod weights; use crate::weights::WeightInfo; diff --git a/pallets/ddc-nodes/src/lib.rs b/pallets/ddc-nodes/src/lib.rs index 83e7ee60b..9858855df 100644 --- a/pallets/ddc-nodes/src/lib.rs +++ b/pallets/ddc-nodes/src/lib.rs @@ -11,9 +11,9 @@ //! The DDC Nodes pallet depends on the [`GenesisConfig`]. The //! `GenesisConfig` is optional and allow to set some initial nodes in DDC. +#![allow(clippy::manual_inspect)] #![cfg_attr(not(feature = "std"), no_std)] #![recursion_limit = "256"] - #[cfg(test)] pub(crate) mod mock; #[cfg(test)] diff --git a/pallets/ddc-payouts/src/lib.rs b/pallets/ddc-payouts/src/lib.rs index f543db269..36dd5b26b 100644 --- a/pallets/ddc-payouts/src/lib.rs +++ b/pallets/ddc-payouts/src/lib.rs @@ -13,7 +13,7 @@ #![cfg_attr(not(feature = "std"), no_std)] #![recursion_limit = "256"] - +#![allow(clippy::manual_inspect)] pub mod weights; use crate::weights::WeightInfo; diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index ae4ae6d5f..c9fb017c8 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -12,7 +12,7 @@ //! `GenesisConfig` is optional and allow to set some initial stakers in DDC. #![cfg_attr(not(feature = "std"), no_std)] #![recursion_limit = "256"] - +#![allow(clippy::manual_inspect)] #[cfg(feature = "runtime-benchmarks")] pub mod benchmarking; #[cfg(any(feature = "runtime-benchmarks", test))] diff --git a/pallets/origins/src/lib.rs b/pallets/origins/src/lib.rs index a8ae6d921..ee5ab6df4 100644 --- a/pallets/origins/src/lib.rs +++ b/pallets/origins/src/lib.rs @@ -1,5 +1,5 @@ //! Custom origins for governance interventions. - +#![allow(clippy::manual_inspect)] #![cfg_attr(not(feature = "std"), no_std)] pub use pallet::*; diff --git a/runtime/cere-dev/Cargo.toml b/runtime/cere-dev/Cargo.toml index 6b402c88e..f11ee48b7 100644 --- a/runtime/cere-dev/Cargo.toml +++ b/runtime/cere-dev/Cargo.toml @@ -20,6 +20,7 @@ scale-info = { workspace = true } static_assertions = { workspace = true } # Substrate dependencies +ddc-primitives = { workspace = true } frame-benchmarking = { workspace = true, optional = true } frame-election-provider-support = { workspace = true } frame-executive = { workspace = true } @@ -28,7 +29,6 @@ frame-system = { workspace = true } frame-system-benchmarking = { workspace = true, optional = true } frame-system-rpc-runtime-api = { workspace = true } frame-try-runtime = { workspace = true, optional = true } -ddc-primitives = { workspace = true } pallet-authority-discovery = { workspace = true } pallet-authorship = { workspace = true } pallet-babe = { workspace = true } @@ -105,6 +105,16 @@ pallet-erc20 = { workspace = true } pallet-erc721 = { workspace = true } pallet-origins = { workspace = true } +# Hyperbridge Depedencies +anyhow = { workspace = true } +frame-metadata-hash-extension = { workspace = true } +ismp = { workspace = true } +ismp-grandpa = { workspace = true } +pallet-hyperbridge = { workspace = true } +pallet-ismp = { workspace = true, features = ["unsigned"] } +pallet-ismp-runtime-api = { workspace = true } +sp-mmr-primitives = { workspace = true } + [build-dependencies] substrate-wasm-builder = { workspace = true, default-features = true } @@ -192,6 +202,13 @@ std = [ "pallet-ddc-clusters-gov/std", "sp-arithmetic/std", "pallet-origins/std", + "pallet-hyperbridge/std", + "ismp/std", + "pallet-ismp/std", + "pallet-ismp-runtime-api/std", + "ismp-grandpa/std", + "anyhow/std", + "frame-metadata-hash-extension/std", ] runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", @@ -298,4 +315,7 @@ try-runtime = [ "pallet-preimage/try-runtime", "pallet-origins/try-runtime", "pallet-ddc-clusters-gov/try-runtime", + "pallet-ismp/try-runtime", + "pallet-hyperbridge/try-runtime", + "ismp-grandpa/try-runtime", ] diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index 6361a3eae..63f46574f 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -23,7 +23,11 @@ #![recursion_limit = "256"] use codec::{Decode, Encode, MaxEncodedLen}; -use ddc_primitives::traits::pallet::{GetDdcOrigin, PalletVisitor}; +use ddc_primitives::{ + traits::pallet::{GetDdcOrigin, PalletVisitor}, + AccountIndex, Balance, BlockNumber, Hash, Moment, Nonce, +}; +pub use ddc_primitives::{AccountId, Signature}; use frame_election_provider_support::{ bounds::ElectionBoundsBuilder, onchain, BalancingConfig, SequentialPhragmen, VoteWeight, }; @@ -54,8 +58,6 @@ use frame_system::{ limits::{BlockLength, BlockWeights}, EnsureRoot, EnsureSigned, }; -pub use ddc_primitives::{AccountId, Signature}; -use ddc_primitives::{AccountIndex, Balance, BlockNumber, Hash, Moment, Nonce}; #[cfg(any(feature = "std", test))] pub use pallet_balances::Call as BalancesCall; pub use pallet_chainbridge; @@ -124,6 +126,17 @@ use governance::{ /// Generated voter bag information. mod voter_bags; +use ismp::{ + consensus::{ConsensusClientId, StateMachineHeight, StateMachineId}, + error::Error, + host::StateMachine, + module::IsmpModule, + router::{IsmpRouter, Request, Response}, +}; +use ismp_grandpa::consensus::GrandpaConsensusClient; +use pallet_ismp::offchain::{Leaf, Proof, ProofKeys}; +use sp_core::H256; +mod weights; // Make the WASM binary available. #[cfg(feature = "std")] include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); @@ -148,7 +161,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // and set impl_version to 0. If only runtime // implementation changes and behavior does not, then leave spec_version as // is and increment impl_version. - spec_version: 70000, + spec_version: 71000, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 24, @@ -941,6 +954,7 @@ where frame_system::CheckNonce::::from(nonce), frame_system::CheckWeight::::new(), pallet_transaction_payment::ChargeTransactionPayment::::from(tip), + frame_metadata_hash_extension::CheckMetadataHash::new(false), ); let raw_payload = SignedPayload::new(call, extra) .map_err(|e| { @@ -1285,6 +1299,69 @@ impl, T: frame_system::Config> GetDdcOrigin } } +parameter_types! { + // The hyperbridge parachain on Polkadot + pub const Coprocessor: Option = Some(StateMachine::Polkadot(3367)); + // The host state machine of this pallet, this must be unique to all every solochain + pub const HostStateMachine: StateMachine = StateMachine::Substrate(*b"solo"); // your unique chain id here +} + +impl pallet_ismp::Config for Runtime { + // Configure the runtime event + type RuntimeEvent = RuntimeEvent; + // Permissioned origin who can create or update consensus clients + type AdminOrigin = EnsureRoot; + // The state machine identifier for this state machine + type HostStateMachine = HostStateMachine; + // The pallet_timestamp pallet + type TimestampProvider = Timestamp; + // The currency implementation that is offered to relayers + // this could also be `frame_support::traits::tokens::fungible::ItemOf` + type Currency = Balances; + // The balance type for the currency implementation + type Balance = Balance; + // Router implementation for routing requests/responses to their respective modules + type Router = ModuleRouter; + // Optional coprocessor for incoming requests/responses + type Coprocessor = Coprocessor; + // Supported consensus clients + type ConsensusClients = ( + // Add the grandpa consensus client here + GrandpaConsensusClient, + ); + // Offchain database implementation. Outgoing requests and responses are + // inserted in this database, while their commitments are stored onchain. + // + // The default implementation for `()` should suffice + type OffchainDB = (); + // Weight provider for local modules + type WeightProvider = (); +} + +impl pallet_hyperbridge::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type IsmpHost = Ismp; +} + +#[derive(Default)] +pub struct ModuleRouter; + +impl IsmpRouter for ModuleRouter { + fn module_for_id(&self, id: Vec) -> Result, anyhow::Error> { + return match id.as_slice() { + pallet_hyperbridge::PALLET_HYPERBRIDGE_ID => + Ok(Box::new(pallet_hyperbridge::Pallet::::default())), + _ => Err(Error::ModuleNotFound(id).into()), + }; + } +} + +impl ismp_grandpa::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type IsmpHost = Ismp; + type WeightInfo = weights::ismp_grandpa::WeightInfo; +} + construct_runtime!( pub enum Runtime { @@ -1338,6 +1415,9 @@ construct_runtime!( // End OpenGov. TechComm: pallet_collective::, DdcClustersGov: pallet_ddc_clusters_gov, + Ismp: pallet_ismp, + IsmpGrandpa: ismp_grandpa, + Hyperbridge: pallet_hyperbridge, } ); @@ -1365,6 +1445,7 @@ pub type SignedExtra = ( frame_system::CheckNonce, frame_system::CheckWeight, pallet_transaction_payment::ChargeTransactionPayment, + frame_metadata_hash_extension::CheckMetadataHash, ); /// Unchecked extrinsic type as expected by this runtime. @@ -1437,6 +1518,7 @@ mod benches { } impl_runtime_apis! { + impl sp_genesis_builder::GenesisBuilder for Runtime { fn get_preset(id: &Option) -> Option> { @@ -1677,6 +1759,50 @@ impl_runtime_apis! { } } + impl pallet_ismp_runtime_api::IsmpRuntimeApi::Hash> for Runtime { + fn host_state_machine() -> StateMachine { + ::HostStateMachine::get() + } + + fn challenge_period(id: StateMachineId) -> Option { + pallet_ismp::Pallet::::challenge_period(id) + } + + fn generate_proof( + keys: ProofKeys + ) -> Result<(Vec, Proof<::Hash>), sp_mmr_primitives::Error> { + pallet_ismp::Pallet::::generate_proof(keys) + } + + fn block_events() -> Vec { + pallet_ismp::Pallet::::block_events() + } + + fn block_events_with_metadata() -> Vec<(ismp::events::Event, Option)> { + pallet_ismp::Pallet::::block_events_with_metadata() + } + + fn consensus_state(id: ConsensusClientId) -> Option> { + pallet_ismp::Pallet::::consensus_states(id) + } + + fn state_machine_update_time(height: StateMachineHeight) -> Option { + pallet_ismp::Pallet::::state_machine_update_time(height) + } + + fn latest_state_machine_height(id: StateMachineId) -> Option { + pallet_ismp::Pallet::::latest_state_machine_height(id) + } + + fn requests(commitments: Vec) -> Vec { + pallet_ismp::Pallet::::requests(commitments) + } + + fn responses(commitments: Vec) -> Vec { + pallet_ismp::Pallet::::responses(commitments) + } + } + impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi< Block, Balance, diff --git a/runtime/cere-dev/src/weights/ismp_grandpa.rs b/runtime/cere-dev/src/weights/ismp_grandpa.rs new file mode 100644 index 000000000..d20a7327b --- /dev/null +++ b/runtime/cere-dev/src/weights/ismp_grandpa.rs @@ -0,0 +1,62 @@ + +//! Autogenerated weights for `ismp_grandpa` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 42.0.0 +//! DATE: 2024-12-18, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `polytope-labs`, CPU: `AMD Ryzen Threadripper PRO 5995WX 64-Cores` +//! WASM-EXECUTION: `Compiled`, CHAIN: `None`, DB CACHE: 1024 + +// Executed Command: +// target/release/hyperbridge +// benchmark +// pallet +// --wasm-execution=compiled +// --pallet=ismp_grandpa +// --extrinsic=* +// --steps=50 +// --repeat=20 +// --genesis-builder=runtime +// --runtime=./target/release/wbuild/gargantua-runtime/gargantua_runtime.compact.wasm +// --output=parachain/runtimes/gargantua/src/weights/ismp_grandpa.rs + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(missing_docs)] + +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; + +/// Weight functions for `ismp_grandpa`. +pub struct WeightInfo(PhantomData); +impl ismp_grandpa::WeightInfo for WeightInfo { + /// Storage: `IsmpGrandpa::SupportedStateMachines` (r:0 w:100) + /// Proof: `IsmpGrandpa::SupportedStateMachines` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// The range of component `n` is `[1, 100]`. + fn add_state_machines(n: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 6_913_000 picoseconds. + Weight::from_parts(7_832_568, 0) + .saturating_add(Weight::from_parts(0, 0)) + // Standard Error: 7_710 + .saturating_add(Weight::from_parts(1_434_418, 0).saturating_mul(n.into())) + .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(n.into()))) + } + /// Storage: `IsmpGrandpa::SupportedStateMachines` (r:0 w:100) + /// Proof: `IsmpGrandpa::SupportedStateMachines` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// The range of component `n` is `[1, 100]`. + fn remove_state_machines(n: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 7_204_000 picoseconds. + Weight::from_parts(5_126_127, 0) + .saturating_add(Weight::from_parts(0, 0)) + // Standard Error: 8_195 + .saturating_add(Weight::from_parts(1_417_249, 0).saturating_mul(n.into())) + .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(n.into()))) + } +} diff --git a/runtime/cere-dev/src/weights/mod.rs b/runtime/cere-dev/src/weights/mod.rs new file mode 100644 index 000000000..b26bc0709 --- /dev/null +++ b/runtime/cere-dev/src/weights/mod.rs @@ -0,0 +1 @@ +pub mod ismp_grandpa; diff --git a/runtime/cere/Cargo.toml b/runtime/cere/Cargo.toml index fa7923190..f11741abd 100644 --- a/runtime/cere/Cargo.toml +++ b/runtime/cere/Cargo.toml @@ -20,6 +20,7 @@ scale-info = { version = "2.1.2", default-features = false, features = ["derive" static_assertions = "1.1.0" # Substrate dependencies +ddc-primitives = { workspace = true } frame-benchmarking = { workspace = true, optional = true } frame-election-provider-support = { workspace = true } frame-executive = { workspace = true } @@ -28,7 +29,6 @@ frame-system = { workspace = true } frame-system-benchmarking = { workspace = true, optional = true } frame-system-rpc-runtime-api = { workspace = true } frame-try-runtime = { workspace = true, optional = true } -ddc-primitives = { workspace = true } pallet-authority-discovery = { workspace = true } pallet-authorship = { workspace = true } pallet-babe = { workspace = true } @@ -105,6 +105,16 @@ pallet-origins = { workspace = true } pallet-referenda = { workspace = true } pallet-whitelist = { workspace = true } +# Hyperbridge Depedencies +anyhow = { workspace = true } +frame-metadata-hash-extension = { workspace = true } +ismp = { workspace = true } +ismp-grandpa = { workspace = true } +pallet-hyperbridge = { workspace = true } +pallet-ismp = { workspace = true, features = ["unsigned"] } +pallet-ismp-runtime-api = { workspace = true } +sp-mmr-primitives = { workspace = true } + [build-dependencies] substrate-wasm-builder = { workspace = true, default-features = true } @@ -190,6 +200,13 @@ std = [ "pallet-whitelist/std", "pallet-preimage/std", "pallet-origins/std", + "pallet-hyperbridge/std", + "ismp/std", + "pallet-ismp/std", + "pallet-ismp-runtime-api/std", + "ismp-grandpa/std", + "anyhow/std", + "frame-metadata-hash-extension/std", ] runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", @@ -296,4 +313,7 @@ try-runtime = [ "pallet-preimage/try-runtime", "pallet-origins/try-runtime", "pallet-ddc-clusters-gov/try-runtime", + "pallet-ismp/try-runtime", + "pallet-hyperbridge/try-runtime", + "ismp-grandpa/try-runtime", ] diff --git a/runtime/cere/src/lib.rs b/runtime/cere/src/lib.rs index af53812b5..7a4bb9d2f 100644 --- a/runtime/cere/src/lib.rs +++ b/runtime/cere/src/lib.rs @@ -22,7 +22,10 @@ // `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256. #![recursion_limit = "256"] use codec::{Decode, Encode, MaxEncodedLen}; -use ddc_primitives::traits::pallet::PalletVisitor; +use ddc_primitives::{ + traits::pallet::PalletVisitor, AccountIndex, Balance, BlockNumber, Hash, Moment, Nonce, +}; +pub use ddc_primitives::{AccountId, Signature}; use frame_election_provider_support::{ bounds::ElectionBoundsBuilder, onchain, BalancingConfig, SequentialPhragmen, VoteWeight, }; @@ -53,8 +56,6 @@ use frame_system::{ limits::{BlockLength, BlockWeights}, EnsureRoot, EnsureSigned, }; -pub use ddc_primitives::{AccountId, Signature}; -use ddc_primitives::{AccountIndex, Balance, BlockNumber, Hash, Moment, Nonce}; #[cfg(any(feature = "std", test))] pub use pallet_balances::Call as BalancesCall; pub use pallet_chainbridge; @@ -119,6 +120,18 @@ use governance::{ /// Generated voter bag information. mod voter_bags; +use ismp::{ + consensus::{ConsensusClientId, StateMachineHeight, StateMachineId}, + error::Error, + host::StateMachine, + module::IsmpModule, + router::{IsmpRouter, Request, Response}, +}; +use ismp_grandpa::consensus::GrandpaConsensusClient; +use pallet_ismp::offchain::{Leaf, Proof, ProofKeys}; +use sp_core::H256; +mod weights; + // Make the WASM binary available. #[cfg(feature = "std")] include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); @@ -143,7 +156,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // and set impl_version to 0. If only runtime // implementation changes and behavior does not, then leave spec_version as // is and increment impl_version. - spec_version: 70000, + spec_version: 71000, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 24, @@ -943,6 +956,7 @@ where frame_system::CheckNonce::::from(nonce), frame_system::CheckWeight::::new(), pallet_transaction_payment::ChargeTransactionPayment::::from(tip), + frame_metadata_hash_extension::CheckMetadataHash::new(false), ); let raw_payload = SignedPayload::new(call, extra) .map_err(|e| { @@ -1287,6 +1301,69 @@ impl, T: frame_system::Config> GetDdcOrigin } } +parameter_types! { + // The hyperbridge parachain on Polkadot + pub const Coprocessor: Option = Some(StateMachine::Polkadot(3367)); + // The host state machine of this pallet, this must be unique to all every solochain + pub const HostStateMachine: StateMachine = StateMachine::Substrate(*b"solo"); // your unique chain id here +} + +impl pallet_ismp::Config for Runtime { + // Configure the runtime event + type RuntimeEvent = RuntimeEvent; + // Permissioned origin who can create or update consensus clients + type AdminOrigin = EnsureRoot; + // The state machine identifier for this state machine + type HostStateMachine = HostStateMachine; + // The pallet_timestamp pallet + type TimestampProvider = Timestamp; + // The currency implementation that is offered to relayers + // this could also be `frame_support::traits::tokens::fungible::ItemOf` + type Currency = Balances; + // The balance type for the currency implementation + type Balance = Balance; + // Router implementation for routing requests/responses to their respective modules + type Router = ModuleRouter; + // Optional coprocessor for incoming requests/responses + type Coprocessor = Coprocessor; + // Supported consensus clients + type ConsensusClients = ( + // Add the grandpa consensus client here + GrandpaConsensusClient, + ); + // Offchain database implementation. Outgoing requests and responses are + // inserted in this database, while their commitments are stored onchain. + // + // The default implementation for `()` should suffice + type OffchainDB = (); + // Weight provider for local modules + type WeightProvider = (); +} + +impl pallet_hyperbridge::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type IsmpHost = Ismp; +} + +#[derive(Default)] +pub struct ModuleRouter; + +impl IsmpRouter for ModuleRouter { + fn module_for_id(&self, id: Vec) -> Result, anyhow::Error> { + return match id.as_slice() { + pallet_hyperbridge::PALLET_HYPERBRIDGE_ID => + Ok(Box::new(pallet_hyperbridge::Pallet::::default())), + _ => Err(Error::ModuleNotFound(id).into()), + }; + } +} + +impl ismp_grandpa::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type IsmpHost = Ismp; + type WeightInfo = weights::ismp_grandpa::WeightInfo; +} + construct_runtime!( pub enum Runtime { @@ -1340,6 +1417,9 @@ construct_runtime!( // End OpenGov. TechComm: pallet_collective::, DdcClustersGov: pallet_ddc_clusters_gov, + Ismp: pallet_ismp, + IsmpGrandpa: ismp_grandpa, + Hyperbridge: pallet_hyperbridge, } ); @@ -1367,6 +1447,7 @@ pub type SignedExtra = ( frame_system::CheckNonce, frame_system::CheckWeight, pallet_transaction_payment::ChargeTransactionPayment, + frame_metadata_hash_extension::CheckMetadataHash, ); /// Unchecked extrinsic type as expected by this runtime. @@ -1632,6 +1713,50 @@ impl_runtime_apis! { } } + impl pallet_ismp_runtime_api::IsmpRuntimeApi::Hash> for Runtime { + fn host_state_machine() -> StateMachine { + ::HostStateMachine::get() + } + + fn challenge_period(id: StateMachineId) -> Option { + pallet_ismp::Pallet::::challenge_period(id) + } + + fn generate_proof( + keys: ProofKeys + ) -> Result<(Vec, Proof<::Hash>), sp_mmr_primitives::Error> { + pallet_ismp::Pallet::::generate_proof(keys) + } + + fn block_events() -> Vec { + pallet_ismp::Pallet::::block_events() + } + + fn block_events_with_metadata() -> Vec<(ismp::events::Event, Option)> { + pallet_ismp::Pallet::::block_events_with_metadata() + } + + fn consensus_state(id: ConsensusClientId) -> Option> { + pallet_ismp::Pallet::::consensus_states(id) + } + + fn state_machine_update_time(height: StateMachineHeight) -> Option { + pallet_ismp::Pallet::::state_machine_update_time(height) + } + + fn latest_state_machine_height(id: StateMachineId) -> Option { + pallet_ismp::Pallet::::latest_state_machine_height(id) + } + + fn requests(commitments: Vec) -> Vec { + pallet_ismp::Pallet::::requests(commitments) + } + + fn responses(commitments: Vec) -> Vec { + pallet_ismp::Pallet::::responses(commitments) + } + } + impl pallet_contracts::ContractsApi for Runtime { fn call( diff --git a/runtime/cere/src/weights/ismp_grandpa.rs b/runtime/cere/src/weights/ismp_grandpa.rs new file mode 100644 index 000000000..d20a7327b --- /dev/null +++ b/runtime/cere/src/weights/ismp_grandpa.rs @@ -0,0 +1,62 @@ + +//! Autogenerated weights for `ismp_grandpa` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 42.0.0 +//! DATE: 2024-12-18, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `polytope-labs`, CPU: `AMD Ryzen Threadripper PRO 5995WX 64-Cores` +//! WASM-EXECUTION: `Compiled`, CHAIN: `None`, DB CACHE: 1024 + +// Executed Command: +// target/release/hyperbridge +// benchmark +// pallet +// --wasm-execution=compiled +// --pallet=ismp_grandpa +// --extrinsic=* +// --steps=50 +// --repeat=20 +// --genesis-builder=runtime +// --runtime=./target/release/wbuild/gargantua-runtime/gargantua_runtime.compact.wasm +// --output=parachain/runtimes/gargantua/src/weights/ismp_grandpa.rs + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(missing_docs)] + +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; + +/// Weight functions for `ismp_grandpa`. +pub struct WeightInfo(PhantomData); +impl ismp_grandpa::WeightInfo for WeightInfo { + /// Storage: `IsmpGrandpa::SupportedStateMachines` (r:0 w:100) + /// Proof: `IsmpGrandpa::SupportedStateMachines` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// The range of component `n` is `[1, 100]`. + fn add_state_machines(n: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 6_913_000 picoseconds. + Weight::from_parts(7_832_568, 0) + .saturating_add(Weight::from_parts(0, 0)) + // Standard Error: 7_710 + .saturating_add(Weight::from_parts(1_434_418, 0).saturating_mul(n.into())) + .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(n.into()))) + } + /// Storage: `IsmpGrandpa::SupportedStateMachines` (r:0 w:100) + /// Proof: `IsmpGrandpa::SupportedStateMachines` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// The range of component `n` is `[1, 100]`. + fn remove_state_machines(n: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 7_204_000 picoseconds. + Weight::from_parts(5_126_127, 0) + .saturating_add(Weight::from_parts(0, 0)) + // Standard Error: 8_195 + .saturating_add(Weight::from_parts(1_417_249, 0).saturating_mul(n.into())) + .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(n.into()))) + } +} diff --git a/runtime/cere/src/weights/mod.rs b/runtime/cere/src/weights/mod.rs new file mode 100644 index 000000000..b26bc0709 --- /dev/null +++ b/runtime/cere/src/weights/mod.rs @@ -0,0 +1 @@ +pub mod ismp_grandpa; diff --git a/runtime/common/Cargo.toml b/runtime/common/Cargo.toml index 145011876..a9b1b1338 100644 --- a/runtime/common/Cargo.toml +++ b/runtime/common/Cargo.toml @@ -12,9 +12,9 @@ repository.workspace = true codec = { workspace = true } log = { workspace = true, default-features = false } +ddc-primitives = { workspace = true } frame-support = { workspace = true } frame-system = { workspace = true } -ddc-primitives = { workspace = true } pallet-contracts = { workspace = true } pallet-referenda = { workspace = true } pallet-session = { workspace = true }