Prune messages from on-idle callback (#1650)

* prune messages from on-idle callback

* no more secondary lanes at deployments

* clippy

* Update modules/messages/src/lib.rs

Co-authored-by: Adrian Catangiu <adrian@parity.io>

* sub -> add

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

* ensure spent_weight is correct

Co-authored-by: Adrian Catangiu <adrian@parity.io>
This commit is contained in:
Svyatoslav Nikolsky
2022-11-21 13:29:26 +03:00
committed by Bastian Köcher
parent 8e660dd74e
commit eabfea6229
13 changed files with 322 additions and 110 deletions
@@ -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;
@@ -455,7 +455,7 @@ impl XcmBridge for ToMillauBridge {
}
fn xcm_lane() -> bp_messages::LaneId {
DEFAULT_XCM_LANE_TO_MILLAU
XCM_LANE
}
}
@@ -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.
@@ -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;
@@ -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,
@@ -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.
@@ -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 {