diff --git a/modules/relayers/Cargo.toml b/modules/relayers/Cargo.toml index 0f014ae8..313243b4 100644 --- a/modules/relayers/Cargo.toml +++ b/modules/relayers/Cargo.toml @@ -15,7 +15,6 @@ scale-info = { workspace = true } # darwinia bp-messages = { workspace = true, default-features = false } bp-relayers = { workspace = true, default-features = false } -pallet-bridge-messages = { workspace = true, default-features = false } # paritytech frame-benchmarking = { workspace = true, default-features = false, optional = true } @@ -41,7 +40,6 @@ std = [ "frame-support/std", "frame-system/std", "log/std", - "pallet-bridge-messages/std", "scale-info/std", "sp-arithmetic/std", "sp-runtime/std", diff --git a/modules/relayers/src/lib.rs b/modules/relayers/src/lib.rs index 1490a9c9..8d97dc43 100644 --- a/modules/relayers/src/lib.rs +++ b/modules/relayers/src/lib.rs @@ -28,7 +28,7 @@ use sp_std::marker::PhantomData; use weights::WeightInfo; pub use pallet::*; -pub use payment_adapter::MessageDeliveryAndDispatchPaymentAdapter; +pub use payment_adapter::DeliveryConfirmationPaymentsAdapter; pub mod benchmarking; diff --git a/modules/relayers/src/mock.rs b/modules/relayers/src/mock.rs index 56a98c66..b1336356 100644 --- a/modules/relayers/src/mock.rs +++ b/modules/relayers/src/mock.rs @@ -18,9 +18,7 @@ use crate as pallet_bridge_relayers; -use bp_messages::{ - source_chain::ForbidOutboundMessages, target_chain::ForbidInboundMessages, LaneId, -}; +use bp_messages::LaneId; use bp_relayers::PaymentProcedure; use frame_support::{parameter_types, weights::RuntimeDbWeight}; use sp_core::H256; @@ -43,42 +41,10 @@ frame_support::construct_runtime! { { System: frame_system::{Pallet, Call, Config, Storage, Event}, Balances: pallet_balances::{Pallet, Event}, - Messages: pallet_bridge_messages::{Pallet, Event}, Relayers: pallet_bridge_relayers::{Pallet, Call, Event}, } } -parameter_types! { - pub const DbWeight: RuntimeDbWeight = RuntimeDbWeight { read: 1, write: 2 }; -} - -impl frame_system::Config for TestRuntime { - type RuntimeOrigin = RuntimeOrigin; - type Index = u64; - type RuntimeCall = RuntimeCall; - type BlockNumber = u64; - type Hash = H256; - type Hashing = BlakeTwo256; - type AccountId = AccountId; - type Lookup = IdentityLookup; - type Header = SubstrateHeader; - type RuntimeEvent = RuntimeEvent; - type BlockHashCount = frame_support::traits::ConstU64<250>; - type Version = (); - type PalletInfo = PalletInfo; - type AccountData = pallet_balances::AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type BaseCallFilter = frame_support::traits::Everything; - type SystemWeightInfo = (); - type BlockWeights = (); - type BlockLength = (); - type DbWeight = DbWeight; - type SS58Prefix = (); - type OnSetCode = (); - type MaxConsumers = frame_support::traits::ConstU32<16>; -} - impl pallet_balances::Config for TestRuntime { type MaxLocks = (); type Balance = Balance; diff --git a/modules/relayers/src/payment_adapter.rs b/modules/relayers/src/payment_adapter.rs index 5b8d2a0f..e2d47841 100644 --- a/modules/relayers/src/payment_adapter.rs +++ b/modules/relayers/src/payment_adapter.rs @@ -19,22 +19,25 @@ use crate::{Config, Pallet}; -use bp_messages::source_chain::{MessageDeliveryAndDispatchPayment, RelayersRewards}; -use frame_support::sp_runtime::SaturatedConversion; +use bp_messages::source_chain::{ + DeliveryConfirmationPayments, MessageDeliveryAndDispatchPayment, RelayersRewards, +}; +use frame_support::{sp_runtime::SaturatedConversion, traits::Get}; use sp_arithmetic::traits::{Saturating, UniqueSaturatedFrom, Zero}; use sp_std::{collections::vec_deque::VecDeque, marker::PhantomData, ops::RangeInclusive}; /// Adapter that allows relayers pallet to be used as a delivery+dispatch payment mechanism /// for the messages pallet. -pub struct MessageDeliveryAndDispatchPaymentAdapter( - PhantomData<(T, MessagesInstance)>, +pub struct DeliveryConfirmationPaymentsAdapter( + PhantomData<(T, DeliveryReward, ConfirmationReward)>, ); -impl MessageDeliveryAndDispatchPayment - for MessageDeliveryAndDispatchPaymentAdapter +// TODO (https://github.com/paritytech/parity-bridges-common/pull/1652): this impl must be removed +impl + MessageDeliveryAndDispatchPayment + for DeliveryConfirmationPaymentsAdapter where - T: Config + pallet_bridge_messages::Config, - MessagesInstance: 'static, + T: Config, { type Error = &'static str; @@ -44,23 +47,47 @@ where confirmation_relayer: &T::AccountId, received_range: &RangeInclusive, ) { - let relayers_rewards = pallet_bridge_messages::calc_relayers_rewards::( - messages_relayers, - received_range, - ); + let relayers_rewards = + bp_messages::calc_relayers_rewards::(messages_relayers, received_range); register_relayers_rewards::( confirmation_relayer, relayers_rewards, lane_id, - // TODO (https://github.com/paritytech/parity-bridges-common/issues/1318): this shall be fixed - // in some way. ATM the future of the `register_relayer_reward` is not yet known 100_000_u32.into(), 10_000_u32.into(), ); } } +impl DeliveryConfirmationPayments + for DeliveryConfirmationPaymentsAdapter +where + T: Config, + DeliveryReward: Get, + ConfirmationReward: Get, +{ + type Error = &'static str; + + fn pay_reward( + lane_id: bp_messages::LaneId, + messages_relayers: VecDeque>, + confirmation_relayer: &T::AccountId, + received_range: &RangeInclusive, + ) { + let relayers_rewards = + bp_messages::calc_relayers_rewards::(messages_relayers, received_range); + + register_relayers_rewards::( + confirmation_relayer, + relayers_rewards, + lane_id, + DeliveryReward::get(), + ConfirmationReward::get(), + ); + } +} + // Update rewards to given relayers, optionally rewarding confirmation relayer. fn register_relayers_rewards( confirmation_relayer: &T::AccountId,