mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-30 22:27:56 +00:00
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:
committed by
Bastian Köcher
parent
f31b5d8634
commit
f5fee288b9
@@ -33,6 +33,8 @@ pub mod rialto_parachain_messages;
|
||||
pub mod xcm_config;
|
||||
|
||||
use bp_parachains::SingleParaStoredHeaderDataBuilder;
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
use bp_relayers::{RewardsAccountOwner, RewardsAccountParams};
|
||||
use bp_runtime::HeaderId;
|
||||
use pallet_grandpa::{
|
||||
fg_primitives, AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList,
|
||||
@@ -389,7 +391,7 @@ impl pallet_bridge_relayers::Config for Runtime {
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type Reward = Balance;
|
||||
type PaymentProcedure =
|
||||
bp_relayers::PayLaneRewardFromAccount<pallet_balances::Pallet<Runtime>, AccountId>;
|
||||
bp_relayers::PayRewardFromAccount<pallet_balances::Pallet<Runtime>, AccountId>;
|
||||
type WeightInfo = ();
|
||||
}
|
||||
|
||||
@@ -449,6 +451,7 @@ impl pallet_bridge_messages::Config<WithRialtoMessagesInstance> for Runtime {
|
||||
type LaneMessageVerifier = crate::rialto_messages::ToRialtoMessageVerifier;
|
||||
type DeliveryConfirmationPayments = pallet_bridge_relayers::DeliveryConfirmationPaymentsAdapter<
|
||||
Runtime,
|
||||
WithRialtoMessagesInstance,
|
||||
frame_support::traits::ConstU64<100_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 DeliveryConfirmationPayments = pallet_bridge_relayers::DeliveryConfirmationPaymentsAdapter<
|
||||
Runtime,
|
||||
WithRialtoParachainMessagesInstance,
|
||||
frame_support::traits::ConstU64<100_000>,
|
||||
frame_support::traits::ConstU64<10_000>,
|
||||
>;
|
||||
@@ -997,7 +1001,14 @@ impl_runtime_apis! {
|
||||
}
|
||||
|
||||
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 {
|
||||
fn prepare_environment(
|
||||
lane: bp_messages::LaneId,
|
||||
account_params: RewardsAccountParams,
|
||||
reward: Balance,
|
||||
) {
|
||||
use frame_support::traits::fungible::Mutate;
|
||||
let lane_rewards_account = bp_relayers::PayLaneRewardFromAccount::<
|
||||
let rewards_account = bp_relayers::PayRewardFromAccount::<
|
||||
Balances,
|
||||
AccountId
|
||||
>::lane_rewards_account(lane);
|
||||
Balances::mint_into(&lane_rewards_account, reward).unwrap();
|
||||
>::rewards_account(account_params);
|
||||
Balances::mint_into(&rewards_account, reward).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -521,7 +521,7 @@ impl pallet_bridge_relayers::Config for Runtime {
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type Reward = Balance;
|
||||
type PaymentProcedure =
|
||||
bp_relayers::PayLaneRewardFromAccount<pallet_balances::Pallet<Runtime>, AccountId>;
|
||||
bp_relayers::PayRewardFromAccount<pallet_balances::Pallet<Runtime>, AccountId>;
|
||||
type WeightInfo = ();
|
||||
}
|
||||
|
||||
@@ -569,6 +569,7 @@ impl pallet_bridge_messages::Config<WithMillauMessagesInstance> for Runtime {
|
||||
type LaneMessageVerifier = crate::millau_messages::ToMillauMessageVerifier;
|
||||
type DeliveryConfirmationPayments = pallet_bridge_relayers::DeliveryConfirmationPaymentsAdapter<
|
||||
Runtime,
|
||||
WithMillauMessagesInstance,
|
||||
frame_support::traits::ConstU128<100_000>,
|
||||
frame_support::traits::ConstU128<100_000>,
|
||||
>;
|
||||
|
||||
@@ -393,7 +393,7 @@ impl pallet_bridge_relayers::Config for Runtime {
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type Reward = Balance;
|
||||
type PaymentProcedure =
|
||||
bp_relayers::PayLaneRewardFromAccount<pallet_balances::Pallet<Runtime>, AccountId>;
|
||||
bp_relayers::PayRewardFromAccount<pallet_balances::Pallet<Runtime>, AccountId>;
|
||||
type WeightInfo = ();
|
||||
}
|
||||
|
||||
@@ -443,6 +443,7 @@ impl pallet_bridge_messages::Config<WithMillauMessagesInstance> for Runtime {
|
||||
type LaneMessageVerifier = crate::millau_messages::ToMillauMessageVerifier;
|
||||
type DeliveryConfirmationPayments = pallet_bridge_relayers::DeliveryConfirmationPaymentsAdapter<
|
||||
Runtime,
|
||||
WithMillauMessagesInstance,
|
||||
frame_support::traits::ConstU128<100_000>,
|
||||
frame_support::traits::ConstU128<100_000>,
|
||||
>;
|
||||
|
||||
@@ -19,6 +19,7 @@ bp-header-chain = { path = "../../primitives/header-chain", default-features = f
|
||||
bp-messages = { path = "../../primitives/messages", default-features = false }
|
||||
bp-parachains = { path = "../../primitives/parachains", 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 }
|
||||
pallet-bridge-grandpa = { path = "../../modules/grandpa", default-features = false }
|
||||
pallet-bridge-messages = { path = "../../modules/messages", default-features = false }
|
||||
|
||||
@@ -85,6 +85,8 @@ pub type BridgedChainHeader =
|
||||
|
||||
/// Message lane used in tests.
|
||||
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.
|
||||
pub const MAXIMAL_PENDING_MESSAGES_AT_TEST_LANE: MessageNonce = 32;
|
||||
/// Minimal extrinsic weight at the `BridgedChain`.
|
||||
@@ -118,7 +120,7 @@ crate::generate_bridge_reject_obsolete_headers_and_messages! {
|
||||
|
||||
parameter_types! {
|
||||
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 ExistentialDeposit: ThisChainBalance = 500;
|
||||
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 DeliveryConfirmationPayments = pallet_bridge_relayers::DeliveryConfirmationPaymentsAdapter<
|
||||
TestRuntime,
|
||||
(),
|
||||
frame_support::traits::ConstU64<100_000>,
|
||||
frame_support::traits::ConstU64<10_000>,
|
||||
>;
|
||||
@@ -251,7 +254,7 @@ pub struct OnThisChainBridge;
|
||||
|
||||
impl MessageBridge for OnThisChainBridge {
|
||||
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 = "";
|
||||
|
||||
type ThisChain = ThisChain;
|
||||
@@ -265,7 +268,7 @@ impl MessageBridge for OnThisChainBridge {
|
||||
pub struct 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_MESSAGES_PALLET_NAME: &'static str = "";
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ use crate::messages_call_ext::{
|
||||
MessagesCallSubType, ReceiveMessagesProofHelper, ReceiveMessagesProofInfo,
|
||||
};
|
||||
use bp_messages::LaneId;
|
||||
use bp_relayers::{RewardsAccountOwner, RewardsAccountParams};
|
||||
use bp_runtime::StaticStrProvider;
|
||||
use codec::{Decode, Encode};
|
||||
use frame_support::{
|
||||
@@ -397,7 +398,15 @@ where
|
||||
let refund = Refund::compute_refund(info, &post_info, post_info_len, tip);
|
||||
|
||||
// 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!(
|
||||
target: "runtime::bridge",
|
||||
@@ -433,6 +442,7 @@ mod tests {
|
||||
parameter_types! {
|
||||
TestParachain: u32 = 1000;
|
||||
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);
|
||||
@@ -872,7 +882,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
RelayersPallet::<TestRuntime>::relayer_reward(
|
||||
relayer_account_at_this_chain(),
|
||||
TestLaneId::get()
|
||||
DirectedTestLaneId::get()
|
||||
),
|
||||
Some(regular_reward),
|
||||
);
|
||||
@@ -891,7 +901,7 @@ mod tests {
|
||||
run_post_dispatch(Some(pre_dispatch_data), Ok(()));
|
||||
let reward_after_two_calls = RelayersPallet::<TestRuntime>::relayer_reward(
|
||||
relayer_account_at_this_chain(),
|
||||
TestLaneId::get(),
|
||||
DirectedTestLaneId::get(),
|
||||
)
|
||||
.unwrap();
|
||||
assert!(
|
||||
@@ -912,7 +922,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
RelayersPallet::<TestRuntime>::relayer_reward(
|
||||
relayer_account_at_this_chain(),
|
||||
TestLaneId::get()
|
||||
DirectedTestLaneId::get()
|
||||
),
|
||||
Some(expected_reward()),
|
||||
);
|
||||
@@ -928,7 +938,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
RelayersPallet::<TestRuntime>::relayer_reward(
|
||||
relayer_account_at_this_chain(),
|
||||
TestLaneId::get()
|
||||
DirectedTestLaneId::get()
|
||||
),
|
||||
Some(expected_reward()),
|
||||
);
|
||||
@@ -944,7 +954,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
RelayersPallet::<TestRuntime>::relayer_reward(
|
||||
relayer_account_at_this_chain(),
|
||||
TestLaneId::get()
|
||||
DirectedTestLaneId::get()
|
||||
),
|
||||
Some(expected_reward()),
|
||||
);
|
||||
|
||||
@@ -16,6 +16,7 @@ scale-info = { version = "2.1.1", default-features = false, features = ["derive"
|
||||
bp-messages = { path = "../../primitives/messages", default-features = false }
|
||||
bp-relayers = { path = "../../primitives/relayers", default-features = false }
|
||||
bp-runtime = { path = "../../primitives/runtime", default-features = false }
|
||||
pallet-bridge-messages = { path = "../messages", default-features = false }
|
||||
|
||||
# Substrate Dependencies
|
||||
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
|
||||
use crate::*;
|
||||
|
||||
use bp_messages::LaneId;
|
||||
use bp_relayers::RewardsAccountOwner;
|
||||
use frame_benchmarking::{benchmarks, whitelisted_caller};
|
||||
use frame_system::RawOrigin;
|
||||
|
||||
@@ -32,19 +34,21 @@ pub struct Pallet<T: Config>(crate::Pallet<T>);
|
||||
/// Trait that must be implemented by runtime.
|
||||
pub trait Config: crate::Config {
|
||||
/// 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! {
|
||||
// Benchmark `claim_rewards` call.
|
||||
claim_rewards {
|
||||
let lane = LaneId([0, 0, 0, 0]);
|
||||
let account_params =
|
||||
RewardsAccountParams::new(lane, *b"test", RewardsAccountOwner::ThisChain);
|
||||
let relayer: T::AccountId = whitelisted_caller();
|
||||
let reward = T::Reward::from(REWARD_AMOUNT);
|
||||
|
||||
T::prepare_environment(lane, reward);
|
||||
RelayerRewards::<T>::insert(&relayer, lane, reward);
|
||||
}: _(RawOrigin::Signed(relayer), lane)
|
||||
T::prepare_environment(account_params, reward);
|
||||
RelayerRewards::<T>::insert(&relayer, account_params, reward);
|
||||
}: _(RawOrigin::Signed(relayer), account_params)
|
||||
verify {
|
||||
// we can't check anything here, because `PaymentProcedure` is responsible for
|
||||
// payment logic, so we assume that if call has succeeded, the procedure has
|
||||
|
||||
@@ -20,8 +20,7 @@
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
#![warn(missing_docs)]
|
||||
|
||||
use bp_messages::LaneId;
|
||||
use bp_relayers::{PaymentProcedure, RelayerRewardsKeyProvider};
|
||||
use bp_relayers::{PaymentProcedure, RelayerRewardsKeyProvider, RewardsAccountParams};
|
||||
use bp_runtime::StorageDoubleMapKeyProvider;
|
||||
use frame_support::sp_runtime::Saturating;
|
||||
use sp_arithmetic::traits::{AtLeast32BitUnsigned, Zero};
|
||||
@@ -72,28 +71,32 @@ pub mod pallet {
|
||||
/// Claim accumulated rewards.
|
||||
#[pallet::call_index(0)]
|
||||
#[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)?;
|
||||
|
||||
RelayerRewards::<T>::try_mutate_exists(
|
||||
&relayer,
|
||||
lane_id,
|
||||
rewards_account_params,
|
||||
|maybe_reward| -> DispatchResult {
|
||||
let reward = maybe_reward.take().ok_or(Error::<T>::NoRewardForRelayer)?;
|
||||
T::PaymentProcedure::pay_reward(&relayer, lane_id, reward).map_err(|e| {
|
||||
log::trace!(
|
||||
target: LOG_TARGET,
|
||||
"Failed to pay {:?} rewards to {:?}: {:?}",
|
||||
lane_id,
|
||||
relayer,
|
||||
e,
|
||||
);
|
||||
Error::<T>::FailedToPayReward
|
||||
})?;
|
||||
T::PaymentProcedure::pay_reward(&relayer, rewards_account_params, reward)
|
||||
.map_err(|e| {
|
||||
log::trace!(
|
||||
target: LOG_TARGET,
|
||||
"Failed to pay {:?} rewards to {:?}: {:?}",
|
||||
rewards_account_params,
|
||||
relayer,
|
||||
e,
|
||||
);
|
||||
Error::<T>::FailedToPayReward
|
||||
})?;
|
||||
|
||||
Self::deposit_event(Event::<T>::RewardPaid {
|
||||
relayer: relayer.clone(),
|
||||
lane_id,
|
||||
rewards_account_params,
|
||||
reward,
|
||||
});
|
||||
Ok(())
|
||||
@@ -104,23 +107,31 @@ pub mod pallet {
|
||||
|
||||
impl<T: Config> Pallet<T> {
|
||||
/// 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() {
|
||||
return
|
||||
}
|
||||
|
||||
RelayerRewards::<T>::mutate(relayer, lane_id, |old_reward: &mut Option<T::Reward>| {
|
||||
let new_reward = old_reward.unwrap_or_else(Zero::zero).saturating_add(reward);
|
||||
*old_reward = Some(new_reward);
|
||||
RelayerRewards::<T>::mutate(
|
||||
relayer,
|
||||
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!(
|
||||
target: crate::LOG_TARGET,
|
||||
"Relayer {:?} can now claim reward for serving lane {:?}: {:?}",
|
||||
relayer,
|
||||
lane_id,
|
||||
new_reward,
|
||||
);
|
||||
});
|
||||
log::trace!(
|
||||
target: crate::LOG_TARGET,
|
||||
"Relayer {:?} can now claim reward for serving payer {:?}: {:?}",
|
||||
relayer,
|
||||
rewards_account_params,
|
||||
new_reward,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,8 +142,8 @@ pub mod pallet {
|
||||
RewardPaid {
|
||||
/// Relayer account that has been rewarded.
|
||||
relayer: T::AccountId,
|
||||
/// Relayer has received reward for serving this lane.
|
||||
lane_id: LaneId,
|
||||
/// Relayer has received reward from this account.
|
||||
rewards_account_params: RewardsAccountParams,
|
||||
/// Reward amount.
|
||||
reward: T::Reward,
|
||||
},
|
||||
@@ -166,6 +177,8 @@ mod tests {
|
||||
use mock::{RuntimeEvent as TestEvent, *};
|
||||
|
||||
use crate::Event::RewardPaid;
|
||||
use bp_messages::LaneId;
|
||||
use bp_relayers::RewardsAccountOwner;
|
||||
use frame_support::{
|
||||
assert_noop, assert_ok,
|
||||
traits::fungible::{Inspect, Mutate},
|
||||
@@ -182,7 +195,10 @@ mod tests {
|
||||
fn root_cant_claim_anything() {
|
||||
run_test(|| {
|
||||
assert_noop!(
|
||||
Pallet::<TestRuntime>::claim_rewards(RuntimeOrigin::root(), TEST_LANE_ID),
|
||||
Pallet::<TestRuntime>::claim_rewards(
|
||||
RuntimeOrigin::root(),
|
||||
TEST_REWARDS_ACCOUNT_PARAMS
|
||||
),
|
||||
DispatchError::BadOrigin,
|
||||
);
|
||||
});
|
||||
@@ -194,7 +210,7 @@ mod tests {
|
||||
assert_noop!(
|
||||
Pallet::<TestRuntime>::claim_rewards(
|
||||
RuntimeOrigin::signed(REGULAR_RELAYER),
|
||||
TEST_LANE_ID
|
||||
TEST_REWARDS_ACCOUNT_PARAMS
|
||||
),
|
||||
Error::<TestRuntime>::NoRewardForRelayer,
|
||||
);
|
||||
@@ -204,11 +220,15 @@ mod tests {
|
||||
#[test]
|
||||
fn relayer_cant_claim_if_payment_procedure_fails() {
|
||||
run_test(|| {
|
||||
RelayerRewards::<TestRuntime>::insert(FAILING_RELAYER, TEST_LANE_ID, 100);
|
||||
RelayerRewards::<TestRuntime>::insert(
|
||||
FAILING_RELAYER,
|
||||
TEST_REWARDS_ACCOUNT_PARAMS,
|
||||
100,
|
||||
);
|
||||
assert_noop!(
|
||||
Pallet::<TestRuntime>::claim_rewards(
|
||||
RuntimeOrigin::signed(FAILING_RELAYER),
|
||||
TEST_LANE_ID
|
||||
TEST_REWARDS_ACCOUNT_PARAMS
|
||||
),
|
||||
Error::<TestRuntime>::FailedToPayReward,
|
||||
);
|
||||
@@ -220,12 +240,19 @@ mod tests {
|
||||
run_test(|| {
|
||||
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(
|
||||
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.
|
||||
assert_eq!(
|
||||
@@ -234,7 +261,7 @@ mod tests {
|
||||
phase: Phase::Initialization,
|
||||
event: TestEvent::Relayers(RewardPaid {
|
||||
relayer: REGULAR_RELAYER,
|
||||
lane_id: TEST_LANE_ID,
|
||||
rewards_account_params: TEST_REWARDS_ACCOUNT_PARAMS,
|
||||
reward: 100
|
||||
}),
|
||||
topics: vec![],
|
||||
@@ -244,30 +271,39 @@ mod tests {
|
||||
}
|
||||
|
||||
#[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 PayLaneRewardFromAccount = bp_relayers::PayLaneRewardFromAccount<Balances, AccountId>;
|
||||
type PayLaneRewardFromAccount = bp_relayers::PayRewardFromAccount<Balances, AccountId>;
|
||||
|
||||
run_test(|| {
|
||||
let lane0_rewards_account =
|
||||
PayLaneRewardFromAccount::lane_rewards_account(LaneId([0, 0, 0, 0]));
|
||||
let lane1_rewards_account =
|
||||
PayLaneRewardFromAccount::lane_rewards_account(LaneId([0, 0, 0, 1]));
|
||||
let in_lane_0 = RewardsAccountParams::new(
|
||||
LaneId([0, 0, 0, 0]),
|
||||
*b"test",
|
||||
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();
|
||||
Balances::mint_into(&lane1_rewards_account, 100).unwrap();
|
||||
assert_eq!(Balances::balance(&lane0_rewards_account), 100);
|
||||
assert_eq!(Balances::balance(&lane1_rewards_account), 100);
|
||||
let in_lane0_rewards_account = PayLaneRewardFromAccount::rewards_account(in_lane_0);
|
||||
let out_lane1_rewards_account = PayLaneRewardFromAccount::rewards_account(out_lane_1);
|
||||
|
||||
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);
|
||||
|
||||
PayLaneRewardFromAccount::pay_reward(&1, LaneId([0, 0, 0, 0]), 100).unwrap();
|
||||
assert_eq!(Balances::balance(&lane0_rewards_account), 0);
|
||||
assert_eq!(Balances::balance(&lane1_rewards_account), 100);
|
||||
PayLaneRewardFromAccount::pay_reward(&1, in_lane_0, 100).unwrap();
|
||||
assert_eq!(Balances::balance(&in_lane0_rewards_account), 0);
|
||||
assert_eq!(Balances::balance(&out_lane1_rewards_account), 100);
|
||||
assert_eq!(Balances::balance(&1), 100);
|
||||
|
||||
PayLaneRewardFromAccount::pay_reward(&1, LaneId([0, 0, 0, 1]), 100).unwrap();
|
||||
assert_eq!(Balances::balance(&lane0_rewards_account), 0);
|
||||
assert_eq!(Balances::balance(&lane1_rewards_account), 0);
|
||||
PayLaneRewardFromAccount::pay_reward(&1, out_lane_1, 100).unwrap();
|
||||
assert_eq!(Balances::balance(&in_lane0_rewards_account), 0);
|
||||
assert_eq!(Balances::balance(&out_lane1_rewards_account), 0);
|
||||
assert_eq!(Balances::balance(&1), 200);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
use crate as pallet_bridge_relayers;
|
||||
|
||||
use bp_messages::LaneId;
|
||||
use bp_relayers::PaymentProcedure;
|
||||
use bp_relayers::{PaymentProcedure, RewardsAccountOwner, RewardsAccountParams};
|
||||
use frame_support::{parameter_types, weights::RuntimeDbWeight};
|
||||
use sp_core::H256;
|
||||
use sp_runtime::{
|
||||
@@ -96,7 +96,8 @@ impl pallet_bridge_relayers::Config for TestRuntime {
|
||||
}
|
||||
|
||||
/// 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.
|
||||
pub const REGULAR_RELAYER: AccountId = 1;
|
||||
@@ -112,7 +113,7 @@ impl PaymentProcedure<AccountId, Balance> for TestPaymentProcedure {
|
||||
|
||||
fn pay_reward(
|
||||
relayer: &AccountId,
|
||||
_lane_id: LaneId,
|
||||
_lane_id: RewardsAccountParams,
|
||||
_reward: Balance,
|
||||
) -> Result<(), Self::Error> {
|
||||
match *relayer {
|
||||
|
||||
@@ -18,28 +18,33 @@
|
||||
|
||||
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 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 DeliveryConfirmationPaymentsAdapter<T, DeliveryReward, ConfirmationReward>(
|
||||
PhantomData<(T, DeliveryReward, ConfirmationReward)>,
|
||||
pub struct DeliveryConfirmationPaymentsAdapter<T, MI, DeliveryReward, ConfirmationReward>(
|
||||
PhantomData<(T, MI, DeliveryReward, ConfirmationReward)>,
|
||||
);
|
||||
|
||||
impl<T, DeliveryReward, ConfirmationReward> DeliveryConfirmationPayments<T::AccountId>
|
||||
for DeliveryConfirmationPaymentsAdapter<T, DeliveryReward, ConfirmationReward>
|
||||
impl<T, MI, DeliveryReward, ConfirmationReward> DeliveryConfirmationPayments<T::AccountId>
|
||||
for DeliveryConfirmationPaymentsAdapter<T, MI, DeliveryReward, ConfirmationReward>
|
||||
where
|
||||
T: Config,
|
||||
T: Config + pallet_bridge_messages::Config<MI>,
|
||||
MI: 'static,
|
||||
DeliveryReward: Get<T::Reward>,
|
||||
ConfirmationReward: Get<T::Reward>,
|
||||
{
|
||||
type Error = &'static str;
|
||||
|
||||
fn pay_reward(
|
||||
lane_id: bp_messages::LaneId,
|
||||
lane_id: LaneId,
|
||||
messages_relayers: VecDeque<bp_messages::UnrewardedRelayer<T::AccountId>>,
|
||||
confirmation_relayer: &T::AccountId,
|
||||
received_range: &RangeInclusive<bp_messages::MessageNonce>,
|
||||
@@ -50,7 +55,11 @@ where
|
||||
register_relayers_rewards::<T>(
|
||||
confirmation_relayer,
|
||||
relayers_rewards,
|
||||
lane_id,
|
||||
RewardsAccountParams::new(
|
||||
lane_id,
|
||||
T::BridgedChainId::get(),
|
||||
RewardsAccountOwner::BridgedChain,
|
||||
),
|
||||
DeliveryReward::get(),
|
||||
ConfirmationReward::get(),
|
||||
);
|
||||
@@ -61,7 +70,7 @@ where
|
||||
fn register_relayers_rewards<T: Config>(
|
||||
confirmation_relayer: &T::AccountId,
|
||||
relayers_rewards: RelayersRewards<T::AccountId>,
|
||||
lane_id: bp_messages::LaneId,
|
||||
lane_id: RewardsAccountParams,
|
||||
delivery_fee: T::Reward,
|
||||
confirmation_fee: T::Reward,
|
||||
) {
|
||||
@@ -121,13 +130,19 @@ mod tests {
|
||||
register_relayers_rewards::<TestRuntime>(
|
||||
&RELAYER_2,
|
||||
relayers_rewards(),
|
||||
TEST_LANE_ID,
|
||||
TEST_REWARDS_ACCOUNT_PARAMS,
|
||||
50,
|
||||
10,
|
||||
);
|
||||
|
||||
assert_eq!(RelayerRewards::<TestRuntime>::get(RELAYER_1, TEST_LANE_ID), Some(80));
|
||||
assert_eq!(RelayerRewards::<TestRuntime>::get(RELAYER_2, TEST_LANE_ID), Some(170));
|
||||
assert_eq!(
|
||||
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>(
|
||||
&RELAYER_3,
|
||||
relayers_rewards(),
|
||||
TEST_LANE_ID,
|
||||
TEST_REWARDS_ACCOUNT_PARAMS,
|
||||
50,
|
||||
10,
|
||||
);
|
||||
|
||||
assert_eq!(RelayerRewards::<TestRuntime>::get(RELAYER_1, TEST_LANE_ID), Some(80));
|
||||
assert_eq!(RelayerRewards::<TestRuntime>::get(RELAYER_2, TEST_LANE_ID), Some(120));
|
||||
assert_eq!(RelayerRewards::<TestRuntime>::get(RELAYER_3, TEST_LANE_ID), Some(50));
|
||||
assert_eq!(
|
||||
RelayerRewards::<TestRuntime>::get(RELAYER_1, TEST_REWARDS_ACCOUNT_PARAMS),
|
||||
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>(
|
||||
&RELAYER_3,
|
||||
relayers_rewards(),
|
||||
TEST_LANE_ID,
|
||||
TEST_REWARDS_ACCOUNT_PARAMS,
|
||||
50,
|
||||
1000,
|
||||
);
|
||||
|
||||
assert_eq!(RelayerRewards::<TestRuntime>::get(RELAYER_1, TEST_LANE_ID), None);
|
||||
assert_eq!(RelayerRewards::<TestRuntime>::get(RELAYER_2, TEST_LANE_ID), None);
|
||||
assert_eq!(RelayerRewards::<TestRuntime>::get(RELAYER_3, TEST_LANE_ID), Some(250));
|
||||
assert_eq!(
|
||||
RelayerRewards::<TestRuntime>::get(RELAYER_1, TEST_REWARDS_ACCOUNT_PARAMS),
|
||||
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)
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,9 +17,9 @@
|
||||
//! Autogenerated weights for pallet_bridge_relayers
|
||||
//!
|
||||
//! 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`
|
||||
//! 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
|
||||
|
||||
// Executed Command:
|
||||
@@ -60,7 +60,7 @@ pub struct BridgeWeight<T>(PhantomData<T>);
|
||||
impl<T: frame_system::Config> WeightInfo for BridgeWeight<T> {
|
||||
/// 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)
|
||||
///
|
||||
/// Storage: System Account (r:1 w:1)
|
||||
@@ -69,10 +69,10 @@ impl<T: frame_system::Config> WeightInfo for BridgeWeight<T> {
|
||||
/// MaxEncodedLen)
|
||||
fn claim_rewards() -> Weight {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `534`
|
||||
// Estimated: `5106`
|
||||
// Minimum execution time: 48_239 nanoseconds.
|
||||
Weight::from_parts(50_579_000, 5106)
|
||||
// Measured: `275`
|
||||
// Estimated: `5111`
|
||||
// Minimum execution time: 43_031 nanoseconds.
|
||||
Weight::from_parts(44_527_000, 5111)
|
||||
.saturating_add(T::DbWeight::get().reads(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 () {
|
||||
/// 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)
|
||||
///
|
||||
/// Storage: System Account (r:1 w:1)
|
||||
@@ -91,10 +91,10 @@ impl WeightInfo for () {
|
||||
/// MaxEncodedLen)
|
||||
fn claim_rewards() -> Weight {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `534`
|
||||
// Estimated: `5106`
|
||||
// Minimum execution time: 48_239 nanoseconds.
|
||||
Weight::from_parts(50_579_000, 5106)
|
||||
// Measured: `275`
|
||||
// Estimated: `5111`
|
||||
// Minimum execution time: 43_031 nanoseconds.
|
||||
Weight::from_parts(44_527_000, 5111)
|
||||
.saturating_add(RocksDbWeight::get().reads(2_u64))
|
||||
.saturating_add(RocksDbWeight::get().writes(2_u64))
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ edition = "2021"
|
||||
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
|
||||
|
||||
[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
|
||||
|
||||
|
||||
@@ -20,46 +20,95 @@
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
use bp_messages::LaneId;
|
||||
use bp_runtime::StorageDoubleMapKeyProvider;
|
||||
use bp_runtime::{ChainId, StorageDoubleMapKeyProvider};
|
||||
use frame_support::{Blake2_128Concat, Identity};
|
||||
use scale_info::TypeInfo;
|
||||
use sp_runtime::{
|
||||
codec::{Codec, Decode, Encode, EncodeLike},
|
||||
codec::{Codec, Decode, Encode, EncodeLike, MaxEncodedLen},
|
||||
traits::AccountIdConversion,
|
||||
TypeId,
|
||||
};
|
||||
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.
|
||||
pub trait PaymentProcedure<Relayer, Reward> {
|
||||
/// Error that may be returned by the procedure.
|
||||
type Error: Debug;
|
||||
|
||||
/// Pay reward to the relayer for serving given message lane.
|
||||
fn pay_reward(relayer: &Relayer, lane_id: LaneId, reward: Reward) -> Result<(), Self::Error>;
|
||||
/// Pay reward to the relayer from the account with provided params.
|
||||
fn pay_reward(
|
||||
relayer: &Relayer,
|
||||
rewards_account_params: RewardsAccountParams,
|
||||
reward: Reward,
|
||||
) -> Result<(), Self::Error>;
|
||||
}
|
||||
|
||||
impl<Relayer, Reward> PaymentProcedure<Relayer, Reward> for () {
|
||||
type Error = &'static str;
|
||||
|
||||
fn pay_reward(_: &Relayer, _: LaneId, _: Reward) -> Result<(), Self::Error> {
|
||||
fn pay_reward(_: &Relayer, _: RewardsAccountParams, _: Reward) -> Result<(), Self::Error> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// Reward payment procedure that does `balances::transfer` call from the account, derived from
|
||||
/// given lane.
|
||||
pub struct PayLaneRewardFromAccount<T, Relayer>(PhantomData<(T, Relayer)>);
|
||||
/// given params.
|
||||
pub struct PayRewardFromAccount<T, Relayer>(PhantomData<(T, Relayer)>);
|
||||
|
||||
impl<T, Relayer> PayLaneRewardFromAccount<T, Relayer>
|
||||
impl<T, Relayer> PayRewardFromAccount<T, Relayer>
|
||||
where
|
||||
Relayer: Decode + Encode,
|
||||
{
|
||||
/// Return account that pay rewards for serving given lane.
|
||||
pub fn lane_rewards_account(lane_id: LaneId) -> Relayer {
|
||||
lane_id.into_sub_account_truncating(b"bridge-lane")
|
||||
/// Return account that pays rewards based on the provided parameters.
|
||||
pub fn rewards_account(params: RewardsAccountParams) -> Relayer {
|
||||
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
|
||||
T: frame_support::traits::fungible::Transfer<Relayer>,
|
||||
Relayer: Decode + Encode,
|
||||
@@ -68,10 +117,11 @@ where
|
||||
|
||||
fn pay_reward(
|
||||
relayer: &Relayer,
|
||||
lane_id: LaneId,
|
||||
rewards_account_params: RewardsAccountParams,
|
||||
reward: T::Balance,
|
||||
) -> 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 Key1 = AccountId;
|
||||
type Hasher2 = Identity;
|
||||
type Key2 = LaneId;
|
||||
type Key2 = RewardsAccountParams;
|
||||
type Value = Reward;
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use bp_messages::LaneId;
|
||||
use sp_runtime::testing::H256;
|
||||
|
||||
#[test]
|
||||
fn lanes_are_using_different_accounts() {
|
||||
fn different_lanes_are_using_different_accounts() {
|
||||
assert_eq!(
|
||||
PayLaneRewardFromAccount::<(), H256>::lane_rewards_account(LaneId([0, 0, 0, 0])),
|
||||
hex_literal::hex!("626c616e000000006272696467652d6c616e6500000000000000000000000000")
|
||||
PayRewardFromAccount::<(), H256>::rewards_account(RewardsAccountParams::new(
|
||||
LaneId([0, 0, 0, 0]),
|
||||
*b"test",
|
||||
RewardsAccountOwner::ThisChain
|
||||
)),
|
||||
hex_literal::hex!("62726170000000007465737400726577617264732d6163636f756e7400000000")
|
||||
.into(),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
PayLaneRewardFromAccount::<(), H256>::lane_rewards_account(LaneId([0, 0, 0, 1])),
|
||||
hex_literal::hex!("626c616e000000016272696467652d6c616e6500000000000000000000000000")
|
||||
PayRewardFromAccount::<(), H256>::rewards_account(RewardsAccountParams::new(
|
||||
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(),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -74,6 +74,12 @@ pub const POLKADOT_CHAIN_ID: ChainId = *b"pdot";
|
||||
/// Bridge-with-Kusama instance id.
|
||||
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.
|
||||
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-messages = { path = "../../primitives/messages" }
|
||||
bp-parachains = { path = "../../primitives/parachains" }
|
||||
bp-runtime = { path = "../../primitives/runtime" }
|
||||
bp-wococo = { path = "../../primitives/chain-wococo" }
|
||||
|
||||
bridge-runtime-common = { path = "../../bin/runtime-common" }
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
use bp_bridge_hub_rococo::AVERAGE_BLOCK_INTERVAL;
|
||||
use bp_messages::MessageNonce;
|
||||
use bp_runtime::ChainId;
|
||||
use codec::Encode;
|
||||
use relay_substrate_client::{
|
||||
Chain, ChainWithBalances, ChainWithMessages, ChainWithTransactions, ChainWithUtilityPallet,
|
||||
@@ -41,6 +42,7 @@ impl UnderlyingChainProvider for BridgeHubRococo {
|
||||
}
|
||||
|
||||
impl Chain for BridgeHubRococo {
|
||||
const ID: ChainId = bp_runtime::BRIDGE_HUB_ROCOCO_CHAIN_ID;
|
||||
const NAME: &'static str = "BridgeHubRococo";
|
||||
const TOKEN_ID: Option<&'static str> = None;
|
||||
const BEST_FINALIZED_HEADER_ID_METHOD: &'static str =
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
use bp_bridge_hub_wococo::AVERAGE_BLOCK_INTERVAL;
|
||||
use bp_messages::MessageNonce;
|
||||
use bp_runtime::ChainId;
|
||||
use codec::Encode;
|
||||
use relay_substrate_client::{
|
||||
Chain, ChainWithBalances, ChainWithMessages, ChainWithTransactions, ChainWithUtilityPallet,
|
||||
@@ -41,6 +42,7 @@ impl UnderlyingChainProvider for BridgeHubWococo {
|
||||
}
|
||||
|
||||
impl Chain for BridgeHubWococo {
|
||||
const ID: ChainId = bp_runtime::BRIDGE_HUB_WOCOCO_CHAIN_ID;
|
||||
const NAME: &'static str = "BridgeHubWococo";
|
||||
const TOKEN_ID: Option<&'static str> = None;
|
||||
const BEST_FINALIZED_HEADER_ID_METHOD: &'static str =
|
||||
|
||||
@@ -12,6 +12,7 @@ relay-utils = { path = "../utils" }
|
||||
# Bridge dependencies
|
||||
|
||||
bp-kusama = { path = "../../primitives/chain-kusama" }
|
||||
bp-runtime = { path = "../../primitives/runtime" }
|
||||
|
||||
# Substrate Dependencies
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
//! Types used to connect to the Kusama chain.
|
||||
|
||||
use bp_kusama::AccountInfoStorageMapKeyProvider;
|
||||
use bp_runtime::ChainId;
|
||||
use relay_substrate_client::{Chain, ChainWithBalances, UnderlyingChainProvider};
|
||||
use sp_core::storage::StorageKey;
|
||||
use std::time::Duration;
|
||||
@@ -33,6 +34,7 @@ impl UnderlyingChainProvider for Kusama {
|
||||
}
|
||||
|
||||
impl Chain for Kusama {
|
||||
const ID: ChainId = bp_runtime::KUSAMA_CHAIN_ID;
|
||||
const NAME: &'static str = "Kusama";
|
||||
const TOKEN_ID: Option<&'static str> = Some("kusama");
|
||||
const BEST_FINALIZED_HEADER_ID_METHOD: &'static str =
|
||||
|
||||
@@ -14,6 +14,7 @@ relay-utils = { path = "../utils" }
|
||||
|
||||
bp-messages = { path = "../../primitives/messages" }
|
||||
bp-millau = { path = "../../primitives/chain-millau" }
|
||||
bp-runtime = { path = "../../primitives/runtime" }
|
||||
millau-runtime = { path = "../../bin/millau/runtime" }
|
||||
|
||||
# Substrate Dependencies
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
//! Types used to connect to the Millau-Substrate chain.
|
||||
|
||||
use bp_messages::MessageNonce;
|
||||
use bp_runtime::ChainId;
|
||||
use codec::{Compact, Decode, Encode};
|
||||
use relay_substrate_client::{
|
||||
BalanceOf, Chain, ChainWithBalances, ChainWithMessages, ChainWithTransactions,
|
||||
@@ -54,6 +55,7 @@ impl ChainWithMessages for Millau {
|
||||
}
|
||||
|
||||
impl Chain for Millau {
|
||||
const ID: ChainId = bp_runtime::MILLAU_CHAIN_ID;
|
||||
const NAME: &'static str = "Millau";
|
||||
// Rialto token has no value, but we associate it with KSM token
|
||||
const TOKEN_ID: Option<&'static str> = Some("kusama");
|
||||
|
||||
@@ -12,6 +12,7 @@ relay-utils = { path = "../utils" }
|
||||
# Bridge dependencies
|
||||
|
||||
bp-polkadot = { path = "../../primitives/chain-polkadot" }
|
||||
bp-runtime = { path = "../../primitives/runtime" }
|
||||
|
||||
# Substrate Dependencies
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
//! Types used to connect to the Polkadot chain.
|
||||
|
||||
use bp_polkadot::AccountInfoStorageMapKeyProvider;
|
||||
use bp_runtime::ChainId;
|
||||
use relay_substrate_client::{Chain, ChainWithBalances, UnderlyingChainProvider};
|
||||
use sp_core::storage::StorageKey;
|
||||
use std::time::Duration;
|
||||
@@ -33,6 +34,7 @@ impl UnderlyingChainProvider for Polkadot {
|
||||
}
|
||||
|
||||
impl Chain for Polkadot {
|
||||
const ID: ChainId = bp_runtime::POLKADOT_CHAIN_ID;
|
||||
const NAME: &'static str = "Polkadot";
|
||||
const TOKEN_ID: Option<&'static str> = Some("polkadot");
|
||||
const BEST_FINALIZED_HEADER_ID_METHOD: &'static str =
|
||||
|
||||
@@ -17,6 +17,7 @@ bp-messages = { path = "../../primitives/messages" }
|
||||
bp-millau = { path = "../../primitives/chain-millau" }
|
||||
bp-polkadot-core = { path = "../../primitives/polkadot-core" }
|
||||
bp-rialto-parachain = { path = "../../primitives/chain-rialto-parachain" }
|
||||
bp-runtime = { path = "../../primitives/runtime" }
|
||||
|
||||
bridge-runtime-common = { path = "../../bin/runtime-common" }
|
||||
relay-substrate-client = { path = "../client-substrate" }
|
||||
|
||||
@@ -20,6 +20,7 @@ pub mod codegen_runtime;
|
||||
|
||||
use bp_messages::MessageNonce;
|
||||
use bp_polkadot_core::PolkadotSignedExtension;
|
||||
use bp_runtime::ChainId;
|
||||
use codec::Encode;
|
||||
use relay_substrate_client::{
|
||||
Chain, ChainWithBalances, ChainWithMessages, ChainWithTransactions, Error as SubstrateError,
|
||||
@@ -48,6 +49,7 @@ impl UnderlyingChainProvider for RialtoParachain {
|
||||
}
|
||||
|
||||
impl Chain for RialtoParachain {
|
||||
const ID: ChainId = bp_runtime::RIALTO_PARACHAIN_CHAIN_ID;
|
||||
const NAME: &'static str = "RialtoParachain";
|
||||
// RialtoParachain token has no value, but we associate it with DOT token
|
||||
const TOKEN_ID: Option<&'static str> = Some("polkadot");
|
||||
|
||||
@@ -14,6 +14,7 @@ relay-utils = { path = "../utils" }
|
||||
|
||||
bp-messages = { path = "../../primitives/messages" }
|
||||
bp-rialto = { path = "../../primitives/chain-rialto" }
|
||||
bp-runtime = { path = "../../primitives/runtime" }
|
||||
rialto-runtime = { path = "../../bin/rialto/runtime" }
|
||||
|
||||
# Substrate Dependencies
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
//! Types used to connect to the Rialto-Substrate chain.
|
||||
|
||||
use bp_messages::MessageNonce;
|
||||
use bp_runtime::ChainId;
|
||||
use codec::{Compact, Decode, Encode};
|
||||
use relay_substrate_client::{
|
||||
BalanceOf, Chain, ChainWithBalances, ChainWithMessages, ChainWithTransactions,
|
||||
@@ -39,6 +40,7 @@ impl UnderlyingChainProvider for Rialto {
|
||||
}
|
||||
|
||||
impl Chain for Rialto {
|
||||
const ID: ChainId = bp_runtime::RIALTO_CHAIN_ID;
|
||||
const NAME: &'static str = "Rialto";
|
||||
// Rialto token has no value, but we associate it with DOT token
|
||||
const TOKEN_ID: Option<&'static str> = Some("polkadot");
|
||||
|
||||
@@ -12,6 +12,7 @@ relay-utils = { path = "../utils" }
|
||||
# Bridge dependencies
|
||||
|
||||
bp-rococo = { path = "../../primitives/chain-rococo" }
|
||||
bp-runtime = { path = "../../primitives/runtime" }
|
||||
|
||||
# Substrate Dependencies
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
//! Types used to connect to the Rococo-Substrate chain.
|
||||
|
||||
use bp_runtime::ChainId;
|
||||
use relay_substrate_client::{Chain, ChainWithBalances, RelayChain, UnderlyingChainProvider};
|
||||
use sp_core::storage::StorageKey;
|
||||
use std::time::Duration;
|
||||
@@ -35,6 +36,7 @@ impl UnderlyingChainProvider for Rococo {
|
||||
}
|
||||
|
||||
impl Chain for Rococo {
|
||||
const ID: ChainId = bp_runtime::ROCOCO_CHAIN_ID;
|
||||
const NAME: &'static str = "Rococo";
|
||||
const TOKEN_ID: Option<&'static str> = None;
|
||||
const BEST_FINALIZED_HEADER_ID_METHOD: &'static str =
|
||||
|
||||
@@ -18,8 +18,8 @@ use crate::calls::UtilityCall;
|
||||
|
||||
use bp_messages::MessageNonce;
|
||||
use bp_runtime::{
|
||||
Chain as ChainBase, EncodedOrDecodedCall, HashOf, Parachain as ParachainBase, TransactionEra,
|
||||
TransactionEraOf, UnderlyingChainProvider,
|
||||
Chain as ChainBase, ChainId, EncodedOrDecodedCall, HashOf, Parachain as ParachainBase,
|
||||
TransactionEra, TransactionEraOf, UnderlyingChainProvider,
|
||||
};
|
||||
use codec::{Codec, Encode};
|
||||
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.
|
||||
pub trait Chain: ChainBase + Clone {
|
||||
/// Chain id.
|
||||
const ID: ChainId;
|
||||
/// Chain name.
|
||||
const NAME: &'static str;
|
||||
/// Identifier of the basic token of the chain (if applicable).
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#![cfg(any(feature = "test-helpers", test))]
|
||||
|
||||
use crate::{Chain, ChainWithBalances};
|
||||
use bp_runtime::ChainId;
|
||||
use frame_support::weights::Weight;
|
||||
use std::time::Duration;
|
||||
|
||||
@@ -50,6 +51,7 @@ impl bp_runtime::Chain for TestChain {
|
||||
}
|
||||
|
||||
impl Chain for TestChain {
|
||||
const ID: ChainId = *b"test";
|
||||
const NAME: &'static str = "Test";
|
||||
const TOKEN_ID: Option<&'static str> = None;
|
||||
const BEST_FINALIZED_HEADER_ID_METHOD: &'static str = "TestMethod";
|
||||
|
||||
@@ -11,6 +11,7 @@ relay-utils = { path = "../utils" }
|
||||
|
||||
# Bridge dependencies
|
||||
|
||||
bp-runtime = { path = "../../primitives/runtime" }
|
||||
bp-westend = { path = "../../primitives/chain-westend" }
|
||||
|
||||
# Substrate Dependencies
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
//! Types used to connect to the Westend chain.
|
||||
|
||||
use bp_runtime::ChainId;
|
||||
use relay_substrate_client::{Chain, ChainWithBalances, RelayChain, UnderlyingChainProvider};
|
||||
use sp_core::storage::StorageKey;
|
||||
use std::time::Duration;
|
||||
@@ -35,6 +36,7 @@ impl UnderlyingChainProvider for Westend {
|
||||
}
|
||||
|
||||
impl Chain for Westend {
|
||||
const ID: ChainId = bp_runtime::WESTEND_CHAIN_ID;
|
||||
const NAME: &'static str = "Westend";
|
||||
const TOKEN_ID: Option<&'static str> = None;
|
||||
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
|
||||
// primitives here.
|
||||
impl Chain for Westmint {
|
||||
const ID: ChainId = bp_runtime::WESTMINT_CHAIN_ID;
|
||||
const NAME: &'static str = "Westmint";
|
||||
const TOKEN_ID: Option<&'static str> = None;
|
||||
const BEST_FINALIZED_HEADER_ID_METHOD: &'static str =
|
||||
|
||||
@@ -11,6 +11,7 @@ relay-utils = { path = "../utils" }
|
||||
|
||||
# Bridge dependencies
|
||||
|
||||
bp-runtime = { path = "../../primitives/runtime" }
|
||||
bp-wococo = { path = "../../primitives/chain-wococo" }
|
||||
|
||||
# Substrate Dependencies
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
//! Types used to connect to the Wococo-Substrate chain.
|
||||
|
||||
use bp_runtime::ChainId;
|
||||
use relay_substrate_client::{Chain, ChainWithBalances, RelayChain, UnderlyingChainProvider};
|
||||
use sp_core::storage::StorageKey;
|
||||
use std::time::Duration;
|
||||
@@ -35,6 +36,7 @@ impl UnderlyingChainProvider for Wococo {
|
||||
}
|
||||
|
||||
impl Chain for Wococo {
|
||||
const ID: ChainId = bp_runtime::WOCOCO_CHAIN_ID;
|
||||
const NAME: &'static str = "Wococo";
|
||||
const TOKEN_ID: Option<&'static str> = None;
|
||||
const BEST_FINALIZED_HEADER_ID_METHOD: &'static str =
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
use crate::TaggedAccount;
|
||||
|
||||
use bp_messages::LaneId;
|
||||
use bp_relayers::{RewardsAccountOwner, RewardsAccountParams};
|
||||
use bp_runtime::StorageDoubleMapKeyProvider;
|
||||
use codec::Decode;
|
||||
use frame_system::AccountInfo;
|
||||
@@ -82,18 +83,29 @@ where
|
||||
|
||||
if let Some(relayers_pallet_name) = BC::WITH_CHAIN_RELAYERS_PALLET_NAME {
|
||||
for lane in lanes {
|
||||
let relay_account_reward_metric = FloatStorageValueMetric::new(
|
||||
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(),
|
||||
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!("Reward of the {} relay account for serving lane {:?} with {} at the {}", account.tag(), lane, BC::NAME, C::NAME),
|
||||
)?;
|
||||
relay_account_reward_metric.register_and_spawn(&metrics.registry)?;
|
||||
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 at {} for delivering messages from {} on lane {:?}", account.tag(), C::NAME, BC::NAME, lane),
|
||||
)?.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)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user