|
| 1 | +// Copyright 2022 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 | +#![cfg_attr(not(feature = "std"), no_std)] |
| 18 | + |
| 19 | +use bp_messages::*; |
| 20 | +pub use bp_polkadot_core::{ |
| 21 | + AccountId, AccountInfoStorageMapKeyProvider, AccountPublic, Balance, BlockNumber, Hash, Hasher, |
| 22 | + Hashing, Header, Index, Nonce, Perbill, Signature, SignedBlock, SignedExtensions, |
| 23 | + UncheckedExtrinsic, MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX, |
| 24 | + MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX, TX_EXTRA_BYTES, |
| 25 | +}; |
| 26 | +use frame_support::{ |
| 27 | + dispatch::DispatchClass, |
| 28 | + parameter_types, |
| 29 | + sp_runtime::{MultiAddress, MultiSigner}, |
| 30 | + weights::{constants, WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial}, |
| 31 | +}; |
| 32 | +use frame_system::limits; |
| 33 | + |
| 34 | +/// All cumulus bridge hubs allow normal extrinsics to fill block up to 75 percent. |
| 35 | +/// |
| 36 | +/// This is a copy-paste from the cumulus repo's `parachains-common` crate. |
| 37 | +pub const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75); |
| 38 | + |
| 39 | +/// All cumulus bridge hubs chains allow for 0.5 seconds of compute with a 6-second average block |
| 40 | +/// time. |
| 41 | +/// |
| 42 | +/// This is a copy-paste from the cumulus repo's `parachains-common` crate. |
| 43 | +pub const MAXIMUM_BLOCK_WEIGHT: Weight = constants::WEIGHT_PER_SECOND |
| 44 | + .saturating_div(2) |
| 45 | + .set_proof_size(polkadot_primitives::v2::MAX_POV_SIZE as u64); |
| 46 | + |
| 47 | +/// All cumulus bridge hubs assume that about 5 percent of the block weight is consumed by |
| 48 | +/// `on_initialize` handlers. This is used to limit the maximal weight of a single extrinsic. |
| 49 | +/// |
| 50 | +/// This is a copy-paste from the cumulus repo's `parachains-common` crate. |
| 51 | +pub const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(5); |
| 52 | + |
| 53 | +parameter_types! { |
| 54 | + pub BlockLength: limits::BlockLength = limits::BlockLength::max_with_normal_ratio( |
| 55 | + 5 * 1024 * 1024, |
| 56 | + NORMAL_DISPATCH_RATIO, |
| 57 | + ); |
| 58 | + |
| 59 | + pub const BlockExecutionWeight: Weight = constants::WEIGHT_PER_NANOS.saturating_mul(5_000_000); |
| 60 | + |
| 61 | + pub const ExtrinsicBaseWeight: Weight = constants::WEIGHT_PER_NANOS.saturating_mul(125_000); |
| 62 | + |
| 63 | + pub BlockWeights: limits::BlockWeights = limits::BlockWeights::builder() |
| 64 | + .base_block(BlockExecutionWeight::get()) |
| 65 | + .for_class(DispatchClass::all(), |weights| { |
| 66 | + weights.base_extrinsic = ExtrinsicBaseWeight::get(); |
| 67 | + }) |
| 68 | + .for_class(DispatchClass::Normal, |weights| { |
| 69 | + weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT); |
| 70 | + }) |
| 71 | + .for_class(DispatchClass::Operational, |weights| { |
| 72 | + weights.max_total = Some(MAXIMUM_BLOCK_WEIGHT); |
| 73 | + // Operational transactions have an extra reserved space, so that they |
| 74 | + // are included even if block reached `MAXIMUM_BLOCK_WEIGHT`. |
| 75 | + weights.reserved = Some( |
| 76 | + MAXIMUM_BLOCK_WEIGHT - NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT, |
| 77 | + ); |
| 78 | + }) |
| 79 | + .avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO) |
| 80 | + .build_or_panic(); |
| 81 | +} |
| 82 | + |
| 83 | +/// [`WeightToFee`] should reflect cumulus/bridge-hub-* [`WeightToFee`] |
| 84 | +pub struct WeightToFee; |
| 85 | +impl WeightToFeePolynomial for WeightToFee { |
| 86 | + type Balance = Balance; |
| 87 | + fn polynomial() -> WeightToFeeCoefficients<Self::Balance> { |
| 88 | + pub const CENTS: Balance = polkadot_runtime_constants::currency::CENTS; |
| 89 | + |
| 90 | + // In BridgeHub, we map the extrinsic base weight to 1/100 CENT. |
| 91 | + let p = CENTS; |
| 92 | + let q = 100 * Balance::from(constants::ExtrinsicBaseWeight::get().ref_time()); |
| 93 | + smallvec::smallvec![WeightToFeeCoefficient { |
| 94 | + degree: 1, |
| 95 | + negative: false, |
| 96 | + coeff_frac: Perbill::from_rational(p % q, q), |
| 97 | + coeff_integer: p / q, |
| 98 | + }] |
| 99 | + } |
| 100 | +} |
| 101 | + |
| 102 | +/// Public key of the chain account that may be used to verify signatures. |
| 103 | +pub type AccountSigner = MultiSigner; |
| 104 | + |
| 105 | +/// The address format for describing accounts. |
| 106 | +pub type Address = MultiAddress<AccountId, ()>; |
0 commit comments