mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-08 07:48:00 +00:00
Removed relayer_account: &AccountId from MessageDispatch (#2080)
* SourceBridgeHubChain/TargetBridgeHubChain replaced with RelayerAccountChain * Fix * Removed `relayer_account: &AccountId` from `MessageDispatch`
This commit is contained in:
committed by
Bastian Köcher
parent
1f8b4d989e
commit
db53d68e9b
@@ -64,8 +64,6 @@ pub type ToRialtoMessagesDeliveryProof =
|
||||
/// Call-dispatch based message dispatch for Rialto -> Millau messages.
|
||||
pub type FromRialtoMessageDispatch =
|
||||
bridge_runtime_common::messages_xcm_extension::XcmBlobMessageDispatch<
|
||||
bp_millau::Millau,
|
||||
bp_rialto::Rialto,
|
||||
crate::xcm_config::OnMillauBlobDispatcher,
|
||||
(),
|
||||
>;
|
||||
|
||||
@@ -59,8 +59,6 @@ pub type FromRialtoParachainMessagePayload = messages::target::FromBridgedChainM
|
||||
/// Call-dispatch based message dispatch for RialtoParachain -> Millau messages.
|
||||
pub type FromRialtoParachainMessageDispatch =
|
||||
bridge_runtime_common::messages_xcm_extension::XcmBlobMessageDispatch<
|
||||
bp_millau::Millau,
|
||||
bp_rialto::Rialto,
|
||||
crate::xcm_config::OnMillauBlobDispatcher,
|
||||
(),
|
||||
>;
|
||||
|
||||
@@ -349,8 +349,7 @@ mod tests {
|
||||
|
||||
// we care only about handing message to the XCM dispatcher, so we don't care about its
|
||||
// actual dispatch
|
||||
let dispatch_result =
|
||||
FromRialtoMessageDispatch::dispatch(&AccountId::from([0u8; 32]), incoming_message);
|
||||
let dispatch_result = FromRialtoMessageDispatch::dispatch(incoming_message);
|
||||
assert!(matches!(
|
||||
dispatch_result.dispatch_level_result,
|
||||
XcmBlobMessageDispatchResult::NotDispatched(_),
|
||||
@@ -363,8 +362,7 @@ mod tests {
|
||||
|
||||
// we care only about handing message to the XCM dispatcher, so we don't care about its
|
||||
// actual dispatch
|
||||
let dispatch_result =
|
||||
FromRialtoMessageDispatch::dispatch(&AccountId::from([0u8; 32]), incoming_message);
|
||||
let dispatch_result = FromRialtoMessageDispatch::dispatch(incoming_message);
|
||||
assert!(matches!(
|
||||
dispatch_result.dispatch_level_result,
|
||||
XcmBlobMessageDispatchResult::NotDispatched(_),
|
||||
|
||||
@@ -926,8 +926,7 @@ mod tests {
|
||||
|
||||
// we care only about handing message to the XCM dispatcher, so we don't care about its
|
||||
// actual dispatch
|
||||
let dispatch_result =
|
||||
FromMillauMessageDispatch::dispatch(&AccountId::from([0u8; 32]), incoming_message);
|
||||
let dispatch_result = FromMillauMessageDispatch::dispatch(incoming_message);
|
||||
assert!(matches!(
|
||||
dispatch_result.dispatch_level_result,
|
||||
XcmBlobMessageDispatchResult::NotDispatched(_),
|
||||
|
||||
@@ -60,8 +60,6 @@ pub type FromMillauMessagePayload = messages::target::FromBridgedChainMessagePay
|
||||
/// Call-dispatch based message dispatch for Millau -> RialtoParachain messages.
|
||||
pub type FromMillauMessageDispatch =
|
||||
bridge_runtime_common::messages_xcm_extension::XcmBlobMessageDispatch<
|
||||
bp_rialto_parachain::RialtoParachain,
|
||||
bp_millau::Millau,
|
||||
crate::OnRialtoParachainBlobDispatcher,
|
||||
(),
|
||||
>;
|
||||
|
||||
@@ -57,8 +57,6 @@ pub type FromMillauMessagePayload = messages::target::FromBridgedChainMessagePay
|
||||
/// Call-dispatch based message dispatch for Millau -> Rialto messages.
|
||||
pub type FromMillauMessageDispatch =
|
||||
bridge_runtime_common::messages_xcm_extension::XcmBlobMessageDispatch<
|
||||
bp_rialto::Rialto,
|
||||
bp_millau::Millau,
|
||||
crate::xcm_config::OnRialtoBlobDispatcher,
|
||||
(),
|
||||
>;
|
||||
|
||||
@@ -266,8 +266,7 @@ mod tests {
|
||||
|
||||
// we care only about handing message to the XCM dispatcher, so we don't care about its
|
||||
// actual dispatch
|
||||
let dispatch_result =
|
||||
FromMillauMessageDispatch::dispatch(&AccountId::from([0u8; 32]), incoming_message);
|
||||
let dispatch_result = FromMillauMessageDispatch::dispatch(incoming_message);
|
||||
assert!(matches!(
|
||||
dispatch_result.dispatch_level_result,
|
||||
XcmBlobMessageDispatchResult::NotDispatched(_),
|
||||
|
||||
@@ -26,7 +26,7 @@ use bp_messages::{
|
||||
target_chain::{DispatchMessage, MessageDispatch},
|
||||
LaneId,
|
||||
};
|
||||
use bp_runtime::{messages::MessageDispatchResult, AccountIdOf, Chain};
|
||||
use bp_runtime::messages::MessageDispatchResult;
|
||||
use codec::{Decode, Encode};
|
||||
use frame_support::{dispatch::Weight, CloneNoBound, EqNoBound, PartialEqNoBound};
|
||||
use pallet_bridge_messages::WeightInfoExt as MessagesPalletWeights;
|
||||
@@ -46,23 +46,12 @@ pub enum XcmBlobMessageDispatchResult {
|
||||
}
|
||||
|
||||
/// [`XcmBlobMessageDispatch`] is responsible for dispatching received messages
|
||||
pub struct XcmBlobMessageDispatch<SourceBridgeHubChain, TargetBridgeHubChain, DispatchBlob, Weights>
|
||||
{
|
||||
_marker: sp_std::marker::PhantomData<(
|
||||
SourceBridgeHubChain,
|
||||
TargetBridgeHubChain,
|
||||
DispatchBlob,
|
||||
Weights,
|
||||
)>,
|
||||
pub struct XcmBlobMessageDispatch<DispatchBlob, Weights> {
|
||||
_marker: sp_std::marker::PhantomData<(DispatchBlob, Weights)>,
|
||||
}
|
||||
|
||||
impl<
|
||||
SourceBridgeHubChain: Chain,
|
||||
TargetBridgeHubChain: Chain,
|
||||
BlobDispatcher: DispatchBlob,
|
||||
Weights: MessagesPalletWeights,
|
||||
> MessageDispatch<AccountIdOf<SourceBridgeHubChain>>
|
||||
for XcmBlobMessageDispatch<SourceBridgeHubChain, TargetBridgeHubChain, BlobDispatcher, Weights>
|
||||
impl<BlobDispatcher: DispatchBlob, Weights: MessagesPalletWeights> MessageDispatch
|
||||
for XcmBlobMessageDispatch<BlobDispatcher, Weights>
|
||||
{
|
||||
type DispatchPayload = XcmAsPlainPayload;
|
||||
type DispatchLevelResult = XcmBlobMessageDispatchResult;
|
||||
@@ -78,7 +67,6 @@ impl<
|
||||
}
|
||||
|
||||
fn dispatch(
|
||||
_relayer_account: &AccountIdOf<SourceBridgeHubChain>,
|
||||
message: DispatchMessage<Self::DispatchPayload>,
|
||||
) -> MessageDispatchResult<Self::DispatchLevelResult> {
|
||||
let payload = match message.data.payload {
|
||||
|
||||
@@ -834,6 +834,7 @@ mod tests {
|
||||
run_test(|| {
|
||||
assert_eq!(BestFinalized::<TestRuntime>::get(), None,);
|
||||
assert_eq!(Pallet::<TestRuntime>::best_finalized(), None);
|
||||
assert_eq!(PalletOperatingMode::<TestRuntime>::try_get(), Err(()));
|
||||
|
||||
let init_data = init_with_origin(RuntimeOrigin::root()).unwrap();
|
||||
|
||||
@@ -843,7 +844,10 @@ mod tests {
|
||||
CurrentAuthoritySet::<TestRuntime>::get().authorities,
|
||||
init_data.authority_list
|
||||
);
|
||||
assert_eq!(PalletOperatingMode::<TestRuntime>::get(), BasicOperatingMode::Normal);
|
||||
assert_eq!(
|
||||
PalletOperatingMode::<TestRuntime>::try_get(),
|
||||
Ok(BasicOperatingMode::Normal)
|
||||
);
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -164,10 +164,9 @@ impl<S: InboundLaneStorage> InboundLane<S> {
|
||||
}
|
||||
|
||||
/// Receive new message.
|
||||
pub fn receive_message<Dispatch: MessageDispatch<AccountId>, AccountId>(
|
||||
pub fn receive_message<Dispatch: MessageDispatch>(
|
||||
&mut self,
|
||||
relayer_at_bridged_chain: &S::Relayer,
|
||||
relayer_at_this_chain: &AccountId,
|
||||
nonce: MessageNonce,
|
||||
message_data: DispatchMessageData<Dispatch::DispatchPayload>,
|
||||
) -> ReceivalResult<Dispatch::DispatchLevelResult> {
|
||||
@@ -189,13 +188,10 @@ impl<S: InboundLaneStorage> InboundLane<S> {
|
||||
}
|
||||
|
||||
// then, dispatch message
|
||||
let dispatch_result = Dispatch::dispatch(
|
||||
relayer_at_this_chain,
|
||||
DispatchMessage {
|
||||
key: MessageKey { lane_id: self.storage.id(), nonce },
|
||||
data: message_data,
|
||||
},
|
||||
);
|
||||
let dispatch_result = Dispatch::dispatch(DispatchMessage {
|
||||
key: MessageKey { lane_id: self.storage.id(), nonce },
|
||||
data: message_data,
|
||||
});
|
||||
|
||||
// now let's update inbound lane storage
|
||||
match data.relayers.back_mut() {
|
||||
@@ -234,8 +230,7 @@ mod tests {
|
||||
nonce: MessageNonce,
|
||||
) {
|
||||
assert_eq!(
|
||||
lane.receive_message::<TestMessageDispatch, _>(
|
||||
&TEST_RELAYER_A,
|
||||
lane.receive_message::<TestMessageDispatch>(
|
||||
&TEST_RELAYER_A,
|
||||
nonce,
|
||||
inbound_message_data(REGULAR_PAYLOAD)
|
||||
@@ -362,8 +357,7 @@ mod tests {
|
||||
run_test(|| {
|
||||
let mut lane = inbound_lane::<TestRuntime, _>(TEST_LANE_ID);
|
||||
assert_eq!(
|
||||
lane.receive_message::<TestMessageDispatch, _>(
|
||||
&TEST_RELAYER_A,
|
||||
lane.receive_message::<TestMessageDispatch>(
|
||||
&TEST_RELAYER_A,
|
||||
10,
|
||||
inbound_message_data(REGULAR_PAYLOAD)
|
||||
@@ -382,8 +376,7 @@ mod tests {
|
||||
<TestRuntime as Config>::MaxUnrewardedRelayerEntriesAtInboundLane::get();
|
||||
for current_nonce in 1..max_nonce + 1 {
|
||||
assert_eq!(
|
||||
lane.receive_message::<TestMessageDispatch, _>(
|
||||
&(TEST_RELAYER_A + current_nonce),
|
||||
lane.receive_message::<TestMessageDispatch>(
|
||||
&(TEST_RELAYER_A + current_nonce),
|
||||
current_nonce,
|
||||
inbound_message_data(REGULAR_PAYLOAD)
|
||||
@@ -393,8 +386,7 @@ mod tests {
|
||||
}
|
||||
// Fails to dispatch new message from different than latest relayer.
|
||||
assert_eq!(
|
||||
lane.receive_message::<TestMessageDispatch, _>(
|
||||
&(TEST_RELAYER_A + max_nonce + 1),
|
||||
lane.receive_message::<TestMessageDispatch>(
|
||||
&(TEST_RELAYER_A + max_nonce + 1),
|
||||
max_nonce + 1,
|
||||
inbound_message_data(REGULAR_PAYLOAD)
|
||||
@@ -403,8 +395,7 @@ mod tests {
|
||||
);
|
||||
// Fails to dispatch new messages from latest relayer. Prevents griefing attacks.
|
||||
assert_eq!(
|
||||
lane.receive_message::<TestMessageDispatch, _>(
|
||||
&(TEST_RELAYER_A + max_nonce),
|
||||
lane.receive_message::<TestMessageDispatch>(
|
||||
&(TEST_RELAYER_A + max_nonce),
|
||||
max_nonce + 1,
|
||||
inbound_message_data(REGULAR_PAYLOAD)
|
||||
@@ -421,8 +412,7 @@ mod tests {
|
||||
let max_nonce = <TestRuntime as Config>::MaxUnconfirmedMessagesAtInboundLane::get();
|
||||
for current_nonce in 1..=max_nonce {
|
||||
assert_eq!(
|
||||
lane.receive_message::<TestMessageDispatch, _>(
|
||||
&TEST_RELAYER_A,
|
||||
lane.receive_message::<TestMessageDispatch>(
|
||||
&TEST_RELAYER_A,
|
||||
current_nonce,
|
||||
inbound_message_data(REGULAR_PAYLOAD)
|
||||
@@ -432,8 +422,7 @@ mod tests {
|
||||
}
|
||||
// Fails to dispatch new message from different than latest relayer.
|
||||
assert_eq!(
|
||||
lane.receive_message::<TestMessageDispatch, _>(
|
||||
&TEST_RELAYER_B,
|
||||
lane.receive_message::<TestMessageDispatch>(
|
||||
&TEST_RELAYER_B,
|
||||
max_nonce + 1,
|
||||
inbound_message_data(REGULAR_PAYLOAD)
|
||||
@@ -442,8 +431,7 @@ mod tests {
|
||||
);
|
||||
// Fails to dispatch new messages from latest relayer.
|
||||
assert_eq!(
|
||||
lane.receive_message::<TestMessageDispatch, _>(
|
||||
&TEST_RELAYER_A,
|
||||
lane.receive_message::<TestMessageDispatch>(
|
||||
&TEST_RELAYER_A,
|
||||
max_nonce + 1,
|
||||
inbound_message_data(REGULAR_PAYLOAD)
|
||||
@@ -458,8 +446,7 @@ mod tests {
|
||||
run_test(|| {
|
||||
let mut lane = inbound_lane::<TestRuntime, _>(TEST_LANE_ID);
|
||||
assert_eq!(
|
||||
lane.receive_message::<TestMessageDispatch, _>(
|
||||
&TEST_RELAYER_A,
|
||||
lane.receive_message::<TestMessageDispatch>(
|
||||
&TEST_RELAYER_A,
|
||||
1,
|
||||
inbound_message_data(REGULAR_PAYLOAD)
|
||||
@@ -467,8 +454,7 @@ mod tests {
|
||||
ReceivalResult::Dispatched(dispatch_result(0))
|
||||
);
|
||||
assert_eq!(
|
||||
lane.receive_message::<TestMessageDispatch, _>(
|
||||
&TEST_RELAYER_B,
|
||||
lane.receive_message::<TestMessageDispatch>(
|
||||
&TEST_RELAYER_B,
|
||||
2,
|
||||
inbound_message_data(REGULAR_PAYLOAD)
|
||||
@@ -476,8 +462,7 @@ mod tests {
|
||||
ReceivalResult::Dispatched(dispatch_result(0))
|
||||
);
|
||||
assert_eq!(
|
||||
lane.receive_message::<TestMessageDispatch, _>(
|
||||
&TEST_RELAYER_A,
|
||||
lane.receive_message::<TestMessageDispatch>(
|
||||
&TEST_RELAYER_A,
|
||||
3,
|
||||
inbound_message_data(REGULAR_PAYLOAD)
|
||||
@@ -500,8 +485,7 @@ mod tests {
|
||||
run_test(|| {
|
||||
let mut lane = inbound_lane::<TestRuntime, _>(TEST_LANE_ID);
|
||||
assert_eq!(
|
||||
lane.receive_message::<TestMessageDispatch, _>(
|
||||
&TEST_RELAYER_A,
|
||||
lane.receive_message::<TestMessageDispatch>(
|
||||
&TEST_RELAYER_A,
|
||||
1,
|
||||
inbound_message_data(REGULAR_PAYLOAD)
|
||||
@@ -509,8 +493,7 @@ mod tests {
|
||||
ReceivalResult::Dispatched(dispatch_result(0))
|
||||
);
|
||||
assert_eq!(
|
||||
lane.receive_message::<TestMessageDispatch, _>(
|
||||
&TEST_RELAYER_B,
|
||||
lane.receive_message::<TestMessageDispatch>(
|
||||
&TEST_RELAYER_B,
|
||||
1,
|
||||
inbound_message_data(REGULAR_PAYLOAD)
|
||||
@@ -536,8 +519,7 @@ mod tests {
|
||||
let mut payload = REGULAR_PAYLOAD;
|
||||
*payload.dispatch_result.unspent_weight.ref_time_mut() = 1;
|
||||
assert_eq!(
|
||||
lane.receive_message::<TestMessageDispatch, _>(
|
||||
&TEST_RELAYER_A,
|
||||
lane.receive_message::<TestMessageDispatch>(
|
||||
&TEST_RELAYER_A,
|
||||
1,
|
||||
inbound_message_data(payload)
|
||||
|
||||
@@ -162,10 +162,7 @@ pub mod pallet {
|
||||
/// Source header chain, as it is represented on target chain.
|
||||
type SourceHeaderChain: SourceHeaderChain;
|
||||
/// Message dispatch.
|
||||
type MessageDispatch: MessageDispatch<
|
||||
Self::AccountId,
|
||||
DispatchPayload = Self::InboundPayload,
|
||||
>;
|
||||
type MessageDispatch: MessageDispatch<DispatchPayload = Self::InboundPayload>;
|
||||
}
|
||||
|
||||
/// Shortcut to messages proof type for Config.
|
||||
@@ -361,9 +358,8 @@ pub mod pallet {
|
||||
fail!(Error::<T, I>::InsufficientDispatchWeight);
|
||||
}
|
||||
|
||||
let receival_result = lane.receive_message::<T::MessageDispatch, T::AccountId>(
|
||||
let receival_result = lane.receive_message::<T::MessageDispatch>(
|
||||
&relayer_id_at_bridged_chain,
|
||||
&relayer_id_at_this_chain,
|
||||
message.key.nonce,
|
||||
message.data,
|
||||
);
|
||||
@@ -545,11 +541,7 @@ pub mod pallet {
|
||||
MessageAccepted { lane_id: LaneId, nonce: MessageNonce },
|
||||
/// Messages have been received from the bridged chain.
|
||||
MessagesReceived(
|
||||
Vec<
|
||||
ReceivedMessages<
|
||||
<T::MessageDispatch as MessageDispatch<T::AccountId>>::DispatchLevelResult,
|
||||
>,
|
||||
>,
|
||||
Vec<ReceivedMessages<<T::MessageDispatch as MessageDispatch>::DispatchLevelResult>>,
|
||||
),
|
||||
/// Messages in the inclusive range have been delivered to the bridged chain.
|
||||
MessagesDelivered { lane_id: LaneId, messages: DeliveredMessages },
|
||||
|
||||
@@ -416,7 +416,7 @@ impl SourceHeaderChain for TestSourceHeaderChain {
|
||||
#[derive(Debug)]
|
||||
pub struct TestMessageDispatch;
|
||||
|
||||
impl MessageDispatch<AccountId> for TestMessageDispatch {
|
||||
impl MessageDispatch for TestMessageDispatch {
|
||||
type DispatchPayload = TestPayload;
|
||||
type DispatchLevelResult = TestDispatchLevelResult;
|
||||
|
||||
@@ -428,7 +428,6 @@ impl MessageDispatch<AccountId> for TestMessageDispatch {
|
||||
}
|
||||
|
||||
fn dispatch(
|
||||
_relayer_account: &AccountId,
|
||||
message: DispatchMessage<TestPayload>,
|
||||
) -> MessageDispatchResult<TestDispatchLevelResult> {
|
||||
match message.data.payload.as_ref() {
|
||||
|
||||
@@ -83,7 +83,7 @@ pub trait SourceHeaderChain {
|
||||
}
|
||||
|
||||
/// Called when inbound message is received.
|
||||
pub trait MessageDispatch<AccountId> {
|
||||
pub trait MessageDispatch {
|
||||
/// Decoded message payload type. Valid message may contain invalid payload. In this case
|
||||
/// message is delivered, but dispatch fails. Therefore, two separate types of payload
|
||||
/// (opaque `MessagePayload` used in delivery and this `DispatchPayload` used in dispatch).
|
||||
@@ -103,11 +103,7 @@ pub trait MessageDispatch<AccountId> {
|
||||
///
|
||||
/// It is up to the implementers of this trait to determine whether the message
|
||||
/// is invalid (i.e. improperly encoded, has too large weight, ...) or not.
|
||||
///
|
||||
/// If your configuration allows paying dispatch fee at the target chain, then
|
||||
/// it must be paid inside this method to the `relayer_account`.
|
||||
fn dispatch(
|
||||
relayer_account: &AccountId,
|
||||
message: DispatchMessage<Self::DispatchPayload>,
|
||||
) -> MessageDispatchResult<Self::DispatchLevelResult>;
|
||||
}
|
||||
@@ -186,7 +182,7 @@ impl<MessagesProof: Parameter + Size, DispatchPayload> SourceHeaderChain
|
||||
}
|
||||
}
|
||||
|
||||
impl<MessagesProof, DispatchPayload: Decode, AccountId> MessageDispatch<AccountId>
|
||||
impl<MessagesProof, DispatchPayload: Decode> MessageDispatch
|
||||
for ForbidInboundMessages<MessagesProof, DispatchPayload>
|
||||
{
|
||||
type DispatchPayload = DispatchPayload;
|
||||
@@ -197,7 +193,6 @@ impl<MessagesProof, DispatchPayload: Decode, AccountId> MessageDispatch<AccountI
|
||||
}
|
||||
|
||||
fn dispatch(
|
||||
_: &AccountId,
|
||||
_: DispatchMessage<Self::DispatchPayload>,
|
||||
) -> MessageDispatchResult<Self::DispatchLevelResult> {
|
||||
MessageDispatchResult { unspent_weight: Weight::zero(), dispatch_level_result: () }
|
||||
|
||||
Reference in New Issue
Block a user