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