Skip to content

Commit 2e94db4

Browse files
authored
Default impl for some methods in messages benchmarking pallet config (paritytech#1777)
* default impl for some methods in messages benchmarking pallet config * typo
1 parent 65a8b9f commit 2e94db4

File tree

2 files changed

+34
-24
lines changed

2 files changed

+34
-24
lines changed

bridges/bin/millau/runtime/src/lib.rs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,21 +1001,6 @@ impl_runtime_apis! {
10011001
use rialto_messages::WithRialtoMessageBridge;
10021002

10031003
impl MessagesConfig<WithRialtoMessagesInstance> for Runtime {
1004-
fn bridged_relayer_id() -> Self::InboundRelayer {
1005-
[0u8; 32].into()
1006-
}
1007-
1008-
fn is_relayer_rewarded(relayer: &Self::AccountId) -> bool {
1009-
pallet_bridge_relayers::Pallet::<Runtime>::relayer_reward(relayer, &Self::bench_lane_id()).is_some()
1010-
}
1011-
1012-
fn endow_account(account: &Self::AccountId) {
1013-
pallet_balances::Pallet::<Runtime>::make_free_balance_be(
1014-
account,
1015-
Balance::MAX / 100,
1016-
);
1017-
}
1018-
10191004
fn prepare_message_proof(
10201005
params: MessageProofParams,
10211006
) -> (rialto_messages::FromRialtoMessagesProof, Weight) {
@@ -1032,8 +1017,8 @@ impl_runtime_apis! {
10321017
)
10331018
}
10341019

1035-
fn is_message_dispatched(_nonce: bp_messages::MessageNonce) -> bool {
1036-
true
1020+
fn is_relayer_rewarded(relayer: &Self::AccountId) -> bool {
1021+
pallet_bridge_relayers::Pallet::<Runtime>::relayer_reward(relayer, &Self::bench_lane_id()).is_some()
10371022
}
10381023
}
10391024

bridges/modules/messages/src/benchmarking.rs

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ use bp_messages::{
2727
UnrewardedRelayersState,
2828
};
2929
use bp_runtime::StorageProofSize;
30+
use codec::Decode;
3031
use frame_benchmarking::{account, benchmarks_instance_pallet};
3132
use frame_support::weights::Weight;
3233
use frame_system::RawOrigin;
34+
use sp_runtime::traits::TrailingZeroInput;
3335
use sp_std::{ops::RangeInclusive, prelude::*};
3436

3537
const SEED: u32 = 0;
@@ -64,15 +66,26 @@ pub struct MessageDeliveryProofParams<ThisChainAccountId> {
6466
/// Trait that must be implemented by runtime.
6567
pub trait Config<I: 'static>: crate::Config<I> {
6668
/// Lane id to use in benchmarks.
69+
///
70+
/// By default, lane 00000000 is used.
6771
fn bench_lane_id() -> LaneId {
68-
Default::default()
72+
LaneId([0, 0, 0, 0])
6973
}
74+
7075
/// Return id of relayer account at the bridged chain.
71-
fn bridged_relayer_id() -> Self::InboundRelayer;
72-
/// Returns true if given relayer has been rewarded for some of its actions.
73-
fn is_relayer_rewarded(relayer: &Self::AccountId) -> bool;
74-
/// Create given account and give it enough balance for test purposes.
75-
fn endow_account(account: &Self::AccountId);
76+
///
77+
/// By default, zero account is returned.
78+
fn bridged_relayer_id() -> Self::InboundRelayer {
79+
Self::InboundRelayer::decode(&mut TrailingZeroInput::zeroes()).unwrap()
80+
}
81+
82+
/// Create given account and give it enough balance for test purposes. Used to create
83+
/// relayer account at the target chain. Is strictly necessary when your rewards scheme
84+
/// assumes that the relayer account must exist.
85+
///
86+
/// Does nothing by default.
87+
fn endow_account(_account: &Self::AccountId) {}
88+
7689
/// Prepare messages proof to receive by the module.
7790
fn prepare_message_proof(
7891
params: MessageProofParams,
@@ -81,8 +94,20 @@ pub trait Config<I: 'static>: crate::Config<I> {
8194
fn prepare_message_delivery_proof(
8295
params: MessageDeliveryProofParams<Self::AccountId>,
8396
) -> <Self::TargetHeaderChain as TargetHeaderChain<Self::OutboundPayload, Self::AccountId>>::MessagesDeliveryProof;
97+
8498
/// Returns true if message has been dispatched (either successfully or not).
85-
fn is_message_dispatched(nonce: MessageNonce) -> bool;
99+
///
100+
/// We assume that messages have near-zero dispatch weight, so most of times it
101+
/// is hard to determine whether messages has been dispatched or not. For example,
102+
/// XCM message can be a call that leaves entry in `frame_system::Events` vector,
103+
/// but not all XCM messages do that and we don't want to include weight of this
104+
/// action to the base weight of message delivery. Hence, the default `true` return
105+
/// value.
106+
fn is_message_dispatched(_nonce: MessageNonce) -> bool {
107+
true
108+
}
109+
/// Returns true if given relayer has been rewarded for some of its actions.
110+
fn is_relayer_rewarded(relayer: &Self::AccountId) -> bool;
86111
}
87112

88113
benchmarks_instance_pallet! {

0 commit comments

Comments
 (0)