Skip to content

Commit ed21892

Browse files
authored
Relayers pallet: extend payment source id (paritytech#1907)
* Add Chain::ID const * Relayers pallet: extend payment source id * Addressed code review comments * Fix benchmarks * Fix dashboards * Renamings * Fix compilation
1 parent d032566 commit ed21892

File tree

37 files changed

+377
-139
lines changed

37 files changed

+377
-139
lines changed

bin/millau/runtime/src/lib.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ pub mod rialto_parachain_messages;
3333
pub mod xcm_config;
3434

3535
use bp_parachains::SingleParaStoredHeaderDataBuilder;
36+
#[cfg(feature = "runtime-benchmarks")]
37+
use bp_relayers::{RewardsAccountOwner, RewardsAccountParams};
3638
use bp_runtime::HeaderId;
3739
use pallet_grandpa::{
3840
fg_primitives, AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList,
@@ -389,7 +391,7 @@ impl pallet_bridge_relayers::Config for Runtime {
389391
type RuntimeEvent = RuntimeEvent;
390392
type Reward = Balance;
391393
type PaymentProcedure =
392-
bp_relayers::PayLaneRewardFromAccount<pallet_balances::Pallet<Runtime>, AccountId>;
394+
bp_relayers::PayRewardFromAccount<pallet_balances::Pallet<Runtime>, AccountId>;
393395
type WeightInfo = ();
394396
}
395397

@@ -449,6 +451,7 @@ impl pallet_bridge_messages::Config<WithRialtoMessagesInstance> for Runtime {
449451
type LaneMessageVerifier = crate::rialto_messages::ToRialtoMessageVerifier;
450452
type DeliveryConfirmationPayments = pallet_bridge_relayers::DeliveryConfirmationPaymentsAdapter<
451453
Runtime,
454+
WithRialtoMessagesInstance,
452455
frame_support::traits::ConstU64<100_000>,
453456
frame_support::traits::ConstU64<10_000>,
454457
>;
@@ -480,6 +483,7 @@ impl pallet_bridge_messages::Config<WithRialtoParachainMessagesInstance> for Run
480483
type LaneMessageVerifier = crate::rialto_parachain_messages::ToRialtoParachainMessageVerifier;
481484
type DeliveryConfirmationPayments = pallet_bridge_relayers::DeliveryConfirmationPaymentsAdapter<
482485
Runtime,
486+
WithRialtoParachainMessagesInstance,
483487
frame_support::traits::ConstU64<100_000>,
484488
frame_support::traits::ConstU64<10_000>,
485489
>;
@@ -997,7 +1001,14 @@ impl_runtime_apis! {
9971001
}
9981002

9991003
fn is_relayer_rewarded(relayer: &Self::AccountId) -> bool {
1000-
pallet_bridge_relayers::Pallet::<Runtime>::relayer_reward(relayer, &Self::bench_lane_id()).is_some()
1004+
use bridge_runtime_common::messages::MessageBridge;
1005+
1006+
let lane = Self::bench_lane_id();
1007+
let bridged_chain_id = WithRialtoMessageBridge::BRIDGED_CHAIN_ID;
1008+
pallet_bridge_relayers::Pallet::<Runtime>::relayer_reward(
1009+
relayer,
1010+
RewardsAccountParams::new(lane, bridged_chain_id, RewardsAccountOwner::BridgedChain)
1011+
).is_some()
10011012
}
10021013
}
10031014

@@ -1027,15 +1038,15 @@ impl_runtime_apis! {
10271038

10281039
impl RelayersConfig for Runtime {
10291040
fn prepare_environment(
1030-
lane: bp_messages::LaneId,
1041+
account_params: RewardsAccountParams,
10311042
reward: Balance,
10321043
) {
10331044
use frame_support::traits::fungible::Mutate;
1034-
let lane_rewards_account = bp_relayers::PayLaneRewardFromAccount::<
1045+
let rewards_account = bp_relayers::PayRewardFromAccount::<
10351046
Balances,
10361047
AccountId
1037-
>::lane_rewards_account(lane);
1038-
Balances::mint_into(&lane_rewards_account, reward).unwrap();
1048+
>::rewards_account(account_params);
1049+
Balances::mint_into(&rewards_account, reward).unwrap();
10391050
}
10401051
}
10411052

bin/rialto-parachain/runtime/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ impl pallet_bridge_relayers::Config for Runtime {
521521
type RuntimeEvent = RuntimeEvent;
522522
type Reward = Balance;
523523
type PaymentProcedure =
524-
bp_relayers::PayLaneRewardFromAccount<pallet_balances::Pallet<Runtime>, AccountId>;
524+
bp_relayers::PayRewardFromAccount<pallet_balances::Pallet<Runtime>, AccountId>;
525525
type WeightInfo = ();
526526
}
527527

@@ -569,6 +569,7 @@ impl pallet_bridge_messages::Config<WithMillauMessagesInstance> for Runtime {
569569
type LaneMessageVerifier = crate::millau_messages::ToMillauMessageVerifier;
570570
type DeliveryConfirmationPayments = pallet_bridge_relayers::DeliveryConfirmationPaymentsAdapter<
571571
Runtime,
572+
WithMillauMessagesInstance,
572573
frame_support::traits::ConstU128<100_000>,
573574
frame_support::traits::ConstU128<100_000>,
574575
>;

bin/rialto/runtime/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ impl pallet_bridge_relayers::Config for Runtime {
393393
type RuntimeEvent = RuntimeEvent;
394394
type Reward = Balance;
395395
type PaymentProcedure =
396-
bp_relayers::PayLaneRewardFromAccount<pallet_balances::Pallet<Runtime>, AccountId>;
396+
bp_relayers::PayRewardFromAccount<pallet_balances::Pallet<Runtime>, AccountId>;
397397
type WeightInfo = ();
398398
}
399399

@@ -443,6 +443,7 @@ impl pallet_bridge_messages::Config<WithMillauMessagesInstance> for Runtime {
443443
type LaneMessageVerifier = crate::millau_messages::ToMillauMessageVerifier;
444444
type DeliveryConfirmationPayments = pallet_bridge_relayers::DeliveryConfirmationPaymentsAdapter<
445445
Runtime,
446+
WithMillauMessagesInstance,
446447
frame_support::traits::ConstU128<100_000>,
447448
frame_support::traits::ConstU128<100_000>,
448449
>;

bin/runtime-common/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ bp-header-chain = { path = "../../primitives/header-chain", default-features = f
1919
bp-messages = { path = "../../primitives/messages", default-features = false }
2020
bp-parachains = { path = "../../primitives/parachains", default-features = false }
2121
bp-polkadot-core = { path = "../../primitives/polkadot-core", default-features = false }
22+
bp-relayers = { path = "../../primitives/relayers", default-features = false }
2223
bp-runtime = { path = "../../primitives/runtime", default-features = false }
2324
pallet-bridge-grandpa = { path = "../../modules/grandpa", default-features = false }
2425
pallet-bridge-messages = { path = "../../modules/messages", default-features = false }

bin/runtime-common/src/mock.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ pub type BridgedChainHeader =
8585

8686
/// Message lane used in tests.
8787
pub const TEST_LANE_ID: LaneId = LaneId([0, 0, 0, 0]);
88+
/// Bridged chain id used in tests.
89+
pub const TEST_BRIDGED_CHAIN_ID: ChainId = *b"brdg";
8890
/// Maximal number of queued messages at the test lane.
8991
pub const MAXIMAL_PENDING_MESSAGES_AT_TEST_LANE: MessageNonce = 32;
9092
/// Minimal extrinsic weight at the `BridgedChain`.
@@ -118,7 +120,7 @@ crate::generate_bridge_reject_obsolete_headers_and_messages! {
118120

119121
parameter_types! {
120122
pub const ActiveOutboundLanes: &'static [LaneId] = &[TEST_LANE_ID];
121-
pub const BridgedChainId: ChainId = *b"brdg";
123+
pub const BridgedChainId: ChainId = TEST_BRIDGED_CHAIN_ID;
122124
pub const BridgedParasPalletName: &'static str = "Paras";
123125
pub const ExistentialDeposit: ThisChainBalance = 500;
124126
pub const DbWeight: RuntimeDbWeight = RuntimeDbWeight { read: 1, write: 2 };
@@ -227,6 +229,7 @@ impl pallet_bridge_messages::Config for TestRuntime {
227229
type LaneMessageVerifier = FromThisChainMessageVerifier<OnThisChainBridge>;
228230
type DeliveryConfirmationPayments = pallet_bridge_relayers::DeliveryConfirmationPaymentsAdapter<
229231
TestRuntime,
232+
(),
230233
frame_support::traits::ConstU64<100_000>,
231234
frame_support::traits::ConstU64<10_000>,
232235
>;
@@ -251,7 +254,7 @@ pub struct OnThisChainBridge;
251254

252255
impl MessageBridge for OnThisChainBridge {
253256
const THIS_CHAIN_ID: ChainId = *b"this";
254-
const BRIDGED_CHAIN_ID: ChainId = *b"brdg";
257+
const BRIDGED_CHAIN_ID: ChainId = TEST_BRIDGED_CHAIN_ID;
255258
const BRIDGED_MESSAGES_PALLET_NAME: &'static str = "";
256259

257260
type ThisChain = ThisChain;
@@ -265,7 +268,7 @@ impl MessageBridge for OnThisChainBridge {
265268
pub struct OnBridgedChainBridge;
266269

267270
impl MessageBridge for OnBridgedChainBridge {
268-
const THIS_CHAIN_ID: ChainId = *b"brdg";
271+
const THIS_CHAIN_ID: ChainId = TEST_BRIDGED_CHAIN_ID;
269272
const BRIDGED_CHAIN_ID: ChainId = *b"this";
270273
const BRIDGED_MESSAGES_PALLET_NAME: &'static str = "";
271274

bin/runtime-common/src/refund_relayer_extension.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use crate::messages_call_ext::{
2323
MessagesCallSubType, ReceiveMessagesProofHelper, ReceiveMessagesProofInfo,
2424
};
2525
use bp_messages::LaneId;
26+
use bp_relayers::{RewardsAccountOwner, RewardsAccountParams};
2627
use bp_runtime::StaticStrProvider;
2728
use codec::{Decode, Encode};
2829
use frame_support::{
@@ -397,7 +398,15 @@ where
397398
let refund = Refund::compute_refund(info, &post_info, post_info_len, tip);
398399

399400
// finally - register refund in relayers pallet
400-
RelayersPallet::<Runtime>::register_relayer_reward(Msgs::Id::get(), &relayer, refund);
401+
RelayersPallet::<Runtime>::register_relayer_reward(
402+
RewardsAccountParams::new(
403+
Msgs::Id::get(),
404+
Runtime::BridgedChainId::get(),
405+
RewardsAccountOwner::ThisChain,
406+
),
407+
&relayer,
408+
refund,
409+
);
401410

402411
log::trace!(
403412
target: "runtime::bridge",
@@ -433,6 +442,7 @@ mod tests {
433442
parameter_types! {
434443
TestParachain: u32 = 1000;
435444
pub TestLaneId: LaneId = TEST_LANE_ID;
445+
pub DirectedTestLaneId: RewardsAccountParams = RewardsAccountParams::new(TEST_LANE_ID, TEST_BRIDGED_CHAIN_ID, RewardsAccountOwner::ThisChain);
436446
}
437447

438448
bp_runtime::generate_static_str_provider!(TestExtension);
@@ -872,7 +882,7 @@ mod tests {
872882
assert_eq!(
873883
RelayersPallet::<TestRuntime>::relayer_reward(
874884
relayer_account_at_this_chain(),
875-
TestLaneId::get()
885+
DirectedTestLaneId::get()
876886
),
877887
Some(regular_reward),
878888
);
@@ -891,7 +901,7 @@ mod tests {
891901
run_post_dispatch(Some(pre_dispatch_data), Ok(()));
892902
let reward_after_two_calls = RelayersPallet::<TestRuntime>::relayer_reward(
893903
relayer_account_at_this_chain(),
894-
TestLaneId::get(),
904+
DirectedTestLaneId::get(),
895905
)
896906
.unwrap();
897907
assert!(
@@ -912,7 +922,7 @@ mod tests {
912922
assert_eq!(
913923
RelayersPallet::<TestRuntime>::relayer_reward(
914924
relayer_account_at_this_chain(),
915-
TestLaneId::get()
925+
DirectedTestLaneId::get()
916926
),
917927
Some(expected_reward()),
918928
);
@@ -928,7 +938,7 @@ mod tests {
928938
assert_eq!(
929939
RelayersPallet::<TestRuntime>::relayer_reward(
930940
relayer_account_at_this_chain(),
931-
TestLaneId::get()
941+
DirectedTestLaneId::get()
932942
),
933943
Some(expected_reward()),
934944
);
@@ -944,7 +954,7 @@ mod tests {
944954
assert_eq!(
945955
RelayersPallet::<TestRuntime>::relayer_reward(
946956
relayer_account_at_this_chain(),
947-
TestLaneId::get()
957+
DirectedTestLaneId::get()
948958
),
949959
Some(expected_reward()),
950960
);

modules/relayers/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ scale-info = { version = "2.1.1", default-features = false, features = ["derive"
1616
bp-messages = { path = "../../primitives/messages", default-features = false }
1717
bp-relayers = { path = "../../primitives/relayers", default-features = false }
1818
bp-runtime = { path = "../../primitives/runtime", default-features = false }
19+
pallet-bridge-messages = { path = "../messages", default-features = false }
1920

2021
# Substrate Dependencies
2122

modules/relayers/src/benchmarking.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
use crate::*;
2222

23+
use bp_messages::LaneId;
24+
use bp_relayers::RewardsAccountOwner;
2325
use frame_benchmarking::{benchmarks, whitelisted_caller};
2426
use frame_system::RawOrigin;
2527

@@ -32,19 +34,21 @@ pub struct Pallet<T: Config>(crate::Pallet<T>);
3234
/// Trait that must be implemented by runtime.
3335
pub trait Config: crate::Config {
3436
/// Prepare environment for paying given reward for serving given lane.
35-
fn prepare_environment(lane: LaneId, reward: Self::Reward);
37+
fn prepare_environment(account_params: RewardsAccountParams, reward: Self::Reward);
3638
}
3739

3840
benchmarks! {
3941
// Benchmark `claim_rewards` call.
4042
claim_rewards {
4143
let lane = LaneId([0, 0, 0, 0]);
44+
let account_params =
45+
RewardsAccountParams::new(lane, *b"test", RewardsAccountOwner::ThisChain);
4246
let relayer: T::AccountId = whitelisted_caller();
4347
let reward = T::Reward::from(REWARD_AMOUNT);
4448

45-
T::prepare_environment(lane, reward);
46-
RelayerRewards::<T>::insert(&relayer, lane, reward);
47-
}: _(RawOrigin::Signed(relayer), lane)
49+
T::prepare_environment(account_params, reward);
50+
RelayerRewards::<T>::insert(&relayer, account_params, reward);
51+
}: _(RawOrigin::Signed(relayer), account_params)
4852
verify {
4953
// we can't check anything here, because `PaymentProcedure` is responsible for
5054
// payment logic, so we assume that if call has succeeded, the procedure has

0 commit comments

Comments
 (0)