pallet_bridge_relayers/weights_ext.rs
1// Copyright (C) Parity Technologies (UK) Ltd.
2// This file is part of Parity Bridges Common.
3
4// Parity Bridges Common is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// Parity Bridges Common is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
16
17//! Weight-related utilities.
18
19use crate::weights::WeightInfo;
20
21use frame_support::pallet_prelude::Weight;
22
23/// Extended weight info.
24pub trait WeightInfoExt: WeightInfo {
25 /// Returns weight, that needs to be added to the pre-dispatch weight of message delivery call,
26 /// if `BridgeRelayersTransactionExtension` signed extension is deployed at runtime level.
27 fn receive_messages_proof_overhead_from_runtime() -> Weight {
28 Self::slash_and_deregister().max(Self::register_relayer_reward())
29 }
30
31 /// Returns weight, that needs to be added to the pre-dispatch weight of message delivery
32 /// confirmation call, if `BridgeRelayersTransactionExtension` signed extension is deployed at
33 /// runtime level.
34 fn receive_messages_delivery_proof_overhead_from_runtime() -> Weight {
35 Self::register_relayer_reward()
36 }
37
38 /// Returns weight that we need to deduct from the message delivery call weight that has
39 /// completed successfully.
40 ///
41 /// Usually, the weight of `slash_and_deregister` is larger than the weight of the
42 /// `register_relayer_reward`. So if relayer has been rewarded, we want to deduct the difference
43 /// to get the actual post-dispatch weight.
44 fn extra_weight_of_successful_receive_messages_proof_call() -> Weight {
45 Self::slash_and_deregister().saturating_sub(Self::register_relayer_reward())
46 }
47}
48
49impl<T: WeightInfo> WeightInfoExt for T {}