Skip to content

Commit

Permalink
Use indirect runtime calls for RialtoParachain
Browse files Browse the repository at this point in the history
  • Loading branch information
serban300 committed Jan 10, 2023
1 parent 9563f9e commit d3cf260
Show file tree
Hide file tree
Showing 15 changed files with 167 additions and 90 deletions.
8 changes: 7 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions primitives/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", d
sp-trie = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
trie-db = { version = "0.24.0", default-features = false }

# Polkadot Dependencies

xcm = { git = "https://github.com/paritytech/polkadot", branch = "master", default-features = false }

[dev-dependencies]
hex-literal = "0.3"

Expand All @@ -45,4 +49,5 @@ std = [
"sp-state-machine/std",
"sp-trie/std",
"trie-db/std",
"xcm/std"
]
22 changes: 21 additions & 1 deletion primitives/runtime/src/calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
use codec::{Decode, Encode};
use scale_info::TypeInfo;
use sp_std::vec::Vec;
use sp_std::{boxed::Box, vec::Vec};

use xcm::{VersionedMultiLocation, VersionedXcm};

/// A minimized version of `frame-system::Call` that can be used without a runtime.
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
Expand All @@ -28,3 +30,21 @@ pub enum SystemCall {
#[codec(index = 1)]
remark(Vec<u8>),
}

/// 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)]
pub enum SudoCall<Call> {
/// `pallet-sudo::Call::sudo`
#[codec(index = 0)]
sudo(Box<Call>),
}

/// A minimized version of `pallet-xcm::Call`, that can be used without a runtime.
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
#[allow(non_camel_case_types)]
pub enum XcmCall {
/// `pallet-xcm::Call::send`
#[codec(index = 0)]
send(Box<VersionedMultiLocation>, Box<VersionedXcm<()>>),
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
//! BridgeHubRococo-to-BridgeHubWococo messages sync entrypoint.
use crate::cli::bridge::{CliBridgeBase, MessagesCliBridge};
use bp_messages::Weight;
use relay_bridge_hub_rococo_client::BridgeHubRococo;
use relay_bridge_hub_wococo_client::BridgeHubWococo;
use substrate_relay_helper::messages_lane::SubstrateMessageLane;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
//! BridgeHubWococo-to-BridgeHubRococo messages sync entrypoint.
use crate::cli::bridge::{CliBridgeBase, MessagesCliBridge};
use bp_messages::Weight;
use relay_bridge_hub_rococo_client::BridgeHubRococo;
use relay_bridge_hub_wococo_client::BridgeHubWococo;
use substrate_relay_helper::messages_lane::SubstrateMessageLane;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,16 @@
use crate::cli::bridge::{CliBridgeBase, MessagesCliBridge, RelayToRelayHeadersCliBridge};
use substrate_relay_helper::finality::{
engine::Grandpa as GrandpaFinalityEngine, DirectSubmitGrandpaFinalityProofCallBuilder,
SubstrateFinalitySyncPipeline,
engine::Grandpa as GrandpaFinalityEngine, SubstrateFinalitySyncPipeline,
};

substrate_relay_helper::generate_mocked_submit_finality_proof_call_builder!(
MillauFinalityToRialtoParachain,
MillauFinalityToRialtoParachainCallBuilder,
relay_rialto_parachain_client::runtime::Call::BridgeMillauGrandpa,
relay_rialto_parachain_client::runtime::BridgeMillauGrandpaCall::submit_finality_proof
);

/// Description of Millau -> Rialto finalized headers bridge.
#[derive(Clone, Debug)]
pub struct MillauFinalityToRialtoParachain;
Expand All @@ -49,11 +55,7 @@ impl SubstrateFinalitySyncPipeline for MillauFinalityToRialtoParachain {
type TargetChain = relay_rialto_parachain_client::RialtoParachain;

type FinalityEngine = GrandpaFinalityEngine<Self::SourceChain>;
type SubmitFinalityProofCallBuilder = DirectSubmitGrandpaFinalityProofCallBuilder<
Self,
rialto_parachain_runtime::Runtime,
rialto_parachain_runtime::MillauGrandpaInstance,
>;
type SubmitFinalityProofCallBuilder = MillauFinalityToRialtoParachainCallBuilder;
}

//// `Millau` to `RialtoParachain` bridge definition.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,16 @@
use relay_millau_client::Millau;
use relay_rialto_parachain_client::RialtoParachain;
use substrate_relay_helper::messages_lane::{
DirectReceiveMessagesDeliveryProofCallBuilder, DirectReceiveMessagesProofCallBuilder,
SubstrateMessageLane,
DirectReceiveMessagesDeliveryProofCallBuilder, SubstrateMessageLane,
};

substrate_relay_helper::generate_mocked_receive_message_proof_call_builder!(
MillauMessagesToRialtoParachain,
MillauMessagesToRialtoParachainReceiveMessagesProofCallBuilder,
relay_rialto_parachain_client::runtime::Call::BridgeMillauMessages,
relay_rialto_parachain_client::runtime::BridgeMillauMessagesCall::receive_messages_proof
);

/// Description of Millau -> RialtoParachain messages bridge.
#[derive(Clone, Debug)]
pub struct MillauMessagesToRialtoParachain;
Expand All @@ -31,11 +37,8 @@ impl SubstrateMessageLane for MillauMessagesToRialtoParachain {
type SourceChain = Millau;
type TargetChain = RialtoParachain;

type ReceiveMessagesProofCallBuilder = DirectReceiveMessagesProofCallBuilder<
Self,
rialto_parachain_runtime::Runtime,
rialto_parachain_runtime::WithMillauMessagesInstance,
>;
type ReceiveMessagesProofCallBuilder =
MillauMessagesToRialtoParachainReceiveMessagesProofCallBuilder;
type ReceiveMessagesDeliveryProofCallBuilder = DirectReceiveMessagesDeliveryProofCallBuilder<
Self,
millau_runtime::Runtime,
Expand Down
12 changes: 4 additions & 8 deletions relays/bin-substrate/src/chains/rialto_parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
//! Rialto parachain specification for CLI.
use crate::cli::{bridge, encode_message::CliEncodeMessage, CliChain};
use bp_runtime::EncodedOrDecodedCall;
use bp_runtime::{calls::XcmCall, EncodedOrDecodedCall};
use relay_rialto_parachain_client::RialtoParachain;
use sp_version::RuntimeVersion;
use xcm::latest::prelude::*;
Expand All @@ -36,13 +36,9 @@ impl CliEncodeMessage for RialtoParachain {
),
};

Ok(rialto_parachain_runtime::RuntimeCall::PolkadotXcm(
rialto_parachain_runtime::XcmCall::send {
dest: Box::new(dest.into()),
message: Box::new(message),
},
)
.into())
let xcm_call = XcmCall::send(Box::new(dest.into()), Box::new(message));

Ok(relay_rialto_parachain_client::runtime::Call::PolkadotXcm(xcm_call).into())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@
use relay_millau_client::Millau;
use relay_rialto_parachain_client::RialtoParachain;
use substrate_relay_helper::{
messages_lane::{
DirectReceiveMessagesDeliveryProofCallBuilder, DirectReceiveMessagesProofCallBuilder,
SubstrateMessageLane,
},
messages_lane::{DirectReceiveMessagesProofCallBuilder, SubstrateMessageLane},
UtilityPalletBatchCallBuilder,
};

substrate_relay_helper::generate_mocked_receive_message_delivery_proof_call_builder!(
RialtoParachainMessagesToMillau,
RialtoParachainMessagesToMillauReceiveMessagesDeliveryProofCallBuilder,
relay_rialto_parachain_client::runtime::Call::BridgeMillauMessages,
relay_rialto_parachain_client::runtime::BridgeMillauMessagesCall::receive_messages_delivery_proof
);

/// Description of RialtoParachain -> Millau messages bridge.
#[derive(Clone, Debug)]
pub struct RialtoParachainMessagesToMillau;
Expand All @@ -39,11 +43,8 @@ impl SubstrateMessageLane for RialtoParachainMessagesToMillau {
millau_runtime::Runtime,
millau_runtime::WithRialtoParachainMessagesInstance,
>;
type ReceiveMessagesDeliveryProofCallBuilder = DirectReceiveMessagesDeliveryProofCallBuilder<
Self,
rialto_parachain_runtime::Runtime,
rialto_parachain_runtime::WithMillauMessagesInstance,
>;
type ReceiveMessagesDeliveryProofCallBuilder =
RialtoParachainMessagesToMillauReceiveMessagesDeliveryProofCallBuilder;

type SourceBatchCallBuilder = ();
type TargetBatchCallBuilder = UtilityPalletBatchCallBuilder<Millau>;
Expand Down
16 changes: 8 additions & 8 deletions relays/bin-substrate/src/cli/init_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use crate::{
},
cli::{bridge::CliBridgeBase, chain_schema::*},
};
use bp_runtime::Chain as ChainBase;
use bp_runtime::{calls::SudoCall, Chain as ChainBase};
use relay_substrate_client::{AccountKeyPairOf, Chain, UnsignedTransaction};
use sp_core::Pair;
use structopt::StructOpt;
Expand Down Expand Up @@ -123,13 +123,13 @@ impl BridgeInitializer for MillauToRialtoParachainCliBridge {
fn encode_init_bridge(
init_data: <Self::Engine as Engine<Self::Source>>::InitializationData,
) -> <Self::Target as Chain>::Call {
let initialize_call = rialto_parachain_runtime::BridgeGrandpaCall::<
rialto_parachain_runtime::Runtime,
rialto_parachain_runtime::MillauGrandpaInstance,
>::initialize {
init_data,
};
rialto_parachain_runtime::SudoCall::sudo { call: Box::new(initialize_call.into()) }.into()
use relay_rialto_parachain_client::runtime;

let initialize_call = runtime::Call::BridgeMillauGrandpa(
runtime::BridgeMillauGrandpaCall::initialize(init_data),
);
let sudo_call = SudoCall::sudo(Box::new(initialize_call));
runtime::Call::Sudo(sudo_call)
}
}

Expand Down
1 change: 1 addition & 0 deletions relays/client-bridge-hub-rococo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ 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" }
Expand Down
12 changes: 9 additions & 3 deletions relays/client-rialto-parachain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,20 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0"

[dependencies]
codec = { package = "parity-scale-codec", version = "3.1.5" }
relay-substrate-client = { path = "../client-substrate" }
relay-utils = { path = "../utils" }
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }

# Bridge dependencies

bp-header-chain = { path = "../../primitives/header-chain" }
bp-messages = { path = "../../primitives/messages" }
bp-millau = { path = "../../primitives/chain-millau" }
bp-polkadot-core = { path = "../../primitives/polkadot-core" }
bp-rialto-parachain = { path = "../../primitives/chain-rialto-parachain" }
rialto-parachain-runtime = { path = "../../bin/rialto-parachain/runtime" }
bp-runtime = { path = "../../primitives/runtime" }

bridge-runtime-common = { path = "../../bin/runtime-common" }
relay-substrate-client = { path = "../client-substrate" }
relay-utils = { path = "../utils" }

# Substrate Dependencies

Expand Down
Loading

0 comments on commit d3cf260

Please sign in to comment.