Skip to content

Commit

Permalink
use complex transactions on RBH/WBH bridge hubs (#1893)
Browse files Browse the repository at this point in the history
  • Loading branch information
svyatonik authored and bkchr committed Apr 10, 2024
1 parent 976e966 commit bb078b8
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

Expand Down Expand Up @@ -59,6 +59,6 @@ impl SubstrateMessageLane for BridgeHubRococoMessagesToBridgeHubWococoMessageLan
type ReceiveMessagesDeliveryProofCallBuilder =
BridgeHubRococoMessagesToBridgeHubWococoMessageLaneReceiveMessagesDeliveryProofCallBuilder;

type SourceBatchCallBuilder = ();
type TargetBatchCallBuilder = ();
type SourceBatchCallBuilder = UtilityPalletBatchCallBuilder<BridgeHubRococo>;
type TargetBatchCallBuilder = UtilityPalletBatchCallBuilder<BridgeHubWococo>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

Expand Down Expand Up @@ -59,6 +59,6 @@ impl SubstrateMessageLane for BridgeHubWococoMessagesToBridgeHubRococoMessageLan
type ReceiveMessagesDeliveryProofCallBuilder =
BridgeHubWococoMessagesToBridgeHubRococoMessageLaneReceiveMessagesDeliveryProofCallBuilder;

type SourceBatchCallBuilder = ();
type TargetBatchCallBuilder = ();
type SourceBatchCallBuilder = UtilityPalletBatchCallBuilder<BridgeHubWococo>;
type TargetBatchCallBuilder = UtilityPalletBatchCallBuilder<BridgeHubRococo>;
}
9 changes: 7 additions & 2 deletions bridges/relays/client-bridge-hub-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -57,6 +58,10 @@ impl ChainWithBalances for BridgeHubRococo {
}
}

impl ChainWithUtilityPallet for BridgeHubRococo {
type UtilityPallet = MockedRuntimeUtilityPallet<runtime::Call>;
}

impl ChainWithTransactions for BridgeHubRococo {
type AccountKeyPair = sp_core::sr25519::Pair;
type SignedTransaction = runtime::UncheckedExtrinsic;
Expand Down
11 changes: 10 additions & 1 deletion bridges/relays/client-bridge-hub-rococo/src/runtime_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Call, SignedExtension>;
Expand All @@ -49,6 +49,9 @@ pub enum Call {
#[cfg(test)]
#[codec(index = 0)]
System(SystemCall),
/// Utility pallet.
#[codec(index = 40)]
Utility(UtilityCall<Call>),

/// Wococo bridge pallet.
#[codec(index = 41)]
Expand All @@ -60,3 +63,9 @@ pub enum Call {
#[codec(index = 46)]
BridgeWococoMessages(BridgeWococoMessagesCall),
}

impl From<UtilityCall<Call>> for Call {
fn from(call: UtilityCall<Call>) -> Call {
Call::Utility(call)
}
}
9 changes: 7 additions & 2 deletions bridges/relays/client-bridge-hub-wococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -56,6 +57,10 @@ impl ChainWithBalances for BridgeHubWococo {
}
}

impl ChainWithUtilityPallet for BridgeHubWococo {
type UtilityPallet = MockedRuntimeUtilityPallet<runtime::Call>;
}

impl ChainWithTransactions for BridgeHubWococo {
type AccountKeyPair = sp_core::sr25519::Pair;
type SignedTransaction = runtime::UncheckedExtrinsic;
Expand Down
11 changes: 10 additions & 1 deletion bridges/relays/client-bridge-hub-wococo/src/runtime_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Call, SignedExtension>;
Expand All @@ -47,6 +47,9 @@ pub enum Call {
#[cfg(test)]
#[codec(index = 0)]
System(SystemCall),
/// Utility pallet.
#[codec(index = 40)]
Utility(UtilityCall<Call>),

/// Rococo bridge pallet.
#[codec(index = 43)]
Expand All @@ -59,6 +62,12 @@ pub enum Call {
BridgeRococoMessages(BridgeRococoMessagesCall),
}

impl From<UtilityCall<Call>> for Call {
fn from(call: UtilityCall<Call>) -> Call {
Call::Utility(call)
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
9 changes: 9 additions & 0 deletions bridges/relays/client-substrate/src/calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ pub enum SystemCall {
remark(Vec<u8>),
}

/// 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<Call> {
/// `pallet-utility::Call::batch_all`
#[codec(index = 2)]
batch_all(Vec<Call>),
}

/// 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)]
Expand Down
17 changes: 17 additions & 0 deletions bridges/relays/client-substrate/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.