Relayers pallet: extend payment source id (#1907)

* Add Chain::ID const

* Relayers pallet: extend payment source id

* Addressed code review comments

* Fix benchmarks

* Fix dashboards

* Renamings

* Fix compilation
This commit is contained in:
Serban Iorga
2023-02-28 11:31:54 +02:00
committed by Bastian Köcher
parent f31b5d8634
commit f5fee288b9
37 changed files with 375 additions and 137 deletions
+17 -6
View File
@@ -33,6 +33,8 @@ pub mod rialto_parachain_messages;
pub mod xcm_config; pub mod xcm_config;
use bp_parachains::SingleParaStoredHeaderDataBuilder; use bp_parachains::SingleParaStoredHeaderDataBuilder;
#[cfg(feature = "runtime-benchmarks")]
use bp_relayers::{RewardsAccountOwner, RewardsAccountParams};
use bp_runtime::HeaderId; use bp_runtime::HeaderId;
use pallet_grandpa::{ use pallet_grandpa::{
fg_primitives, AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList, fg_primitives, AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList,
@@ -389,7 +391,7 @@ impl pallet_bridge_relayers::Config for Runtime {
type RuntimeEvent = RuntimeEvent; type RuntimeEvent = RuntimeEvent;
type Reward = Balance; type Reward = Balance;
type PaymentProcedure = type PaymentProcedure =
bp_relayers::PayLaneRewardFromAccount<pallet_balances::Pallet<Runtime>, AccountId>; bp_relayers::PayRewardFromAccount<pallet_balances::Pallet<Runtime>, AccountId>;
type WeightInfo = (); type WeightInfo = ();
} }
@@ -449,6 +451,7 @@ impl pallet_bridge_messages::Config<WithRialtoMessagesInstance> for Runtime {
type LaneMessageVerifier = crate::rialto_messages::ToRialtoMessageVerifier; type LaneMessageVerifier = crate::rialto_messages::ToRialtoMessageVerifier;
type DeliveryConfirmationPayments = pallet_bridge_relayers::DeliveryConfirmationPaymentsAdapter< type DeliveryConfirmationPayments = pallet_bridge_relayers::DeliveryConfirmationPaymentsAdapter<
Runtime, Runtime,
WithRialtoMessagesInstance,
frame_support::traits::ConstU64<100_000>, frame_support::traits::ConstU64<100_000>,
frame_support::traits::ConstU64<10_000>, frame_support::traits::ConstU64<10_000>,
>; >;
@@ -480,6 +483,7 @@ impl pallet_bridge_messages::Config<WithRialtoParachainMessagesInstance> for Run
type LaneMessageVerifier = crate::rialto_parachain_messages::ToRialtoParachainMessageVerifier; type LaneMessageVerifier = crate::rialto_parachain_messages::ToRialtoParachainMessageVerifier;
type DeliveryConfirmationPayments = pallet_bridge_relayers::DeliveryConfirmationPaymentsAdapter< type DeliveryConfirmationPayments = pallet_bridge_relayers::DeliveryConfirmationPaymentsAdapter<
Runtime, Runtime,
WithRialtoParachainMessagesInstance,
frame_support::traits::ConstU64<100_000>, frame_support::traits::ConstU64<100_000>,
frame_support::traits::ConstU64<10_000>, frame_support::traits::ConstU64<10_000>,
>; >;
@@ -997,7 +1001,14 @@ impl_runtime_apis! {
} }
fn is_relayer_rewarded(relayer: &Self::AccountId) -> bool { fn is_relayer_rewarded(relayer: &Self::AccountId) -> bool {
pallet_bridge_relayers::Pallet::<Runtime>::relayer_reward(relayer, &Self::bench_lane_id()).is_some() use bridge_runtime_common::messages::MessageBridge;
let lane = Self::bench_lane_id();
let bridged_chain_id = WithRialtoMessageBridge::BRIDGED_CHAIN_ID;
pallet_bridge_relayers::Pallet::<Runtime>::relayer_reward(
relayer,
RewardsAccountParams::new(lane, bridged_chain_id, RewardsAccountOwner::BridgedChain)
).is_some()
} }
} }
@@ -1027,15 +1038,15 @@ impl_runtime_apis! {
impl RelayersConfig for Runtime { impl RelayersConfig for Runtime {
fn prepare_environment( fn prepare_environment(
lane: bp_messages::LaneId, account_params: RewardsAccountParams,
reward: Balance, reward: Balance,
) { ) {
use frame_support::traits::fungible::Mutate; use frame_support::traits::fungible::Mutate;
let lane_rewards_account = bp_relayers::PayLaneRewardFromAccount::< let rewards_account = bp_relayers::PayRewardFromAccount::<
Balances, Balances,
AccountId AccountId
>::lane_rewards_account(lane); >::rewards_account(account_params);
Balances::mint_into(&lane_rewards_account, reward).unwrap(); Balances::mint_into(&rewards_account, reward).unwrap();
} }
} }
@@ -521,7 +521,7 @@ impl pallet_bridge_relayers::Config for Runtime {
type RuntimeEvent = RuntimeEvent; type RuntimeEvent = RuntimeEvent;
type Reward = Balance; type Reward = Balance;
type PaymentProcedure = type PaymentProcedure =
bp_relayers::PayLaneRewardFromAccount<pallet_balances::Pallet<Runtime>, AccountId>; bp_relayers::PayRewardFromAccount<pallet_balances::Pallet<Runtime>, AccountId>;
type WeightInfo = (); type WeightInfo = ();
} }
@@ -569,6 +569,7 @@ impl pallet_bridge_messages::Config<WithMillauMessagesInstance> for Runtime {
type LaneMessageVerifier = crate::millau_messages::ToMillauMessageVerifier; type LaneMessageVerifier = crate::millau_messages::ToMillauMessageVerifier;
type DeliveryConfirmationPayments = pallet_bridge_relayers::DeliveryConfirmationPaymentsAdapter< type DeliveryConfirmationPayments = pallet_bridge_relayers::DeliveryConfirmationPaymentsAdapter<
Runtime, Runtime,
WithMillauMessagesInstance,
frame_support::traits::ConstU128<100_000>, frame_support::traits::ConstU128<100_000>,
frame_support::traits::ConstU128<100_000>, frame_support::traits::ConstU128<100_000>,
>; >;
+2 -1
View File
@@ -393,7 +393,7 @@ impl pallet_bridge_relayers::Config for Runtime {
type RuntimeEvent = RuntimeEvent; type RuntimeEvent = RuntimeEvent;
type Reward = Balance; type Reward = Balance;
type PaymentProcedure = type PaymentProcedure =
bp_relayers::PayLaneRewardFromAccount<pallet_balances::Pallet<Runtime>, AccountId>; bp_relayers::PayRewardFromAccount<pallet_balances::Pallet<Runtime>, AccountId>;
type WeightInfo = (); type WeightInfo = ();
} }
@@ -443,6 +443,7 @@ impl pallet_bridge_messages::Config<WithMillauMessagesInstance> for Runtime {
type LaneMessageVerifier = crate::millau_messages::ToMillauMessageVerifier; type LaneMessageVerifier = crate::millau_messages::ToMillauMessageVerifier;
type DeliveryConfirmationPayments = pallet_bridge_relayers::DeliveryConfirmationPaymentsAdapter< type DeliveryConfirmationPayments = pallet_bridge_relayers::DeliveryConfirmationPaymentsAdapter<
Runtime, Runtime,
WithMillauMessagesInstance,
frame_support::traits::ConstU128<100_000>, frame_support::traits::ConstU128<100_000>,
frame_support::traits::ConstU128<100_000>, frame_support::traits::ConstU128<100_000>,
>; >;
+1
View File
@@ -19,6 +19,7 @@ bp-header-chain = { path = "../../primitives/header-chain", default-features = f
bp-messages = { path = "../../primitives/messages", default-features = false } bp-messages = { path = "../../primitives/messages", default-features = false }
bp-parachains = { path = "../../primitives/parachains", default-features = false } bp-parachains = { path = "../../primitives/parachains", default-features = false }
bp-polkadot-core = { path = "../../primitives/polkadot-core", default-features = false } bp-polkadot-core = { path = "../../primitives/polkadot-core", default-features = false }
bp-relayers = { path = "../../primitives/relayers", default-features = false }
bp-runtime = { path = "../../primitives/runtime", default-features = false } bp-runtime = { path = "../../primitives/runtime", default-features = false }
pallet-bridge-grandpa = { path = "../../modules/grandpa", default-features = false } pallet-bridge-grandpa = { path = "../../modules/grandpa", default-features = false }
pallet-bridge-messages = { path = "../../modules/messages", default-features = false } pallet-bridge-messages = { path = "../../modules/messages", default-features = false }
+6 -3
View File
@@ -85,6 +85,8 @@ pub type BridgedChainHeader =
/// Message lane used in tests. /// Message lane used in tests.
pub const TEST_LANE_ID: LaneId = LaneId([0, 0, 0, 0]); pub const TEST_LANE_ID: LaneId = LaneId([0, 0, 0, 0]);
/// Bridged chain id used in tests.
pub const TEST_BRIDGED_CHAIN_ID: ChainId = *b"brdg";
/// Maximal number of queued messages at the test lane. /// Maximal number of queued messages at the test lane.
pub const MAXIMAL_PENDING_MESSAGES_AT_TEST_LANE: MessageNonce = 32; pub const MAXIMAL_PENDING_MESSAGES_AT_TEST_LANE: MessageNonce = 32;
/// Minimal extrinsic weight at the `BridgedChain`. /// Minimal extrinsic weight at the `BridgedChain`.
@@ -118,7 +120,7 @@ crate::generate_bridge_reject_obsolete_headers_and_messages! {
parameter_types! { parameter_types! {
pub const ActiveOutboundLanes: &'static [LaneId] = &[TEST_LANE_ID]; pub const ActiveOutboundLanes: &'static [LaneId] = &[TEST_LANE_ID];
pub const BridgedChainId: ChainId = *b"brdg"; pub const BridgedChainId: ChainId = TEST_BRIDGED_CHAIN_ID;
pub const BridgedParasPalletName: &'static str = "Paras"; pub const BridgedParasPalletName: &'static str = "Paras";
pub const ExistentialDeposit: ThisChainBalance = 500; pub const ExistentialDeposit: ThisChainBalance = 500;
pub const DbWeight: RuntimeDbWeight = RuntimeDbWeight { read: 1, write: 2 }; pub const DbWeight: RuntimeDbWeight = RuntimeDbWeight { read: 1, write: 2 };
@@ -227,6 +229,7 @@ impl pallet_bridge_messages::Config for TestRuntime {
type LaneMessageVerifier = FromThisChainMessageVerifier<OnThisChainBridge>; type LaneMessageVerifier = FromThisChainMessageVerifier<OnThisChainBridge>;
type DeliveryConfirmationPayments = pallet_bridge_relayers::DeliveryConfirmationPaymentsAdapter< type DeliveryConfirmationPayments = pallet_bridge_relayers::DeliveryConfirmationPaymentsAdapter<
TestRuntime, TestRuntime,
(),
frame_support::traits::ConstU64<100_000>, frame_support::traits::ConstU64<100_000>,
frame_support::traits::ConstU64<10_000>, frame_support::traits::ConstU64<10_000>,
>; >;
@@ -251,7 +254,7 @@ pub struct OnThisChainBridge;
impl MessageBridge for OnThisChainBridge { impl MessageBridge for OnThisChainBridge {
const THIS_CHAIN_ID: ChainId = *b"this"; const THIS_CHAIN_ID: ChainId = *b"this";
const BRIDGED_CHAIN_ID: ChainId = *b"brdg"; const BRIDGED_CHAIN_ID: ChainId = TEST_BRIDGED_CHAIN_ID;
const BRIDGED_MESSAGES_PALLET_NAME: &'static str = ""; const BRIDGED_MESSAGES_PALLET_NAME: &'static str = "";
type ThisChain = ThisChain; type ThisChain = ThisChain;
@@ -265,7 +268,7 @@ impl MessageBridge for OnThisChainBridge {
pub struct OnBridgedChainBridge; pub struct OnBridgedChainBridge;
impl MessageBridge for OnBridgedChainBridge { impl MessageBridge for OnBridgedChainBridge {
const THIS_CHAIN_ID: ChainId = *b"brdg"; const THIS_CHAIN_ID: ChainId = TEST_BRIDGED_CHAIN_ID;
const BRIDGED_CHAIN_ID: ChainId = *b"this"; const BRIDGED_CHAIN_ID: ChainId = *b"this";
const BRIDGED_MESSAGES_PALLET_NAME: &'static str = ""; const BRIDGED_MESSAGES_PALLET_NAME: &'static str = "";
@@ -23,6 +23,7 @@ use crate::messages_call_ext::{
MessagesCallSubType, ReceiveMessagesProofHelper, ReceiveMessagesProofInfo, MessagesCallSubType, ReceiveMessagesProofHelper, ReceiveMessagesProofInfo,
}; };
use bp_messages::LaneId; use bp_messages::LaneId;
use bp_relayers::{RewardsAccountOwner, RewardsAccountParams};
use bp_runtime::StaticStrProvider; use bp_runtime::StaticStrProvider;
use codec::{Decode, Encode}; use codec::{Decode, Encode};
use frame_support::{ use frame_support::{
@@ -397,7 +398,15 @@ where
let refund = Refund::compute_refund(info, &post_info, post_info_len, tip); let refund = Refund::compute_refund(info, &post_info, post_info_len, tip);
// finally - register refund in relayers pallet // finally - register refund in relayers pallet
RelayersPallet::<Runtime>::register_relayer_reward(Msgs::Id::get(), &relayer, refund); RelayersPallet::<Runtime>::register_relayer_reward(
RewardsAccountParams::new(
Msgs::Id::get(),
Runtime::BridgedChainId::get(),
RewardsAccountOwner::ThisChain,
),
&relayer,
refund,
);
log::trace!( log::trace!(
target: "runtime::bridge", target: "runtime::bridge",
@@ -433,6 +442,7 @@ mod tests {
parameter_types! { parameter_types! {
TestParachain: u32 = 1000; TestParachain: u32 = 1000;
pub TestLaneId: LaneId = TEST_LANE_ID; pub TestLaneId: LaneId = TEST_LANE_ID;
pub DirectedTestLaneId: RewardsAccountParams = RewardsAccountParams::new(TEST_LANE_ID, TEST_BRIDGED_CHAIN_ID, RewardsAccountOwner::ThisChain);
} }
bp_runtime::generate_static_str_provider!(TestExtension); bp_runtime::generate_static_str_provider!(TestExtension);
@@ -872,7 +882,7 @@ mod tests {
assert_eq!( assert_eq!(
RelayersPallet::<TestRuntime>::relayer_reward( RelayersPallet::<TestRuntime>::relayer_reward(
relayer_account_at_this_chain(), relayer_account_at_this_chain(),
TestLaneId::get() DirectedTestLaneId::get()
), ),
Some(regular_reward), Some(regular_reward),
); );
@@ -891,7 +901,7 @@ mod tests {
run_post_dispatch(Some(pre_dispatch_data), Ok(())); run_post_dispatch(Some(pre_dispatch_data), Ok(()));
let reward_after_two_calls = RelayersPallet::<TestRuntime>::relayer_reward( let reward_after_two_calls = RelayersPallet::<TestRuntime>::relayer_reward(
relayer_account_at_this_chain(), relayer_account_at_this_chain(),
TestLaneId::get(), DirectedTestLaneId::get(),
) )
.unwrap(); .unwrap();
assert!( assert!(
@@ -912,7 +922,7 @@ mod tests {
assert_eq!( assert_eq!(
RelayersPallet::<TestRuntime>::relayer_reward( RelayersPallet::<TestRuntime>::relayer_reward(
relayer_account_at_this_chain(), relayer_account_at_this_chain(),
TestLaneId::get() DirectedTestLaneId::get()
), ),
Some(expected_reward()), Some(expected_reward()),
); );
@@ -928,7 +938,7 @@ mod tests {
assert_eq!( assert_eq!(
RelayersPallet::<TestRuntime>::relayer_reward( RelayersPallet::<TestRuntime>::relayer_reward(
relayer_account_at_this_chain(), relayer_account_at_this_chain(),
TestLaneId::get() DirectedTestLaneId::get()
), ),
Some(expected_reward()), Some(expected_reward()),
); );
@@ -944,7 +954,7 @@ mod tests {
assert_eq!( assert_eq!(
RelayersPallet::<TestRuntime>::relayer_reward( RelayersPallet::<TestRuntime>::relayer_reward(
relayer_account_at_this_chain(), relayer_account_at_this_chain(),
TestLaneId::get() DirectedTestLaneId::get()
), ),
Some(expected_reward()), Some(expected_reward()),
); );
+1
View File
@@ -16,6 +16,7 @@ scale-info = { version = "2.1.1", default-features = false, features = ["derive"
bp-messages = { path = "../../primitives/messages", default-features = false } bp-messages = { path = "../../primitives/messages", default-features = false }
bp-relayers = { path = "../../primitives/relayers", default-features = false } bp-relayers = { path = "../../primitives/relayers", default-features = false }
bp-runtime = { path = "../../primitives/runtime", default-features = false } bp-runtime = { path = "../../primitives/runtime", default-features = false }
pallet-bridge-messages = { path = "../messages", default-features = false }
# Substrate Dependencies # Substrate Dependencies
+8 -4
View File
@@ -20,6 +20,8 @@
use crate::*; use crate::*;
use bp_messages::LaneId;
use bp_relayers::RewardsAccountOwner;
use frame_benchmarking::{benchmarks, whitelisted_caller}; use frame_benchmarking::{benchmarks, whitelisted_caller};
use frame_system::RawOrigin; use frame_system::RawOrigin;
@@ -32,19 +34,21 @@ pub struct Pallet<T: Config>(crate::Pallet<T>);
/// Trait that must be implemented by runtime. /// Trait that must be implemented by runtime.
pub trait Config: crate::Config { pub trait Config: crate::Config {
/// Prepare environment for paying given reward for serving given lane. /// Prepare environment for paying given reward for serving given lane.
fn prepare_environment(lane: LaneId, reward: Self::Reward); fn prepare_environment(account_params: RewardsAccountParams, reward: Self::Reward);
} }
benchmarks! { benchmarks! {
// Benchmark `claim_rewards` call. // Benchmark `claim_rewards` call.
claim_rewards { claim_rewards {
let lane = LaneId([0, 0, 0, 0]); let lane = LaneId([0, 0, 0, 0]);
let account_params =
RewardsAccountParams::new(lane, *b"test", RewardsAccountOwner::ThisChain);
let relayer: T::AccountId = whitelisted_caller(); let relayer: T::AccountId = whitelisted_caller();
let reward = T::Reward::from(REWARD_AMOUNT); let reward = T::Reward::from(REWARD_AMOUNT);
T::prepare_environment(lane, reward); T::prepare_environment(account_params, reward);
RelayerRewards::<T>::insert(&relayer, lane, reward); RelayerRewards::<T>::insert(&relayer, account_params, reward);
}: _(RawOrigin::Signed(relayer), lane) }: _(RawOrigin::Signed(relayer), account_params)
verify { verify {
// we can't check anything here, because `PaymentProcedure` is responsible for // we can't check anything here, because `PaymentProcedure` is responsible for
// payment logic, so we assume that if call has succeeded, the procedure has // payment logic, so we assume that if call has succeeded, the procedure has
+89 -53
View File
@@ -20,8 +20,7 @@
#![cfg_attr(not(feature = "std"), no_std)] #![cfg_attr(not(feature = "std"), no_std)]
#![warn(missing_docs)] #![warn(missing_docs)]
use bp_messages::LaneId; use bp_relayers::{PaymentProcedure, RelayerRewardsKeyProvider, RewardsAccountParams};
use bp_relayers::{PaymentProcedure, RelayerRewardsKeyProvider};
use bp_runtime::StorageDoubleMapKeyProvider; use bp_runtime::StorageDoubleMapKeyProvider;
use frame_support::sp_runtime::Saturating; use frame_support::sp_runtime::Saturating;
use sp_arithmetic::traits::{AtLeast32BitUnsigned, Zero}; use sp_arithmetic::traits::{AtLeast32BitUnsigned, Zero};
@@ -72,28 +71,32 @@ pub mod pallet {
/// Claim accumulated rewards. /// Claim accumulated rewards.
#[pallet::call_index(0)] #[pallet::call_index(0)]
#[pallet::weight(T::WeightInfo::claim_rewards())] #[pallet::weight(T::WeightInfo::claim_rewards())]
pub fn claim_rewards(origin: OriginFor<T>, lane_id: LaneId) -> DispatchResult { pub fn claim_rewards(
origin: OriginFor<T>,
rewards_account_params: RewardsAccountParams,
) -> DispatchResult {
let relayer = ensure_signed(origin)?; let relayer = ensure_signed(origin)?;
RelayerRewards::<T>::try_mutate_exists( RelayerRewards::<T>::try_mutate_exists(
&relayer, &relayer,
lane_id, rewards_account_params,
|maybe_reward| -> DispatchResult { |maybe_reward| -> DispatchResult {
let reward = maybe_reward.take().ok_or(Error::<T>::NoRewardForRelayer)?; let reward = maybe_reward.take().ok_or(Error::<T>::NoRewardForRelayer)?;
T::PaymentProcedure::pay_reward(&relayer, lane_id, reward).map_err(|e| { T::PaymentProcedure::pay_reward(&relayer, rewards_account_params, reward)
log::trace!( .map_err(|e| {
target: LOG_TARGET, log::trace!(
"Failed to pay {:?} rewards to {:?}: {:?}", target: LOG_TARGET,
lane_id, "Failed to pay {:?} rewards to {:?}: {:?}",
relayer, rewards_account_params,
e, relayer,
); e,
Error::<T>::FailedToPayReward );
})?; Error::<T>::FailedToPayReward
})?;
Self::deposit_event(Event::<T>::RewardPaid { Self::deposit_event(Event::<T>::RewardPaid {
relayer: relayer.clone(), relayer: relayer.clone(),
lane_id, rewards_account_params,
reward, reward,
}); });
Ok(()) Ok(())
@@ -104,23 +107,31 @@ pub mod pallet {
impl<T: Config> Pallet<T> { impl<T: Config> Pallet<T> {
/// Register reward for given relayer. /// Register reward for given relayer.
pub fn register_relayer_reward(lane_id: LaneId, relayer: &T::AccountId, reward: T::Reward) { pub fn register_relayer_reward(
rewards_account_params: RewardsAccountParams,
relayer: &T::AccountId,
reward: T::Reward,
) {
if reward.is_zero() { if reward.is_zero() {
return return
} }
RelayerRewards::<T>::mutate(relayer, lane_id, |old_reward: &mut Option<T::Reward>| { RelayerRewards::<T>::mutate(
let new_reward = old_reward.unwrap_or_else(Zero::zero).saturating_add(reward); relayer,
*old_reward = Some(new_reward); rewards_account_params,
|old_reward: &mut Option<T::Reward>| {
let new_reward = old_reward.unwrap_or_else(Zero::zero).saturating_add(reward);
*old_reward = Some(new_reward);
log::trace!( log::trace!(
target: crate::LOG_TARGET, target: crate::LOG_TARGET,
"Relayer {:?} can now claim reward for serving lane {:?}: {:?}", "Relayer {:?} can now claim reward for serving payer {:?}: {:?}",
relayer, relayer,
lane_id, rewards_account_params,
new_reward, new_reward,
); );
}); },
);
} }
} }
@@ -131,8 +142,8 @@ pub mod pallet {
RewardPaid { RewardPaid {
/// Relayer account that has been rewarded. /// Relayer account that has been rewarded.
relayer: T::AccountId, relayer: T::AccountId,
/// Relayer has received reward for serving this lane. /// Relayer has received reward from this account.
lane_id: LaneId, rewards_account_params: RewardsAccountParams,
/// Reward amount. /// Reward amount.
reward: T::Reward, reward: T::Reward,
}, },
@@ -166,6 +177,8 @@ mod tests {
use mock::{RuntimeEvent as TestEvent, *}; use mock::{RuntimeEvent as TestEvent, *};
use crate::Event::RewardPaid; use crate::Event::RewardPaid;
use bp_messages::LaneId;
use bp_relayers::RewardsAccountOwner;
use frame_support::{ use frame_support::{
assert_noop, assert_ok, assert_noop, assert_ok,
traits::fungible::{Inspect, Mutate}, traits::fungible::{Inspect, Mutate},
@@ -182,7 +195,10 @@ mod tests {
fn root_cant_claim_anything() { fn root_cant_claim_anything() {
run_test(|| { run_test(|| {
assert_noop!( assert_noop!(
Pallet::<TestRuntime>::claim_rewards(RuntimeOrigin::root(), TEST_LANE_ID), Pallet::<TestRuntime>::claim_rewards(
RuntimeOrigin::root(),
TEST_REWARDS_ACCOUNT_PARAMS
),
DispatchError::BadOrigin, DispatchError::BadOrigin,
); );
}); });
@@ -194,7 +210,7 @@ mod tests {
assert_noop!( assert_noop!(
Pallet::<TestRuntime>::claim_rewards( Pallet::<TestRuntime>::claim_rewards(
RuntimeOrigin::signed(REGULAR_RELAYER), RuntimeOrigin::signed(REGULAR_RELAYER),
TEST_LANE_ID TEST_REWARDS_ACCOUNT_PARAMS
), ),
Error::<TestRuntime>::NoRewardForRelayer, Error::<TestRuntime>::NoRewardForRelayer,
); );
@@ -204,11 +220,15 @@ mod tests {
#[test] #[test]
fn relayer_cant_claim_if_payment_procedure_fails() { fn relayer_cant_claim_if_payment_procedure_fails() {
run_test(|| { run_test(|| {
RelayerRewards::<TestRuntime>::insert(FAILING_RELAYER, TEST_LANE_ID, 100); RelayerRewards::<TestRuntime>::insert(
FAILING_RELAYER,
TEST_REWARDS_ACCOUNT_PARAMS,
100,
);
assert_noop!( assert_noop!(
Pallet::<TestRuntime>::claim_rewards( Pallet::<TestRuntime>::claim_rewards(
RuntimeOrigin::signed(FAILING_RELAYER), RuntimeOrigin::signed(FAILING_RELAYER),
TEST_LANE_ID TEST_REWARDS_ACCOUNT_PARAMS
), ),
Error::<TestRuntime>::FailedToPayReward, Error::<TestRuntime>::FailedToPayReward,
); );
@@ -220,12 +240,19 @@ mod tests {
run_test(|| { run_test(|| {
get_ready_for_events(); get_ready_for_events();
RelayerRewards::<TestRuntime>::insert(REGULAR_RELAYER, TEST_LANE_ID, 100); RelayerRewards::<TestRuntime>::insert(
REGULAR_RELAYER,
TEST_REWARDS_ACCOUNT_PARAMS,
100,
);
assert_ok!(Pallet::<TestRuntime>::claim_rewards( assert_ok!(Pallet::<TestRuntime>::claim_rewards(
RuntimeOrigin::signed(REGULAR_RELAYER), RuntimeOrigin::signed(REGULAR_RELAYER),
TEST_LANE_ID TEST_REWARDS_ACCOUNT_PARAMS
)); ));
assert_eq!(RelayerRewards::<TestRuntime>::get(REGULAR_RELAYER, TEST_LANE_ID), None); assert_eq!(
RelayerRewards::<TestRuntime>::get(REGULAR_RELAYER, TEST_REWARDS_ACCOUNT_PARAMS),
None
);
//Check if the `RewardPaid` event was emitted. //Check if the `RewardPaid` event was emitted.
assert_eq!( assert_eq!(
@@ -234,7 +261,7 @@ mod tests {
phase: Phase::Initialization, phase: Phase::Initialization,
event: TestEvent::Relayers(RewardPaid { event: TestEvent::Relayers(RewardPaid {
relayer: REGULAR_RELAYER, relayer: REGULAR_RELAYER,
lane_id: TEST_LANE_ID, rewards_account_params: TEST_REWARDS_ACCOUNT_PARAMS,
reward: 100 reward: 100
}), }),
topics: vec![], topics: vec![],
@@ -244,30 +271,39 @@ mod tests {
} }
#[test] #[test]
fn pay_lane_reward_from_account_actually_pays_reward() { fn pay_reward_from_account_actually_pays_reward() {
type Balances = pallet_balances::Pallet<TestRuntime>; type Balances = pallet_balances::Pallet<TestRuntime>;
type PayLaneRewardFromAccount = bp_relayers::PayLaneRewardFromAccount<Balances, AccountId>; type PayLaneRewardFromAccount = bp_relayers::PayRewardFromAccount<Balances, AccountId>;
run_test(|| { run_test(|| {
let lane0_rewards_account = let in_lane_0 = RewardsAccountParams::new(
PayLaneRewardFromAccount::lane_rewards_account(LaneId([0, 0, 0, 0])); LaneId([0, 0, 0, 0]),
let lane1_rewards_account = *b"test",
PayLaneRewardFromAccount::lane_rewards_account(LaneId([0, 0, 0, 1])); RewardsAccountOwner::ThisChain,
);
let out_lane_1 = RewardsAccountParams::new(
LaneId([0, 0, 0, 1]),
*b"test",
RewardsAccountOwner::BridgedChain,
);
Balances::mint_into(&lane0_rewards_account, 100).unwrap(); let in_lane0_rewards_account = PayLaneRewardFromAccount::rewards_account(in_lane_0);
Balances::mint_into(&lane1_rewards_account, 100).unwrap(); let out_lane1_rewards_account = PayLaneRewardFromAccount::rewards_account(out_lane_1);
assert_eq!(Balances::balance(&lane0_rewards_account), 100);
assert_eq!(Balances::balance(&lane1_rewards_account), 100); Balances::mint_into(&in_lane0_rewards_account, 100).unwrap();
Balances::mint_into(&out_lane1_rewards_account, 100).unwrap();
assert_eq!(Balances::balance(&in_lane0_rewards_account), 100);
assert_eq!(Balances::balance(&out_lane1_rewards_account), 100);
assert_eq!(Balances::balance(&1), 0); assert_eq!(Balances::balance(&1), 0);
PayLaneRewardFromAccount::pay_reward(&1, LaneId([0, 0, 0, 0]), 100).unwrap(); PayLaneRewardFromAccount::pay_reward(&1, in_lane_0, 100).unwrap();
assert_eq!(Balances::balance(&lane0_rewards_account), 0); assert_eq!(Balances::balance(&in_lane0_rewards_account), 0);
assert_eq!(Balances::balance(&lane1_rewards_account), 100); assert_eq!(Balances::balance(&out_lane1_rewards_account), 100);
assert_eq!(Balances::balance(&1), 100); assert_eq!(Balances::balance(&1), 100);
PayLaneRewardFromAccount::pay_reward(&1, LaneId([0, 0, 0, 1]), 100).unwrap(); PayLaneRewardFromAccount::pay_reward(&1, out_lane_1, 100).unwrap();
assert_eq!(Balances::balance(&lane0_rewards_account), 0); assert_eq!(Balances::balance(&in_lane0_rewards_account), 0);
assert_eq!(Balances::balance(&lane1_rewards_account), 0); assert_eq!(Balances::balance(&out_lane1_rewards_account), 0);
assert_eq!(Balances::balance(&1), 200); assert_eq!(Balances::balance(&1), 200);
}); });
} }
+4 -3
View File
@@ -19,7 +19,7 @@
use crate as pallet_bridge_relayers; use crate as pallet_bridge_relayers;
use bp_messages::LaneId; use bp_messages::LaneId;
use bp_relayers::PaymentProcedure; use bp_relayers::{PaymentProcedure, RewardsAccountOwner, RewardsAccountParams};
use frame_support::{parameter_types, weights::RuntimeDbWeight}; use frame_support::{parameter_types, weights::RuntimeDbWeight};
use sp_core::H256; use sp_core::H256;
use sp_runtime::{ use sp_runtime::{
@@ -96,7 +96,8 @@ impl pallet_bridge_relayers::Config for TestRuntime {
} }
/// Message lane that we're using in tests. /// Message lane that we're using in tests.
pub const TEST_LANE_ID: LaneId = LaneId([0, 0, 0, 0]); pub const TEST_REWARDS_ACCOUNT_PARAMS: RewardsAccountParams =
RewardsAccountParams::new(LaneId([0, 0, 0, 0]), *b"test", RewardsAccountOwner::ThisChain);
/// Regular relayer that may receive rewards. /// Regular relayer that may receive rewards.
pub const REGULAR_RELAYER: AccountId = 1; pub const REGULAR_RELAYER: AccountId = 1;
@@ -112,7 +113,7 @@ impl PaymentProcedure<AccountId, Balance> for TestPaymentProcedure {
fn pay_reward( fn pay_reward(
relayer: &AccountId, relayer: &AccountId,
_lane_id: LaneId, _lane_id: RewardsAccountParams,
_reward: Balance, _reward: Balance,
) -> Result<(), Self::Error> { ) -> Result<(), Self::Error> {
match *relayer { match *relayer {
+53 -20
View File
@@ -18,28 +18,33 @@
use crate::{Config, Pallet}; use crate::{Config, Pallet};
use bp_messages::source_chain::{DeliveryConfirmationPayments, RelayersRewards}; use bp_messages::{
source_chain::{DeliveryConfirmationPayments, RelayersRewards},
LaneId,
};
use bp_relayers::{RewardsAccountOwner, RewardsAccountParams};
use frame_support::{sp_runtime::SaturatedConversion, traits::Get}; use frame_support::{sp_runtime::SaturatedConversion, traits::Get};
use sp_arithmetic::traits::{Saturating, UniqueSaturatedFrom, Zero}; use sp_arithmetic::traits::{Saturating, UniqueSaturatedFrom, Zero};
use sp_std::{collections::vec_deque::VecDeque, marker::PhantomData, ops::RangeInclusive}; 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 /// Adapter that allows relayers pallet to be used as a delivery+dispatch payment mechanism
/// for the messages pallet. /// for the messages pallet.
pub struct DeliveryConfirmationPaymentsAdapter<T, DeliveryReward, ConfirmationReward>( pub struct DeliveryConfirmationPaymentsAdapter<T, MI, DeliveryReward, ConfirmationReward>(
PhantomData<(T, DeliveryReward, ConfirmationReward)>, PhantomData<(T, MI, DeliveryReward, ConfirmationReward)>,
); );
impl<T, DeliveryReward, ConfirmationReward> DeliveryConfirmationPayments<T::AccountId> impl<T, MI, DeliveryReward, ConfirmationReward> DeliveryConfirmationPayments<T::AccountId>
for DeliveryConfirmationPaymentsAdapter<T, DeliveryReward, ConfirmationReward> for DeliveryConfirmationPaymentsAdapter<T, MI, DeliveryReward, ConfirmationReward>
where where
T: Config, T: Config + pallet_bridge_messages::Config<MI>,
MI: 'static,
DeliveryReward: Get<T::Reward>, DeliveryReward: Get<T::Reward>,
ConfirmationReward: Get<T::Reward>, ConfirmationReward: Get<T::Reward>,
{ {
type Error = &'static str; type Error = &'static str;
fn pay_reward( fn pay_reward(
lane_id: bp_messages::LaneId, lane_id: LaneId,
messages_relayers: VecDeque<bp_messages::UnrewardedRelayer<T::AccountId>>, messages_relayers: VecDeque<bp_messages::UnrewardedRelayer<T::AccountId>>,
confirmation_relayer: &T::AccountId, confirmation_relayer: &T::AccountId,
received_range: &RangeInclusive<bp_messages::MessageNonce>, received_range: &RangeInclusive<bp_messages::MessageNonce>,
@@ -50,7 +55,11 @@ where
register_relayers_rewards::<T>( register_relayers_rewards::<T>(
confirmation_relayer, confirmation_relayer,
relayers_rewards, relayers_rewards,
lane_id, RewardsAccountParams::new(
lane_id,
T::BridgedChainId::get(),
RewardsAccountOwner::BridgedChain,
),
DeliveryReward::get(), DeliveryReward::get(),
ConfirmationReward::get(), ConfirmationReward::get(),
); );
@@ -61,7 +70,7 @@ where
fn register_relayers_rewards<T: Config>( fn register_relayers_rewards<T: Config>(
confirmation_relayer: &T::AccountId, confirmation_relayer: &T::AccountId,
relayers_rewards: RelayersRewards<T::AccountId>, relayers_rewards: RelayersRewards<T::AccountId>,
lane_id: bp_messages::LaneId, lane_id: RewardsAccountParams,
delivery_fee: T::Reward, delivery_fee: T::Reward,
confirmation_fee: T::Reward, confirmation_fee: T::Reward,
) { ) {
@@ -121,13 +130,19 @@ mod tests {
register_relayers_rewards::<TestRuntime>( register_relayers_rewards::<TestRuntime>(
&RELAYER_2, &RELAYER_2,
relayers_rewards(), relayers_rewards(),
TEST_LANE_ID, TEST_REWARDS_ACCOUNT_PARAMS,
50, 50,
10, 10,
); );
assert_eq!(RelayerRewards::<TestRuntime>::get(RELAYER_1, TEST_LANE_ID), Some(80)); assert_eq!(
assert_eq!(RelayerRewards::<TestRuntime>::get(RELAYER_2, TEST_LANE_ID), Some(170)); RelayerRewards::<TestRuntime>::get(RELAYER_1, TEST_REWARDS_ACCOUNT_PARAMS),
Some(80)
);
assert_eq!(
RelayerRewards::<TestRuntime>::get(RELAYER_2, TEST_REWARDS_ACCOUNT_PARAMS),
Some(170)
);
}); });
} }
@@ -137,14 +152,23 @@ mod tests {
register_relayers_rewards::<TestRuntime>( register_relayers_rewards::<TestRuntime>(
&RELAYER_3, &RELAYER_3,
relayers_rewards(), relayers_rewards(),
TEST_LANE_ID, TEST_REWARDS_ACCOUNT_PARAMS,
50, 50,
10, 10,
); );
assert_eq!(RelayerRewards::<TestRuntime>::get(RELAYER_1, TEST_LANE_ID), Some(80)); assert_eq!(
assert_eq!(RelayerRewards::<TestRuntime>::get(RELAYER_2, TEST_LANE_ID), Some(120)); RelayerRewards::<TestRuntime>::get(RELAYER_1, TEST_REWARDS_ACCOUNT_PARAMS),
assert_eq!(RelayerRewards::<TestRuntime>::get(RELAYER_3, TEST_LANE_ID), Some(50)); Some(80)
);
assert_eq!(
RelayerRewards::<TestRuntime>::get(RELAYER_2, TEST_REWARDS_ACCOUNT_PARAMS),
Some(120)
);
assert_eq!(
RelayerRewards::<TestRuntime>::get(RELAYER_3, TEST_REWARDS_ACCOUNT_PARAMS),
Some(50)
);
}); });
} }
@@ -154,14 +178,23 @@ mod tests {
register_relayers_rewards::<TestRuntime>( register_relayers_rewards::<TestRuntime>(
&RELAYER_3, &RELAYER_3,
relayers_rewards(), relayers_rewards(),
TEST_LANE_ID, TEST_REWARDS_ACCOUNT_PARAMS,
50, 50,
1000, 1000,
); );
assert_eq!(RelayerRewards::<TestRuntime>::get(RELAYER_1, TEST_LANE_ID), None); assert_eq!(
assert_eq!(RelayerRewards::<TestRuntime>::get(RELAYER_2, TEST_LANE_ID), None); RelayerRewards::<TestRuntime>::get(RELAYER_1, TEST_REWARDS_ACCOUNT_PARAMS),
assert_eq!(RelayerRewards::<TestRuntime>::get(RELAYER_3, TEST_LANE_ID), Some(250)); None
);
assert_eq!(
RelayerRewards::<TestRuntime>::get(RELAYER_2, TEST_REWARDS_ACCOUNT_PARAMS),
None
);
assert_eq!(
RelayerRewards::<TestRuntime>::get(RELAYER_3, TEST_REWARDS_ACCOUNT_PARAMS),
Some(250)
);
}); });
} }
} }
+12 -12
View File
@@ -17,9 +17,9 @@
//! Autogenerated weights for pallet_bridge_relayers //! Autogenerated weights for pallet_bridge_relayers
//! //!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2023-02-06, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! DATE: 2023-02-27, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000` //! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `covid`, CPU: `11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz` //! HOSTNAME: `serban-ROG-Zephyrus`, CPU: `12th Gen Intel(R) Core(TM) i7-12700H`
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024
// Executed Command: // Executed Command:
@@ -60,7 +60,7 @@ pub struct BridgeWeight<T>(PhantomData<T>);
impl<T: frame_system::Config> WeightInfo for BridgeWeight<T> { impl<T: frame_system::Config> WeightInfo for BridgeWeight<T> {
/// Storage: BridgeRelayers RelayerRewards (r:1 w:1) /// Storage: BridgeRelayers RelayerRewards (r:1 w:1)
/// ///
/// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(60), added: 2535, /// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(65), added: 2540,
/// mode: MaxEncodedLen) /// mode: MaxEncodedLen)
/// ///
/// Storage: System Account (r:1 w:1) /// Storage: System Account (r:1 w:1)
@@ -69,10 +69,10 @@ impl<T: frame_system::Config> WeightInfo for BridgeWeight<T> {
/// MaxEncodedLen) /// MaxEncodedLen)
fn claim_rewards() -> Weight { fn claim_rewards() -> Weight {
// Proof Size summary in bytes: // Proof Size summary in bytes:
// Measured: `534` // Measured: `275`
// Estimated: `5106` // Estimated: `5111`
// Minimum execution time: 48_239 nanoseconds. // Minimum execution time: 43_031 nanoseconds.
Weight::from_parts(50_579_000, 5106) Weight::from_parts(44_527_000, 5111)
.saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().reads(2_u64))
.saturating_add(T::DbWeight::get().writes(2_u64)) .saturating_add(T::DbWeight::get().writes(2_u64))
} }
@@ -82,7 +82,7 @@ impl<T: frame_system::Config> WeightInfo for BridgeWeight<T> {
impl WeightInfo for () { impl WeightInfo for () {
/// Storage: BridgeRelayers RelayerRewards (r:1 w:1) /// Storage: BridgeRelayers RelayerRewards (r:1 w:1)
/// ///
/// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(60), added: 2535, /// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(65), added: 2540,
/// mode: MaxEncodedLen) /// mode: MaxEncodedLen)
/// ///
/// Storage: System Account (r:1 w:1) /// Storage: System Account (r:1 w:1)
@@ -91,10 +91,10 @@ impl WeightInfo for () {
/// MaxEncodedLen) /// MaxEncodedLen)
fn claim_rewards() -> Weight { fn claim_rewards() -> Weight {
// Proof Size summary in bytes: // Proof Size summary in bytes:
// Measured: `534` // Measured: `275`
// Estimated: `5106` // Estimated: `5111`
// Minimum execution time: 48_239 nanoseconds. // Minimum execution time: 43_031 nanoseconds.
Weight::from_parts(50_579_000, 5106) Weight::from_parts(44_527_000, 5111)
.saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().reads(2_u64))
.saturating_add(RocksDbWeight::get().writes(2_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64))
} }
+2
View File
@@ -7,6 +7,8 @@ edition = "2021"
license = "GPL-3.0-or-later WITH Classpath-exception-2.0" license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
[dependencies] [dependencies]
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive", "bit-vec"] }
scale-info = { version = "2.1.1", default-features = false, features = ["bit-vec", "derive"] }
# Bridge Dependencies # Bridge Dependencies
+102 -20
View File
@@ -20,46 +20,95 @@
#![cfg_attr(not(feature = "std"), no_std)] #![cfg_attr(not(feature = "std"), no_std)]
use bp_messages::LaneId; use bp_messages::LaneId;
use bp_runtime::StorageDoubleMapKeyProvider; use bp_runtime::{ChainId, StorageDoubleMapKeyProvider};
use frame_support::{Blake2_128Concat, Identity}; use frame_support::{Blake2_128Concat, Identity};
use scale_info::TypeInfo;
use sp_runtime::{ use sp_runtime::{
codec::{Codec, Decode, Encode, EncodeLike}, codec::{Codec, Decode, Encode, EncodeLike, MaxEncodedLen},
traits::AccountIdConversion, traits::AccountIdConversion,
TypeId,
}; };
use sp_std::{fmt::Debug, marker::PhantomData}; use sp_std::{fmt::Debug, marker::PhantomData};
/// The owner of the sovereign account that should pay the rewards.
///
/// Each of the 2 final points connected by a bridge owns a sovereign account at each end of the
/// bridge. So here, at this end of the bridge there can be 2 sovereign accounts that pay rewards.
#[derive(Copy, Clone, Debug, Decode, Encode, Eq, PartialEq, TypeInfo, MaxEncodedLen)]
pub enum RewardsAccountOwner {
/// The sovereign account of the final chain on this end of the bridge.
ThisChain,
/// The sovereign account of the final chain on the other end of the bridge.
BridgedChain,
}
/// Structure used to identify the account that pays a reward to the relayer.
///
/// A bridge connects 2 bridge ends. Each one is located on a separate relay chain. The bridge ends
/// can be the final destinations of the bridge, or they can be intermediary points
/// (e.g. a bridge hub) used to forward messages between pairs of parachains on the bridged relay
/// chains. A pair of such parachains is connected using a bridge lane. Each of the 2 final
/// destinations of a bridge lane must have a sovereign account at each end of the bridge and each
/// of the sovereign accounts will pay rewards for different operations. So we need multiple
/// parameters to identify the account that pays a reward to the relayer.
#[derive(Copy, Clone, Debug, Decode, Encode, Eq, PartialEq, TypeInfo, MaxEncodedLen)]
pub struct RewardsAccountParams {
lane_id: LaneId,
bridged_chain_id: ChainId,
owner: RewardsAccountOwner,
}
impl RewardsAccountParams {
/// Create a new instance of `RewardsAccountParams`.
pub const fn new(
lane_id: LaneId,
bridged_chain_id: ChainId,
owner: RewardsAccountOwner,
) -> Self {
Self { lane_id, bridged_chain_id, owner }
}
}
impl TypeId for RewardsAccountParams {
const TYPE_ID: [u8; 4] = *b"brap";
}
/// Reward payment procedure. /// Reward payment procedure.
pub trait PaymentProcedure<Relayer, Reward> { pub trait PaymentProcedure<Relayer, Reward> {
/// Error that may be returned by the procedure. /// Error that may be returned by the procedure.
type Error: Debug; type Error: Debug;
/// Pay reward to the relayer for serving given message lane. /// Pay reward to the relayer from the account with provided params.
fn pay_reward(relayer: &Relayer, lane_id: LaneId, reward: Reward) -> Result<(), Self::Error>; fn pay_reward(
relayer: &Relayer,
rewards_account_params: RewardsAccountParams,
reward: Reward,
) -> Result<(), Self::Error>;
} }
impl<Relayer, Reward> PaymentProcedure<Relayer, Reward> for () { impl<Relayer, Reward> PaymentProcedure<Relayer, Reward> for () {
type Error = &'static str; type Error = &'static str;
fn pay_reward(_: &Relayer, _: LaneId, _: Reward) -> Result<(), Self::Error> { fn pay_reward(_: &Relayer, _: RewardsAccountParams, _: Reward) -> Result<(), Self::Error> {
Ok(()) Ok(())
} }
} }
/// Reward payment procedure that does `balances::transfer` call from the account, derived from /// Reward payment procedure that does `balances::transfer` call from the account, derived from
/// given lane. /// given params.
pub struct PayLaneRewardFromAccount<T, Relayer>(PhantomData<(T, Relayer)>); pub struct PayRewardFromAccount<T, Relayer>(PhantomData<(T, Relayer)>);
impl<T, Relayer> PayLaneRewardFromAccount<T, Relayer> impl<T, Relayer> PayRewardFromAccount<T, Relayer>
where where
Relayer: Decode + Encode, Relayer: Decode + Encode,
{ {
/// Return account that pay rewards for serving given lane. /// Return account that pays rewards based on the provided parameters.
pub fn lane_rewards_account(lane_id: LaneId) -> Relayer { pub fn rewards_account(params: RewardsAccountParams) -> Relayer {
lane_id.into_sub_account_truncating(b"bridge-lane") params.into_sub_account_truncating(b"rewards-account")
} }
} }
impl<T, Relayer> PaymentProcedure<Relayer, T::Balance> for PayLaneRewardFromAccount<T, Relayer> impl<T, Relayer> PaymentProcedure<Relayer, T::Balance> for PayRewardFromAccount<T, Relayer>
where where
T: frame_support::traits::fungible::Transfer<Relayer>, T: frame_support::traits::fungible::Transfer<Relayer>,
Relayer: Decode + Encode, Relayer: Decode + Encode,
@@ -68,10 +117,11 @@ where
fn pay_reward( fn pay_reward(
relayer: &Relayer, relayer: &Relayer,
lane_id: LaneId, rewards_account_params: RewardsAccountParams,
reward: T::Balance, reward: T::Balance,
) -> Result<(), Self::Error> { ) -> Result<(), Self::Error> {
T::transfer(&Self::lane_rewards_account(lane_id), relayer, reward, false).map(drop) T::transfer(&Self::rewards_account(rewards_account_params), relayer, reward, false)
.map(drop)
} }
} }
@@ -89,26 +139,58 @@ where
type Hasher1 = Blake2_128Concat; type Hasher1 = Blake2_128Concat;
type Key1 = AccountId; type Key1 = AccountId;
type Hasher2 = Identity; type Hasher2 = Identity;
type Key2 = LaneId; type Key2 = RewardsAccountParams;
type Value = Reward; type Value = Reward;
} }
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use bp_messages::LaneId;
use sp_runtime::testing::H256; use sp_runtime::testing::H256;
#[test] #[test]
fn lanes_are_using_different_accounts() { fn different_lanes_are_using_different_accounts() {
assert_eq!( assert_eq!(
PayLaneRewardFromAccount::<(), H256>::lane_rewards_account(LaneId([0, 0, 0, 0])), PayRewardFromAccount::<(), H256>::rewards_account(RewardsAccountParams::new(
hex_literal::hex!("626c616e000000006272696467652d6c616e6500000000000000000000000000") LaneId([0, 0, 0, 0]),
*b"test",
RewardsAccountOwner::ThisChain
)),
hex_literal::hex!("62726170000000007465737400726577617264732d6163636f756e7400000000")
.into(), .into(),
); );
assert_eq!( assert_eq!(
PayLaneRewardFromAccount::<(), H256>::lane_rewards_account(LaneId([0, 0, 0, 1])), PayRewardFromAccount::<(), H256>::rewards_account(RewardsAccountParams::new(
hex_literal::hex!("626c616e000000016272696467652d6c616e6500000000000000000000000000") LaneId([0, 0, 0, 1]),
*b"test",
RewardsAccountOwner::ThisChain
)),
hex_literal::hex!("62726170000000017465737400726577617264732d6163636f756e7400000000")
.into(),
);
}
#[test]
fn different_directions_are_using_different_accounts() {
assert_eq!(
PayRewardFromAccount::<(), H256>::rewards_account(RewardsAccountParams::new(
LaneId([0, 0, 0, 0]),
*b"test",
RewardsAccountOwner::ThisChain
)),
hex_literal::hex!("62726170000000007465737400726577617264732d6163636f756e7400000000")
.into(),
);
assert_eq!(
PayRewardFromAccount::<(), H256>::rewards_account(RewardsAccountParams::new(
LaneId([0, 0, 0, 0]),
*b"test",
RewardsAccountOwner::BridgedChain
)),
hex_literal::hex!("62726170000000007465737401726577617264732d6163636f756e7400000000")
.into(), .into(),
); );
} }
+6
View File
@@ -74,6 +74,12 @@ pub const POLKADOT_CHAIN_ID: ChainId = *b"pdot";
/// Bridge-with-Kusama instance id. /// Bridge-with-Kusama instance id.
pub const KUSAMA_CHAIN_ID: ChainId = *b"ksma"; pub const KUSAMA_CHAIN_ID: ChainId = *b"ksma";
/// Bridge-with-Westend instance id.
pub const WESTEND_CHAIN_ID: ChainId = *b"wend";
/// Bridge-with-Westend instance id.
pub const WESTMINT_CHAIN_ID: ChainId = *b"wmnt";
/// Bridge-with-Rococo instance id. /// Bridge-with-Rococo instance id.
pub const ROCOCO_CHAIN_ID: ChainId = *b"roco"; pub const ROCOCO_CHAIN_ID: ChainId = *b"roco";
@@ -17,6 +17,7 @@ bp-bridge-hub-wococo = { path = "../../primitives/chain-bridge-hub-wococo" }
bp-header-chain = { path = "../../primitives/header-chain" } bp-header-chain = { path = "../../primitives/header-chain" }
bp-messages = { path = "../../primitives/messages" } bp-messages = { path = "../../primitives/messages" }
bp-parachains = { path = "../../primitives/parachains" } bp-parachains = { path = "../../primitives/parachains" }
bp-runtime = { path = "../../primitives/runtime" }
bp-wococo = { path = "../../primitives/chain-wococo" } bp-wococo = { path = "../../primitives/chain-wococo" }
bridge-runtime-common = { path = "../../bin/runtime-common" } bridge-runtime-common = { path = "../../bin/runtime-common" }
@@ -18,6 +18,7 @@
use bp_bridge_hub_rococo::AVERAGE_BLOCK_INTERVAL; use bp_bridge_hub_rococo::AVERAGE_BLOCK_INTERVAL;
use bp_messages::MessageNonce; use bp_messages::MessageNonce;
use bp_runtime::ChainId;
use codec::Encode; use codec::Encode;
use relay_substrate_client::{ use relay_substrate_client::{
Chain, ChainWithBalances, ChainWithMessages, ChainWithTransactions, ChainWithUtilityPallet, Chain, ChainWithBalances, ChainWithMessages, ChainWithTransactions, ChainWithUtilityPallet,
@@ -41,6 +42,7 @@ impl UnderlyingChainProvider for BridgeHubRococo {
} }
impl Chain for BridgeHubRococo { impl Chain for BridgeHubRococo {
const ID: ChainId = bp_runtime::BRIDGE_HUB_ROCOCO_CHAIN_ID;
const NAME: &'static str = "BridgeHubRococo"; const NAME: &'static str = "BridgeHubRococo";
const TOKEN_ID: Option<&'static str> = None; const TOKEN_ID: Option<&'static str> = None;
const BEST_FINALIZED_HEADER_ID_METHOD: &'static str = const BEST_FINALIZED_HEADER_ID_METHOD: &'static str =
@@ -18,6 +18,7 @@
use bp_bridge_hub_wococo::AVERAGE_BLOCK_INTERVAL; use bp_bridge_hub_wococo::AVERAGE_BLOCK_INTERVAL;
use bp_messages::MessageNonce; use bp_messages::MessageNonce;
use bp_runtime::ChainId;
use codec::Encode; use codec::Encode;
use relay_substrate_client::{ use relay_substrate_client::{
Chain, ChainWithBalances, ChainWithMessages, ChainWithTransactions, ChainWithUtilityPallet, Chain, ChainWithBalances, ChainWithMessages, ChainWithTransactions, ChainWithUtilityPallet,
@@ -41,6 +42,7 @@ impl UnderlyingChainProvider for BridgeHubWococo {
} }
impl Chain for BridgeHubWococo { impl Chain for BridgeHubWococo {
const ID: ChainId = bp_runtime::BRIDGE_HUB_WOCOCO_CHAIN_ID;
const NAME: &'static str = "BridgeHubWococo"; const NAME: &'static str = "BridgeHubWococo";
const TOKEN_ID: Option<&'static str> = None; const TOKEN_ID: Option<&'static str> = None;
const BEST_FINALIZED_HEADER_ID_METHOD: &'static str = const BEST_FINALIZED_HEADER_ID_METHOD: &'static str =
+1
View File
@@ -12,6 +12,7 @@ relay-utils = { path = "../utils" }
# Bridge dependencies # Bridge dependencies
bp-kusama = { path = "../../primitives/chain-kusama" } bp-kusama = { path = "../../primitives/chain-kusama" }
bp-runtime = { path = "../../primitives/runtime" }
# Substrate Dependencies # Substrate Dependencies
+2
View File
@@ -17,6 +17,7 @@
//! Types used to connect to the Kusama chain. //! Types used to connect to the Kusama chain.
use bp_kusama::AccountInfoStorageMapKeyProvider; use bp_kusama::AccountInfoStorageMapKeyProvider;
use bp_runtime::ChainId;
use relay_substrate_client::{Chain, ChainWithBalances, UnderlyingChainProvider}; use relay_substrate_client::{Chain, ChainWithBalances, UnderlyingChainProvider};
use sp_core::storage::StorageKey; use sp_core::storage::StorageKey;
use std::time::Duration; use std::time::Duration;
@@ -33,6 +34,7 @@ impl UnderlyingChainProvider for Kusama {
} }
impl Chain for Kusama { impl Chain for Kusama {
const ID: ChainId = bp_runtime::KUSAMA_CHAIN_ID;
const NAME: &'static str = "Kusama"; const NAME: &'static str = "Kusama";
const TOKEN_ID: Option<&'static str> = Some("kusama"); const TOKEN_ID: Option<&'static str> = Some("kusama");
const BEST_FINALIZED_HEADER_ID_METHOD: &'static str = const BEST_FINALIZED_HEADER_ID_METHOD: &'static str =
+1
View File
@@ -14,6 +14,7 @@ relay-utils = { path = "../utils" }
bp-messages = { path = "../../primitives/messages" } bp-messages = { path = "../../primitives/messages" }
bp-millau = { path = "../../primitives/chain-millau" } bp-millau = { path = "../../primitives/chain-millau" }
bp-runtime = { path = "../../primitives/runtime" }
millau-runtime = { path = "../../bin/millau/runtime" } millau-runtime = { path = "../../bin/millau/runtime" }
# Substrate Dependencies # Substrate Dependencies
+2
View File
@@ -17,6 +17,7 @@
//! Types used to connect to the Millau-Substrate chain. //! Types used to connect to the Millau-Substrate chain.
use bp_messages::MessageNonce; use bp_messages::MessageNonce;
use bp_runtime::ChainId;
use codec::{Compact, Decode, Encode}; use codec::{Compact, Decode, Encode};
use relay_substrate_client::{ use relay_substrate_client::{
BalanceOf, Chain, ChainWithBalances, ChainWithMessages, ChainWithTransactions, BalanceOf, Chain, ChainWithBalances, ChainWithMessages, ChainWithTransactions,
@@ -54,6 +55,7 @@ impl ChainWithMessages for Millau {
} }
impl Chain for Millau { impl Chain for Millau {
const ID: ChainId = bp_runtime::MILLAU_CHAIN_ID;
const NAME: &'static str = "Millau"; const NAME: &'static str = "Millau";
// Rialto token has no value, but we associate it with KSM token // Rialto token has no value, but we associate it with KSM token
const TOKEN_ID: Option<&'static str> = Some("kusama"); const TOKEN_ID: Option<&'static str> = Some("kusama");
@@ -12,6 +12,7 @@ relay-utils = { path = "../utils" }
# Bridge dependencies # Bridge dependencies
bp-polkadot = { path = "../../primitives/chain-polkadot" } bp-polkadot = { path = "../../primitives/chain-polkadot" }
bp-runtime = { path = "../../primitives/runtime" }
# Substrate Dependencies # Substrate Dependencies
@@ -17,6 +17,7 @@
//! Types used to connect to the Polkadot chain. //! Types used to connect to the Polkadot chain.
use bp_polkadot::AccountInfoStorageMapKeyProvider; use bp_polkadot::AccountInfoStorageMapKeyProvider;
use bp_runtime::ChainId;
use relay_substrate_client::{Chain, ChainWithBalances, UnderlyingChainProvider}; use relay_substrate_client::{Chain, ChainWithBalances, UnderlyingChainProvider};
use sp_core::storage::StorageKey; use sp_core::storage::StorageKey;
use std::time::Duration; use std::time::Duration;
@@ -33,6 +34,7 @@ impl UnderlyingChainProvider for Polkadot {
} }
impl Chain for Polkadot { impl Chain for Polkadot {
const ID: ChainId = bp_runtime::POLKADOT_CHAIN_ID;
const NAME: &'static str = "Polkadot"; const NAME: &'static str = "Polkadot";
const TOKEN_ID: Option<&'static str> = Some("polkadot"); const TOKEN_ID: Option<&'static str> = Some("polkadot");
const BEST_FINALIZED_HEADER_ID_METHOD: &'static str = const BEST_FINALIZED_HEADER_ID_METHOD: &'static str =
@@ -17,6 +17,7 @@ bp-messages = { path = "../../primitives/messages" }
bp-millau = { path = "../../primitives/chain-millau" } bp-millau = { path = "../../primitives/chain-millau" }
bp-polkadot-core = { path = "../../primitives/polkadot-core" } bp-polkadot-core = { path = "../../primitives/polkadot-core" }
bp-rialto-parachain = { path = "../../primitives/chain-rialto-parachain" } bp-rialto-parachain = { path = "../../primitives/chain-rialto-parachain" }
bp-runtime = { path = "../../primitives/runtime" }
bridge-runtime-common = { path = "../../bin/runtime-common" } bridge-runtime-common = { path = "../../bin/runtime-common" }
relay-substrate-client = { path = "../client-substrate" } relay-substrate-client = { path = "../client-substrate" }
@@ -20,6 +20,7 @@ pub mod codegen_runtime;
use bp_messages::MessageNonce; use bp_messages::MessageNonce;
use bp_polkadot_core::PolkadotSignedExtension; use bp_polkadot_core::PolkadotSignedExtension;
use bp_runtime::ChainId;
use codec::Encode; use codec::Encode;
use relay_substrate_client::{ use relay_substrate_client::{
Chain, ChainWithBalances, ChainWithMessages, ChainWithTransactions, Error as SubstrateError, Chain, ChainWithBalances, ChainWithMessages, ChainWithTransactions, Error as SubstrateError,
@@ -48,6 +49,7 @@ impl UnderlyingChainProvider for RialtoParachain {
} }
impl Chain for RialtoParachain { impl Chain for RialtoParachain {
const ID: ChainId = bp_runtime::RIALTO_PARACHAIN_CHAIN_ID;
const NAME: &'static str = "RialtoParachain"; const NAME: &'static str = "RialtoParachain";
// RialtoParachain token has no value, but we associate it with DOT token // RialtoParachain token has no value, but we associate it with DOT token
const TOKEN_ID: Option<&'static str> = Some("polkadot"); const TOKEN_ID: Option<&'static str> = Some("polkadot");
+1
View File
@@ -14,6 +14,7 @@ relay-utils = { path = "../utils" }
bp-messages = { path = "../../primitives/messages" } bp-messages = { path = "../../primitives/messages" }
bp-rialto = { path = "../../primitives/chain-rialto" } bp-rialto = { path = "../../primitives/chain-rialto" }
bp-runtime = { path = "../../primitives/runtime" }
rialto-runtime = { path = "../../bin/rialto/runtime" } rialto-runtime = { path = "../../bin/rialto/runtime" }
# Substrate Dependencies # Substrate Dependencies
+2
View File
@@ -17,6 +17,7 @@
//! Types used to connect to the Rialto-Substrate chain. //! Types used to connect to the Rialto-Substrate chain.
use bp_messages::MessageNonce; use bp_messages::MessageNonce;
use bp_runtime::ChainId;
use codec::{Compact, Decode, Encode}; use codec::{Compact, Decode, Encode};
use relay_substrate_client::{ use relay_substrate_client::{
BalanceOf, Chain, ChainWithBalances, ChainWithMessages, ChainWithTransactions, BalanceOf, Chain, ChainWithBalances, ChainWithMessages, ChainWithTransactions,
@@ -39,6 +40,7 @@ impl UnderlyingChainProvider for Rialto {
} }
impl Chain for Rialto { impl Chain for Rialto {
const ID: ChainId = bp_runtime::RIALTO_CHAIN_ID;
const NAME: &'static str = "Rialto"; const NAME: &'static str = "Rialto";
// Rialto token has no value, but we associate it with DOT token // Rialto token has no value, but we associate it with DOT token
const TOKEN_ID: Option<&'static str> = Some("polkadot"); const TOKEN_ID: Option<&'static str> = Some("polkadot");
+1
View File
@@ -12,6 +12,7 @@ relay-utils = { path = "../utils" }
# Bridge dependencies # Bridge dependencies
bp-rococo = { path = "../../primitives/chain-rococo" } bp-rococo = { path = "../../primitives/chain-rococo" }
bp-runtime = { path = "../../primitives/runtime" }
# Substrate Dependencies # Substrate Dependencies
+2
View File
@@ -16,6 +16,7 @@
//! Types used to connect to the Rococo-Substrate chain. //! Types used to connect to the Rococo-Substrate chain.
use bp_runtime::ChainId;
use relay_substrate_client::{Chain, ChainWithBalances, RelayChain, UnderlyingChainProvider}; use relay_substrate_client::{Chain, ChainWithBalances, RelayChain, UnderlyingChainProvider};
use sp_core::storage::StorageKey; use sp_core::storage::StorageKey;
use std::time::Duration; use std::time::Duration;
@@ -35,6 +36,7 @@ impl UnderlyingChainProvider for Rococo {
} }
impl Chain for Rococo { impl Chain for Rococo {
const ID: ChainId = bp_runtime::ROCOCO_CHAIN_ID;
const NAME: &'static str = "Rococo"; const NAME: &'static str = "Rococo";
const TOKEN_ID: Option<&'static str> = None; const TOKEN_ID: Option<&'static str> = None;
const BEST_FINALIZED_HEADER_ID_METHOD: &'static str = const BEST_FINALIZED_HEADER_ID_METHOD: &'static str =
+4 -2
View File
@@ -18,8 +18,8 @@ use crate::calls::UtilityCall;
use bp_messages::MessageNonce; use bp_messages::MessageNonce;
use bp_runtime::{ use bp_runtime::{
Chain as ChainBase, EncodedOrDecodedCall, HashOf, Parachain as ParachainBase, TransactionEra, Chain as ChainBase, ChainId, EncodedOrDecodedCall, HashOf, Parachain as ParachainBase,
TransactionEraOf, UnderlyingChainProvider, TransactionEra, TransactionEraOf, UnderlyingChainProvider,
}; };
use codec::{Codec, Encode}; use codec::{Codec, Encode};
use jsonrpsee::core::{DeserializeOwned, Serialize}; use jsonrpsee::core::{DeserializeOwned, Serialize};
@@ -35,6 +35,8 @@ use std::{fmt::Debug, time::Duration};
/// Substrate-based chain from minimal relay-client point of view. /// Substrate-based chain from minimal relay-client point of view.
pub trait Chain: ChainBase + Clone { pub trait Chain: ChainBase + Clone {
/// Chain id.
const ID: ChainId;
/// Chain name. /// Chain name.
const NAME: &'static str; const NAME: &'static str;
/// Identifier of the basic token of the chain (if applicable). /// Identifier of the basic token of the chain (if applicable).
@@ -22,6 +22,7 @@
#![cfg(any(feature = "test-helpers", test))] #![cfg(any(feature = "test-helpers", test))]
use crate::{Chain, ChainWithBalances}; use crate::{Chain, ChainWithBalances};
use bp_runtime::ChainId;
use frame_support::weights::Weight; use frame_support::weights::Weight;
use std::time::Duration; use std::time::Duration;
@@ -50,6 +51,7 @@ impl bp_runtime::Chain for TestChain {
} }
impl Chain for TestChain { impl Chain for TestChain {
const ID: ChainId = *b"test";
const NAME: &'static str = "Test"; const NAME: &'static str = "Test";
const TOKEN_ID: Option<&'static str> = None; const TOKEN_ID: Option<&'static str> = None;
const BEST_FINALIZED_HEADER_ID_METHOD: &'static str = "TestMethod"; const BEST_FINALIZED_HEADER_ID_METHOD: &'static str = "TestMethod";
+1
View File
@@ -11,6 +11,7 @@ relay-utils = { path = "../utils" }
# Bridge dependencies # Bridge dependencies
bp-runtime = { path = "../../primitives/runtime" }
bp-westend = { path = "../../primitives/chain-westend" } bp-westend = { path = "../../primitives/chain-westend" }
# Substrate Dependencies # Substrate Dependencies
+3
View File
@@ -16,6 +16,7 @@
//! Types used to connect to the Westend chain. //! Types used to connect to the Westend chain.
use bp_runtime::ChainId;
use relay_substrate_client::{Chain, ChainWithBalances, RelayChain, UnderlyingChainProvider}; use relay_substrate_client::{Chain, ChainWithBalances, RelayChain, UnderlyingChainProvider};
use sp_core::storage::StorageKey; use sp_core::storage::StorageKey;
use std::time::Duration; use std::time::Duration;
@@ -35,6 +36,7 @@ impl UnderlyingChainProvider for Westend {
} }
impl Chain for Westend { impl Chain for Westend {
const ID: ChainId = bp_runtime::WESTEND_CHAIN_ID;
const NAME: &'static str = "Westend"; const NAME: &'static str = "Westend";
const TOKEN_ID: Option<&'static str> = None; const TOKEN_ID: Option<&'static str> = None;
const BEST_FINALIZED_HEADER_ID_METHOD: &'static str = const BEST_FINALIZED_HEADER_ID_METHOD: &'static str =
@@ -68,6 +70,7 @@ impl UnderlyingChainProvider for Westmint {
// Westmint seems to use the same configuration as all Polkadot-like chains, so we'll use Westend // Westmint seems to use the same configuration as all Polkadot-like chains, so we'll use Westend
// primitives here. // primitives here.
impl Chain for Westmint { impl Chain for Westmint {
const ID: ChainId = bp_runtime::WESTMINT_CHAIN_ID;
const NAME: &'static str = "Westmint"; const NAME: &'static str = "Westmint";
const TOKEN_ID: Option<&'static str> = None; const TOKEN_ID: Option<&'static str> = None;
const BEST_FINALIZED_HEADER_ID_METHOD: &'static str = const BEST_FINALIZED_HEADER_ID_METHOD: &'static str =
+1
View File
@@ -11,6 +11,7 @@ relay-utils = { path = "../utils" }
# Bridge dependencies # Bridge dependencies
bp-runtime = { path = "../../primitives/runtime" }
bp-wococo = { path = "../../primitives/chain-wococo" } bp-wococo = { path = "../../primitives/chain-wococo" }
# Substrate Dependencies # Substrate Dependencies
+2
View File
@@ -16,6 +16,7 @@
//! Types used to connect to the Wococo-Substrate chain. //! Types used to connect to the Wococo-Substrate chain.
use bp_runtime::ChainId;
use relay_substrate_client::{Chain, ChainWithBalances, RelayChain, UnderlyingChainProvider}; use relay_substrate_client::{Chain, ChainWithBalances, RelayChain, UnderlyingChainProvider};
use sp_core::storage::StorageKey; use sp_core::storage::StorageKey;
use std::time::Duration; use std::time::Duration;
@@ -35,6 +36,7 @@ impl UnderlyingChainProvider for Wococo {
} }
impl Chain for Wococo { impl Chain for Wococo {
const ID: ChainId = bp_runtime::WOCOCO_CHAIN_ID;
const NAME: &'static str = "Wococo"; const NAME: &'static str = "Wococo";
const TOKEN_ID: Option<&'static str> = None; const TOKEN_ID: Option<&'static str> = None;
const BEST_FINALIZED_HEADER_ID_METHOD: &'static str = const BEST_FINALIZED_HEADER_ID_METHOD: &'static str =
@@ -19,6 +19,7 @@
use crate::TaggedAccount; use crate::TaggedAccount;
use bp_messages::LaneId; use bp_messages::LaneId;
use bp_relayers::{RewardsAccountOwner, RewardsAccountParams};
use bp_runtime::StorageDoubleMapKeyProvider; use bp_runtime::StorageDoubleMapKeyProvider;
use codec::Decode; use codec::Decode;
use frame_system::AccountInfo; use frame_system::AccountInfo;
@@ -82,18 +83,29 @@ where
if let Some(relayers_pallet_name) = BC::WITH_CHAIN_RELAYERS_PALLET_NAME { if let Some(relayers_pallet_name) = BC::WITH_CHAIN_RELAYERS_PALLET_NAME {
for lane in lanes { for lane in lanes {
let relay_account_reward_metric = FloatStorageValueMetric::new( FloatStorageValueMetric::new(
AccountBalance::<C> { token_decimals, _phantom: Default::default() }, AccountBalance::<C> { token_decimals, _phantom: Default::default() },
client.clone(), client.clone(),
bp_relayers::RelayerRewardsKeyProvider::<AccountIdOf<C>, BalanceOf<C>>::final_key( bp_relayers::RelayerRewardsKeyProvider::<AccountIdOf<C>, BalanceOf<C>>::final_key(
relayers_pallet_name, relayers_pallet_name,
account.id(), account.id(),
lane, &RewardsAccountParams::new(*lane, BC::ID, RewardsAccountOwner::ThisChain),
), ),
format!("at_{}_relay_{}_reward_for_lane_{}_with_{}", C::NAME, account.tag(), hex::encode(lane.as_ref()), BC::NAME), format!("at_{}_relay_{}_reward_for_msgs_from_{}_on_lane_{}", C::NAME, account.tag(), BC::NAME, hex::encode(lane.as_ref())),
format!("Reward of the {} relay account for serving lane {:?} with {} at the {}", account.tag(), lane, BC::NAME, C::NAME), format!("Reward of the {} relay account at {} for delivering messages from {} on lane {:?}", account.tag(), C::NAME, BC::NAME, lane),
)?; )?.register_and_spawn(&metrics.registry)?;
relay_account_reward_metric.register_and_spawn(&metrics.registry)?;
FloatStorageValueMetric::new(
AccountBalance::<C> { token_decimals, _phantom: Default::default() },
client.clone(),
bp_relayers::RelayerRewardsKeyProvider::<AccountIdOf<C>, BalanceOf<C>>::final_key(
relayers_pallet_name,
account.id(),
&RewardsAccountParams::new(*lane, BC::ID, RewardsAccountOwner::BridgedChain),
),
format!("at_{}_relay_{}_reward_for_msgs_to_{}_on_lane_{}", C::NAME, account.tag(), BC::NAME, hex::encode(lane.as_ref())),
format!("Reward of the {} relay account at {} for delivering messages confirmations from {} on lane {:?}", account.tag(), C::NAME, BC::NAME, lane),
)?.register_and_spawn(&metrics.registry)?;
} }
} }
} }