Skip to content

Commit

Permalink
Xcm in Rialto<>Millau bridge (paritytech#1379)
Browse files Browse the repository at this point in the history
* add XCM pallet to Millau runtime

* some progress

* messages are delivered (no fee)

* temp

* flush

* flush

* some progress

* progress

* Trap(42) is dispatched successfully

* fix spelling

* no more manual sending

* parametrize weight credit for tests

* actually charge fees

* enable send-using-messages-pallet to keep our test deployments alive + send valid XCM sometimes

* fix benchmarks build

* fix tests
  • Loading branch information
svyatonik authored and serban300 committed Apr 9, 2024
1 parent b51e428 commit f816995
Show file tree
Hide file tree
Showing 19 changed files with 1,059 additions and 431 deletions.
1 change: 1 addition & 0 deletions bridges/bin/millau/node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ fn testnet_genesis(
owner: Some(get_account_id_from_seed::<sr25519::Public>("RialtoMessagesOwner")),
..Default::default()
},
xcm_pallet: Default::default(),
}
}

Expand Down
18 changes: 18 additions & 0 deletions bridges/bin/millau/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
hex-literal = "0.3"
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] }
libsecp256k1 = { version = "0.7", optional = true, default-features = false, features = ["hmac"] }
log = { version = "0.4.14", default-features = false }
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
serde = { version = "1.0", optional = true, features = ["derive"] }

Expand Down Expand Up @@ -53,6 +54,7 @@ sp-consensus-aura = { git = "https://github.com/paritytech/substrate", branch =
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-finality-grandpa = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-inherents = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-io = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-mmr-primitives = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-offchain = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
Expand All @@ -62,8 +64,16 @@ sp-transaction-pool = { git = "https://github.com/paritytech/substrate", branch
sp-trie = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-version = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }

# Polkadot Dependencies

pallet-xcm = { git = "https://github.com/paritytech/polkadot", branch = "gav-xcm-v3", default-features = false }
xcm = { git = "https://github.com/paritytech/polkadot", branch = "gav-xcm-v3", default-features = false }
xcm-builder = { git = "https://github.com/paritytech/polkadot", branch = "gav-xcm-v3", default-features = false }
xcm-executor = { git = "https://github.com/paritytech/polkadot", branch = "gav-xcm-v3", default-features = false }

[dev-dependencies]
bridge-runtime-common = { path = "../../runtime-common", features = ["integrity-test"] }
env_logger = "0.8"
static_assertions = "1.1"

[build-dependencies]
Expand All @@ -85,6 +95,7 @@ std = [
"frame-support/std",
"frame-system-rpc-runtime-api/std",
"frame-system/std",
"log/std",
"pallet-aura/std",
"pallet-balances/std",
"pallet-beefy/std",
Expand All @@ -100,6 +111,7 @@ std = [
"pallet-timestamp/std",
"pallet-transaction-payment-rpc-runtime-api/std",
"pallet-transaction-payment/std",
"pallet-xcm/std",
"scale-info/std",
"serde",
"sp-api/std",
Expand All @@ -108,13 +120,17 @@ std = [
"sp-core/std",
"sp-finality-grandpa/std",
"sp-inherents/std",
"sp-io/std",
"sp-offchain/std",
"sp-runtime/std",
"sp-session/std",
"sp-std/std",
"sp-transaction-pool/std",
"sp-trie/std",
"sp-version/std",
"xcm/std",
"xcm-builder/std",
"xcm-executor/std",
]
runtime-benchmarks = [
"bridge-runtime-common/runtime-benchmarks",
Expand All @@ -123,5 +139,7 @@ runtime-benchmarks = [
"frame-system/runtime-benchmarks",
"libsecp256k1",
"pallet-bridge-messages/runtime-benchmarks",
"pallet-xcm/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"xcm-builder/runtime-benchmarks",
]
13 changes: 6 additions & 7 deletions bridges/bin/millau/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));

pub mod rialto_messages;
pub mod xcm_config;

use crate::rialto_messages::{ToRialtoMessagePayload, WithRialtoMessageBridge};

Expand Down Expand Up @@ -451,13 +452,7 @@ impl pallet_bridge_messages::Config<WithRialtoMessagesInstance> for Runtime {

type TargetHeaderChain = crate::rialto_messages::Rialto;
type LaneMessageVerifier = crate::rialto_messages::ToRialtoMessageVerifier;
type MessageDeliveryAndDispatchPayment =
pallet_bridge_messages::instant_payments::InstantCurrencyPayments<
Runtime,
WithRialtoMessagesInstance,
pallet_balances::Pallet<Runtime>,
GetDeliveryConfirmationTransactionFee,
>;
type MessageDeliveryAndDispatchPayment = ();
type OnMessageAccepted = ();
type OnDeliveryConfirmed = ();

Expand Down Expand Up @@ -499,6 +494,9 @@ construct_runtime!(

// Westend bridge modules.
BridgeWestendGrandpa: pallet_bridge_grandpa::<Instance1>::{Pallet, Call, Config<T>, Storage},

// Pallet for sending XCM.
XcmPallet: pallet_xcm::{Pallet, Call, Storage, Event<T>, Origin, Config} = 99,
}
);

Expand Down Expand Up @@ -750,6 +748,7 @@ impl_runtime_apis! {
Runtime,
WithRialtoMessagesInstance,
WithRialtoMessageBridge,
xcm_config::OutboundXcmWeigher,
>(lane, begin, end)
}
}
Expand Down
44 changes: 30 additions & 14 deletions bridges/bin/millau/runtime/src/rialto_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

//! Everything required to serve Millau <-> Rialto messages.

use crate::Runtime;
use crate::{Call, OriginCaller, Runtime};

use bp_messages::{
source_chain::{SenderOrigin, TargetHeaderChain},
Expand All @@ -40,6 +40,10 @@ pub const INITIAL_RIALTO_TO_MILLAU_CONVERSION_RATE: FixedU128 =
FixedU128::from_inner(FixedU128::DIV);
/// Initial value of `RialtoFeeMultiplier` parameter.
pub const INITIAL_RIALTO_FEE_MULTIPLIER: FixedU128 = FixedU128::from_inner(FixedU128::DIV);
/// Weight of 2 XCM instructions is for simple `Trap(42)` program, coming through bridge
/// (it is prepended with `UniversalOrigin` instruction). It is used just for simplest manual
/// tests, confirming that we don't break encoding somewhere between.
pub const BASE_XCM_WEIGHT_TWICE: Weight = 2 * crate::xcm_config::BASE_XCM_WEIGHT;

parameter_types! {
/// Rialto to Millau conversion rate. Initially we treat both tokens as equal.
Expand All @@ -56,7 +60,7 @@ pub type ToRialtoMessageVerifier =
messages::source::FromThisChainMessageVerifier<WithRialtoMessageBridge>;

/// Message payload for Rialto -> Millau messages.
pub type FromRialtoMessagePayload = messages::target::FromBridgedChainMessagePayload;
pub type FromRialtoMessagePayload = messages::target::FromBridgedChainMessagePayload<Call>;

/// Messages proof for Rialto -> Millau messages.
pub type FromRialtoMessagesProof = messages::target::FromBridgedChainMessagesProof<bp_rialto::Hash>;
Expand All @@ -68,9 +72,11 @@ pub type ToRialtoMessagesDeliveryProof =
/// Call-dispatch based message dispatch for Rialto -> Millau messages.
pub type FromRialtoMessageDispatch = messages::target::FromBridgedChainMessageDispatch<
WithRialtoMessageBridge,
crate::Runtime,
pallet_balances::Pallet<Runtime>,
(),
xcm_executor::XcmExecutor<crate::xcm_config::XcmConfig>,
crate::xcm_config::XcmWeigher,
// 2 XCM instructions is for simple `Trap(42)` program, coming through bridge
// (it is prepended with `UniversalOrigin` instruction)
frame_support::traits::ConstU64<BASE_XCM_WEIGHT_TWICE>,
>;

/// Millau <-> Rialto message bridge.
Expand Down Expand Up @@ -115,7 +121,23 @@ impl messages::ThisChainWithMessages for Millau {
type Call = crate::Call;

fn is_message_accepted(send_origin: &Self::Origin, lane: &LaneId) -> bool {
(*lane == [0, 0, 0, 0] || *lane == [0, 0, 0, 1]) && send_origin.linked_account().is_some()
let here_location =
xcm::v3::MultiLocation::from(crate::xcm_config::UniversalLocation::get());
match send_origin.caller {
OriginCaller::XcmPallet(pallet_xcm::Origin::Xcm(ref location))
if *location == here_location =>
{
log::trace!(target: "runtime::bridge", "Verifying message sent using XCM pallet to Rialto");
},
_ => {
// keep in mind that in this case all messages are free (in term of fees)
// => it's just to keep testing bridge on our test deployments until we'll have a
// better option
log::trace!(target: "runtime::bridge", "Verifying message sent using messages pallet to Rialto");
},
}

*lane == [0, 0, 0, 0] || *lane == [0, 0, 0, 1]
}

fn maximal_pending_messages_at_outbound_lane() -> MessageNonce {
Expand Down Expand Up @@ -262,14 +284,8 @@ impl SourceHeaderChain<bp_rialto::Balance> for Rialto {

impl SenderOrigin<crate::AccountId> for crate::Origin {
fn linked_account(&self) -> Option<crate::AccountId> {
match self.caller {
crate::OriginCaller::system(frame_system::RawOrigin::Signed(ref submitter)) =>
Some(submitter.clone()),
crate::OriginCaller::system(frame_system::RawOrigin::Root) |
crate::OriginCaller::system(frame_system::RawOrigin::None) =>
crate::RootAccountForPayments::get(),
_ => None,
}
// XCM deals wit fees in our deployments
None
}
}

Expand Down
Loading

0 comments on commit f816995

Please sign in to comment.