Skip to content

Commit

Permalink
Change LaneId underlying type from [u8; 4] to H256 (#2221)
Browse files Browse the repository at this point in the history
* change LaneId underlying type from [u8; 4] to H256

* fixed typo

* added some tests

* spelling

* started fixing testnets

* uncommented call size test

* changed RewardsAccountParams encoding + added values separator when computing LaneId

* review suggestions
  • Loading branch information
svyatonik authored Jun 22, 2023
1 parent 891588d commit 594ebac
Show file tree
Hide file tree
Showing 56 changed files with 567 additions and 388 deletions.
6 changes: 6 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ You will also see the message lane relayers listening for new messages.

```
# Message Relayer Logs
[Millau_to_Rialto_MessageLane_00000000] [date] DEBUG bridge Asking Millau::ReceivingConfirmationsDelivery about best message nonces
[Millau_to_Rialto_MessageLane_0x52011894c856c0c613a2ad2395dfbb509090f6b7a6aef9359adb75aa26a586c7] [date] DEBUG bridge Asking Millau::ReceivingConfirmationsDelivery about best message nonces
[...] [date] INFO bridge Synced Some(2) of Some(3) nonces in Millau::MessagesDelivery -> Rialto::MessagesDelivery race
[...] [date] DEBUG bridge Asking Millau::MessagesDelivery about message nonces
[...] [date] DEBUG bridge Received best nonces from Millau::ReceivingConfirmationsDelivery: TargetClientNonces { latest_nonce: 0, nonces_data: () }
Expand Down
1 change: 1 addition & 0 deletions bin/millau/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ serde_json = "1.0.97"
# Bridge dependencies

bp-messages = { path = "../../../primitives/messages" }
bridge-runtime-common = { path = "../../runtime-common" }
millau-runtime = { path = "../runtime" }

# Substrate Dependencies
Expand Down
8 changes: 6 additions & 2 deletions bin/millau/node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// 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 bridge_runtime_common::messages_xcm_extension::XcmBlobHauler;
use millau_runtime::{
AccountId, AuraConfig, BalancesConfig, BeefyConfig, BridgeRialtoMessagesConfig,
BridgeRialtoParachainMessagesConfig, BridgeWestendGrandpaConfig, GrandpaConfig,
Expand Down Expand Up @@ -223,14 +224,17 @@ fn testnet_genesis(
},
bridge_rialto_messages: BridgeRialtoMessagesConfig {
owner: Some(get_account_id_from_seed::<sr25519::Public>(RIALTO_MESSAGES_PALLET_OWNER)),
opened_lanes: vec![bp_messages::LaneId::default()],
opened_lanes: vec![millau_runtime::rialto_messages::ToRialtoXcmBlobHauler::xcm_lane()],
..Default::default()
},
bridge_rialto_parachain_messages: BridgeRialtoParachainMessagesConfig {
owner: Some(get_account_id_from_seed::<sr25519::Public>(
RIALTO_PARACHAIN_MESSAGES_PALLET_OWNER,
)),
opened_lanes: vec![bp_messages::LaneId::default()],
opened_lanes: vec![
millau_runtime::rialto_parachain_messages::ToRialtoParachainXcmBlobHauler::xcm_lane(
),
],
..Default::default()
},
xcm_pallet: Default::default(),
Expand Down
3 changes: 1 addition & 2 deletions bin/millau/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,6 @@ impl pallet_bridge_messages::Config<WithRialtoParachainMessagesInstance> for Run
}

parameter_types! {
pub const RialtoParachainMessagesLane: bp_messages::LaneId = rialto_parachain_messages::XCM_LANE;
pub const RialtoParasPalletName: &'static str = bp_rialto::PARAS_PALLET_NAME;
pub const WestendParasPalletName: &'static str = bp_westend::PARAS_PALLET_NAME;
pub const MaxRialtoParaHeadDataSize: u32 = bp_rialto::MAX_NESTED_PARACHAIN_HEAD_DATA_SIZE;
Expand Down Expand Up @@ -586,7 +585,7 @@ pub type PriorityBoostPerMessage = ConstU64<327_319_648>;
pub type BridgeRefundRialtoParachainMessages = RefundBridgedParachainMessages<
Runtime,
RefundableParachain<WithRialtoParachainsInstance, bp_rialto_parachain::RialtoParachain>,
RefundableMessagesLane<WithRialtoParachainMessagesInstance, RialtoParachainMessagesLane>,
RefundableMessagesLane<Runtime, WithRialtoParachainMessagesInstance>,
ActualFeeRefund<Runtime>,
PriorityBoostPerMessage,
StrBridgeRefundRialtoPara2000Lane0Msgs,
Expand Down
21 changes: 17 additions & 4 deletions bin/millau/runtime/src/rialto_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@
use crate::{Runtime, WithRialtoMessagesInstance};

use bp_messages::LaneId;
use bridge_runtime_common::messages_xcm_extension::{XcmBlobHauler, XcmBlobHaulerAdapter};
use bridge_runtime_common::messages_xcm_extension::{
LaneIdFromChainId, XcmBlobHauler, XcmBlobHaulerAdapter,
};
use frame_support::{parameter_types, weights::Weight};
use pallet_bridge_relayers::WeightInfoExt as _;
use sp_core::Get;
use xcm_builder::HaulBlobExporter;

/// Default lane that is used to send messages to Rialto.
pub const XCM_LANE: LaneId = LaneId([0, 0, 0, 0]);
/// 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.
Expand Down Expand Up @@ -60,7 +61,7 @@ impl XcmBlobHauler for ToRialtoXcmBlobHauler {
type MessageSender = pallet_bridge_messages::Pallet<Runtime, WithRialtoMessagesInstance>;

fn xcm_lane() -> LaneId {
XCM_LANE
LaneIdFromChainId::<Runtime, WithRialtoMessagesInstance>::get()
}
}

Expand All @@ -80,6 +81,7 @@ impl pallet_bridge_messages::WeightInfoExt for crate::weights::RialtoMessagesWei

#[cfg(test)]
mod tests {
use super::*;
use crate::{RialtoGrandpaInstance, Runtime, WithRialtoMessagesInstance};

use bridge_runtime_common::{
Expand Down Expand Up @@ -121,4 +123,15 @@ mod tests {
},
});
}

#[test]
fn rialto_millau_bridge_identifier_did_not_changed() {
// there's nothing criminal if it is changed, but then thou need to fix it across
// all deployments scripts, alerts and so on
assert_eq!(
*ToRialtoXcmBlobHauler::xcm_lane().as_ref(),
hex_literal::hex!("52011894c856c0c613a2ad2395dfbb509090f6b7a6aef9359adb75aa26a586c7")
.into(),
);
}
}
21 changes: 17 additions & 4 deletions bin/millau/runtime/src/rialto_parachain_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@
use crate::{Runtime, WithRialtoParachainMessagesInstance};

use bp_messages::LaneId;
use bridge_runtime_common::messages_xcm_extension::{XcmBlobHauler, XcmBlobHaulerAdapter};
use bridge_runtime_common::messages_xcm_extension::{
LaneIdFromChainId, XcmBlobHauler, XcmBlobHaulerAdapter,
};
use frame_support::{parameter_types, weights::Weight};
use pallet_bridge_relayers::WeightInfoExt as _;
use sp_core::Get;
use xcm_builder::HaulBlobExporter;

/// Default lane that is used to send messages to Rialto parachain.
pub const XCM_LANE: LaneId = LaneId([0, 0, 0, 0]);
/// 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.
Expand Down Expand Up @@ -61,7 +62,7 @@ impl XcmBlobHauler for ToRialtoParachainXcmBlobHauler {
pallet_bridge_messages::Pallet<Runtime, WithRialtoParachainMessagesInstance>;

fn xcm_lane() -> LaneId {
XCM_LANE
LaneIdFromChainId::<Runtime, WithRialtoParachainMessagesInstance>::get()
}
}

Expand All @@ -83,6 +84,7 @@ impl pallet_bridge_messages::WeightInfoExt

#[cfg(test)]
mod tests {
use super::*;
use crate::{
PriorityBoostPerMessage, RialtoGrandpaInstance, Runtime,
WithRialtoParachainMessagesInstance,
Expand Down Expand Up @@ -134,4 +136,15 @@ mod tests {
PriorityBoostPerMessage,
>(1_000_000);
}

#[test]
fn rialto_parachain_millau_bridge_identifier_did_not_changed() {
// there's nothing criminal if it is changed, but then thou need to fix it across
// all deployments scripts, alerts and so on
assert_eq!(
*ToRialtoParachainXcmBlobHauler::xcm_lane().as_ref(),
hex_literal::hex!("6aa61bff567db6b5d5f0cb815ee6d8f5ac630e222a95700cb3d594134e3805de")
.into(),
);
}
}
55 changes: 28 additions & 27 deletions bin/millau/runtime/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,9 @@ mod tests {
target_chain::{DispatchMessage, DispatchMessageData, MessageDispatch},
LaneId, MessageKey, OutboundLaneData,
};
use bridge_runtime_common::messages_xcm_extension::XcmBlobMessageDispatchResult;
use bridge_runtime_common::messages_xcm_extension::{
XcmBlobHauler, XcmBlobMessageDispatchResult,
};
use codec::Encode;
use pallet_bridge_messages::OutboundLanes;
use xcm_executor::XcmExecutor;
Expand All @@ -269,16 +271,15 @@ mod tests {
fn xcm_messages_to_rialto_are_sent_using_bridge_exporter() {
new_test_ext().execute_with(|| {
// ensure that the there are no messages queued
let lane_id = crate::rialto_messages::ToRialtoXcmBlobHauler::xcm_lane();
OutboundLanes::<Runtime, WithRialtoMessagesInstance>::insert(
crate::rialto_messages::XCM_LANE,
lane_id,
OutboundLaneData::opened(),
);
assert_eq!(
OutboundLanes::<Runtime, WithRialtoMessagesInstance>::get(
crate::rialto_messages::XCM_LANE
)
.unwrap()
.latest_generated_nonce,
OutboundLanes::<Runtime, WithRialtoMessagesInstance>::get(lane_id)
.unwrap()
.latest_generated_nonce,
0,
);

Expand All @@ -295,11 +296,9 @@ mod tests {

// ensure that the message has been queued
assert_eq!(
OutboundLanes::<Runtime, WithRialtoMessagesInstance>::get(
crate::rialto_messages::XCM_LANE
)
.unwrap()
.latest_generated_nonce,
OutboundLanes::<Runtime, WithRialtoMessagesInstance>::get(lane_id)
.unwrap()
.latest_generated_nonce,
1,
);
})
Expand All @@ -309,16 +308,16 @@ mod tests {
fn xcm_messages_to_rialto_parachain_are_sent_using_bridge_exporter() {
new_test_ext().execute_with(|| {
// ensure that the there are no messages queued
let lane_id =
crate::rialto_parachain_messages::ToRialtoParachainXcmBlobHauler::xcm_lane();
OutboundLanes::<Runtime, WithRialtoParachainMessagesInstance>::insert(
crate::rialto_parachain_messages::XCM_LANE,
lane_id,
OutboundLaneData::opened(),
);
assert_eq!(
OutboundLanes::<Runtime, WithRialtoParachainMessagesInstance>::get(
crate::rialto_parachain_messages::XCM_LANE
)
.unwrap()
.latest_generated_nonce,
OutboundLanes::<Runtime, WithRialtoParachainMessagesInstance>::get(lane_id)
.unwrap()
.latest_generated_nonce,
0,
);

Expand All @@ -335,32 +334,32 @@ mod tests {

// ensure that the message has been queued
assert_eq!(
OutboundLanes::<Runtime, WithRialtoParachainMessagesInstance>::get(
crate::rialto_parachain_messages::XCM_LANE
)
.unwrap()
.latest_generated_nonce,
OutboundLanes::<Runtime, WithRialtoParachainMessagesInstance>::get(lane_id)
.unwrap()
.latest_generated_nonce,
1,
);
})
}

fn prepare_inbound_bridge_message() -> DispatchMessage<Vec<u8>> {
fn prepare_inbound_bridge_message(lane_id: LaneId) -> DispatchMessage<Vec<u8>> {
let xcm = xcm::VersionedXcm::<RuntimeCall>::V3(vec![Instruction::Trap(42)].into());
let location =
xcm::VersionedInteriorMultiLocation::V3(X1(GlobalConsensus(ThisNetwork::get())));
// this is the `BridgeMessage` from polkadot xcm builder, but it has no constructor
// or public fields, so just tuple
let bridge_message = (location, xcm).encode();
DispatchMessage {
key: MessageKey { lane_id: LaneId([0, 0, 0, 0]), nonce: 1 },
key: MessageKey { lane_id, nonce: 1 },
data: DispatchMessageData { payload: Ok(bridge_message) },
}
}

#[test]
fn xcm_messages_from_rialto_are_dispatched() {
let incoming_message = prepare_inbound_bridge_message();
let incoming_message = prepare_inbound_bridge_message(
crate::rialto_messages::ToRialtoXcmBlobHauler::xcm_lane(),
);

// we care only about handing message to the XCM dispatcher, so we don't care about its
// actual dispatch
Expand All @@ -373,7 +372,9 @@ mod tests {

#[test]
fn xcm_messages_from_rialto_parachain_are_dispatched() {
let incoming_message = prepare_inbound_bridge_message();
let incoming_message = prepare_inbound_bridge_message(
crate::rialto_parachain_messages::ToRialtoParachainXcmBlobHauler::xcm_lane(),
);

// we care only about handing message to the XCM dispatcher, so we don't care about its
// actual dispatch
Expand Down
1 change: 1 addition & 0 deletions bin/rialto-parachain/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jsonrpsee = { version = "0.16.2", features = ["server"] }
# Local Dependencies

bp-messages = { path = "../../../primitives/messages" }
bridge-runtime-common = { path = "../../runtime-common" }
rialto-parachain-runtime = { path = '../runtime' }

# Substrate Dependencies
Expand Down
5 changes: 4 additions & 1 deletion bin/rialto-parachain/node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// 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 bridge_runtime_common::messages_xcm_extension::XcmBlobHauler;
use cumulus_primitives_core::ParaId;
use rialto_parachain_runtime::{AccountId, AuraId, BridgeMillauMessagesConfig, Signature};
use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup};
Expand Down Expand Up @@ -192,7 +193,9 @@ fn testnet_genesis(
aura_ext: Default::default(),
bridge_millau_messages: BridgeMillauMessagesConfig {
owner: Some(get_account_id_from_seed::<sr25519::Public>(MILLAU_MESSAGES_PALLET_OWNER)),
opened_lanes: vec![bp_messages::LaneId::default()],
opened_lanes: vec![
rialto_parachain_runtime::millau_messages::ToMillauXcmBlobHauler::xcm_lane(),
],
..Default::default()
},
}
Expand Down
Loading

0 comments on commit 594ebac

Please sign in to comment.