referrerpolicy=no-referrer-when-downgrade

bp_header_chain/
call_info.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//! Defines structures related to calls of the `pallet-bridge-grandpa` pallet.
18
19use crate::{justification, InitializationData};
20
21use bp_runtime::HeaderOf;
22use codec::{Decode, Encode};
23use frame_support::{weights::Weight, RuntimeDebugNoBound};
24use scale_info::TypeInfo;
25use sp_consensus_grandpa::SetId;
26use sp_runtime::traits::{Header as HeaderT, Zero};
27use sp_std::{boxed::Box, fmt::Debug};
28
29/// A minimized version of `pallet-bridge-grandpa::Call` that can be used without a runtime.
30#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
31#[allow(non_camel_case_types)]
32pub enum BridgeGrandpaCall<Header: HeaderT> {
33	/// `pallet-bridge-grandpa::Call::submit_finality_proof`
34	#[codec(index = 0)]
35	submit_finality_proof {
36		/// The header that we are going to finalize.
37		finality_target: Box<Header>,
38		/// Finality justification for the `finality_target`.
39		justification: justification::GrandpaJustification<Header>,
40	},
41	/// `pallet-bridge-grandpa::Call::initialize`
42	#[codec(index = 1)]
43	initialize {
44		/// All data, required to initialize the pallet.
45		init_data: InitializationData<Header>,
46	},
47	/// `pallet-bridge-grandpa::Call::submit_finality_proof_ex`
48	#[codec(index = 4)]
49	submit_finality_proof_ex {
50		/// The header that we are going to finalize.
51		finality_target: Box<Header>,
52		/// Finality justification for the `finality_target`.
53		justification: justification::GrandpaJustification<Header>,
54		/// An identifier of the validators set, that have signed the justification.
55		current_set_id: SetId,
56	},
57}
58
59/// The `BridgeGrandpaCall` for a pallet that bridges with given `C`;
60pub type BridgeGrandpaCallOf<C> = BridgeGrandpaCall<HeaderOf<C>>;
61
62/// A digest information on the `BridgeGrandpaCall::submit_finality_proof` call.
63#[derive(Copy, Clone, PartialEq, RuntimeDebugNoBound)]
64pub struct SubmitFinalityProofInfo<N: Debug> {
65	/// Number of the finality target.
66	pub block_number: N,
67	/// An identifier of the validators set that has signed the submitted justification.
68	/// It might be `None` if deprecated version of the `submit_finality_proof` is used.
69	pub current_set_id: Option<SetId>,
70	/// If `true`, then the call proves new **mandatory** header.
71	pub is_mandatory: bool,
72	/// If `true`, then the call must be free (assuming that everything else is valid) to
73	/// be treated as valid.
74	pub is_free_execution_expected: bool,
75	/// Extra weight that we assume is included in the call.
76	///
77	/// We have some assumptions about headers and justifications of the bridged chain.
78	/// We know that if our assumptions are correct, then the call must not have the
79	/// weight above some limit. The fee paid for weight above that limit, is never refunded.
80	pub extra_weight: Weight,
81	/// Extra size (in bytes) that we assume are included in the call.
82	///
83	/// We have some assumptions about headers and justifications of the bridged chain.
84	/// We know that if our assumptions are correct, then the call must not have the
85	/// weight above some limit. The fee paid for bytes above that limit, is never refunded.
86	pub extra_size: u32,
87}
88
89impl<N: Debug> SubmitFinalityProofInfo<N> {
90	/// Returns `true` if call size/weight is below our estimations for regular calls.
91	pub fn fits_limits(&self) -> bool {
92		self.extra_weight.is_zero() && self.extra_size.is_zero()
93	}
94}