Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use complex transactions on RBH/WBH bridge hubs #1893

Merged
merged 1 commit into from
Feb 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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 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 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 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 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 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/>.

use crate::calls::UtilityCall;

use bp_messages::MessageNonce;
use bp_runtime::{
Chain as ChainBase, EncodedOrDecodedCall, HashOf, Parachain as ParachainBase, TransactionEra,
Expand Down Expand Up @@ -276,6 +278,21 @@ where
}
}

/// Structure that implements `UtilityPalletProvider` based on a call conversion.
pub struct MockedRuntimeUtilityPallet<Call> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont know, I just cannot get used to Mock word for production code :D
Wdyt about WrappedRuntimeUtilityPallet (we have runtime_wrapper.rs in clients) or just RuntimeUtilityPallet or some other equivalent to FullRuntimeUtilityPallet?
Also, maybe in near future we will have CodegenRuntimeUtilityPallet for Serban's subxt stuff

_phantom: std::marker::PhantomData<Call>,
}

impl<C, Call> UtilityPallet<C> for MockedRuntimeUtilityPallet<Call>
where
C: Chain,
C::Call: From<UtilityCall<C::Call>>,
{
fn build_batch_call(calls: Vec<C::Call>) -> C::Call {
UtilityCall::batch_all(calls).into()
}
}

/// Substrate-based chain that uses `pallet-utility`.
pub trait ChainWithUtilityPallet: Chain {
/// The utility pallet provider.
Expand Down
4 changes: 2 additions & 2 deletions relays/client-substrate/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down