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;
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>,
>;
+2 -1
View File
@@ -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>,
>;
+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-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 }
+6 -3
View File
@@ -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()),
);