mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 11:01:01 +00:00
remove message sender origin (#2322)
This commit is contained in:
committed by
Bastian Köcher
parent
7807b9de93
commit
f42b883745
@@ -27,7 +27,6 @@ use bridge_runtime_common::{
|
|||||||
};
|
};
|
||||||
use frame_support::{parameter_types, weights::Weight, RuntimeDebug};
|
use frame_support::{parameter_types, weights::Weight, RuntimeDebug};
|
||||||
use pallet_bridge_relayers::WeightInfoExt as _;
|
use pallet_bridge_relayers::WeightInfoExt as _;
|
||||||
use xcm::latest::prelude::*;
|
|
||||||
use xcm_builder::HaulBlobExporter;
|
use xcm_builder::HaulBlobExporter;
|
||||||
|
|
||||||
/// Default lane that is used to send messages to Rialto.
|
/// Default lane that is used to send messages to Rialto.
|
||||||
@@ -124,12 +123,6 @@ pub struct ToRialtoXcmBlobHauler;
|
|||||||
|
|
||||||
impl XcmBlobHauler for ToRialtoXcmBlobHauler {
|
impl XcmBlobHauler for ToRialtoXcmBlobHauler {
|
||||||
type MessageSender = pallet_bridge_messages::Pallet<Runtime, WithRialtoMessagesInstance>;
|
type MessageSender = pallet_bridge_messages::Pallet<Runtime, WithRialtoMessagesInstance>;
|
||||||
type MessageSenderOrigin = RuntimeOrigin;
|
|
||||||
|
|
||||||
fn message_sender_origin() -> RuntimeOrigin {
|
|
||||||
pallet_xcm::Origin::from(MultiLocation::new(1, crate::xcm_config::UniversalLocation::get()))
|
|
||||||
.into()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn xcm_lane() -> LaneId {
|
fn xcm_lane() -> LaneId {
|
||||||
XCM_LANE
|
XCM_LANE
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ use bridge_runtime_common::{
|
|||||||
};
|
};
|
||||||
use frame_support::{parameter_types, weights::Weight, RuntimeDebug};
|
use frame_support::{parameter_types, weights::Weight, RuntimeDebug};
|
||||||
use pallet_bridge_relayers::WeightInfoExt as _;
|
use pallet_bridge_relayers::WeightInfoExt as _;
|
||||||
use xcm::latest::prelude::*;
|
|
||||||
use xcm_builder::HaulBlobExporter;
|
use xcm_builder::HaulBlobExporter;
|
||||||
|
|
||||||
/// Default lane that is used to send messages to Rialto parachain.
|
/// Default lane that is used to send messages to Rialto parachain.
|
||||||
@@ -125,12 +124,6 @@ pub struct ToRialtoParachainXcmBlobHauler;
|
|||||||
impl XcmBlobHauler for ToRialtoParachainXcmBlobHauler {
|
impl XcmBlobHauler for ToRialtoParachainXcmBlobHauler {
|
||||||
type MessageSender =
|
type MessageSender =
|
||||||
pallet_bridge_messages::Pallet<Runtime, WithRialtoParachainMessagesInstance>;
|
pallet_bridge_messages::Pallet<Runtime, WithRialtoParachainMessagesInstance>;
|
||||||
type MessageSenderOrigin = RuntimeOrigin;
|
|
||||||
|
|
||||||
fn message_sender_origin() -> RuntimeOrigin {
|
|
||||||
pallet_xcm::Origin::from(MultiLocation::new(1, crate::xcm_config::UniversalLocation::get()))
|
|
||||||
.into()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn xcm_lane() -> LaneId {
|
fn xcm_lane() -> LaneId {
|
||||||
XCM_LANE
|
XCM_LANE
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ use bridge_runtime_common::{
|
|||||||
messages_xcm_extension::{XcmBlobHauler, XcmBlobHaulerAdapter},
|
messages_xcm_extension::{XcmBlobHauler, XcmBlobHaulerAdapter},
|
||||||
};
|
};
|
||||||
use frame_support::{parameter_types, weights::Weight, RuntimeDebug};
|
use frame_support::{parameter_types, weights::Weight, RuntimeDebug};
|
||||||
use xcm::latest::prelude::*;
|
|
||||||
use xcm_builder::HaulBlobExporter;
|
use xcm_builder::HaulBlobExporter;
|
||||||
|
|
||||||
/// Default lane that is used to send messages to Millau.
|
/// Default lane that is used to send messages to Millau.
|
||||||
@@ -124,11 +123,6 @@ pub struct ToMillauXcmBlobHauler;
|
|||||||
|
|
||||||
impl XcmBlobHauler for ToMillauXcmBlobHauler {
|
impl XcmBlobHauler for ToMillauXcmBlobHauler {
|
||||||
type MessageSender = pallet_bridge_messages::Pallet<Runtime, WithMillauMessagesInstance>;
|
type MessageSender = pallet_bridge_messages::Pallet<Runtime, WithMillauMessagesInstance>;
|
||||||
type MessageSenderOrigin = RuntimeOrigin;
|
|
||||||
|
|
||||||
fn message_sender_origin() -> RuntimeOrigin {
|
|
||||||
pallet_xcm::Origin::from(MultiLocation::new(1, crate::UniversalLocation::get())).into()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn xcm_lane() -> LaneId {
|
fn xcm_lane() -> LaneId {
|
||||||
XCM_LANE
|
XCM_LANE
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ use bridge_runtime_common::{
|
|||||||
messages_xcm_extension::{XcmBlobHauler, XcmBlobHaulerAdapter},
|
messages_xcm_extension::{XcmBlobHauler, XcmBlobHaulerAdapter},
|
||||||
};
|
};
|
||||||
use frame_support::{parameter_types, weights::Weight, RuntimeDebug};
|
use frame_support::{parameter_types, weights::Weight, RuntimeDebug};
|
||||||
use xcm::latest::prelude::*;
|
|
||||||
use xcm_builder::HaulBlobExporter;
|
use xcm_builder::HaulBlobExporter;
|
||||||
|
|
||||||
/// Lane that is used for XCM messages exchange.
|
/// Lane that is used for XCM messages exchange.
|
||||||
@@ -123,12 +122,6 @@ pub struct ToMillauXcmBlobHauler;
|
|||||||
|
|
||||||
impl XcmBlobHauler for ToMillauXcmBlobHauler {
|
impl XcmBlobHauler for ToMillauXcmBlobHauler {
|
||||||
type MessageSender = pallet_bridge_messages::Pallet<Runtime, WithMillauMessagesInstance>;
|
type MessageSender = pallet_bridge_messages::Pallet<Runtime, WithMillauMessagesInstance>;
|
||||||
type MessageSenderOrigin = RuntimeOrigin;
|
|
||||||
|
|
||||||
fn message_sender_origin() -> RuntimeOrigin {
|
|
||||||
pallet_xcm::Origin::from(MultiLocation::new(1, crate::xcm_config::UniversalLocation::get()))
|
|
||||||
.into()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn xcm_lane() -> LaneId {
|
fn xcm_lane() -> LaneId {
|
||||||
XCM_LANE
|
XCM_LANE
|
||||||
|
|||||||
@@ -72,8 +72,6 @@ pub type HasherOf<C> = bp_runtime::HasherOf<UnderlyingChainOf<C>>;
|
|||||||
pub type AccountIdOf<C> = bp_runtime::AccountIdOf<UnderlyingChainOf<C>>;
|
pub type AccountIdOf<C> = bp_runtime::AccountIdOf<UnderlyingChainOf<C>>;
|
||||||
/// Type of balances that is used on the chain.
|
/// Type of balances that is used on the chain.
|
||||||
pub type BalanceOf<C> = bp_runtime::BalanceOf<UnderlyingChainOf<C>>;
|
pub type BalanceOf<C> = bp_runtime::BalanceOf<UnderlyingChainOf<C>>;
|
||||||
/// Type of origin that is used on the chain.
|
|
||||||
pub type OriginOf<C> = <C as ThisChainWithMessages>::RuntimeOrigin;
|
|
||||||
|
|
||||||
/// Sub-module that is declaring types required for processing This -> Bridged chain messages.
|
/// Sub-module that is declaring types required for processing This -> Bridged chain messages.
|
||||||
pub mod source {
|
pub mod source {
|
||||||
@@ -138,17 +136,11 @@ pub mod source {
|
|||||||
#[derive(RuntimeDebug)]
|
#[derive(RuntimeDebug)]
|
||||||
pub struct FromThisChainMessageVerifier<B>(PhantomData<B>);
|
pub struct FromThisChainMessageVerifier<B>(PhantomData<B>);
|
||||||
|
|
||||||
impl<B> LaneMessageVerifier<OriginOf<ThisChain<B>>, FromThisChainMessagePayload>
|
impl<B> LaneMessageVerifier<FromThisChainMessagePayload> for FromThisChainMessageVerifier<B>
|
||||||
for FromThisChainMessageVerifier<B>
|
|
||||||
where
|
where
|
||||||
B: MessageBridge,
|
B: MessageBridge,
|
||||||
// matches requirements from the `frame_system::Config::Origin`
|
|
||||||
OriginOf<ThisChain<B>>: Clone
|
|
||||||
+ Into<Result<frame_system::RawOrigin<AccountIdOf<ThisChain<B>>>, OriginOf<ThisChain<B>>>>,
|
|
||||||
AccountIdOf<ThisChain<B>>: PartialEq + Clone,
|
|
||||||
{
|
{
|
||||||
fn verify_message(
|
fn verify_message(
|
||||||
_submitter: &OriginOf<ThisChain<B>>,
|
|
||||||
_lane: &LaneId,
|
_lane: &LaneId,
|
||||||
_lane_outbound_data: &OutboundLaneData,
|
_lane_outbound_data: &OutboundLaneData,
|
||||||
_payload: &FromThisChainMessagePayload,
|
_payload: &FromThisChainMessagePayload,
|
||||||
|
|||||||
@@ -110,12 +110,7 @@ impl<BlobDispatcher: DispatchBlob, Weights: MessagesPalletWeights> MessageDispat
|
|||||||
/// one side, where on the other it can be dispatched by [`XcmBlobMessageDispatch`].
|
/// one side, where on the other it can be dispatched by [`XcmBlobMessageDispatch`].
|
||||||
pub trait XcmBlobHauler {
|
pub trait XcmBlobHauler {
|
||||||
/// Runtime message sender adapter.
|
/// Runtime message sender adapter.
|
||||||
type MessageSender: MessagesBridge<Self::MessageSenderOrigin, XcmAsPlainPayload>;
|
type MessageSender: MessagesBridge<XcmAsPlainPayload>;
|
||||||
|
|
||||||
/// Runtime message sender origin, which is used by [`Self::MessageSender`].
|
|
||||||
type MessageSenderOrigin;
|
|
||||||
/// Our location within the Consensus Universe.
|
|
||||||
fn message_sender_origin() -> Self::MessageSenderOrigin;
|
|
||||||
|
|
||||||
/// Return message lane (as "point-to-point link") used to deliver XCM messages.
|
/// Return message lane (as "point-to-point link") used to deliver XCM messages.
|
||||||
fn xcm_lane() -> LaneId;
|
fn xcm_lane() -> LaneId;
|
||||||
@@ -124,12 +119,10 @@ pub trait XcmBlobHauler {
|
|||||||
/// XCM bridge adapter which connects [`XcmBlobHauler`] with [`XcmBlobHauler::MessageSender`] and
|
/// XCM bridge adapter which connects [`XcmBlobHauler`] with [`XcmBlobHauler::MessageSender`] and
|
||||||
/// makes sure that XCM blob is sent to the [`pallet_bridge_messages`] queue to be relayed.
|
/// makes sure that XCM blob is sent to the [`pallet_bridge_messages`] queue to be relayed.
|
||||||
pub struct XcmBlobHaulerAdapter<XcmBlobHauler>(sp_std::marker::PhantomData<XcmBlobHauler>);
|
pub struct XcmBlobHaulerAdapter<XcmBlobHauler>(sp_std::marker::PhantomData<XcmBlobHauler>);
|
||||||
impl<HaulerOrigin, H: XcmBlobHauler<MessageSenderOrigin = HaulerOrigin>> HaulBlob
|
impl<H: XcmBlobHauler> HaulBlob for XcmBlobHaulerAdapter<H> {
|
||||||
for XcmBlobHaulerAdapter<H>
|
|
||||||
{
|
|
||||||
fn haul_blob(blob: sp_std::prelude::Vec<u8>) -> Result<(), HaulBlobError> {
|
fn haul_blob(blob: sp_std::prelude::Vec<u8>) -> Result<(), HaulBlobError> {
|
||||||
let lane = H::xcm_lane();
|
let lane = H::xcm_lane();
|
||||||
H::MessageSender::send_message(H::message_sender_origin(), lane, blob)
|
H::MessageSender::send_message(lane, blob)
|
||||||
.map(|artifacts| (lane, artifacts.nonce).using_encoded(sp_io::hashing::blake2_256))
|
.map(|artifacts| (lane, artifacts.nonce).using_encoded(sp_io::hashing::blake2_256))
|
||||||
.map(|result| {
|
.map(|result| {
|
||||||
log::info!(
|
log::info!(
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ pub mod pallet {
|
|||||||
/// Target header chain.
|
/// Target header chain.
|
||||||
type TargetHeaderChain: TargetHeaderChain<Self::OutboundPayload, Self::AccountId>;
|
type TargetHeaderChain: TargetHeaderChain<Self::OutboundPayload, Self::AccountId>;
|
||||||
/// Message payload verifier.
|
/// Message payload verifier.
|
||||||
type LaneMessageVerifier: LaneMessageVerifier<Self::RuntimeOrigin, Self::OutboundPayload>;
|
type LaneMessageVerifier: LaneMessageVerifier<Self::OutboundPayload>;
|
||||||
/// Delivery confirmation payments.
|
/// Delivery confirmation payments.
|
||||||
type DeliveryConfirmationPayments: DeliveryConfirmationPayments<Self::AccountId>;
|
type DeliveryConfirmationPayments: DeliveryConfirmationPayments<Self::AccountId>;
|
||||||
|
|
||||||
@@ -643,8 +643,7 @@ pub mod pallet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, I> bp_messages::source_chain::MessagesBridge<T::RuntimeOrigin, T::OutboundPayload>
|
impl<T, I> bp_messages::source_chain::MessagesBridge<T::OutboundPayload> for Pallet<T, I>
|
||||||
for Pallet<T, I>
|
|
||||||
where
|
where
|
||||||
T: Config<I>,
|
T: Config<I>,
|
||||||
I: 'static,
|
I: 'static,
|
||||||
@@ -652,17 +651,15 @@ where
|
|||||||
type Error = sp_runtime::DispatchErrorWithPostInfo<PostDispatchInfo>;
|
type Error = sp_runtime::DispatchErrorWithPostInfo<PostDispatchInfo>;
|
||||||
|
|
||||||
fn send_message(
|
fn send_message(
|
||||||
sender: T::RuntimeOrigin,
|
|
||||||
lane: LaneId,
|
lane: LaneId,
|
||||||
message: T::OutboundPayload,
|
message: T::OutboundPayload,
|
||||||
) -> Result<SendMessageArtifacts, Self::Error> {
|
) -> Result<SendMessageArtifacts, Self::Error> {
|
||||||
crate::send_message::<T, I>(sender, lane, message)
|
crate::send_message::<T, I>(lane, message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Function that actually sends message.
|
/// Function that actually sends message.
|
||||||
fn send_message<T: Config<I>, I: 'static>(
|
fn send_message<T: Config<I>, I: 'static>(
|
||||||
submitter: T::RuntimeOrigin,
|
|
||||||
lane_id: LaneId,
|
lane_id: LaneId,
|
||||||
payload: T::OutboundPayload,
|
payload: T::OutboundPayload,
|
||||||
) -> sp_std::result::Result<
|
) -> sp_std::result::Result<
|
||||||
@@ -688,8 +685,7 @@ fn send_message<T: Config<I>, I: 'static>(
|
|||||||
|
|
||||||
// now let's enforce any additional lane rules
|
// now let's enforce any additional lane rules
|
||||||
let mut lane = outbound_lane::<T, I>(lane_id);
|
let mut lane = outbound_lane::<T, I>(lane_id);
|
||||||
T::LaneMessageVerifier::verify_message(&submitter, &lane_id, &lane.data(), &payload).map_err(
|
T::LaneMessageVerifier::verify_message(&lane_id, &lane.data(), &payload).map_err(|err| {
|
||||||
|err| {
|
|
||||||
log::trace!(
|
log::trace!(
|
||||||
target: LOG_TARGET,
|
target: LOG_TARGET,
|
||||||
"Message to lane {:?} is rejected by lane verifier: {:?}",
|
"Message to lane {:?} is rejected by lane verifier: {:?}",
|
||||||
@@ -698,8 +694,7 @@ fn send_message<T: Config<I>, I: 'static>(
|
|||||||
);
|
);
|
||||||
|
|
||||||
Error::<T, I>::MessageRejectedByLaneVerifier(err)
|
Error::<T, I>::MessageRejectedByLaneVerifier(err)
|
||||||
},
|
})?;
|
||||||
)?;
|
|
||||||
|
|
||||||
// finally, save message in outbound storage and emit event
|
// finally, save message in outbound storage and emit event
|
||||||
let encoded_payload = payload.encode();
|
let encoded_payload = payload.encode();
|
||||||
@@ -915,7 +910,7 @@ mod tests {
|
|||||||
|
|
||||||
let message_nonce =
|
let message_nonce =
|
||||||
outbound_lane::<TestRuntime, ()>(TEST_LANE_ID).data().latest_generated_nonce + 1;
|
outbound_lane::<TestRuntime, ()>(TEST_LANE_ID).data().latest_generated_nonce + 1;
|
||||||
send_message::<TestRuntime, ()>(RuntimeOrigin::signed(1), TEST_LANE_ID, REGULAR_PAYLOAD)
|
send_message::<TestRuntime, ()>(TEST_LANE_ID, REGULAR_PAYLOAD)
|
||||||
.expect("send_message has failed");
|
.expect("send_message has failed");
|
||||||
|
|
||||||
// check event with assigned nonce
|
// check event with assigned nonce
|
||||||
@@ -982,11 +977,7 @@ mod tests {
|
|||||||
));
|
));
|
||||||
|
|
||||||
assert_noop!(
|
assert_noop!(
|
||||||
send_message::<TestRuntime, ()>(
|
send_message::<TestRuntime, ()>(TEST_LANE_ID, REGULAR_PAYLOAD,),
|
||||||
RuntimeOrigin::signed(1),
|
|
||||||
TEST_LANE_ID,
|
|
||||||
REGULAR_PAYLOAD,
|
|
||||||
),
|
|
||||||
Error::<TestRuntime, ()>::NotOperatingNormally,
|
Error::<TestRuntime, ()>::NotOperatingNormally,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -1036,11 +1027,7 @@ mod tests {
|
|||||||
);
|
);
|
||||||
|
|
||||||
assert_noop!(
|
assert_noop!(
|
||||||
send_message::<TestRuntime, ()>(
|
send_message::<TestRuntime, ()>(TEST_LANE_ID, REGULAR_PAYLOAD,),
|
||||||
RuntimeOrigin::signed(1),
|
|
||||||
TEST_LANE_ID,
|
|
||||||
REGULAR_PAYLOAD,
|
|
||||||
),
|
|
||||||
Error::<TestRuntime, ()>::NotOperatingNormally,
|
Error::<TestRuntime, ()>::NotOperatingNormally,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -1090,11 +1077,7 @@ mod tests {
|
|||||||
.extra
|
.extra
|
||||||
.extend_from_slice(&[0u8; MAX_OUTBOUND_PAYLOAD_SIZE as usize]);
|
.extend_from_slice(&[0u8; MAX_OUTBOUND_PAYLOAD_SIZE as usize]);
|
||||||
assert_noop!(
|
assert_noop!(
|
||||||
send_message::<TestRuntime, ()>(
|
send_message::<TestRuntime, ()>(TEST_LANE_ID, message_payload.clone(),),
|
||||||
RuntimeOrigin::signed(1),
|
|
||||||
TEST_LANE_ID,
|
|
||||||
message_payload.clone(),
|
|
||||||
),
|
|
||||||
Error::<TestRuntime, ()>::MessageRejectedByPallet(
|
Error::<TestRuntime, ()>::MessageRejectedByPallet(
|
||||||
VerificationError::MessageTooLarge
|
VerificationError::MessageTooLarge
|
||||||
),
|
),
|
||||||
@@ -1105,11 +1088,7 @@ mod tests {
|
|||||||
message_payload.extra.pop();
|
message_payload.extra.pop();
|
||||||
}
|
}
|
||||||
assert_eq!(message_payload.encoded_size() as u32, MAX_OUTBOUND_PAYLOAD_SIZE);
|
assert_eq!(message_payload.encoded_size() as u32, MAX_OUTBOUND_PAYLOAD_SIZE);
|
||||||
assert_ok!(send_message::<TestRuntime, ()>(
|
assert_ok!(send_message::<TestRuntime, ()>(TEST_LANE_ID, message_payload,),);
|
||||||
RuntimeOrigin::signed(1),
|
|
||||||
TEST_LANE_ID,
|
|
||||||
message_payload,
|
|
||||||
),);
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1118,11 +1097,7 @@ mod tests {
|
|||||||
run_test(|| {
|
run_test(|| {
|
||||||
// messages with this payload are rejected by target chain verifier
|
// messages with this payload are rejected by target chain verifier
|
||||||
assert_noop!(
|
assert_noop!(
|
||||||
send_message::<TestRuntime, ()>(
|
send_message::<TestRuntime, ()>(TEST_LANE_ID, PAYLOAD_REJECTED_BY_TARGET_CHAIN,),
|
||||||
RuntimeOrigin::signed(1),
|
|
||||||
TEST_LANE_ID,
|
|
||||||
PAYLOAD_REJECTED_BY_TARGET_CHAIN,
|
|
||||||
),
|
|
||||||
Error::<TestRuntime, ()>::MessageRejectedByChainVerifier(VerificationError::Other(
|
Error::<TestRuntime, ()>::MessageRejectedByChainVerifier(VerificationError::Other(
|
||||||
mock::TEST_ERROR
|
mock::TEST_ERROR
|
||||||
)),
|
)),
|
||||||
@@ -1137,7 +1112,7 @@ mod tests {
|
|||||||
let mut message = REGULAR_PAYLOAD;
|
let mut message = REGULAR_PAYLOAD;
|
||||||
message.reject_by_lane_verifier = true;
|
message.reject_by_lane_verifier = true;
|
||||||
assert_noop!(
|
assert_noop!(
|
||||||
send_message::<TestRuntime, ()>(RuntimeOrigin::signed(1), TEST_LANE_ID, message,),
|
send_message::<TestRuntime, ()>(TEST_LANE_ID, message,),
|
||||||
Error::<TestRuntime, ()>::MessageRejectedByLaneVerifier(VerificationError::Other(
|
Error::<TestRuntime, ()>::MessageRejectedByLaneVerifier(VerificationError::Other(
|
||||||
mock::TEST_ERROR
|
mock::TEST_ERROR
|
||||||
)),
|
)),
|
||||||
@@ -1293,16 +1268,8 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn receive_messages_delivery_proof_rewards_relayers() {
|
fn receive_messages_delivery_proof_rewards_relayers() {
|
||||||
run_test(|| {
|
run_test(|| {
|
||||||
assert_ok!(send_message::<TestRuntime, ()>(
|
assert_ok!(send_message::<TestRuntime, ()>(TEST_LANE_ID, REGULAR_PAYLOAD,));
|
||||||
RuntimeOrigin::signed(1),
|
assert_ok!(send_message::<TestRuntime, ()>(TEST_LANE_ID, REGULAR_PAYLOAD,));
|
||||||
TEST_LANE_ID,
|
|
||||||
REGULAR_PAYLOAD,
|
|
||||||
));
|
|
||||||
assert_ok!(send_message::<TestRuntime, ()>(
|
|
||||||
RuntimeOrigin::signed(1),
|
|
||||||
TEST_LANE_ID,
|
|
||||||
REGULAR_PAYLOAD,
|
|
||||||
));
|
|
||||||
|
|
||||||
// this reports delivery of message 1 => reward is paid to TEST_RELAYER_A
|
// this reports delivery of message 1 => reward is paid to TEST_RELAYER_A
|
||||||
let single_message_delivery_proof = TestMessagesDeliveryProof(Ok((
|
let single_message_delivery_proof = TestMessagesDeliveryProof(Ok((
|
||||||
@@ -1899,11 +1866,7 @@ mod tests {
|
|||||||
send_regular_message();
|
send_regular_message();
|
||||||
receive_messages_delivery_proof();
|
receive_messages_delivery_proof();
|
||||||
// send + receive confirmation for lane 2
|
// send + receive confirmation for lane 2
|
||||||
assert_ok!(send_message::<TestRuntime, ()>(
|
assert_ok!(send_message::<TestRuntime, ()>(TEST_LANE_ID_2, REGULAR_PAYLOAD,));
|
||||||
RuntimeOrigin::signed(1),
|
|
||||||
TEST_LANE_ID_2,
|
|
||||||
REGULAR_PAYLOAD,
|
|
||||||
));
|
|
||||||
assert_ok!(Pallet::<TestRuntime>::receive_messages_delivery_proof(
|
assert_ok!(Pallet::<TestRuntime>::receive_messages_delivery_proof(
|
||||||
RuntimeOrigin::signed(1),
|
RuntimeOrigin::signed(1),
|
||||||
TestMessagesDeliveryProof(Ok((
|
TestMessagesDeliveryProof(Ok((
|
||||||
@@ -1979,11 +1942,7 @@ mod tests {
|
|||||||
fn outbound_message_from_unconfigured_lane_is_rejected() {
|
fn outbound_message_from_unconfigured_lane_is_rejected() {
|
||||||
run_test(|| {
|
run_test(|| {
|
||||||
assert_noop!(
|
assert_noop!(
|
||||||
send_message::<TestRuntime, ()>(
|
send_message::<TestRuntime, ()>(TEST_LANE_ID_3, REGULAR_PAYLOAD,),
|
||||||
RuntimeOrigin::signed(1),
|
|
||||||
TEST_LANE_ID_3,
|
|
||||||
REGULAR_PAYLOAD,
|
|
||||||
),
|
|
||||||
Error::<TestRuntime, ()>::InactiveOutboundLane,
|
Error::<TestRuntime, ()>::InactiveOutboundLane,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -310,9 +310,8 @@ impl TargetHeaderChain<TestPayload, TestRelayer> for TestTargetHeaderChain {
|
|||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct TestLaneMessageVerifier;
|
pub struct TestLaneMessageVerifier;
|
||||||
|
|
||||||
impl LaneMessageVerifier<RuntimeOrigin, TestPayload> for TestLaneMessageVerifier {
|
impl LaneMessageVerifier<TestPayload> for TestLaneMessageVerifier {
|
||||||
fn verify_message(
|
fn verify_message(
|
||||||
_submitter: &RuntimeOrigin,
|
|
||||||
_lane: &LaneId,
|
_lane: &LaneId,
|
||||||
_lane_outbound_data: &OutboundLaneData,
|
_lane_outbound_data: &OutboundLaneData,
|
||||||
payload: &TestPayload,
|
payload: &TestPayload,
|
||||||
|
|||||||
@@ -71,11 +71,10 @@ pub trait TargetHeaderChain<Payload, AccountId> {
|
|||||||
/// Lane3 until some block, ...), then it may be built using this verifier.
|
/// Lane3 until some block, ...), then it may be built using this verifier.
|
||||||
///
|
///
|
||||||
/// Any fee requirements should also be enforced here.
|
/// Any fee requirements should also be enforced here.
|
||||||
pub trait LaneMessageVerifier<SenderOrigin, Payload> {
|
pub trait LaneMessageVerifier<Payload> {
|
||||||
/// Verify message payload and return Ok(()) if message is valid and allowed to be sent over the
|
/// Verify message payload and return Ok(()) if message is valid and allowed to be sent over the
|
||||||
/// lane.
|
/// lane.
|
||||||
fn verify_message(
|
fn verify_message(
|
||||||
submitter: &SenderOrigin,
|
|
||||||
lane: &LaneId,
|
lane: &LaneId,
|
||||||
outbound_data: &OutboundLaneData,
|
outbound_data: &OutboundLaneData,
|
||||||
payload: &Payload,
|
payload: &Payload,
|
||||||
@@ -124,32 +123,24 @@ pub struct SendMessageArtifacts {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Messages bridge API to be used from other pallets.
|
/// Messages bridge API to be used from other pallets.
|
||||||
pub trait MessagesBridge<SenderOrigin, Payload> {
|
pub trait MessagesBridge<Payload> {
|
||||||
/// Error type.
|
/// Error type.
|
||||||
type Error: Debug;
|
type Error: Debug;
|
||||||
|
|
||||||
/// Send message over the bridge.
|
/// Send message over the bridge.
|
||||||
///
|
///
|
||||||
/// Returns unique message nonce or error if send has failed.
|
/// Returns unique message nonce or error if send has failed.
|
||||||
fn send_message(
|
fn send_message(lane: LaneId, message: Payload) -> Result<SendMessageArtifacts, Self::Error>;
|
||||||
sender: SenderOrigin,
|
|
||||||
lane: LaneId,
|
|
||||||
message: Payload,
|
|
||||||
) -> Result<SendMessageArtifacts, Self::Error>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Bridge that does nothing when message is being sent.
|
/// Bridge that does nothing when message is being sent.
|
||||||
#[derive(Eq, RuntimeDebug, PartialEq)]
|
#[derive(Eq, RuntimeDebug, PartialEq)]
|
||||||
pub struct NoopMessagesBridge;
|
pub struct NoopMessagesBridge;
|
||||||
|
|
||||||
impl<SenderOrigin, Payload> MessagesBridge<SenderOrigin, Payload> for NoopMessagesBridge {
|
impl<Payload> MessagesBridge<Payload> for NoopMessagesBridge {
|
||||||
type Error = &'static str;
|
type Error = &'static str;
|
||||||
|
|
||||||
fn send_message(
|
fn send_message(_lane: LaneId, _message: Payload) -> Result<SendMessageArtifacts, Self::Error> {
|
||||||
_sender: SenderOrigin,
|
|
||||||
_lane: LaneId,
|
|
||||||
_message: Payload,
|
|
||||||
) -> Result<SendMessageArtifacts, Self::Error> {
|
|
||||||
Ok(SendMessageArtifacts { nonce: 0 })
|
Ok(SendMessageArtifacts { nonce: 0 })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -176,9 +167,8 @@ impl<Payload, AccountId> TargetHeaderChain<Payload, AccountId> for ForbidOutboun
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<SenderOrigin, Payload> LaneMessageVerifier<SenderOrigin, Payload> for ForbidOutboundMessages {
|
impl<Payload> LaneMessageVerifier<Payload> for ForbidOutboundMessages {
|
||||||
fn verify_message(
|
fn verify_message(
|
||||||
_submitter: &SenderOrigin,
|
|
||||||
_lane: &LaneId,
|
_lane: &LaneId,
|
||||||
_outbound_data: &OutboundLaneData,
|
_outbound_data: &OutboundLaneData,
|
||||||
_payload: &Payload,
|
_payload: &Payload,
|
||||||
|
|||||||
Reference in New Issue
Block a user