Skip to content

Commit a2e9b88

Browse files
committed
complex parachain relay
1 parent 0b2901a commit a2e9b88

28 files changed

Lines changed: 1640 additions & 313 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bin/millau/runtime/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ impl_runtime_apis! {
805805
fn best_finalized() -> (bp_rialto::BlockNumber, bp_rialto::Hash) {
806806
// the parachains finality pallet is never decoding parachain heads, so it is
807807
// only done in the integration code
808-
use crate::rialto_parachain_messages::RIALTO_PARACHAIN_ID;
808+
use bp_rialto_parachain::RIALTO_PARACHAIN_ID;
809809
let best_rialto_parachain_head = pallet_bridge_parachains::Pallet::<
810810
Runtime,
811811
WitRialtoParachainsInstance,

bin/millau/runtime/src/rialto_messages.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl MessageBridge for WithRialtoMessageBridge {
9797
bridged_to_this_conversion_rate_override: Option<FixedU128>,
9898
) -> bp_millau::Balance {
9999
let conversion_rate = bridged_to_this_conversion_rate_override
100-
.unwrap_or_else(|| RialtoToMillauConversionRate::get());
100+
.unwrap_or_else(RialtoToMillauConversionRate::get);
101101
bp_millau::Balance::try_from(conversion_rate.saturating_mul_int(bridged_balance))
102102
.unwrap_or(bp_millau::Balance::MAX)
103103
}

bin/millau/runtime/src/rialto_parachain_messages.rs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
use crate::Runtime;
2020

2121
use bp_messages::{
22-
source_chain::{SenderOrigin, TargetHeaderChain},
22+
source_chain::TargetHeaderChain,
2323
target_chain::{ProvedMessages, SourceHeaderChain},
2424
InboundLaneData, LaneId, Message, MessageNonce, Parameter as MessagesParameter,
2525
};
@@ -36,13 +36,6 @@ use scale_info::TypeInfo;
3636
use sp_runtime::{traits::Saturating, FixedPointNumber, FixedU128};
3737
use sp_std::convert::TryFrom;
3838

39-
/// Identifier of RialtoParachain in the Rialto relay chain.
40-
///
41-
/// This identifier is not something that is declared either by Rialto or RialtoParachain. This
42-
/// is an identifier of registration. So in theory it may be changed. But since bridge is going
43-
/// to be deployed after parachain registration AND since parachain de-registration is highly
44-
/// likely impossible, it is fine to declare this constant here.
45-
pub const RIALTO_PARACHAIN_ID: u32 = 2000;
4639
/// Weight of 2 XCM instructions is for simple `Trap(42)` program, coming through bridge
4740
/// (it is prepended with `UniversalOrigin` instruction). It is used just for simplest manual
4841
/// tests, confirming that we don't break encoding somewhere between.
@@ -109,7 +102,7 @@ impl MessageBridge for WithRialtoParachainMessageBridge {
109102
bridged_to_this_conversion_rate_override: Option<FixedU128>,
110103
) -> bp_millau::Balance {
111104
let conversion_rate = bridged_to_this_conversion_rate_override
112-
.unwrap_or_else(|| RialtoParachainToMillauConversionRate::get());
105+
.unwrap_or_else(RialtoParachainToMillauConversionRate::get);
113106
bp_millau::Balance::try_from(conversion_rate.saturating_mul_int(bridged_balance))
114107
.unwrap_or(bp_millau::Balance::MAX)
115108
}
@@ -132,8 +125,8 @@ impl messages::ThisChainWithMessages for Millau {
132125
type Call = crate::Call;
133126
type Origin = crate::Origin;
134127

135-
fn is_message_accepted(send_origin: &Self::Origin, lane: &LaneId) -> bool {
136-
(*lane == [0, 0, 0, 0] || *lane == [0, 0, 0, 1]) && send_origin.linked_account().is_some()
128+
fn is_message_accepted(_send_origin: &Self::Origin, lane: &LaneId) -> bool {
129+
*lane == [0, 0, 0, 0] || *lane == [0, 0, 0, 1]
137130
}
138131

139132
fn maximal_pending_messages_at_outbound_lane() -> MessageNonce {
@@ -260,7 +253,7 @@ impl TargetHeaderChain<ToRialtoParachainMessagePayload, bp_rialto_parachain::Acc
260253
bp_rialto_parachain::Header,
261254
Runtime,
262255
crate::WitRialtoParachainsInstance,
263-
>(ParaId(RIALTO_PARACHAIN_ID), proof)
256+
>(ParaId(bp_rialto_parachain::RIALTO_PARACHAIN_ID), proof)
264257
}
265258
}
266259

@@ -282,7 +275,7 @@ impl SourceHeaderChain<bp_rialto_parachain::Balance> for RialtoParachain {
282275
bp_rialto_parachain::Header,
283276
Runtime,
284277
crate::WitRialtoParachainsInstance,
285-
>(ParaId(RIALTO_PARACHAIN_ID), proof, messages_count)
278+
>(ParaId(bp_rialto_parachain::RIALTO_PARACHAIN_ID), proof, messages_count)
286279
}
287280
}
288281

primitives/chain-millau/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,6 @@ pub const WITH_MILLAU_MESSAGES_PALLET_NAME: &str = "BridgeMillauMessages";
284284
/// Name of the Rialto->Millau (actually DOT->KSM) conversion rate stored in the Millau runtime.
285285
pub const RIALTO_TO_MILLAU_CONVERSION_RATE_PARAMETER_NAME: &str = "RialtoToMillauConversionRate";
286286

287-
/// Name of the With-Rialto parachains bridge pallet name in the Millau runtime.
288-
pub const BRIDGE_PARAS_PALLET_NAME: &str = "BridgeRialtoParachains";
289-
290287
/// Name of the `MillauFinalityApi::best_finalized` runtime method.
291288
pub const BEST_FINALIZED_MILLAU_HEADER_METHOD: &str = "MillauFinalityApi_best_finalized";
292289

primitives/chain-rialto-parachain/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ use sp_runtime::{
3232
};
3333
use sp_std::vec::Vec;
3434

35+
/// Identifier of RialtoParachain in the Rialto relay chain.
36+
///
37+
/// This identifier is not something that is declared either by Rialto or RialtoParachain. This
38+
/// is an identifier of registration. So in theory it may be changed. But since bridge is going
39+
/// to be deployed after parachain registration AND since parachain de-registration is highly
40+
/// likely impossible, it is fine to declare this constant here.
41+
pub const RIALTO_PARACHAIN_ID: u32 = 2000;
42+
3543
/// Number of extra bytes (excluding size of storage value itself) of storage proof, built at
3644
/// RialtoParachain chain. This mostly depends on number of entries (and their density) in the
3745
/// storage trie. Some reserve is reserved to account future chain growth.

primitives/chain-rialto/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ frame_support::parameter_types! {
228228
pub const WITH_RIALTO_GRANDPA_PALLET_NAME: &str = "BridgeRialtoGrandpa";
229229
/// Name of the With-Rialto messages pallet instance that is deployed at bridged chains.
230230
pub const WITH_RIALTO_MESSAGES_PALLET_NAME: &str = "BridgeRialtoMessages";
231+
/// Name of the With-Rialto parachains bridge pallet instance that is deployed at bridged chains.
232+
pub const WITH_RIALTO_BRIDGE_PARAS_PALLET_NAME: &str = "BridgeRialtoParachains";
231233

232234
/// Name of the Millau->Rialto (actually KSM->DOT) conversion rate stored in the Rialto runtime.
233235
pub const MILLAU_TO_RIALTO_CONVERSION_RATE_PARAMETER_NAME: &str = "MillauToRialtoConversionRate";

relays/bin-substrate/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ messages-relay = { path = "../messages" }
4141
millau-runtime = { path = "../../bin/millau/runtime" }
4242
pallet-bridge-grandpa = { path = "../../modules/grandpa" }
4343
pallet-bridge-messages = { path = "../../modules/messages" }
44+
pallet-bridge-parachains = { path = "../../modules/parachains" }
4445
parachains-relay = { path = "../parachains" }
4546
relay-kusama-client = { path = "../client-kusama" }
4647
relay-millau-client = { path = "../client-millau" }

relays/bin-substrate/src/chains/millau.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ impl CliEncodeMessage for Millau {
4343
},
4444
)
4545
.into(),
46+
bridge::MILLAU_TO_RIALTO_PARACHAIN_INDEX =>
47+
millau_runtime::Call::BridgeRialtoParachainMessages(
48+
millau_runtime::MessagesCall::send_message {
49+
lane_id: lane,
50+
payload,
51+
delivery_and_dispatch_fee: fee,
52+
},
53+
)
54+
.into(),
4655
_ => anyhow::bail!(
4756
"Unsupported target bridge pallet with instance index: {}",
4857
bridge_instance_index

relays/bin-substrate/src/chains/rialto_parachains_to_millau.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919
use parachains_relay::ParachainsPipeline;
2020
use relay_millau_client::Millau;
2121
use relay_rialto_client::Rialto;
22-
use substrate_relay_helper::parachains_target::DirectSubmitParachainHeadsCallBuilder;
22+
use relay_rialto_parachain_client::RialtoParachain;
23+
use substrate_relay_helper::parachains::{
24+
DirectSubmitParachainHeadsCallBuilder, SubstrateParachainsPipeline,
25+
};
2326

2427
/// Rialto-to-Millau parachains sync description.
2528
#[derive(Clone, Debug)]
@@ -30,6 +33,17 @@ impl ParachainsPipeline for RialtoParachainsToMillau {
3033
type TargetChain = Millau;
3134
}
3235

36+
impl SubstrateParachainsPipeline for RialtoParachainsToMillau {
37+
type SourceParachain = RialtoParachain;
38+
type SourceRelayChain = Rialto;
39+
type TargetChain = Millau;
40+
41+
type SubmitParachainHeadsCallBuilder = RialtoParachainsToMillauSubmitParachainHeadsCallBuilder;
42+
type TransactionSignScheme = Millau;
43+
44+
const SOURCE_PARACHAIN_PARA_ID: u32 = bp_rialto_parachain::RIALTO_PARACHAIN_ID;
45+
}
46+
3347
/// `submit_parachain_heads` call builder for Rialto-to-Millau parachains sync pipeline.
3448
pub type RialtoParachainsToMillauSubmitParachainHeadsCallBuilder =
3549
DirectSubmitParachainHeadsCallBuilder<

0 commit comments

Comments
 (0)