diff --git a/bridges/bin/runtime-common/src/messages.rs b/bridges/bin/runtime-common/src/messages.rs index 9aced1c361abd..3e69463480db0 100644 --- a/bridges/bin/runtime-common/src/messages.rs +++ b/bridges/bin/runtime-common/src/messages.rs @@ -692,6 +692,13 @@ pub mod target { } } +/// The `BridgeMessagesCall` used by a chain. +pub type BridgeMessagesCallOf = bp_messages::BridgeMessagesCall< + bp_runtime::AccountIdOf, + target::FromBridgedChainMessagesProof>, + source::FromBridgedChainMessagesDeliveryProof>, +>; + #[cfg(test)] mod tests { use super::*; diff --git a/bridges/modules/grandpa/src/lib.rs b/bridges/modules/grandpa/src/lib.rs index 926594ad79604..6853bb9cb3bb0 100644 --- a/bridges/modules/grandpa/src/lib.rs +++ b/bridges/modules/grandpa/src/lib.rs @@ -612,6 +612,7 @@ mod tests { run_test, test_header, RuntimeOrigin, TestHeader, TestNumber, TestRuntime, MAX_BRIDGED_AUTHORITIES, }; + use bp_header_chain::BridgeGrandpaCall; use bp_runtime::BasicOperatingMode; use bp_test_utils::{ authority_list, generate_owned_bridge_module_tests, make_default_justification, @@ -1160,5 +1161,33 @@ mod tests { ); } + #[test] + fn test_bridge_grandpa_call_is_correctly_defined() { + let header = test_header(0); + let init_data = InitializationData { + header: Box::new(header.clone()), + authority_list: authority_list(), + set_id: 1, + operating_mode: BasicOperatingMode::Normal, + }; + let justification = make_default_justification(&header); + + let direct_initialize_call = + Call::::initialize { init_data: init_data.clone() }; + let indirect_initialize_call = BridgeGrandpaCall::::initialize(init_data); + assert_eq!(direct_initialize_call.encode(), indirect_initialize_call.encode()); + + let direct_submit_finality_proof_call = Call::::submit_finality_proof { + finality_target: Box::new(header.clone()), + justification: justification.clone(), + }; + let indirect_submit_finality_proof_call = + BridgeGrandpaCall::::submit_finality_proof(Box::new(header), justification); + assert_eq!( + direct_submit_finality_proof_call.encode(), + indirect_submit_finality_proof_call.encode() + ); + } + generate_owned_bridge_module_tests!(BasicOperatingMode::Normal, BasicOperatingMode::Halted); } diff --git a/bridges/modules/messages/src/lib.rs b/bridges/modules/messages/src/lib.rs index f2d7f4c728cac..b8d79b83b4187 100644 --- a/bridges/modules/messages/src/lib.rs +++ b/bridges/modules/messages/src/lib.rs @@ -885,13 +885,13 @@ fn verify_and_decode_messages_proof::receive_messages_proof { + relayer_id_at_bridged_chain: account_id, + proof: message_proof.clone(), + messages_count: 1, + dispatch_weight: REGULAR_PAYLOAD.declared_weight, + }; + let indirect_receive_messages_proof_call = BridgeMessagesCall::< + AccountId, + TestMessagesProof, + TestMessagesDeliveryProof, + >::receive_messages_proof( + account_id, + message_proof, + 1, + REGULAR_PAYLOAD.declared_weight, + ); + assert_eq!( + direct_receive_messages_proof_call.encode(), + indirect_receive_messages_proof_call.encode() + ); + + let direct_receive_messages_delivery_proof_call = + Call::::receive_messages_delivery_proof { + proof: message_delivery_proof.clone(), + relayers_state: unrewarded_relayer_state.clone(), + }; + let indirect_receive_messages_delivery_proof_call = BridgeMessagesCall::< + AccountId, + TestMessagesProof, + TestMessagesDeliveryProof, + >::receive_messages_delivery_proof( + message_delivery_proof, + unrewarded_relayer_state, + ); + assert_eq!( + direct_receive_messages_delivery_proof_call.encode(), + indirect_receive_messages_delivery_proof_call.encode() + ); + } + generate_owned_bridge_module_tests!( MessagesOperatingMode::Basic(BasicOperatingMode::Normal), MessagesOperatingMode::Basic(BasicOperatingMode::Halted) diff --git a/bridges/modules/parachains/src/lib.rs b/bridges/modules/parachains/src/lib.rs index 3cfda0012732b..633b39329a012 100644 --- a/bridges/modules/parachains/src/lib.rs +++ b/bridges/modules/parachains/src/lib.rs @@ -661,7 +661,9 @@ mod tests { }; use codec::Encode; - use bp_parachains::{BestParaHeadHash, ImportedParaHeadsKeyProvider, ParasInfoKeyProvider}; + use bp_parachains::{ + BestParaHeadHash, BridgeParachainCall, ImportedParaHeadsKeyProvider, ParasInfoKeyProvider, + }; use bp_runtime::{ record_all_trie_keys, BasicOperatingMode, OwnedBridgeModuleError, StorageDoubleMapKeyProvider, StorageMapKeyProvider, @@ -1471,5 +1473,24 @@ mod tests { }); } + #[test] + fn test_bridge_parachain_call_is_correctly_defined() { + let (state_root, proof, _) = prepare_parachain_heads_proof(vec![(1, head_data(1, 0))]); + let parachains = vec![(ParaId(2), Default::default())]; + let relay_header_id = (0, test_relay_header(0, state_root).hash()); + + let direct_submit_parachain_heads_call = Call::::submit_parachain_heads { + at_relay_block: relay_header_id, + parachains: parachains.clone(), + parachain_heads_proof: proof.clone(), + }; + let indirect_submit_parachain_heads_call = + BridgeParachainCall::submit_parachain_heads(relay_header_id, parachains, proof); + assert_eq!( + direct_submit_parachain_heads_call.encode(), + indirect_submit_parachain_heads_call.encode() + ); + } + generate_owned_bridge_module_tests!(BasicOperatingMode::Normal, BasicOperatingMode::Halted); } diff --git a/bridges/primitives/chain-bridge-hub-cumulus/Cargo.toml b/bridges/primitives/chain-bridge-hub-cumulus/Cargo.toml index d413ce2ca4ca3..a4a8f9663df5d 100644 --- a/bridges/primitives/chain-bridge-hub-cumulus/Cargo.toml +++ b/bridges/primitives/chain-bridge-hub-cumulus/Cargo.toml @@ -7,8 +7,6 @@ edition = "2021" license = "GPL-3.0-or-later WITH Classpath-exception-2.0" [dependencies] -smallvec = "1.10.0" - # Bridge Dependencies bp-polkadot-core = { path = "../../primitives/polkadot-core", default-features = false } @@ -23,15 +21,15 @@ sp-api = { git = "https://github.com/paritytech/substrate", branch = "master", d sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } # Polkadot Dependencies -polkadot-primitives = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" } -polkadot-runtime-constants = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" } +polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = "master", default-features = false } +polkadot-runtime-constants = { git = "https://github.com/paritytech/polkadot", branch = "master", default-features = false } [features] default = ["std"] std = [ "bp-polkadot-core/std", - "bp-messages/std", "bp-runtime/std", + "bp-messages/std", "frame-system/std", "frame-support/std", "sp-api/std", diff --git a/bridges/primitives/chain-bridge-hub-rococo/Cargo.toml b/bridges/primitives/chain-bridge-hub-rococo/Cargo.toml index 806587bb9a101..0cc57f3995906 100644 --- a/bridges/primitives/chain-bridge-hub-rococo/Cargo.toml +++ b/bridges/primitives/chain-bridge-hub-rococo/Cargo.toml @@ -7,8 +7,6 @@ edition = "2021" license = "GPL-3.0-or-later WITH Classpath-exception-2.0" [dependencies] -smallvec = "1.10.0" - # Bridge Dependencies bp-bridge-hub-cumulus = { path = "../chain-bridge-hub-cumulus", default-features = false } diff --git a/bridges/primitives/chain-bridge-hub-wococo/src/lib.rs b/bridges/primitives/chain-bridge-hub-wococo/src/lib.rs index e9a170223b995..e04ca3ff22806 100644 --- a/bridges/primitives/chain-bridge-hub-wococo/src/lib.rs +++ b/bridges/primitives/chain-bridge-hub-wococo/src/lib.rs @@ -16,13 +16,9 @@ //! Module with configuration which reflects BridgeHubWococo runtime setup //! (AccountId, Headers, Hashes...) -//! -//! but actually this is just reexported BridgeHubRococo stuff, because they are supposed to be -//! identical, at least uses the same parachain runtime #![cfg_attr(not(feature = "std"), no_std)] -// Re-export only what is really needed pub use bp_bridge_hub_cumulus::*; use bp_messages::*; use bp_runtime::{ diff --git a/bridges/primitives/header-chain/src/lib.rs b/bridges/primitives/header-chain/src/lib.rs index 9924366326450..dffa7f7dc6e0e 100644 --- a/bridges/primitives/header-chain/src/lib.rs +++ b/bridges/primitives/header-chain/src/lib.rs @@ -19,7 +19,7 @@ #![cfg_attr(not(feature = "std"), no_std)] -use bp_runtime::{BasicOperatingMode, Chain, HashOf, HasherOf, StorageProofChecker}; +use bp_runtime::{BasicOperatingMode, Chain, HashOf, HasherOf, HeaderOf, StorageProofChecker}; use codec::{Codec, Decode, Encode, EncodeLike, MaxEncodedLen}; use core::{clone::Clone, cmp::Eq, default::Default, fmt::Debug}; use frame_support::PalletError; @@ -169,3 +169,18 @@ impl ConsensusLogReader for GrandpaConsensusLogReader { GrandpaConsensusLogReader::::find_authorities_change(digest).is_some() } } + +/// A minimized version of `pallet-bridge-grandpa::Call` that can be used without a runtime. +#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)] +#[allow(non_camel_case_types)] +pub enum BridgeGrandpaCall { + /// `pallet-bridge-grandpa::Call::submit_finality_proof` + #[codec(index = 0)] + submit_finality_proof(Box
, justification::GrandpaJustification
), + /// `pallet-bridge-grandpa::Call::initialize` + #[codec(index = 1)] + initialize(InitializationData
), +} + +/// The `BridgeGrandpaCall` used by a chain. +pub type BridgeGrandpaCallOf = BridgeGrandpaCall>; diff --git a/bridges/primitives/messages/src/lib.rs b/bridges/primitives/messages/src/lib.rs index 8262586567f12..61d475cb46c1b 100644 --- a/bridges/primitives/messages/src/lib.rs +++ b/bridges/primitives/messages/src/lib.rs @@ -391,6 +391,18 @@ where relayers_rewards } +/// A minimized version of `pallet-bridge-messages::Call` that can be used without a runtime. +#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)] +#[allow(non_camel_case_types)] +pub enum BridgeMessagesCall { + /// `pallet-bridge-messages::Call::receive_messages_proof` + #[codec(index = 2)] + receive_messages_proof(AccountId, MessagesProof, u32, Weight), + /// `pallet-bridge-messages::Call::receive_messages_delivery_proof` + #[codec(index = 3)] + receive_messages_delivery_proof(MessagesDeliveryProof, UnrewardedRelayersState), +} + #[cfg(test)] mod tests { use super::*; diff --git a/bridges/primitives/parachains/src/lib.rs b/bridges/primitives/parachains/src/lib.rs index cafe40da05636..6b38d648d79d5 100644 --- a/bridges/primitives/parachains/src/lib.rs +++ b/bridges/primitives/parachains/src/lib.rs @@ -21,8 +21,8 @@ pub use bp_header_chain::StoredHeaderData; use bp_polkadot_core::{ - parachains::{ParaHash, ParaHead, ParaId}, - BlockNumber as RelayBlockNumber, + parachains::{ParaHash, ParaHead, ParaHeadsProof, ParaId}, + BlockNumber as RelayBlockNumber, Hash as RelayBlockHash, }; use bp_runtime::{ BlockNumberOf, Chain, HashOf, HeaderOf, Parachain, StorageDoubleMapKeyProvider, @@ -150,3 +150,16 @@ impl ParaStoredHeaderDataBuilder for C { None } } + +/// A minimized version of `pallet-bridge-parachains::Call` that can be used without a runtime. +#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)] +#[allow(non_camel_case_types)] +pub enum BridgeParachainCall { + /// `pallet-bridge-parachains::Call::submit_parachain_heads` + #[codec(index = 0)] + submit_parachain_heads( + (RelayBlockNumber, RelayBlockHash), + Vec<(ParaId, ParaHash)>, + ParaHeadsProof, + ), +} diff --git a/bridges/primitives/polkadot-core/src/lib.rs b/bridges/primitives/polkadot-core/src/lib.rs index 9e1f4b0452f9b..57025f2f3f697 100644 --- a/bridges/primitives/polkadot-core/src/lib.rs +++ b/bridges/primitives/polkadot-core/src/lib.rs @@ -20,7 +20,7 @@ use bp_messages::MessageNonce; use bp_runtime::{Chain, EncodedOrDecodedCall, StorageMapKeyProvider}; use codec::Compact; use frame_support::{ - dispatch::{DispatchClass, Dispatchable}, + dispatch::DispatchClass, parameter_types, weights::{ constants::{BlockExecutionWeight, WEIGHT_PER_SECOND}, @@ -29,7 +29,7 @@ use frame_support::{ Blake2_128Concat, RuntimeDebug, }; use frame_system::limits; -use scale_info::{StaticTypeInfo, TypeInfo}; +use scale_info::TypeInfo; use sp_core::{storage::StorageKey, Hasher as HasherT}; use sp_runtime::{ generic, @@ -194,7 +194,7 @@ pub type UncheckedExtrinsic = generic::UncheckedExtrinsic< AccountAddress, EncodedOrDecodedCall, Signature, - SignedExtensions, + SignedExtensions, >; /// Account address, used by the Polkadot-like chain. @@ -210,34 +210,18 @@ pub type AdditionalSigned = ((), u32, u32, Hash, Hash, (), (), ()); /// A simplified version of signed extensions meant for producing signed transactions /// and signed payload in the client code. -#[derive(PartialEq, Eq, Clone, RuntimeDebug, TypeInfo)] -pub struct SignedExtensions { +#[derive(codec::Encode, codec::Decode, PartialEq, Eq, Clone, RuntimeDebug, TypeInfo)] +pub struct SignedExtensions { encode_payload: SignedExtra, // It may be set to `None` if extensions are decoded. We are never reconstructing transactions // (and it makes no sense to do that) => decoded version of `SignedExtensions` is only used to // read fields of `encode_payload`. And when resigning transaction, we're reconstructing // `SignedExtensions` from the scratch. + #[codec(skip)] additional_signed: Option, - _data: sp_std::marker::PhantomData, } -impl codec::Encode for SignedExtensions { - fn using_encoded R>(&self, f: F) -> R { - self.encode_payload.using_encoded(f) - } -} - -impl codec::Decode for SignedExtensions { - fn decode(input: &mut I) -> Result { - SignedExtra::decode(input).map(|encode_payload| SignedExtensions { - encode_payload, - additional_signed: None, - _data: Default::default(), - }) - } -} - -impl SignedExtensions { +impl SignedExtensions { pub fn new( spec_version: u32, transaction_version: u32, @@ -267,12 +251,11 @@ impl SignedExtensions { (), (), )), - _data: Default::default(), } } } -impl SignedExtensions { +impl SignedExtensions { /// Return signer nonce, used to craft transaction. pub fn nonce(&self) -> Nonce { self.encode_payload.5.into() @@ -284,15 +267,11 @@ impl SignedExtensions { } } -impl sp_runtime::traits::SignedExtension for SignedExtensions -where - Call: codec::Codec + sp_std::fmt::Debug + Sync + Send + Clone + Eq + PartialEq + StaticTypeInfo, - Call: Dispatchable, -{ +impl sp_runtime::traits::SignedExtension for SignedExtensions { const IDENTIFIER: &'static str = "Not needed."; type AccountId = AccountId; - type Call = Call; + type Call = (); type AdditionalSigned = AdditionalSigned; type Pre = (); diff --git a/bridges/primitives/runtime/src/calls.rs b/bridges/primitives/runtime/src/calls.rs new file mode 100644 index 0000000000000..194c2126ba3b2 --- /dev/null +++ b/bridges/primitives/runtime/src/calls.rs @@ -0,0 +1,30 @@ +// Copyright 2019-2023 Parity Technologies (UK) Ltd. +// This file is part of Parity Bridges Common. + +// Parity Bridges Common is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Parity Bridges Common is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Parity Bridges Common. If not, see . + +//! Basic runtime calls. + +use codec::{Decode, Encode}; +use scale_info::TypeInfo; +use sp_std::vec::Vec; + +/// A minimized version of `frame-system::Call` that can be used without a runtime. +#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)] +#[allow(non_camel_case_types)] +pub enum SystemCall { + /// `frame-system::Call::remark` + #[codec(index = 1)] + remark(Vec), +} diff --git a/bridges/primitives/runtime/src/lib.rs b/bridges/primitives/runtime/src/lib.rs index 340088a85b122..4c3fb152fa736 100644 --- a/bridges/primitives/runtime/src/lib.rs +++ b/bridges/primitives/runtime/src/lib.rs @@ -47,6 +47,7 @@ pub use storage_types::BoundedStorageValue; #[cfg(feature = "std")] pub use storage_proof::craft_valid_storage_proof; +pub mod calls; pub mod messages; mod chain; diff --git a/bridges/relays/bin-substrate/Cargo.toml b/bridges/relays/bin-substrate/Cargo.toml index de1807cdc9708..c88b930cbb07b 100644 --- a/bridges/relays/bin-substrate/Cargo.toml +++ b/bridges/relays/bin-substrate/Cargo.toml @@ -26,6 +26,7 @@ bp-bridge-hub-rococo = { path = "../../primitives/chain-bridge-hub-rococo" } bp-bridge-hub-wococo = { path = "../../primitives/chain-bridge-hub-wococo" } bp-header-chain = { path = "../../primitives/header-chain" } bp-messages = { path = "../../primitives/messages" } +bp-parachains = { path = "../../primitives/parachains" } bp-millau = { path = "../../primitives/chain-millau" } bp-polkadot-core = { path = "../../primitives/polkadot-core" } bp-rialto = { path = "../../primitives/chain-rialto" } diff --git a/bridges/relays/bin-substrate/src/chains/rococo_headers_to_bridge_hub_wococo.rs b/bridges/relays/bin-substrate/src/chains/rococo_headers_to_bridge_hub_wococo.rs index 2fac858336d92..6cdae2b212b59 100644 --- a/bridges/relays/bin-substrate/src/chains/rococo_headers_to_bridge_hub_wococo.rs +++ b/bridges/relays/bin-substrate/src/chains/rococo_headers_to_bridge_hub_wococo.rs @@ -33,7 +33,7 @@ substrate_relay_helper::generate_mocked_submit_finality_proof_call_builder!( RococoFinalityToBridgeHubWococo, RococoFinalityToBridgeHubWococoCallBuilder, relay_bridge_hub_wococo_client::runtime::Call::BridgeRococoGrandpa, - relay_bridge_hub_wococo_client::runtime::BridgeGrandpaRococoCall::submit_finality_proof + relay_bridge_hub_wococo_client::runtime::BridgeRococoGrandpaCall::submit_finality_proof ); #[async_trait] diff --git a/bridges/relays/bin-substrate/src/chains/wococo_parachains_to_bridge_hub_rococo.rs b/bridges/relays/bin-substrate/src/chains/wococo_parachains_to_bridge_hub_rococo.rs index f821af1a0cfd9..f79979ff8328b 100644 --- a/bridges/relays/bin-substrate/src/chains/wococo_parachains_to_bridge_hub_rococo.rs +++ b/bridges/relays/bin-substrate/src/chains/wococo_parachains_to_bridge_hub_rococo.rs @@ -51,7 +51,7 @@ impl SubmitParachainHeadsCallBuilder parachain_heads_proof: ParaHeadsProof, ) -> CallOf { relay_bridge_hub_rococo_client::runtime::Call::BridgeWococoParachain( - relay_bridge_hub_rococo_client::runtime::BridgeParachainCall::submit_parachain_heads( + bp_parachains::BridgeParachainCall::submit_parachain_heads( (at_relay_block.0, at_relay_block.1), parachains, parachain_heads_proof, diff --git a/bridges/relays/bin-substrate/src/cli/init_bridge.rs b/bridges/relays/bin-substrate/src/cli/init_bridge.rs index cadc6be4df23f..322cca1bef52c 100644 --- a/bridges/relays/bin-substrate/src/cli/init_bridge.rs +++ b/bridges/relays/bin-substrate/src/cli/init_bridge.rs @@ -176,7 +176,7 @@ impl BridgeInitializer for RococoToBridgeHubWococoCliBridge { init_data: >::InitializationData, ) -> ::Call { relay_bridge_hub_wococo_client::runtime::Call::BridgeRococoGrandpa( - relay_bridge_hub_wococo_client::runtime::BridgeGrandpaRococoCall::initialize(init_data), + relay_bridge_hub_wococo_client::runtime::BridgeRococoGrandpaCall::initialize(init_data), ) } } diff --git a/bridges/relays/client-bridge-hub-rococo/Cargo.toml b/bridges/relays/client-bridge-hub-rococo/Cargo.toml index 4a01d81e7771f..6872c59f7602b 100644 --- a/bridges/relays/client-bridge-hub-rococo/Cargo.toml +++ b/bridges/relays/client-bridge-hub-rococo/Cargo.toml @@ -16,14 +16,13 @@ bp-bridge-hub-rococo = { path = "../../primitives/chain-bridge-hub-rococo" } bp-bridge-hub-wococo = { path = "../../primitives/chain-bridge-hub-wococo" } bp-header-chain = { path = "../../primitives/header-chain" } bp-messages = { path = "../../primitives/messages" } -bp-polkadot-core = { path = "../../primitives/polkadot-core" } +bp-parachains = { path = "../../primitives/parachains" } +bp-rococo = { path = "../../primitives/chain-rococo" } bp-runtime = { path = "../../primitives/runtime" } +bp-wococo = { path = "../../primitives/chain-wococo" } bridge-runtime-common = { path = "../../bin/runtime-common" } # Substrate Dependencies sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master" } - -[dev-dependencies] -sp-finality-grandpa = { git = "https://github.com/paritytech/substrate", branch = "master" } diff --git a/bridges/relays/client-bridge-hub-rococo/src/lib.rs b/bridges/relays/client-bridge-hub-rococo/src/lib.rs index 7e9047e32ce59..08a9e688487e0 100644 --- a/bridges/relays/client-bridge-hub-rococo/src/lib.rs +++ b/bridges/relays/client-bridge-hub-rococo/src/lib.rs @@ -132,8 +132,10 @@ mod tests { #[test] fn parse_transaction_works() { let unsigned = UnsignedTransaction { - call: runtime::Call::System(runtime::SystemCall::remark(b"Hello world!".to_vec())) - .into(), + call: runtime::Call::System(bp_runtime::calls::SystemCall::remark( + b"Hello world!".to_vec(), + )) + .into(), nonce: 777, tip: 888, era: TransactionEra::immortal(), diff --git a/bridges/relays/client-bridge-hub-rococo/src/runtime_wrapper.rs b/bridges/relays/client-bridge-hub-rococo/src/runtime_wrapper.rs index 0571f82f5a6cb..d973bb3bea576 100644 --- a/bridges/relays/client-bridge-hub-rococo/src/runtime_wrapper.rs +++ b/bridges/relays/client-bridge-hub-rococo/src/runtime_wrapper.rs @@ -18,201 +18,48 @@ //! Types that are specific to the BridgeHubRococo runtime. -use bp_polkadot_core::PolkadotLike; use codec::{Decode, Encode}; use scale_info::TypeInfo; -use bp_messages::UnrewardedRelayersState; -use bp_polkadot_core::parachains::{ParaHash, ParaHeadsProof, ParaId}; -use bp_runtime::Chain; +pub use bp_header_chain::BridgeGrandpaCallOf; +pub use bp_parachains::BridgeParachainCall; +pub use bp_runtime::calls::SystemCall; +pub use bridge_runtime_common::messages::BridgeMessagesCallOf; // TODO:check-parameter - check SignedExtension /// Unchecked BridgeHubRococo extrinsic. pub type UncheckedExtrinsic = bp_bridge_hub_rococo::UncheckedExtrinsic; -/// Rococo Runtime `Call` enum. +// The indirect pallet call used to sync `Wococo` GRANDPA finality to `BHRococo`. +pub type BridgeWococoGrandpaCall = BridgeGrandpaCallOf; +// The indirect pallet call used to sync `BridgeHubWococo` messages to `BHRococo`. +pub type BridgeWococoMessagesCall = BridgeMessagesCallOf; + +/// `BridgeHubRococo` Runtime `Call` enum. /// -/// The enum represents a subset of possible `Call`s we can send to Rococo chain. +/// The enum represents a subset of possible `Call`s we can send to `BridgeHubRococo` chain. /// Ideally this code would be auto-generated from metadata, because we want to /// avoid depending directly on the ENTIRE runtime just to get the encoding of `Dispatchable`s. /// -/// All entries here (like pretty much in the entire file) must be kept in sync with Rococo -/// `construct_runtime`, so that we maintain SCALE-compatibility. +/// All entries here (like pretty much in the entire file) must be kept in sync with +/// `BridgeHubRococo` `construct_runtime`, so that we maintain SCALE-compatibility. /// -/// // TODO:check-parameter -> change bko-bridge-rococo-wococo when merged to master in cumulus -/// See: [link](https://github.com/paritytech/cumulus/blob/bko-bridge-rococo-wococo/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs) +/// // TODO:check-parameter -> change bridge-hub-rococo-wococo when merged to master in cumulus +/// See: [link](https://github.com/paritytech/cumulus/blob/bridge-hub-rococo-wococo/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs) #[allow(clippy::large_enum_variant)] #[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)] pub enum Call { - /// System pallet. + #[cfg(test)] #[codec(index = 0)] System(SystemCall), + /// Wococo bridge pallet. #[codec(index = 41)] BridgeWococoGrandpa(BridgeWococoGrandpaCall), - /// Rococo bridge pallet. - #[codec(index = 43)] - BridgeRococoGrandpa(BridgeRococoGrandpaCall), - /// Wococo parachain bridge pallet. #[codec(index = 42)] BridgeWococoParachain(BridgeParachainCall), - /// Rococo parachain bridge pallet. - #[codec(index = 44)] - BridgeRococoParachain(BridgeParachainCall), - /// Wococo messages bridge pallet. #[codec(index = 46)] BridgeWococoMessages(BridgeWococoMessagesCall), - /// Rococo messages bridge pallet. - #[codec(index = 45)] - BridgeRococoMessages(BridgeRococoMessagesCall), -} - -#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)] -#[allow(non_camel_case_types)] -pub enum SystemCall { - #[codec(index = 1)] - remark(Vec), -} - -#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)] -#[allow(non_camel_case_types)] -pub enum BridgeWococoGrandpaCall { - #[codec(index = 0)] - submit_finality_proof( - Box<::Header>, - bp_header_chain::justification::GrandpaJustification<::Header>, - ), - #[codec(index = 1)] - initialize(bp_header_chain::InitializationData<::Header>), -} - -#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)] -#[allow(non_camel_case_types)] -pub enum BridgeRococoGrandpaCall { - #[codec(index = 0)] - submit_finality_proof( - Box<::Header>, - bp_header_chain::justification::GrandpaJustification<::Header>, - ), - #[codec(index = 1)] - initialize(bp_header_chain::InitializationData<::Header>), -} - -pub type RelayBlockHash = bp_polkadot_core::Hash; -pub type RelayBlockNumber = bp_polkadot_core::BlockNumber; - -#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)] -#[allow(non_camel_case_types)] -pub enum BridgeParachainCall { - #[codec(index = 0)] - submit_parachain_heads( - (RelayBlockNumber, RelayBlockHash), - Vec<(ParaId, ParaHash)>, - ParaHeadsProof, - ), -} - -#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)] -#[allow(non_camel_case_types)] -pub enum BridgeWococoMessagesCall { - #[codec(index = 2)] - receive_messages_proof( - relay_substrate_client::AccountIdOf, - bridge_runtime_common::messages::target::FromBridgedChainMessagesProof< - relay_substrate_client::HashOf, - >, - u32, - bp_messages::Weight, - ), - - #[codec(index = 3)] - receive_messages_delivery_proof( - bridge_runtime_common::messages::source::FromBridgedChainMessagesDeliveryProof< - relay_substrate_client::HashOf, - >, - UnrewardedRelayersState, - ), -} - -#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)] -#[allow(non_camel_case_types)] -pub enum BridgeRococoMessagesCall { - #[codec(index = 2)] - receive_messages_proof( - relay_substrate_client::AccountIdOf, - bridge_runtime_common::messages::target::FromBridgedChainMessagesProof< - relay_substrate_client::HashOf, - >, - u32, - bp_messages::Weight, - ), - - #[codec(index = 3)] - receive_messages_delivery_proof( - bridge_runtime_common::messages::source::FromBridgedChainMessagesDeliveryProof< - relay_substrate_client::HashOf, - >, - UnrewardedRelayersState, - ), -} - -impl sp_runtime::traits::Dispatchable for Call { - type RuntimeOrigin = (); - type Config = (); - type Info = (); - type PostInfo = (); - - fn dispatch( - self, - _origin: Self::RuntimeOrigin, - ) -> sp_runtime::DispatchResultWithInfo { - unimplemented!("The Call is not expected to be dispatched.") - } -} - -#[cfg(test)] -mod tests { - use super::*; - use bp_runtime::BasicOperatingMode; - use sp_core::hexdisplay::HexDisplay; - use sp_finality_grandpa::AuthorityList; - use sp_runtime::traits::Header; - use std::str::FromStr; - - pub type RelayBlockHasher = bp_polkadot_core::Hasher; - pub type RelayBlockHeader = sp_runtime::generic::Header; - - #[test] - fn encode_decode_calls() { - let header = RelayBlockHeader::new( - 75, - bp_polkadot_core::Hash::from_str( - "0xd2c0afaab32de0cb8f7f0d89217e37c5ea302c1ffb5a7a83e10d20f12c32874d", - ) - .expect("invalid value"), - bp_polkadot_core::Hash::from_str( - "0x92b965f0656a4e0e5fc0167da2d4b5ee72b3be2c1583c4c1e5236c8c12aa141b", - ) - .expect("invalid value"), - bp_polkadot_core::Hash::from_str( - "0xae4a25acf250d72ed02c149ecc7dd3c9ee976d41a2888fc551de8064521dc01d", - ) - .expect("invalid value"), - Default::default(), - ); - let init_data = bp_header_chain::InitializationData { - header: Box::new(header), - authority_list: AuthorityList::default(), - set_id: 6, - operating_mode: BasicOperatingMode::Normal, - }; - let call = BridgeRococoGrandpaCall::initialize(init_data); - let tx = Call::BridgeRococoGrandpa(call); - - // encode call as hex string - let hex_encoded_call = format!("0x{:?}", HexDisplay::from(&Encode::encode(&tx))); - assert_eq!(hex_encoded_call, "0x2b01ae4a25acf250d72ed02c149ecc7dd3c9ee976d41a2888fc551de8064521dc01d2d0192b965f0656a4e0e5fc0167da2d4b5ee72b3be2c1583c4c1e5236c8c12aa141bd2c0afaab32de0cb8f7f0d89217e37c5ea302c1ffb5a7a83e10d20f12c32874d0000060000000000000000"); - } } diff --git a/bridges/relays/client-bridge-hub-wococo/Cargo.toml b/bridges/relays/client-bridge-hub-wococo/Cargo.toml index fa28dfde202aa..7c9b90975d6ba 100644 --- a/bridges/relays/client-bridge-hub-wococo/Cargo.toml +++ b/bridges/relays/client-bridge-hub-wococo/Cargo.toml @@ -12,11 +12,21 @@ relay-substrate-client = { path = "../client-substrate" } # Bridge dependencies +bp-bridge-hub-rococo = { path = "../../primitives/chain-bridge-hub-rococo" } bp-bridge-hub-wococo = { path = "../../primitives/chain-bridge-hub-wococo" } +bp-header-chain = { path = "../../primitives/header-chain" } bp-messages = { path = "../../primitives/messages" } -relay-bridge-hub-rococo-client = { path = "../client-bridge-hub-rococo" } +bp-parachains = { path = "../../primitives/parachains" } +bp-rococo = { path = "../../primitives/chain-rococo" } +bp-runtime = { path = "../../primitives/runtime" } + +bridge-runtime-common = { path = "../../bin/runtime-common" } # Substrate Dependencies sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master" } + +[dev-dependencies] +bp-polkadot-core = { path = "../../primitives/polkadot-core" } +sp-finality-grandpa = { git = "https://github.com/paritytech/substrate", branch = "master" } diff --git a/bridges/relays/client-bridge-hub-wococo/src/runtime_wrapper.rs b/bridges/relays/client-bridge-hub-wococo/src/runtime_wrapper.rs index 05176af471a9b..c7a92ef9ba445 100644 --- a/bridges/relays/client-bridge-hub-wococo/src/runtime_wrapper.rs +++ b/bridges/relays/client-bridge-hub-wococo/src/runtime_wrapper.rs @@ -16,11 +16,94 @@ //! Types that are specific to the BridgeHubWococo runtime. -// We reuse everything from rococo runtime wrapper -pub type Call = relay_bridge_hub_rococo_client::runtime::Call; +use codec::{Decode, Encode}; +use scale_info::TypeInfo; + +pub use bp_header_chain::BridgeGrandpaCallOf; +pub use bp_parachains::BridgeParachainCall; +pub use bp_runtime::calls::SystemCall; +pub use bridge_runtime_common::messages::BridgeMessagesCallOf; + +// TODO:check-parameter - check SignedExtension +/// Unchecked BridgeHubWococo extrinsic. pub type UncheckedExtrinsic = bp_bridge_hub_wococo::UncheckedExtrinsic; -pub type BridgeGrandpaRococoCall = relay_bridge_hub_rococo_client::runtime::BridgeRococoGrandpaCall; -pub type BridgeParachainCall = relay_bridge_hub_rococo_client::runtime::BridgeParachainCall; -pub type BridgeRococoMessagesCall = - relay_bridge_hub_rococo_client::runtime::BridgeRococoMessagesCall; -pub type SystemCall = relay_bridge_hub_rococo_client::runtime::SystemCall; + +// The indirect pallet call used to sync `Rococo` GRANDPA finality to `BHWococo`. +pub type BridgeRococoGrandpaCall = BridgeGrandpaCallOf; +// The indirect pallet call used to sync `BridgeHubRococo` messages to `BridgeHubWococo`. +pub type BridgeRococoMessagesCall = BridgeMessagesCallOf; + +/// `BridgeHubWococo` Runtime `Call` enum. +/// +/// The enum represents a subset of possible `Call`s we can send to `BridgeHubWococo` chain. +/// Ideally this code would be auto-generated from metadata, because we want to +/// avoid depending directly on the ENTIRE runtime just to get the encoding of `Dispatchable`s. +/// +/// All entries here (like pretty much in the entire file) must be kept in sync with +/// `BridgeHubWococo` `construct_runtime`, so that we maintain SCALE-compatibility. +/// +/// TODO:check-parameter -> change bridge-hub-rococo-wococo when merged to master in cumulus +/// See: [link](https://github.com/paritytech/cumulus/blob/bridge-hub-rococo-wococo/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs) +#[allow(clippy::large_enum_variant)] +#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)] +pub enum Call { + #[cfg(test)] + #[codec(index = 0)] + System(SystemCall), + + /// Rococo bridge pallet. + #[codec(index = 43)] + BridgeRococoGrandpa(BridgeRococoGrandpaCall), + /// Rococo parachain bridge pallet. + #[codec(index = 44)] + BridgeRococoParachain(BridgeParachainCall), + /// Rococo messages bridge pallet. + #[codec(index = 45)] + BridgeRococoMessages(BridgeRococoMessagesCall), +} + +#[cfg(test)] +mod tests { + use super::*; + use bp_runtime::BasicOperatingMode; + use sp_core::hexdisplay::HexDisplay; + use sp_finality_grandpa::AuthorityList; + use sp_runtime::traits::Header; + use std::str::FromStr; + + pub type RelayBlockNumber = bp_polkadot_core::BlockNumber; + pub type RelayBlockHasher = bp_polkadot_core::Hasher; + pub type RelayBlockHeader = sp_runtime::generic::Header; + + #[test] + fn encode_decode_calls() { + let header = RelayBlockHeader::new( + 75, + bp_polkadot_core::Hash::from_str( + "0xd2c0afaab32de0cb8f7f0d89217e37c5ea302c1ffb5a7a83e10d20f12c32874d", + ) + .expect("invalid value"), + bp_polkadot_core::Hash::from_str( + "0x92b965f0656a4e0e5fc0167da2d4b5ee72b3be2c1583c4c1e5236c8c12aa141b", + ) + .expect("invalid value"), + bp_polkadot_core::Hash::from_str( + "0xae4a25acf250d72ed02c149ecc7dd3c9ee976d41a2888fc551de8064521dc01d", + ) + .expect("invalid value"), + Default::default(), + ); + let init_data = bp_header_chain::InitializationData { + header: Box::new(header), + authority_list: AuthorityList::default(), + set_id: 6, + operating_mode: BasicOperatingMode::Normal, + }; + let call = BridgeRococoGrandpaCall::initialize(init_data); + let tx = Call::BridgeRococoGrandpa(call); + + // encode call as hex string + let hex_encoded_call = format!("0x{:?}", HexDisplay::from(&Encode::encode(&tx))); + assert_eq!(hex_encoded_call, "0x2b01ae4a25acf250d72ed02c149ecc7dd3c9ee976d41a2888fc551de8064521dc01d2d0192b965f0656a4e0e5fc0167da2d4b5ee72b3be2c1583c4c1e5236c8c12aa141bd2c0afaab32de0cb8f7f0d89217e37c5ea302c1ffb5a7a83e10d20f12c32874d0000060000000000000000"); + } +} diff --git a/bridges/relays/client-substrate/src/chain.rs b/bridges/relays/client-substrate/src/chain.rs index c199540cbfb31..db08fc1f98ce1 100644 --- a/bridges/relays/client-substrate/src/chain.rs +++ b/bridges/relays/client-substrate/src/chain.rs @@ -26,7 +26,7 @@ use sc_transaction_pool_api::TransactionStatus; use sp_core::{storage::StorageKey, Pair}; use sp_runtime::{ generic::SignedBlock, - traits::{Block as BlockT, Dispatchable, Member}, + traits::{Block as BlockT, Member}, ConsensusEngineId, EncodedJustification, }; use std::{fmt::Debug, time::Duration}; @@ -56,7 +56,7 @@ pub trait Chain: ChainBase + Clone { /// Block type. type SignedBlock: Member + Serialize + DeserializeOwned + BlockWithJustification; /// The aggregated `Call` type. - type Call: Clone + Codec + Dispatchable + Debug + Send; + type Call: Clone + Codec + Debug + Send; } /// Substrate-based relay chain that supports parachains. diff --git a/bridges/relays/lib-substrate-relay/src/on_demand/headers.rs b/bridges/relays/lib-substrate-relay/src/on_demand/headers.rs index 465b03c04a4a4..75b402aff8732 100644 --- a/bridges/relays/lib-substrate-relay/src/on_demand/headers.rs +++ b/bridges/relays/lib-substrate-relay/src/on_demand/headers.rs @@ -316,7 +316,7 @@ async fn background_task( stall_timeout, only_mandatory_headers, }, - metrics_params.clone().unwrap_or_else(|| MetricsParams::disabled()), + metrics_params.clone().unwrap_or_else(MetricsParams::disabled), futures::future::pending(), ) .fuse(),