Skip to content

Commit

Permalink
Rename MessageId -> BridgeMessageId (paritytech#1152)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomusdrw authored and serban300 committed Apr 10, 2024
1 parent cc25369 commit 8b881c9
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion bridges/bin/millau/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ impl pallet_aura::Config for Runtime {
}
impl pallet_bridge_dispatch::Config for Runtime {
type Event = Event;
type MessageId = (bp_messages::LaneId, bp_messages::MessageNonce);
type BridgeMessageId = (bp_messages::LaneId, bp_messages::MessageNonce);
type Call = Call;
type CallFilter = ();
type EncodedCall = crate::rialto_messages::FromRialtoEncodedCall;
Expand Down
2 changes: 1 addition & 1 deletion bridges/bin/rialto/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ impl pallet_bridge_currency_exchange::Config<KovanCurrencyExchange> for Runtime

impl pallet_bridge_dispatch::Config for Runtime {
type Event = Event;
type MessageId = (bp_messages::LaneId, bp_messages::MessageNonce);
type BridgeMessageId = (bp_messages::LaneId, bp_messages::MessageNonce);
type Call = Call;
type CallFilter = ();
type EncodedCall = crate::millau_messages::FromMillauEncodedCall;
Expand Down
2 changes: 1 addition & 1 deletion bridges/bin/runtime-common/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ pub mod target {
where
BalanceOf<ThisChain<B>>: Saturating + FixedPointOperand,
ThisDispatchInstance: 'static,
ThisRuntime: pallet_bridge_dispatch::Config<ThisDispatchInstance, MessageId = (LaneId, MessageNonce)>
ThisRuntime: pallet_bridge_dispatch::Config<ThisDispatchInstance, BridgeMessageId = (LaneId, MessageNonce)>
+ pallet_transaction_payment::Config,
<ThisRuntime as pallet_transaction_payment::Config>::OnChargeTransaction:
pallet_transaction_payment::OnChargeTransaction<ThisRuntime, Balance = BalanceOf<ThisChain<B>>>,
Expand Down
38 changes: 19 additions & 19 deletions bridges/modules/dispatch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub mod pallet {
/// Id of the message. Whenever message is passed to the dispatch module, it emits
/// event with this id + dispatch result. Could be e.g. (LaneId, MessageNonce) if
/// it comes from the messages module.
type MessageId: Parameter;
type BridgeMessageId: Parameter;
/// Type of account ID on source chain.
type SourceChainAccountId: Parameter + Member + MaybeSerializeDeserialize + Debug + MaybeDisplay + Ord + Default;
/// Type of account public key on target chain.
Expand Down Expand Up @@ -91,7 +91,7 @@ pub mod pallet {
type AccountIdConverter: sp_runtime::traits::Convert<sp_core::hash::H256, Self::AccountId>;
}

type MessageIdOf<T, I> = <T as Config<I>>::MessageId;
type BridgeMessageIdOf<T, I> = <T as Config<I>>::BridgeMessageId;

#[pallet::pallet]
#[pallet::generate_store(pub(super) trait Store)]
Expand All @@ -105,37 +105,37 @@ pub mod pallet {

#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
#[pallet::metadata(<T as frame_system::Config>::AccountId = "AccountId", MessageIdOf<T, I> = "MessageId")]
#[pallet::metadata(<T as frame_system::Config>::AccountId = "AccountId", BridgeMessageIdOf<T, I> = "BridgeMessageId")]
pub enum Event<T: Config<I>, I: 'static = ()> {
/// Message has been rejected before reaching dispatch.
MessageRejected(ChainId, MessageIdOf<T, I>),
MessageRejected(ChainId, BridgeMessageIdOf<T, I>),
/// Message has been rejected by dispatcher because of spec version mismatch.
/// Last two arguments are: expected and passed spec version.
MessageVersionSpecMismatch(ChainId, MessageIdOf<T, I>, SpecVersion, SpecVersion),
MessageVersionSpecMismatch(ChainId, BridgeMessageIdOf<T, I>, SpecVersion, SpecVersion),
/// Message has been rejected by dispatcher because of weight mismatch.
/// Last two arguments are: expected and passed call weight.
MessageWeightMismatch(ChainId, MessageIdOf<T, I>, Weight, Weight),
MessageWeightMismatch(ChainId, BridgeMessageIdOf<T, I>, Weight, Weight),
/// Message signature mismatch.
MessageSignatureMismatch(ChainId, MessageIdOf<T, I>),
MessageSignatureMismatch(ChainId, BridgeMessageIdOf<T, I>),
/// We have failed to decode Call from the message.
MessageCallDecodeFailed(ChainId, MessageIdOf<T, I>),
MessageCallDecodeFailed(ChainId, BridgeMessageIdOf<T, I>),
/// The call from the message has been rejected by the call filter.
MessageCallRejected(ChainId, MessageIdOf<T, I>),
MessageCallRejected(ChainId, BridgeMessageIdOf<T, I>),
/// The origin account has failed to pay fee for dispatching the message.
MessageDispatchPaymentFailed(
ChainId,
MessageIdOf<T, I>,
BridgeMessageIdOf<T, I>,
<T as frame_system::Config>::AccountId,
Weight,
),
/// Message has been dispatched with given result.
MessageDispatched(ChainId, MessageIdOf<T, I>, DispatchResult),
MessageDispatched(ChainId, BridgeMessageIdOf<T, I>, DispatchResult),
/// Phantom member, never used. Needed to handle multiple pallet instances.
_Dummy(PhantomData<I>),
}
}

impl<T: Config<I>, I: 'static> MessageDispatch<T::AccountId, T::MessageId> for Pallet<T, I> {
impl<T: Config<I>, I: 'static> MessageDispatch<T::AccountId, T::BridgeMessageId> for Pallet<T, I> {
type Message =
MessagePayload<T::SourceChainAccountId, T::TargetChainAccountPublic, T::TargetChainSignature, T::EncodedCall>;

Expand All @@ -146,7 +146,7 @@ impl<T: Config<I>, I: 'static> MessageDispatch<T::AccountId, T::MessageId> for P
fn dispatch<P: FnOnce(&T::AccountId, bp_message_dispatch::Weight) -> Result<(), ()>>(
source_chain: ChainId,
target_chain: ChainId,
id: T::MessageId,
id: T::BridgeMessageId,
message: Result<Self::Message, ()>,
pay_dispatch_fee: P,
) -> MessageDispatchResult {
Expand Down Expand Up @@ -416,7 +416,7 @@ mod tests {
};

type AccountId = u64;
type MessageId = [u8; 4];
type BridgeMessageId = [u8; 4];

const SOURCE_CHAIN_ID: ChainId = *b"srce";
const TARGET_CHAIN_ID: ChainId = *b"trgt";
Expand Down Expand Up @@ -502,7 +502,7 @@ mod tests {

impl Config for TestRuntime {
type Event = Event;
type MessageId = MessageId;
type BridgeMessageId = BridgeMessageId;
type SourceChainAccountId = AccountId;
type TargetChainAccountPublic = TestAccountPublic;
type TargetChainSignature = TestSignature;
Expand Down Expand Up @@ -542,7 +542,7 @@ mod tests {
fn prepare_message(
origin: CallOrigin<AccountId, TestAccountPublic, TestSignature>,
call: Call,
) -> <Pallet<TestRuntime> as MessageDispatch<AccountId, <TestRuntime as Config>::MessageId>>::Message {
) -> <Pallet<TestRuntime> as MessageDispatch<AccountId, <TestRuntime as Config>::BridgeMessageId>>::Message {
MessagePayload {
spec_version: TEST_SPEC_VERSION,
weight: TEST_WEIGHT,
Expand All @@ -554,20 +554,20 @@ mod tests {

fn prepare_root_message(
call: Call,
) -> <Pallet<TestRuntime> as MessageDispatch<AccountId, <TestRuntime as Config>::MessageId>>::Message {
) -> <Pallet<TestRuntime> as MessageDispatch<AccountId, <TestRuntime as Config>::BridgeMessageId>>::Message {
prepare_message(CallOrigin::SourceRoot, call)
}

fn prepare_target_message(
call: Call,
) -> <Pallet<TestRuntime> as MessageDispatch<AccountId, <TestRuntime as Config>::MessageId>>::Message {
) -> <Pallet<TestRuntime> as MessageDispatch<AccountId, <TestRuntime as Config>::BridgeMessageId>>::Message {
let origin = CallOrigin::TargetAccount(1, TestAccountPublic(1), TestSignature(1));
prepare_message(origin, call)
}

fn prepare_source_message(
call: Call,
) -> <Pallet<TestRuntime> as MessageDispatch<AccountId, <TestRuntime as Config>::MessageId>>::Message {
) -> <Pallet<TestRuntime> as MessageDispatch<AccountId, <TestRuntime as Config>::BridgeMessageId>>::Message {
let origin = CallOrigin::SourceAccount(1);
prepare_message(origin, call)
}
Expand Down
4 changes: 2 additions & 2 deletions bridges/primitives/message-dispatch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub type Weight = u64;
pub type SpecVersion = u32;

/// A generic trait to dispatch arbitrary messages delivered over the bridge.
pub trait MessageDispatch<AccountId, MessageId> {
pub trait MessageDispatch<AccountId, BridgeMessageId> {
/// A type of the message to be dispatched.
type Message: codec::Decode;

Expand All @@ -60,7 +60,7 @@ pub trait MessageDispatch<AccountId, MessageId> {
fn dispatch<P: FnOnce(&AccountId, Weight) -> Result<(), ()>>(
source_chain: ChainId,
target_chain: ChainId,
id: MessageId,
id: BridgeMessageId,
message: Result<Self::Message, ()>,
pay_dispatch_fee: P,
) -> MessageDispatchResult;
Expand Down
2 changes: 1 addition & 1 deletion bridges/primitives/messages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub type LaneId = [u8; 4];
pub type MessageNonce = u64;

/// Message id as a tuple.
pub type MessageId = (LaneId, MessageNonce);
pub type BridgeMessageId = (LaneId, MessageNonce);

/// Opaque message payload. We only decode this payload when it is dispatched.
pub type MessagePayload = Vec<u8>;
Expand Down

0 comments on commit 8b881c9

Please sign in to comment.