Skip to content

Commit

Permalink
use BridgedChain::Account instead of InbundRelayer (#2193)
Browse files Browse the repository at this point in the history
  • Loading branch information
svyatonik authored Jun 7, 2023
1 parent c58be1e commit 3e8e435
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 54 deletions.
8 changes: 2 additions & 6 deletions bin/millau/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,11 +446,9 @@ impl pallet_bridge_messages::Config<WithRialtoMessagesInstance> for Runtime {
type ActiveOutboundLanes = RialtoActiveOutboundLanes;

type OutboundPayload = bridge_runtime_common::messages_xcm_extension::XcmAsPlainPayload;

type InboundPayload = bridge_runtime_common::messages_xcm_extension::XcmAsPlainPayload;
type InboundRelayer = bp_rialto::AccountId;
type DeliveryPayments = ();

type DeliveryPayments = ();
type DeliveryConfirmationPayments = pallet_bridge_relayers::DeliveryConfirmationPaymentsAdapter<
Runtime,
WithRialtoMessagesInstance,
Expand Down Expand Up @@ -478,11 +476,9 @@ impl pallet_bridge_messages::Config<WithRialtoParachainMessagesInstance> for Run
type ActiveOutboundLanes = RialtoParachainActiveOutboundLanes;

type OutboundPayload = bridge_runtime_common::messages_xcm_extension::XcmAsPlainPayload;

type InboundPayload = bridge_runtime_common::messages_xcm_extension::XcmAsPlainPayload;
type InboundRelayer = bp_rialto_parachain::AccountId;
type DeliveryPayments = ();

type DeliveryPayments = ();
type DeliveryConfirmationPayments = pallet_bridge_relayers::DeliveryConfirmationPaymentsAdapter<
Runtime,
WithRialtoParachainMessagesInstance,
Expand Down
4 changes: 1 addition & 3 deletions bin/rialto-parachain/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,11 +569,9 @@ impl pallet_bridge_messages::Config<WithMillauMessagesInstance> for Runtime {
type ActiveOutboundLanes = ActiveOutboundLanes;

type OutboundPayload = bridge_runtime_common::messages_xcm_extension::XcmAsPlainPayload;

type InboundPayload = bridge_runtime_common::messages_xcm_extension::XcmAsPlainPayload;
type InboundRelayer = bp_millau::AccountId;
type DeliveryPayments = ();

type DeliveryPayments = ();
type DeliveryConfirmationPayments = pallet_bridge_relayers::DeliveryConfirmationPaymentsAdapter<
Runtime,
WithMillauMessagesInstance,
Expand Down
4 changes: 1 addition & 3 deletions bin/rialto/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,11 +425,9 @@ impl pallet_bridge_messages::Config<WithMillauMessagesInstance> for Runtime {
type ActiveOutboundLanes = ActiveOutboundLanes;

type OutboundPayload = bridge_runtime_common::messages_xcm_extension::XcmAsPlainPayload;

type InboundPayload = bridge_runtime_common::messages_xcm_extension::XcmAsPlainPayload;
type InboundRelayer = bp_millau::AccountId;
type DeliveryPayments = ();

type DeliveryPayments = ();
type DeliveryConfirmationPayments = pallet_bridge_relayers::DeliveryConfirmationPaymentsAdapter<
Runtime,
WithMillauMessagesInstance,
Expand Down
5 changes: 3 additions & 2 deletions bin/runtime-common/src/messages_call_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.

use bp_messages::{ChainWithMessages, InboundLaneData, LaneId, MessageNonce};
use bp_runtime::AccountIdOf;
use frame_support::{dispatch::CallableCallFor, traits::IsSubType, RuntimeDebug};
use pallet_bridge_messages::{Config, Pallet};
use pallet_bridge_messages::{BridgedChainOf, Config, Pallet};
use sp_runtime::transaction_validity::TransactionValidity;
use sp_std::ops::RangeInclusive;

Expand Down Expand Up @@ -287,7 +288,7 @@ impl<

/// Returns occupation state of unrewarded relayers vector.
fn unrewarded_relayers_occupation<T: Config<I>, I: 'static>(
inbound_lane_data: &InboundLaneData<T::InboundRelayer>,
inbound_lane_data: &InboundLaneData<AccountIdOf<BridgedChainOf<T, I>>>,
) -> UnrewardedRelayerOccupation {
UnrewardedRelayerOccupation {
free_relayer_slots: T::BridgedChain::MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX
Expand Down
1 change: 0 additions & 1 deletion bin/runtime-common/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ impl pallet_bridge_messages::Config for TestRuntime {
type OutboundPayload = XcmAsPlainPayload;

type InboundPayload = Vec<u8>;
type InboundRelayer = BridgedChainAccountId;
type DeliveryPayments = ();

type DeliveryConfirmationPayments = pallet_bridge_relayers::DeliveryConfirmationPaymentsAdapter<
Expand Down
1 change: 0 additions & 1 deletion deployments/types-millau.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
"lane_id": "LaneId",
"nonce:": "MessageNonce"
},
"InboundRelayer": "AccountId",
"InboundLaneData": {
"relayers": "Vec<UnrewardedRelayer>",
"last_confirmed_nonce": "MessageNonce"
Expand Down
1 change: 0 additions & 1 deletion deployments/types-rialto.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
"lane_id": "LaneId",
"nonce:": "MessageNonce"
},
"InboundRelayer": "AccountId",
"InboundLaneData": {
"relayers": "Vec<UnrewardedRelayer>",
"last_confirmed_nonce": "MessageNonce"
Expand Down
1 change: 0 additions & 1 deletion deployments/types/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"lane_id": "LaneId",
"nonce:": "MessageNonce"
},
"InboundRelayer": "AccountId",
"InboundLaneData": {
"relayers": "Vec<UnrewardedRelayer>",
"last_confirmed_nonce": "MessageNonce"
Expand Down
10 changes: 5 additions & 5 deletions modules/messages/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use bp_messages::{
InboundLaneData, LaneId, MessageNonce, OutboundLaneData, UnrewardedRelayer,
UnrewardedRelayersState,
};
use bp_runtime::{HashOf, StorageProofSize};
use bp_runtime::{AccountIdOf, HashOf, StorageProofSize};
use codec::Decode;
use frame_benchmarking::{account, v2::*};
use frame_support::weights::Weight;
Expand Down Expand Up @@ -83,8 +83,8 @@ pub trait Config<I: 'static>: crate::Config<I> {
/// Return id of relayer account at the bridged chain.
///
/// By default, zero account is returned.
fn bridged_relayer_id() -> Self::InboundRelayer {
Self::InboundRelayer::decode(&mut TrailingZeroInput::zeroes()).unwrap()
fn bridged_relayer_id() -> AccountIdOf<BridgedChainOf<Self, I>> {
Decode::decode(&mut TrailingZeroInput::zeroes()).unwrap()
}

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

struct ReceiveMessagesProofSetup<T: Config<I>, I: 'static> {
relayer_id_on_src: T::InboundRelayer,
relayer_id_on_src: AccountIdOf<BridgedChainOf<T, I>>,
relayer_id_on_tgt: T::AccountId,
msgs_count: u32,
_phantom_data: sp_std::marker::PhantomData<I>,
Expand All @@ -155,7 +155,7 @@ impl<T: Config<I>, I: 'static> ReceiveMessagesProofSetup<T, I> {
setup
}

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

Expand Down
15 changes: 9 additions & 6 deletions modules/messages/src/inbound_lane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use bp_messages::{
ChainWithMessages, DeliveredMessages, InboundLaneData, LaneId, MessageKey, MessageNonce,
OutboundLaneData, ReceivalResult, UnrewardedRelayer,
};
use bp_runtime::AccountIdOf;
use codec::{Decode, Encode, EncodeLike, MaxEncodedLen};
use frame_support::RuntimeDebug;
use scale_info::{Type, TypeInfo};
Expand Down Expand Up @@ -54,10 +55,12 @@ pub trait InboundLaneStorage {
///
/// The encoding of this type matches encoding of the corresponding `MessageData`.
#[derive(Encode, Decode, Clone, RuntimeDebug, PartialEq, Eq)]
pub struct StoredInboundLaneData<T: Config<I>, I: 'static>(pub InboundLaneData<T::InboundRelayer>);
pub struct StoredInboundLaneData<T: Config<I>, I: 'static>(
pub InboundLaneData<AccountIdOf<BridgedChainOf<T, I>>>,
);

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

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

impl<T: Config<I>, I: 'static> From<StoredInboundLaneData<T, I>>
for InboundLaneData<T::InboundRelayer>
for InboundLaneData<AccountIdOf<BridgedChainOf<T, I>>>
{
fn from(data: StoredInboundLaneData<T, I>) -> Self {
data.0
}
}

impl<T: Config<I>, I: 'static> EncodeLike<StoredInboundLaneData<T, I>>
for InboundLaneData<T::InboundRelayer>
for InboundLaneData<AccountIdOf<BridgedChainOf<T, I>>>
{
}

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

fn type_info() -> Type {
InboundLaneData::<T::InboundRelayer>::type_info()
InboundLaneData::<AccountIdOf<BridgedChainOf<T, I>>>::type_info()
}
}

impl<T: Config<I>, I: 'static> MaxEncodedLen for StoredInboundLaneData<T, I> {
fn max_encoded_len() -> usize {
InboundLaneData::<T::InboundRelayer>::encoded_size_hint(
InboundLaneData::<AccountIdOf<BridgedChainOf<T, I>>>::encoded_size_hint(
BridgedChainOf::<T, I>::MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX as usize,
)
.unwrap_or(usize::MAX)
Expand Down
39 changes: 18 additions & 21 deletions modules/messages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ use bp_messages::{
MessageKey, MessageNonce, MessagePayload, MessagesOperatingMode, OutboundLaneData,
OutboundMessageDetails, UnrewardedRelayersState, VerificationError,
};
use bp_runtime::{BasicOperatingMode, HashOf, OwnedBridgeModule, PreComputedSize, Size};
use bp_runtime::{
AccountIdOf, BasicOperatingMode, HashOf, OwnedBridgeModule, PreComputedSize, Size,
};
use codec::{Decode, Encode, MaxEncodedLen};
use frame_support::{dispatch::PostDispatchInfo, ensure, fail, traits::Get, DefaultNoBound};
use sp_runtime::traits::UniqueSaturatedFrom;
Expand Down Expand Up @@ -118,24 +120,17 @@ pub mod pallet {

/// Payload type of outbound messages. This payload is dispatched on the bridged chain.
type OutboundPayload: Parameter + Size;

/// Payload type of inbound messages. This payload is dispatched on this chain.
type InboundPayload: Decode;
/// Identifier of relayer that deliver messages to this chain. Relayer reward is paid on the
/// bridged chain.
type InboundRelayer: Parameter + MaxEncodedLen;

// Types that are used by outbound_lane (on source chain).

/// Delivery confirmation payments.
/// Handler for relayer payments that happen during message delivery transaction.
type DeliveryPayments: DeliveryPayments<Self::AccountId>;
/// Handler for relayer payments that happen during message delivery confirmation
/// transaction.
type DeliveryConfirmationPayments: DeliveryConfirmationPayments<Self::AccountId>;

// Types that are used by inbound_lane (on target chain).

/// Message dispatch.
/// Message dispatch handler.
type MessageDispatch: MessageDispatch<DispatchPayload = Self::InboundPayload>;
/// Delivery payments.
type DeliveryPayments: DeliveryPayments<Self::AccountId>;
}

/// Shortcut to this chain type for Config.
Expand Down Expand Up @@ -237,7 +232,7 @@ pub mod pallet {
#[pallet::weight(T::WeightInfo::receive_messages_proof_weight(proof, *messages_count, *dispatch_weight))]
pub fn receive_messages_proof(
origin: OriginFor<T>,
relayer_id_at_bridged_chain: T::InboundRelayer,
relayer_id_at_bridged_chain: AccountIdOf<BridgedChainOf<T, I>>,
proof: FromBridgedChainMessagesProof<HashOf<BridgedChainOf<T, I>>>,
messages_count: u32,
dispatch_weight: Weight,
Expand Down Expand Up @@ -596,7 +591,9 @@ pub mod pallet {
}

/// Return inbound lane data.
pub fn inbound_lane_data(lane: LaneId) -> InboundLaneData<T::InboundRelayer> {
pub fn inbound_lane_data(
lane: LaneId,
) -> InboundLaneData<AccountIdOf<BridgedChainOf<T, I>>> {
InboundLanes::<T, I>::get(lane).0
}
}
Expand Down Expand Up @@ -702,7 +699,7 @@ fn outbound_lane<T: Config<I>, I: 'static>(
/// Runtime inbound lane storage.
struct RuntimeInboundLaneStorage<T: Config<I>, I: 'static = ()> {
lane_id: LaneId,
cached_data: Option<InboundLaneData<T::InboundRelayer>>,
cached_data: Option<InboundLaneData<AccountIdOf<BridgedChainOf<T, I>>>>,
_phantom: PhantomData<I>,
}

Expand All @@ -726,14 +723,14 @@ impl<T: Config<I>, I: 'static> RuntimeInboundLaneStorage<T, I> {
let max_encoded_len = StoredInboundLaneData::<T, I>::max_encoded_len();
let relayers_count = self.get_or_init_data().relayers.len();
let actual_encoded_len =
InboundLaneData::<T::InboundRelayer>::encoded_size_hint(relayers_count)
InboundLaneData::<AccountIdOf<BridgedChainOf<T, I>>>::encoded_size_hint(relayers_count)
.unwrap_or(usize::MAX);
max_encoded_len.saturating_sub(actual_encoded_len) as _
}
}

impl<T: Config<I>, I: 'static> InboundLaneStorage for RuntimeInboundLaneStorage<T, I> {
type Relayer = T::InboundRelayer;
type Relayer = AccountIdOf<BridgedChainOf<T, I>>;

fn id(&self) -> LaneId {
self.lane_id
Expand All @@ -747,19 +744,19 @@ impl<T: Config<I>, I: 'static> InboundLaneStorage for RuntimeInboundLaneStorage<
BridgedChainOf::<T, I>::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX
}

fn get_or_init_data(&mut self) -> InboundLaneData<T::InboundRelayer> {
fn get_or_init_data(&mut self) -> InboundLaneData<AccountIdOf<BridgedChainOf<T, I>>> {
match self.cached_data {
Some(ref data) => data.clone(),
None => {
let data: InboundLaneData<T::InboundRelayer> =
let data: InboundLaneData<AccountIdOf<BridgedChainOf<T, I>>> =
InboundLanes::<T, I>::get(self.lane_id).into();
self.cached_data = Some(data.clone());
data
},
}
}

fn set_data(&mut self, data: InboundLaneData<T::InboundRelayer>) {
fn set_data(&mut self, data: InboundLaneData<AccountIdOf<BridgedChainOf<T, I>>>) {
self.cached_data = Some(data.clone());
InboundLanes::<T, I>::insert(self.lane_id, StoredInboundLaneData::<T, I>(data))
}
Expand Down
3 changes: 1 addition & 2 deletions modules/messages/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl Chain for BridgedChain {
type Hash = BridgedHeaderHash;
type Hasher = BlakeTwo256;
type Header = BridgedChainHeader;
type AccountId = AccountId;
type AccountId = TestRelayer;
type Balance = Balance;
type Index = u64;
type Signature = sp_runtime::MultiSignature;
Expand Down Expand Up @@ -245,7 +245,6 @@ impl Config for TestRuntime {
type OutboundPayload = TestPayload;

type InboundPayload = TestPayload;
type InboundRelayer = TestRelayer;
type DeliveryPayments = TestDeliveryPayments;

type DeliveryConfirmationPayments = TestDeliveryConfirmationPayments;
Expand Down
5 changes: 3 additions & 2 deletions relays/lib-substrate-relay/src/messages/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,10 @@ pub struct DirectReceiveMessagesProofCallBuilder<P, R, I> {
impl<P, R, I> ReceiveMessagesProofCallBuilder<P> for DirectReceiveMessagesProofCallBuilder<P, R, I>
where
P: SubstrateMessageLane,
R: BridgeMessagesConfig<I, InboundRelayer = AccountIdOf<P::SourceChain>>,
R: BridgeMessagesConfig<I>,
I: 'static,
R::BridgedChain: bp_runtime::Chain<Hash = HashOf<P::SourceChain>>,
R::BridgedChain:
bp_runtime::Chain<AccountId = AccountIdOf<P::SourceChain>, Hash = HashOf<P::SourceChain>>,
CallOf<P::TargetChain>: From<BridgeMessagesCall<R, I>> + GetDispatchInfo,
{
fn build_receive_messages_proof_call(
Expand Down

0 comments on commit 3e8e435

Please sign in to comment.