Skip to content

Commit 386fe10

Browse files
svyatonikbkontur
authored andcommitted
use BridgedChain::Account instead of InbundRelayer (#2193)
1 parent 364bbae commit 386fe10

8 files changed

Lines changed: 39 additions & 43 deletions

File tree

bridges/bin/runtime-common/src/messages_call_ext.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,14 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
1616

17-
//! Signed extension for the `pallet-bridge-messages` that is able to reject obsolete
18-
//! (and some other invalid) transactions.
17+
//! Helpers for easier manipulation of call processing with signed extensions.
1918
2019
use bp_messages::{
2120
target_chain::MessageDispatch, ChainWithMessages, InboundLaneData, LaneId, MessageNonce,
2221
};
23-
use bp_runtime::OwnedBridgeModule;
22+
use bp_runtime::{AccountIdOf, OwnedBridgeModule};
2423
use frame_support::{dispatch::CallableCallFor, traits::IsSubType};
25-
use pallet_bridge_messages::{Config, Pallet};
24+
use pallet_bridge_messages::{BridgedChainOf, Config, Pallet};
2625
use sp_runtime::{transaction_validity::TransactionValidity, RuntimeDebug};
2726
use sp_std::ops::RangeInclusive;
2827

@@ -326,7 +325,7 @@ impl<
326325

327326
/// Returns occupation state of unrewarded relayers vector.
328327
fn unrewarded_relayers_occupation<T: Config<I>, I: 'static>(
329-
inbound_lane_data: &InboundLaneData<T::InboundRelayer>,
328+
inbound_lane_data: &InboundLaneData<AccountIdOf<BridgedChainOf<T, I>>>,
330329
) -> UnrewardedRelayerOccupation {
331330
UnrewardedRelayerOccupation {
332331
free_relayer_slots: T::BridgedChain::MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX

bridges/bin/runtime-common/src/mock.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ impl pallet_bridge_messages::Config for TestRuntime {
190190
type OutboundPayload = XcmAsPlainPayload;
191191

192192
type InboundPayload = Vec<u8>;
193-
type InboundRelayer = BridgedChainAccountId;
194193
type DeliveryPayments = ();
195194

196195
type DeliveryConfirmationPayments = pallet_bridge_relayers::DeliveryConfirmationPaymentsAdapter<

bridges/modules/messages/src/benchmarking.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use bp_messages::{
2929
InboundLaneData, LaneId, MessageNonce, OutboundLaneData, UnrewardedRelayer,
3030
UnrewardedRelayersState,
3131
};
32-
use bp_runtime::{HashOf, StorageProofSize};
32+
use bp_runtime::{AccountIdOf, HashOf, StorageProofSize};
3333
use codec::Decode;
3434
use frame_benchmarking::{account, v2::*};
3535
use frame_support::weights::Weight;
@@ -83,8 +83,8 @@ pub trait Config<I: 'static>: crate::Config<I> {
8383
/// Return id of relayer account at the bridged chain.
8484
///
8585
/// By default, zero account is returned.
86-
fn bridged_relayer_id() -> Self::InboundRelayer {
87-
Self::InboundRelayer::decode(&mut TrailingZeroInput::zeroes()).unwrap()
86+
fn bridged_relayer_id() -> AccountIdOf<BridgedChainOf<Self, I>> {
87+
Decode::decode(&mut TrailingZeroInput::zeroes()).unwrap()
8888
}
8989

9090
/// Create given account and give it enough balance for test purposes. Used to create
@@ -132,7 +132,7 @@ fn receive_messages<T: Config<I>, I: 'static>(nonce: MessageNonce) {
132132
}
133133

134134
struct ReceiveMessagesProofSetup<T: Config<I>, I: 'static> {
135-
relayer_id_on_src: T::InboundRelayer,
135+
relayer_id_on_src: AccountIdOf<BridgedChainOf<T, I>>,
136136
relayer_id_on_tgt: T::AccountId,
137137
msgs_count: u32,
138138
_phantom_data: sp_std::marker::PhantomData<I>,
@@ -155,7 +155,7 @@ impl<T: Config<I>, I: 'static> ReceiveMessagesProofSetup<T, I> {
155155
setup
156156
}
157157

158-
fn relayer_id_on_src(&self) -> T::InboundRelayer {
158+
fn relayer_id_on_src(&self) -> AccountIdOf<BridgedChainOf<T, I>> {
159159
self.relayer_id_on_src.clone()
160160
}
161161

bridges/modules/messages/src/inbound_lane.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use bp_messages::{
2323
ChainWithMessages, DeliveredMessages, InboundLaneData, LaneId, MessageKey, MessageNonce,
2424
OutboundLaneData, ReceptionResult, UnrewardedRelayer,
2525
};
26+
use bp_runtime::AccountIdOf;
2627
use codec::{Decode, Encode, EncodeLike, MaxEncodedLen};
2728
use scale_info::{Type, TypeInfo};
2829
use sp_runtime::RuntimeDebug;
@@ -54,10 +55,12 @@ pub trait InboundLaneStorage {
5455
///
5556
/// The encoding of this type matches encoding of the corresponding `MessageData`.
5657
#[derive(Encode, Decode, Clone, RuntimeDebug, PartialEq, Eq)]
57-
pub struct StoredInboundLaneData<T: Config<I>, I: 'static>(pub InboundLaneData<T::InboundRelayer>);
58+
pub struct StoredInboundLaneData<T: Config<I>, I: 'static>(
59+
pub InboundLaneData<AccountIdOf<BridgedChainOf<T, I>>>,
60+
);
5861

5962
impl<T: Config<I>, I: 'static> sp_std::ops::Deref for StoredInboundLaneData<T, I> {
60-
type Target = InboundLaneData<T::InboundRelayer>;
63+
type Target = InboundLaneData<AccountIdOf<BridgedChainOf<T, I>>>;
6164

6265
fn deref(&self) -> &Self::Target {
6366
&self.0
@@ -77,29 +80,29 @@ impl<T: Config<I>, I: 'static> Default for StoredInboundLaneData<T, I> {
7780
}
7881

7982
impl<T: Config<I>, I: 'static> From<StoredInboundLaneData<T, I>>
80-
for InboundLaneData<T::InboundRelayer>
83+
for InboundLaneData<AccountIdOf<BridgedChainOf<T, I>>>
8184
{
8285
fn from(data: StoredInboundLaneData<T, I>) -> Self {
8386
data.0
8487
}
8588
}
8689

8790
impl<T: Config<I>, I: 'static> EncodeLike<StoredInboundLaneData<T, I>>
88-
for InboundLaneData<T::InboundRelayer>
91+
for InboundLaneData<AccountIdOf<BridgedChainOf<T, I>>>
8992
{
9093
}
9194

9295
impl<T: Config<I>, I: 'static> TypeInfo for StoredInboundLaneData<T, I> {
9396
type Identity = Self;
9497

9598
fn type_info() -> Type {
96-
InboundLaneData::<T::InboundRelayer>::type_info()
99+
InboundLaneData::<AccountIdOf<BridgedChainOf<T, I>>>::type_info()
97100
}
98101
}
99102

100103
impl<T: Config<I>, I: 'static> MaxEncodedLen for StoredInboundLaneData<T, I> {
101104
fn max_encoded_len() -> usize {
102-
InboundLaneData::<T::InboundRelayer>::encoded_size_hint(
105+
InboundLaneData::<AccountIdOf<BridgedChainOf<T, I>>>::encoded_size_hint(
103106
BridgedChainOf::<T, I>::MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX as usize,
104107
)
105108
.unwrap_or(usize::MAX)

bridges/modules/messages/src/lib.rs

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ use bp_messages::{
6565
OutboundMessageDetails, UnrewardedRelayersState, VerificationError,
6666
};
6767
use bp_runtime::{
68-
BasicOperatingMode, HashOf, OwnedBridgeModule, PreComputedSize, RangeInclusiveExt, Size,
68+
AccountIdOf, BasicOperatingMode, HashOf, OwnedBridgeModule, PreComputedSize, RangeInclusiveExt,
69+
Size,
6970
};
7071
use codec::{Decode, Encode, MaxEncodedLen};
7172
use frame_support::{dispatch::PostDispatchInfo, ensure, fail, traits::Get, DefaultNoBound};
@@ -120,26 +121,19 @@ pub mod pallet {
120121

121122
/// Payload type of outbound messages. This payload is dispatched on the bridged chain.
122123
type OutboundPayload: Parameter + Size;
123-
124124
/// Payload type of inbound messages. This payload is dispatched on this chain.
125125
type InboundPayload: Decode;
126-
/// Identifier of relayer that deliver messages to this chain. Relayer reward is paid on the
127-
/// bridged chain.
128-
type InboundRelayer: Parameter + MaxEncodedLen;
129-
130-
// Types that are used by outbound_lane (on source chain).
131126

132-
/// Delivery confirmation payments.
127+
/// Handler for relayer payments that happen during message delivery transaction.
128+
type DeliveryPayments: DeliveryPayments<Self::AccountId>;
129+
/// Handler for relayer payments that happen during message delivery confirmation
130+
/// transaction.
133131
type DeliveryConfirmationPayments: DeliveryConfirmationPayments<Self::AccountId>;
134132
/// Delivery confirmation callback.
135133
type OnMessagesDelivered: OnMessagesDelivered;
136134

137-
// Types that are used by inbound_lane (on target chain).
138-
139-
/// Message dispatch.
135+
/// Message dispatch handler.
140136
type MessageDispatch: MessageDispatch<DispatchPayload = Self::InboundPayload>;
141-
/// Delivery payments.
142-
type DeliveryPayments: DeliveryPayments<Self::AccountId>;
143137
}
144138

145139
/// Shortcut to this chain type for Config.
@@ -241,7 +235,7 @@ pub mod pallet {
241235
#[pallet::weight(T::WeightInfo::receive_messages_proof_weight(proof, *messages_count, *dispatch_weight))]
242236
pub fn receive_messages_proof(
243237
origin: OriginFor<T>,
244-
relayer_id_at_bridged_chain: T::InboundRelayer,
238+
relayer_id_at_bridged_chain: AccountIdOf<BridgedChainOf<T, I>>,
245239
proof: FromBridgedChainMessagesProof<HashOf<BridgedChainOf<T, I>>>,
246240
messages_count: u32,
247241
dispatch_weight: Weight,
@@ -645,7 +639,9 @@ pub mod pallet {
645639
}
646640

647641
/// Return inbound lane data.
648-
pub fn inbound_lane_data(lane: LaneId) -> InboundLaneData<T::InboundRelayer> {
642+
pub fn inbound_lane_data(
643+
lane: LaneId,
644+
) -> InboundLaneData<AccountIdOf<BridgedChainOf<T, I>>> {
649645
InboundLanes::<T, I>::get(lane).0
650646
}
651647
}
@@ -744,7 +740,7 @@ fn outbound_lane<T: Config<I>, I: 'static>(
744740
/// Runtime inbound lane storage.
745741
struct RuntimeInboundLaneStorage<T: Config<I>, I: 'static = ()> {
746742
lane_id: LaneId,
747-
cached_data: Option<InboundLaneData<T::InboundRelayer>>,
743+
cached_data: Option<InboundLaneData<AccountIdOf<BridgedChainOf<T, I>>>>,
748744
_phantom: PhantomData<I>,
749745
}
750746

@@ -768,14 +764,14 @@ impl<T: Config<I>, I: 'static> RuntimeInboundLaneStorage<T, I> {
768764
let max_encoded_len = StoredInboundLaneData::<T, I>::max_encoded_len();
769765
let relayers_count = self.get_or_init_data().relayers.len();
770766
let actual_encoded_len =
771-
InboundLaneData::<T::InboundRelayer>::encoded_size_hint(relayers_count)
767+
InboundLaneData::<AccountIdOf<BridgedChainOf<T, I>>>::encoded_size_hint(relayers_count)
772768
.unwrap_or(usize::MAX);
773769
max_encoded_len.saturating_sub(actual_encoded_len) as _
774770
}
775771
}
776772

777773
impl<T: Config<I>, I: 'static> InboundLaneStorage for RuntimeInboundLaneStorage<T, I> {
778-
type Relayer = T::InboundRelayer;
774+
type Relayer = AccountIdOf<BridgedChainOf<T, I>>;
779775

780776
fn id(&self) -> LaneId {
781777
self.lane_id
@@ -789,19 +785,19 @@ impl<T: Config<I>, I: 'static> InboundLaneStorage for RuntimeInboundLaneStorage<
789785
BridgedChainOf::<T, I>::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX
790786
}
791787

792-
fn get_or_init_data(&mut self) -> InboundLaneData<T::InboundRelayer> {
788+
fn get_or_init_data(&mut self) -> InboundLaneData<AccountIdOf<BridgedChainOf<T, I>>> {
793789
match self.cached_data {
794790
Some(ref data) => data.clone(),
795791
None => {
796-
let data: InboundLaneData<T::InboundRelayer> =
792+
let data: InboundLaneData<AccountIdOf<BridgedChainOf<T, I>>> =
797793
InboundLanes::<T, I>::get(self.lane_id).into();
798794
self.cached_data = Some(data.clone());
799795
data
800796
},
801797
}
802798
}
803799

804-
fn set_data(&mut self, data: InboundLaneData<T::InboundRelayer>) {
800+
fn set_data(&mut self, data: InboundLaneData<AccountIdOf<BridgedChainOf<T, I>>>) {
805801
self.cached_data = Some(data.clone());
806802
InboundLanes::<T, I>::insert(self.lane_id, StoredInboundLaneData::<T, I>(data))
807803
}

bridges/modules/messages/src/tests/mock.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ impl Chain for BridgedChain {
115115
type Hash = BridgedHeaderHash;
116116
type Hasher = BlakeTwo256;
117117
type Header = BridgedChainHeader;
118-
type AccountId = AccountId;
118+
type AccountId = TestRelayer;
119119
type Balance = Balance;
120120
type Nonce = u64;
121121
type Signature = sp_runtime::MultiSignature;
@@ -204,7 +204,6 @@ impl Config for TestRuntime {
204204
type OutboundPayload = TestPayload;
205205

206206
type InboundPayload = TestPayload;
207-
type InboundRelayer = TestRelayer;
208207
type DeliveryPayments = TestDeliveryPayments;
209208

210209
type DeliveryConfirmationPayments = TestDeliveryConfirmationPayments;

bridges/modules/xcm-bridge-hub/src/mock.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ impl pallet_bridge_messages::Config for TestRuntime {
8888
type ActiveOutboundLanes = ActiveOutboundLanes;
8989
type OutboundPayload = Vec<u8>;
9090
type InboundPayload = Vec<u8>;
91-
type InboundRelayer = ();
9291
type DeliveryPayments = ();
9392
type DeliveryConfirmationPayments = ();
9493
type OnMessagesDelivered = ();

bridges/relays/lib-substrate-relay/src/messages/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,9 +388,10 @@ pub struct DirectReceiveMessagesProofCallBuilder<P, R, I> {
388388
impl<P, R, I> ReceiveMessagesProofCallBuilder<P> for DirectReceiveMessagesProofCallBuilder<P, R, I>
389389
where
390390
P: SubstrateMessageLane,
391-
R: BridgeMessagesConfig<I, InboundRelayer = AccountIdOf<P::SourceChain>>,
391+
R: BridgeMessagesConfig<I>,
392392
I: 'static,
393-
R::BridgedChain: bp_runtime::Chain<Hash = HashOf<P::SourceChain>>,
393+
R::BridgedChain:
394+
bp_runtime::Chain<AccountId = AccountIdOf<P::SourceChain>, Hash = HashOf<P::SourceChain>>,
394395
CallOf<P::TargetChain>: From<BridgeMessagesCall<R, I>> + GetDispatchInfo,
395396
{
396397
fn build_receive_messages_proof_call(

0 commit comments

Comments
 (0)