Skip to content

Commit

Permalink
Prune messages from on-idle callback (paritytech#1650)
Browse files Browse the repository at this point in the history
* prune messages from on-idle callback

* no more secondary lanes at deployments

* clippy

* Update modules/messages/src/lib.rs

Co-authored-by: Adrian Catangiu <[email protected]>

* sub -> add

* more tests + check that message is sent using one of ActiveOutboundLanes

* ensure spent_weight is correct

Co-authored-by: Adrian Catangiu <[email protected]>
  • Loading branch information
svyatonik and acatangiu committed Nov 21, 2022
1 parent eb4d859 commit fe6e473
Show file tree
Hide file tree
Showing 13 changed files with 322 additions and 110 deletions.
6 changes: 4 additions & 2 deletions bin/millau/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,8 @@ parameter_types! {
pub const RootAccountForPayments: Option<AccountId> = None;
pub const RialtoChainId: bp_runtime::ChainId = bp_runtime::RIALTO_CHAIN_ID;
pub const RialtoParachainChainId: bp_runtime::ChainId = bp_runtime::RIALTO_PARACHAIN_CHAIN_ID;
pub RialtoActiveOutboundLanes: &'static [bp_messages::LaneId] = &[rialto_messages::XCM_LANE];
pub RialtoParachainActiveOutboundLanes: &'static [bp_messages::LaneId] = &[rialto_parachain_messages::XCM_LANE];
}

/// Instance of the messages pallet used to relay messages to/from Rialto chain.
Expand All @@ -477,7 +479,7 @@ pub type WithRialtoMessagesInstance = ();
impl pallet_bridge_messages::Config<WithRialtoMessagesInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = pallet_bridge_messages::weights::BridgeWeight<Runtime>;
type MaxMessagesToPruneAtOnce = MaxMessagesToPruneAtOnce;
type ActiveOutboundLanes = RialtoActiveOutboundLanes;
type MaxUnrewardedRelayerEntriesAtInboundLane = MaxUnrewardedRelayerEntriesAtInboundLane;
type MaxUnconfirmedMessagesAtInboundLane = MaxUnconfirmedMessagesAtInboundLane;

Expand Down Expand Up @@ -506,7 +508,7 @@ pub type WithRialtoParachainMessagesInstance = pallet_bridge_messages::Instance1
impl pallet_bridge_messages::Config<WithRialtoParachainMessagesInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = pallet_bridge_messages::weights::BridgeWeight<Runtime>;
type MaxMessagesToPruneAtOnce = MaxMessagesToPruneAtOnce;
type ActiveOutboundLanes = RialtoParachainActiveOutboundLanes;
type MaxUnrewardedRelayerEntriesAtInboundLane = MaxUnrewardedRelayerEntriesAtInboundLane;
type MaxUnconfirmedMessagesAtInboundLane = MaxUnconfirmedMessagesAtInboundLane;

Expand Down
24 changes: 4 additions & 20 deletions 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::{OriginCaller, RialtoGrandpaInstance, Runtime, RuntimeCall, RuntimeOrigin};
use crate::{RialtoGrandpaInstance, Runtime, RuntimeCall, RuntimeOrigin};

use bp_messages::{
source_chain::TargetHeaderChain,
Expand All @@ -28,7 +28,7 @@ use bridge_runtime_common::messages::{self, MessageBridge};
use frame_support::{parameter_types, weights::Weight, RuntimeDebug};

/// Default lane that is used to send messages to Rialto.
pub const DEFAULT_XCM_LANE_TO_RIALTO: LaneId = [0, 0, 0, 0];
pub const XCM_LANE: 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 @@ -98,24 +98,8 @@ impl messages::ThisChainWithMessages for Millau {
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;

fn is_message_accepted(send_origin: &Self::RuntimeOrigin, lane: &LaneId) -> bool {
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 == DEFAULT_XCM_LANE_TO_RIALTO || *lane == [0, 0, 0, 1]
fn is_message_accepted(_send_origin: &Self::RuntimeOrigin, _lane: &LaneId) -> bool {
true
}

fn maximal_pending_messages_at_outbound_lane() -> MessageNonce {
Expand Down
6 changes: 3 additions & 3 deletions bin/millau/runtime/src/rialto_parachain_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use bridge_runtime_common::messages::{self, MessageBridge};
use frame_support::{parameter_types, weights::Weight, RuntimeDebug};

/// Default lane that is used to send messages to Rialto parachain.
pub const DEFAULT_XCM_LANE_TO_RIALTO_PARACHAIN: LaneId = [0, 0, 0, 0];
pub const XCM_LANE: 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 @@ -103,8 +103,8 @@ impl messages::ThisChainWithMessages for Millau {
type RuntimeCall = RuntimeCall;
type RuntimeOrigin = RuntimeOrigin;

fn is_message_accepted(_send_origin: &Self::RuntimeOrigin, lane: &LaneId) -> bool {
*lane == DEFAULT_XCM_LANE_TO_RIALTO_PARACHAIN || *lane == [0, 0, 0, 1]
fn is_message_accepted(_send_origin: &Self::RuntimeOrigin, _lane: &LaneId) -> bool {
true
}

fn maximal_pending_messages_at_outbound_lane() -> MessageNonce {
Expand Down
10 changes: 4 additions & 6 deletions bin/millau/runtime/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@
//! XCM configurations for the Millau runtime.

use super::{
rialto_messages::{WithRialtoMessageBridge, DEFAULT_XCM_LANE_TO_RIALTO},
rialto_parachain_messages::{
WithRialtoParachainMessageBridge, DEFAULT_XCM_LANE_TO_RIALTO_PARACHAIN,
},
rialto_messages::{WithRialtoMessageBridge, XCM_LANE},
rialto_parachain_messages::{WithRialtoParachainMessageBridge, XCM_LANE as XCM_LANE_PARACHAIN},
AccountId, AllPalletsWithSystem, Balances, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin,
WithRialtoMessagesInstance, WithRialtoParachainMessagesInstance, XcmPallet,
};
Expand Down Expand Up @@ -218,7 +216,7 @@ impl XcmBridge for ToRialtoBridge {
}

fn xcm_lane() -> LaneId {
DEFAULT_XCM_LANE_TO_RIALTO
XCM_LANE
}
}

Expand All @@ -245,7 +243,7 @@ impl XcmBridge for ToRialtoParachainBridge {
}

fn xcm_lane() -> LaneId {
DEFAULT_XCM_LANE_TO_RIALTO_PARACHAIN
XCM_LANE_PARACHAIN
}
}

Expand Down
7 changes: 4 additions & 3 deletions bin/rialto-parachain/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#[cfg(feature = "std")]
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));

use crate::millau_messages::{WithMillauMessageBridge, DEFAULT_XCM_LANE_TO_MILLAU};
use crate::millau_messages::{WithMillauMessageBridge, XCM_LANE};

use bridge_runtime_common::messages::source::{XcmBridge, XcmBridgeAdapter};
use cumulus_pallet_parachain_system::AnyRelayNumber;
Expand Down Expand Up @@ -455,7 +455,7 @@ impl XcmBridge for ToMillauBridge {
}

fn xcm_lane() -> bp_messages::LaneId {
DEFAULT_XCM_LANE_TO_MILLAU
XCM_LANE
}
}

Expand Down Expand Up @@ -554,6 +554,7 @@ parameter_types! {
bp_millau::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX;
pub const RootAccountForPayments: Option<AccountId> = None;
pub const BridgedChainId: bp_runtime::ChainId = bp_runtime::MILLAU_CHAIN_ID;
pub ActiveOutboundLanes: &'static [bp_messages::LaneId] = &[millau_messages::XCM_LANE];
}

/// Instance of the messages pallet used to relay messages to/from Millau chain.
Expand All @@ -562,7 +563,7 @@ pub type WithMillauMessagesInstance = ();
impl pallet_bridge_messages::Config<WithMillauMessagesInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = pallet_bridge_messages::weights::BridgeWeight<Runtime>;
type MaxMessagesToPruneAtOnce = MaxMessagesToPruneAtOnce;
type ActiveOutboundLanes = ActiveOutboundLanes;
type MaxUnrewardedRelayerEntriesAtInboundLane = MaxUnrewardedRelayerEntriesAtInboundLane;
type MaxUnconfirmedMessagesAtInboundLane = MaxUnconfirmedMessagesAtInboundLane;

Expand Down
23 changes: 4 additions & 19 deletions bin/rialto-parachain/runtime/src/millau_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// TODO: this is almost exact copy of `millau_messages.rs` from Rialto runtime.
// Should be extracted to a separate crate and reused here.

use crate::{MillauGrandpaInstance, OriginCaller, Runtime, RuntimeCall, RuntimeOrigin};
use crate::{MillauGrandpaInstance, Runtime, RuntimeCall, RuntimeOrigin};

use bp_messages::{
source_chain::TargetHeaderChain,
Expand All @@ -31,7 +31,7 @@ use bridge_runtime_common::messages::{self, MessageBridge};
use frame_support::{parameter_types, weights::Weight, RuntimeDebug};

/// Default lane that is used to send messages to Millau.
pub const DEFAULT_XCM_LANE_TO_MILLAU: LaneId = [0, 0, 0, 0];
pub const XCM_LANE: 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 @@ -102,23 +102,8 @@ impl messages::ThisChainWithMessages for RialtoParachain {
type RuntimeCall = RuntimeCall;
type RuntimeOrigin = RuntimeOrigin;

fn is_message_accepted(send_origin: &Self::RuntimeOrigin, lane: &LaneId) -> bool {
let here_location = xcm::v3::MultiLocation::from(crate::UniversalLocation::get());
match send_origin.caller {
OriginCaller::PolkadotXcm(pallet_xcm::Origin::Xcm(ref location))
if *location == here_location =>
{
log::trace!(target: "runtime::bridge", "Verifying message sent using XCM pallet to Millau");
},
_ => {
// 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 Millau");
},
}

*lane == [0, 0, 0, 0] || *lane == [0, 0, 0, 1]
fn is_message_accepted(_send_origin: &Self::RuntimeOrigin, _lane: &LaneId) -> bool {
true
}

fn maximal_pending_messages_at_outbound_lane() -> MessageNonce {
Expand Down
3 changes: 2 additions & 1 deletion bin/rialto/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ parameter_types! {
bp_millau::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX;
pub const RootAccountForPayments: Option<AccountId> = None;
pub const BridgedChainId: bp_runtime::ChainId = bp_runtime::MILLAU_CHAIN_ID;
pub ActiveOutboundLanes: &'static [bp_messages::LaneId] = &[millau_messages::XCM_LANE];
}

/// Instance of the messages pallet used to relay messages to/from Millau chain.
Expand All @@ -450,7 +451,7 @@ pub type WithMillauMessagesInstance = ();
impl pallet_bridge_messages::Config<WithMillauMessagesInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = pallet_bridge_messages::weights::BridgeWeight<Runtime>;
type MaxMessagesToPruneAtOnce = MaxMessagesToPruneAtOnce;
type ActiveOutboundLanes = ActiveOutboundLanes;
type MaxUnrewardedRelayerEntriesAtInboundLane = MaxUnrewardedRelayerEntriesAtInboundLane;
type MaxUnconfirmedMessagesAtInboundLane = MaxUnconfirmedMessagesAtInboundLane;

Expand Down
24 changes: 5 additions & 19 deletions bin/rialto/runtime/src/millau_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::{MillauGrandpaInstance, OriginCaller, Runtime, RuntimeCall, RuntimeOrigin};
use crate::{MillauGrandpaInstance, Runtime, RuntimeCall, RuntimeOrigin};

use bp_messages::{
source_chain::TargetHeaderChain,
Expand All @@ -27,6 +27,8 @@ use bp_runtime::{ChainId, MILLAU_CHAIN_ID, RIALTO_CHAIN_ID};
use bridge_runtime_common::messages::{self, MessageBridge};
use frame_support::{parameter_types, weights::Weight, RuntimeDebug};

/// Lane that is used for XCM messages exchange.
pub const XCM_LANE: 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 @@ -96,24 +98,8 @@ impl messages::ThisChainWithMessages for Rialto {
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;

fn is_message_accepted(send_origin: &Self::RuntimeOrigin, lane: &LaneId) -> bool {
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 Millau");
},
_ => {
// 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 Millau");
},
}

*lane == [0, 0, 0, 0] || *lane == [0, 0, 0, 1]
fn is_message_accepted(_send_origin: &Self::RuntimeOrigin, _lane: &LaneId) -> bool {
true
}

fn maximal_pending_messages_at_outbound_lane() -> MessageNonce {
Expand Down
6 changes: 3 additions & 3 deletions bin/runtime-common/src/integrity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,9 @@ where
MI: 'static,
{
assert!(
R::MaxMessagesToPruneAtOnce::get() > 0,
"MaxMessagesToPruneAtOnce ({}) must be larger than zero",
R::MaxMessagesToPruneAtOnce::get(),
!R::ActiveOutboundLanes::get().is_empty(),
"ActiveOutboundLanes ({:?}) must not be empty",
R::ActiveOutboundLanes::get(),
);
assert!(
R::MaxUnrewardedRelayerEntriesAtInboundLane::get() <= params.max_unrewarded_relayers_in_bridged_confirmation_tx,
Expand Down
Loading

0 comments on commit fe6e473

Please sign in to comment.