pallet_bridge_grandpa/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::{BridgeWeight, WeightInfo};
20
21use frame_support::weights::Weight;
22
23/// Extended weight info.
24pub trait WeightInfoExt: WeightInfo {
25 // Our configuration assumes that the runtime has special signed extensions used to:
26 //
27 // 1) boost priority of `submit_finality_proof` transactions;
28 //
29 // 2) slash relayer if he submits an invalid transaction.
30 //
31 // We read and update storage values of other pallets (`pallet-bridge-relayers` and
32 // balances/assets pallet). So we need to add this weight to the weight of our call.
33 // Hence two following methods.
34
35 /// Extra weight that is added to the `submit_finality_proof` call weight by signed extensions
36 /// that are declared at runtime level.
37 fn submit_finality_proof_overhead_from_runtime() -> Weight;
38
39 // Functions that are directly mapped to extrinsics weights.
40
41 /// Weight of message delivery extrinsic.
42 fn submit_finality_proof_weight(precommits_len: u32, votes_ancestries_len: u32) -> Weight {
43 let base_weight = Self::submit_finality_proof(precommits_len, votes_ancestries_len);
44 base_weight.saturating_add(Self::submit_finality_proof_overhead_from_runtime())
45 }
46}
47
48impl<T: frame_system::Config> WeightInfoExt for BridgeWeight<T> {
49 fn submit_finality_proof_overhead_from_runtime() -> Weight {
50 Weight::zero()
51 }
52}
53
54impl WeightInfoExt for () {
55 fn submit_finality_proof_overhead_from_runtime() -> Weight {
56 Weight::zero()
57 }
58}