From 6a0e432f283e7f334945a4e8fe0c614232bb2fad Mon Sep 17 00:00:00 2001 From: Svyatoslav Nikolsky Date: Mon, 20 Feb 2023 11:27:39 +0300 Subject: [PATCH] use complex transactions on RBH/WBH bridge hubs (#1893) --- ..._hub_rococo_messages_to_bridge_hub_wococo.rs | 6 +++--- ..._hub_wococo_messages_to_bridge_hub_rococo.rs | 6 +++--- .../relays/client-bridge-hub-rococo/src/lib.rs | 9 +++++++-- .../src/runtime_wrapper.rs | 11 ++++++++++- .../relays/client-bridge-hub-wococo/src/lib.rs | 9 +++++++-- .../src/runtime_wrapper.rs | 11 ++++++++++- bridges/relays/client-substrate/src/calls.rs | 9 +++++++++ bridges/relays/client-substrate/src/chain.rs | 17 +++++++++++++++++ bridges/relays/client-substrate/src/lib.rs | 4 ++-- 9 files changed, 68 insertions(+), 14 deletions(-) diff --git a/bridges/relays/bin-substrate/src/chains/bridge_hub_rococo_messages_to_bridge_hub_wococo.rs b/bridges/relays/bin-substrate/src/chains/bridge_hub_rococo_messages_to_bridge_hub_wococo.rs index b48ace58987d1..9e4b5b15fd6d4 100644 --- a/bridges/relays/bin-substrate/src/chains/bridge_hub_rococo_messages_to_bridge_hub_wococo.rs +++ b/bridges/relays/bin-substrate/src/chains/bridge_hub_rococo_messages_to_bridge_hub_wococo.rs @@ -19,7 +19,7 @@ use crate::cli::bridge::{CliBridgeBase, MessagesCliBridge}; use relay_bridge_hub_rococo_client::BridgeHubRococo; use relay_bridge_hub_wococo_client::BridgeHubWococo; -use substrate_relay_helper::messages_lane::SubstrateMessageLane; +use substrate_relay_helper::{messages_lane::SubstrateMessageLane, UtilityPalletBatchCallBuilder}; pub struct BridgeHubRococoToBridgeHubWococoMessagesCliBridge {} @@ -59,6 +59,6 @@ impl SubstrateMessageLane for BridgeHubRococoMessagesToBridgeHubWococoMessageLan type ReceiveMessagesDeliveryProofCallBuilder = BridgeHubRococoMessagesToBridgeHubWococoMessageLaneReceiveMessagesDeliveryProofCallBuilder; - type SourceBatchCallBuilder = (); - type TargetBatchCallBuilder = (); + type SourceBatchCallBuilder = UtilityPalletBatchCallBuilder; + type TargetBatchCallBuilder = UtilityPalletBatchCallBuilder; } diff --git a/bridges/relays/bin-substrate/src/chains/bridge_hub_wococo_messages_to_bridge_hub_rococo.rs b/bridges/relays/bin-substrate/src/chains/bridge_hub_wococo_messages_to_bridge_hub_rococo.rs index 3bcf62de333ad..fb5a81c021e19 100644 --- a/bridges/relays/bin-substrate/src/chains/bridge_hub_wococo_messages_to_bridge_hub_rococo.rs +++ b/bridges/relays/bin-substrate/src/chains/bridge_hub_wococo_messages_to_bridge_hub_rococo.rs @@ -19,7 +19,7 @@ use crate::cli::bridge::{CliBridgeBase, MessagesCliBridge}; use relay_bridge_hub_rococo_client::BridgeHubRococo; use relay_bridge_hub_wococo_client::BridgeHubWococo; -use substrate_relay_helper::messages_lane::SubstrateMessageLane; +use substrate_relay_helper::{messages_lane::SubstrateMessageLane, UtilityPalletBatchCallBuilder}; pub struct BridgeHubWococoToBridgeHubRococoMessagesCliBridge {} @@ -59,6 +59,6 @@ impl SubstrateMessageLane for BridgeHubWococoMessagesToBridgeHubRococoMessageLan type ReceiveMessagesDeliveryProofCallBuilder = BridgeHubWococoMessagesToBridgeHubRococoMessageLaneReceiveMessagesDeliveryProofCallBuilder; - type SourceBatchCallBuilder = (); - type TargetBatchCallBuilder = (); + type SourceBatchCallBuilder = UtilityPalletBatchCallBuilder; + type TargetBatchCallBuilder = UtilityPalletBatchCallBuilder; } diff --git a/bridges/relays/client-bridge-hub-rococo/src/lib.rs b/bridges/relays/client-bridge-hub-rococo/src/lib.rs index 80c075cd0d5fd..d2e421423a5a8 100644 --- a/bridges/relays/client-bridge-hub-rococo/src/lib.rs +++ b/bridges/relays/client-bridge-hub-rococo/src/lib.rs @@ -21,8 +21,9 @@ use bp_bridge_hub_wococo::PolkadotSignedExtension; use bp_messages::MessageNonce; use codec::Encode; use relay_substrate_client::{ - Chain, ChainWithBalances, ChainWithMessages, ChainWithTransactions, Error as SubstrateError, - SignParam, UnderlyingChainProvider, UnsignedTransaction, + Chain, ChainWithBalances, ChainWithMessages, ChainWithTransactions, ChainWithUtilityPallet, + Error as SubstrateError, MockedRuntimeUtilityPallet, SignParam, UnderlyingChainProvider, + UnsignedTransaction, }; use sp_core::{storage::StorageKey, Pair}; use sp_runtime::{generic::SignedPayload, traits::IdentifyAccount}; @@ -57,6 +58,10 @@ impl ChainWithBalances for BridgeHubRococo { } } +impl ChainWithUtilityPallet for BridgeHubRococo { + type UtilityPallet = MockedRuntimeUtilityPallet; +} + impl ChainWithTransactions for BridgeHubRococo { type AccountKeyPair = sp_core::sr25519::Pair; type SignedTransaction = runtime::UncheckedExtrinsic; 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 7f526a35aa941..fc945d8c95072 100644 --- a/bridges/relays/client-bridge-hub-rococo/src/runtime_wrapper.rs +++ b/bridges/relays/client-bridge-hub-rococo/src/runtime_wrapper.rs @@ -25,7 +25,7 @@ use bp_bridge_hub_rococo::SignedExtension; pub use bp_header_chain::BridgeGrandpaCallOf; pub use bp_parachains::BridgeParachainCall; pub use bridge_runtime_common::messages::BridgeMessagesCallOf; -pub use relay_substrate_client::calls::SystemCall; +pub use relay_substrate_client::calls::{SystemCall, UtilityCall}; /// Unchecked BridgeHubRococo extrinsic. pub type UncheckedExtrinsic = bp_bridge_hub_rococo::UncheckedExtrinsic; @@ -49,6 +49,9 @@ pub enum Call { #[cfg(test)] #[codec(index = 0)] System(SystemCall), + /// Utility pallet. + #[codec(index = 40)] + Utility(UtilityCall), /// Wococo bridge pallet. #[codec(index = 41)] @@ -60,3 +63,9 @@ pub enum Call { #[codec(index = 46)] BridgeWococoMessages(BridgeWococoMessagesCall), } + +impl From> for Call { + fn from(call: UtilityCall) -> Call { + Call::Utility(call) + } +} diff --git a/bridges/relays/client-bridge-hub-wococo/src/lib.rs b/bridges/relays/client-bridge-hub-wococo/src/lib.rs index 7af310bfd4176..2c211ae86cf44 100644 --- a/bridges/relays/client-bridge-hub-wococo/src/lib.rs +++ b/bridges/relays/client-bridge-hub-wococo/src/lib.rs @@ -20,8 +20,9 @@ use bp_bridge_hub_wococo::{PolkadotSignedExtension, AVERAGE_BLOCK_INTERVAL}; use bp_messages::MessageNonce; use codec::Encode; use relay_substrate_client::{ - Chain, ChainWithBalances, ChainWithMessages, ChainWithTransactions, Error as SubstrateError, - SignParam, UnderlyingChainProvider, UnsignedTransaction, + Chain, ChainWithBalances, ChainWithMessages, ChainWithTransactions, ChainWithUtilityPallet, + Error as SubstrateError, MockedRuntimeUtilityPallet, SignParam, UnderlyingChainProvider, + UnsignedTransaction, }; use sp_core::{storage::StorageKey, Pair}; use sp_runtime::{generic::SignedPayload, traits::IdentifyAccount}; @@ -56,6 +57,10 @@ impl ChainWithBalances for BridgeHubWococo { } } +impl ChainWithUtilityPallet for BridgeHubWococo { + type UtilityPallet = MockedRuntimeUtilityPallet; +} + impl ChainWithTransactions for BridgeHubWococo { type AccountKeyPair = sp_core::sr25519::Pair; type SignedTransaction = runtime::UncheckedExtrinsic; 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 17cc4cbd4e8f8..c16e7d1a45bce 100644 --- a/bridges/relays/client-bridge-hub-wococo/src/runtime_wrapper.rs +++ b/bridges/relays/client-bridge-hub-wococo/src/runtime_wrapper.rs @@ -23,7 +23,7 @@ use bp_bridge_hub_wococo::SignedExtension; pub use bp_header_chain::BridgeGrandpaCallOf; pub use bp_parachains::BridgeParachainCall; pub use bridge_runtime_common::messages::BridgeMessagesCallOf; -pub use relay_substrate_client::calls::SystemCall; +pub use relay_substrate_client::calls::{SystemCall, UtilityCall}; /// Unchecked BridgeHubWococo extrinsic. pub type UncheckedExtrinsic = bp_bridge_hub_wococo::UncheckedExtrinsic; @@ -47,6 +47,9 @@ pub enum Call { #[cfg(test)] #[codec(index = 0)] System(SystemCall), + /// Utility pallet. + #[codec(index = 40)] + Utility(UtilityCall), /// Rococo bridge pallet. #[codec(index = 43)] @@ -59,6 +62,12 @@ pub enum Call { BridgeRococoMessages(BridgeRococoMessagesCall), } +impl From> for Call { + fn from(call: UtilityCall) -> Call { + Call::Utility(call) + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/bridges/relays/client-substrate/src/calls.rs b/bridges/relays/client-substrate/src/calls.rs index 89fc49a209aeb..4e0ae9d99d2e6 100644 --- a/bridges/relays/client-substrate/src/calls.rs +++ b/bridges/relays/client-substrate/src/calls.rs @@ -31,6 +31,15 @@ pub enum SystemCall { remark(Vec), } +/// A minimized version of `pallet-utility::Call` that can be used without a runtime. +#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)] +#[allow(non_camel_case_types)] +pub enum UtilityCall { + /// `pallet-utility::Call::batch_all` + #[codec(index = 2)] + batch_all(Vec), +} + /// A minimized version of `pallet-sudo::Call` that can be used without a runtime. #[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)] #[allow(non_camel_case_types)] diff --git a/bridges/relays/client-substrate/src/chain.rs b/bridges/relays/client-substrate/src/chain.rs index b9c5793842efd..ebd9e7172d895 100644 --- a/bridges/relays/client-substrate/src/chain.rs +++ b/bridges/relays/client-substrate/src/chain.rs @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Parity Bridges Common. If not, see . +use crate::calls::UtilityCall; + use bp_messages::MessageNonce; use bp_runtime::{ Chain as ChainBase, EncodedOrDecodedCall, HashOf, Parachain as ParachainBase, TransactionEra, @@ -276,6 +278,21 @@ where } } +/// Structure that implements `UtilityPalletProvider` based on a call conversion. +pub struct MockedRuntimeUtilityPallet { + _phantom: std::marker::PhantomData, +} + +impl UtilityPallet for MockedRuntimeUtilityPallet +where + C: Chain, + C::Call: From>, +{ + fn build_batch_call(calls: Vec) -> C::Call { + UtilityCall::batch_all(calls).into() + } +} + /// Substrate-based chain that uses `pallet-utility`. pub trait ChainWithUtilityPallet: Chain { /// The utility pallet provider. diff --git a/bridges/relays/client-substrate/src/lib.rs b/bridges/relays/client-substrate/src/lib.rs index c1a96c487c4b7..c8d8b6f8129f9 100644 --- a/bridges/relays/client-substrate/src/lib.rs +++ b/bridges/relays/client-substrate/src/lib.rs @@ -36,8 +36,8 @@ pub use crate::{ chain::{ AccountKeyPairOf, BlockWithJustification, CallOf, Chain, ChainWithBalances, ChainWithGrandpa, ChainWithMessages, ChainWithTransactions, ChainWithUtilityPallet, - FullRuntimeUtilityPallet, Parachain, RelayChain, SignParam, TransactionStatusOf, - UnsignedTransaction, UtilityPallet, + FullRuntimeUtilityPallet, MockedRuntimeUtilityPallet, Parachain, RelayChain, SignParam, + TransactionStatusOf, UnsignedTransaction, UtilityPallet, }, client::{ is_ancient_block, ChainRuntimeVersion, Client, OpaqueGrandpaAuthoritiesSet,