Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename MessageId -> BridgeMessageId #1152

Merged
merged 1 commit into from
Sep 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 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 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 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
2 changes: 1 addition & 1 deletion deployments/types-millau.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"ChainId": "Id",
"LaneId": "Id",
"MessageNonce": "u64",
"MessageId": "(Id, u64)",
"BridgeMessageId": "(Id, u64)",
"MessageKey": {
"lane_id": "LaneId",
"nonce:": "MessageNonce"
Expand Down
2 changes: 1 addition & 1 deletion deployments/types-rialto.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"ChainId": "Id",
"LaneId": "Id",
"MessageNonce": "u64",
"MessageId": "(Id, u64)",
"BridgeMessageId": "(Id, u64)",
"MessageKey": {
"lane_id": "LaneId",
"nonce:": "MessageNonce"
Expand Down
2 changes: 1 addition & 1 deletion deployments/types-rococo.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"ChainId": "Id",
"LaneId": "Id",
"MessageNonce": "u64",
"MessageId": "(Id, u64)",
"BridgeMessageId": "(Id, u64)",
"MessageKey": {
"lane_id": "LaneId",
"nonce:": "MessageNonce"
Expand Down
2 changes: 1 addition & 1 deletion deployments/types-wococo.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"ChainId": "Id",
"LaneId": "Id",
"MessageNonce": "u64",
"MessageId": "(Id, u64)",
"BridgeMessageId": "(Id, u64)",
"MessageKey": {
"lane_id": "LaneId",
"nonce:": "MessageNonce"
Expand Down
2 changes: 1 addition & 1 deletion deployments/types/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"ChainId": "Id",
"LaneId": "Id",
"MessageNonce": "u64",
"MessageId": "(Id, u64)",
"BridgeMessageId": "(Id, u64)",
"MessageKey": {
"lane_id": "LaneId",
"nonce:": "MessageNonce"
Expand Down
38 changes: 19 additions & 19 deletions 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 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 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