difftreelog
fix enable throttling
in: master
6 files changed
node/cli/src/command.rsdiffbeforeafterboth--- a/node/cli/src/command.rs
+++ b/node/cli/src/command.rs
@@ -396,6 +396,8 @@
}
}
#[cfg(feature = "try-runtime")]
+ // embedded try-runtime cli will be removed soon.
+ #[allow(deprecated)]
Some(Subcommand::TryRuntime(cmd)) => {
use std::{future::Future, pin::Pin};
pallets/inflation/src/lib.rsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617//! # Inflation18//!19//! The inflation pallet is designed to increase the number of tokens at certain intervals.20//! With each iteration, increases the `total_issuance` value for the native token.21//! Executing an `on_initialize` hook at the beginning of each block, causing inflation to begin.22//!23//! ## Interface24//!25//! ### Dispatchable Functions26//!27//! * `start_inflation` - This method sets the inflation start date. Can be only called once.28//! Inflation start block can be backdated and will catch up. The method will create Treasury29//! account if it does not exist and perform the first inflation deposit.3031// #![recursion_limit = "1024"]32#![cfg_attr(not(feature = "std"), no_std)]3334#[cfg(feature = "runtime-benchmarks")]35mod benchmarking;3637#[cfg(test)]38mod tests;3940use frame_support::traits::{41 fungible::{Balanced, Inspect, Mutate},42 tokens::Precision,43 Get,44};45use frame_system::pallet_prelude::BlockNumberFor;46pub use pallet::*;47use sp_runtime::{traits::BlockNumberProvider, Perbill};48use sp_std::convert::TryInto;4950type BalanceOf<T> =51 <<T as Config>::Currency as Inspect<<T as frame_system::Config>::AccountId>>::Balance;5253pub const YEAR: u32 = 5_259_600; // 6-second block54 // pub const YEAR: u32 = 2_629_800; // 12-second block55pub const TOTAL_YEARS_UNTIL_FLAT: u32 = 9;56pub const START_INFLATION_PERCENT: u32 = 10;57pub const END_INFLATION_PERCENT: u32 = 4;5859#[frame_support::pallet]60pub mod pallet {61 use frame_support::pallet_prelude::*;62 use frame_system::pallet_prelude::*;6364 use super::*;6566 #[pallet::config]67 pub trait Config: frame_system::Config {68 type Currency: Balanced<Self::AccountId>69 + Inspect<Self::AccountId>70 + Mutate<Self::AccountId>;71 type TreasuryAccountId: Get<Self::AccountId>;7273 // The block number provider, which should be callable from `on_initialize` hook.74 type OnInitializeBlockNumberProvider: BlockNumberProvider<75 BlockNumber = BlockNumberFor<Self>,76 >;7778 /// Number of blocks that pass between treasury balance updates due to inflation79 #[pallet::constant]80 type InflationBlockInterval: Get<BlockNumberFor<Self>>;81 }8283 #[pallet::pallet]84 pub struct Pallet<T>(_);8586 /// starting year total issuance87 #[pallet::storage]88 pub type StartingYearTotalIssuance<T: Config> =89 StorageValue<Value = BalanceOf<T>, QueryKind = ValueQuery>;9091 /// Current inflation for `InflationBlockInterval` number of blocks92 #[pallet::storage]93 pub type BlockInflation<T: Config> = StorageValue<Value = BalanceOf<T>, QueryKind = ValueQuery>;9495 /// Next target (relay) block when inflation will be applied96 #[pallet::storage]97 pub type NextInflationBlock<T: Config> =98 StorageValue<Value = BlockNumberFor<T>, QueryKind = ValueQuery>;99100 /// Next target (relay) block when inflation is recalculated101 #[pallet::storage]102 pub type NextRecalculationBlock<T: Config> =103 StorageValue<Value = BlockNumberFor<T>, QueryKind = ValueQuery>;104105 /// Relay block when inflation has started106 #[pallet::storage]107 pub type StartBlock<T: Config> =108 StorageValue<Value = BlockNumberFor<T>, QueryKind = ValueQuery>;109110 #[pallet::hooks]111 impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {112 fn on_initialize(_: BlockNumberFor<T>) -> Weight113 where114 BlockNumberFor<T>: From<u32>,115 {116 let mut consumed_weight = Weight::zero();117 let mut add_weight = |reads, writes, weight| {118 consumed_weight += T::DbWeight::get().reads_writes(reads, writes);119 consumed_weight += weight;120 };121122 let block_interval: u32 = T::InflationBlockInterval::get().try_into().unwrap_or(0);123 let current_relay_block = T::OnInitializeBlockNumberProvider::current_block_number();124 let next_inflation: BlockNumberFor<T> = <NextInflationBlock<T>>::get();125 add_weight(1, 0, Weight::from_parts(5_000_000, 0));126127 // Apply inflation every InflationBlockInterval blocks128 // If next_inflation == 0, this means inflation wasn't yet initialized129 if (next_inflation != 0u32.into()) && (current_relay_block >= next_inflation) {130 // Recalculate inflation on the first block of the year (or if it is not initialized yet)131 // Do the "current_relay_block >= next_recalculation" check in the "current_relay_block >= next_inflation"132 // block because it saves InflationBlockInterval DB reads for NextRecalculationBlock.133 let next_recalculation: BlockNumberFor<T> = <NextRecalculationBlock<T>>::get();134 add_weight(1, 0, Weight::zero());135 if current_relay_block >= next_recalculation {136 Self::recalculate_inflation(next_recalculation);137 add_weight(0, 4, Weight::from_parts(5_000_000, 0));138 }139140 T::Currency::mint_into(&T::TreasuryAccountId::get(), <BlockInflation<T>>::get())141 .ok();142143 // Update inflation block144 <NextInflationBlock<T>>::set(next_inflation + block_interval.into());145146 add_weight(3, 3, Weight::from_parts(10_000_000, 0));147 }148149 consumed_weight150 }151 }152153 #[pallet::call]154 impl<T: Config> Pallet<T> {155 /// This method sets the inflation start date. Can be only called once.156 /// Inflation start block can be backdated and will catch up. The method will create Treasury157 /// account if it does not exist and perform the first inflation deposit.158 ///159 /// # Permissions160 ///161 /// * Root162 ///163 /// # Arguments164 ///165 /// * inflation_start_relay_block: The relay chain block at which inflation should start166 #[pallet::call_index(0)]167 // Constant weights are deprecated,168 // but in this case writing benchmark is not feasible, `start_inflation` call169 // might be even moved to GenesisConfig170 #[pallet::weight(Weight::from_parts(0, 0))]171 pub fn start_inflation(172 origin: OriginFor<T>,173 inflation_start_relay_block: BlockNumberFor<T>,174 ) -> DispatchResult175 where176 BlockNumberFor<T>: From<u32>,177 {178 ensure_root(origin)?;179180 // Start inflation if it has not been yet initialized181 if <StartBlock<T>>::get() == 0u32.into() {182 // Set inflation global start block183 <StartBlock<T>>::set(inflation_start_relay_block);184185 // Recalculate inflation. This can be backdated and will catch up.186 Self::recalculate_inflation(inflation_start_relay_block);187 let block_interval: u32 = T::InflationBlockInterval::get().try_into().unwrap_or(0);188 <NextInflationBlock<T>>::set(inflation_start_relay_block + block_interval.into());189190 // First time deposit - create Treasury account so that we can call deposit_into_existing everywhere else191 let _ = T::Currency::deposit(192 &T::TreasuryAccountId::get(),193 <BlockInflation<T>>::get(),194 Precision::Exact,195 )?;196 }197198 Ok(())199 }200 }201}202203impl<T: Config> Pallet<T> {204 pub fn recalculate_inflation(recalculation_block: BlockNumberFor<T>) {205 let current_year: u32 = ((recalculation_block - <StartBlock<T>>::get())206 / BlockNumberFor::<T>::from(YEAR))207 .try_into()208 .unwrap_or(0);209 let block_interval: u32 = T::InflationBlockInterval::get().try_into().unwrap_or(0);210211 let one_percent = Perbill::from_percent(1);212213 if current_year <= TOTAL_YEARS_UNTIL_FLAT {214 let amount: BalanceOf<T> = Perbill::from_rational(215 block_interval216 * (START_INFLATION_PERCENT * TOTAL_YEARS_UNTIL_FLAT217 - current_year * (START_INFLATION_PERCENT - END_INFLATION_PERCENT)),218 YEAR * TOTAL_YEARS_UNTIL_FLAT,219 ) * (one_percent * T::Currency::total_issuance());220 <BlockInflation<T>>::put(amount);221 } else {222 let amount: BalanceOf<T> =223 Perbill::from_rational(block_interval * END_INFLATION_PERCENT, YEAR)224 * (one_percent * T::Currency::total_issuance());225 <BlockInflation<T>>::put(amount);226 }227 <StartingYearTotalIssuance<T>>::set(T::Currency::total_issuance());228229 // Update recalculation and inflation blocks230 <NextRecalculationBlock<T>>::set(recalculation_block + YEAR.into());231 }232}primitives/common/src/constants.rsdiffbeforeafterboth--- a/primitives/common/src/constants.rs
+++ b/primitives/common/src/constants.rs
@@ -23,7 +23,10 @@
use crate::types::{Balance, BlockNumber};
+#[cfg(not(feature = "lookahead"))]
pub const MILLISECS_PER_BLOCK: u64 = 12000;
+#[cfg(feature = "lookahead")]
+pub const MILLISECS_PER_BLOCK: u64 = 3000;
pub const MILLISECS_PER_RELAY_BLOCK: u64 = 6000;
pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK;
runtime/common/config/pallets/mod.rsdiffbeforeafterboth--- a/runtime/common/config/pallets/mod.rs
+++ b/runtime/common/config/pallets/mod.rs
@@ -21,7 +21,7 @@
traits::{ConstU32, ConstU64, Currency},
};
use sp_arithmetic::Perbill;
-use sp_runtime::traits::{BlockNumberProvider, AccountIdConversion};
+use sp_runtime::traits::{AccountIdConversion, BlockNumberProvider};
use up_common::{
constants::*,
types::{AccountId, Balance, BlockNumber},
@@ -111,8 +111,8 @@
type BlockNumber = BlockNumber;
fn current_block_number() -> Self::BlockNumber {
+ use hex_literal::hex;
use parity_scale_codec::Decode;
- use hex_literal::hex;
use sp_io::storage;
// TODO: Replace with the following code after https://github.com/paritytech/polkadot-sdk/commit/3ea497b5a0fdda252f9c5a3c257cfaf8685f02fd lands
// <cumulus_pallet_parachain_system::Pallet<Runtime>>::last_relay_block_number()
@@ -122,7 +122,8 @@
// First parachain block
return Default::default()
};
- BlockNumber::decode(&mut encoded.as_ref()).expect("typeof(RelayBlockNumber) == typeof(BlockNumber) == u32; qed")
+ BlockNumber::decode(&mut encoded.as_ref())
+ .expect("typeof(RelayBlockNumber) == typeof(BlockNumber) == u32; qed")
}
}
runtime/common/config/parachain.rsdiffbeforeafterboth--- a/runtime/common/config/parachain.rs
+++ b/runtime/common/config/parachain.rs
@@ -38,9 +38,29 @@
type ReservedDmpWeight = ReservedDmpWeight;
type ReservedXcmpWeight = ReservedXcmpWeight;
type XcmpMessageHandler = XcmpQueue;
+ #[cfg(not(feature = "lookahead"))]
type CheckAssociatedRelayNumber = cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases;
+ #[cfg(feature = "lookahead")]
+ type CheckAssociatedRelayNumber =
+ cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases;
}
impl parachain_info::Config for Runtime {}
impl cumulus_pallet_aura_ext::Config for Runtime {}
+
+/// Maximum number of blocks simultaneously accepted by the Runtime, not yet included
+/// into the relay chain.
+#[cfg(feature = "lookahead")]
+const UNINCLUDED_SEGMENT_CAPACITY: u32 = 3;
+/// How many parachain blocks are processed by the relay chain per parent. Limits the
+/// number of blocks authored per slot.
+#[cfg(feature = "lookahead")]
+const BLOCK_PROCESSING_VELOCITY: u32 = 2;
+#[cfg(feature = "lookahead")]
+pub type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook<
+ Runtime,
+ { MILLISECS_PER_RELAY_BLOCK as u32 },
+ BLOCK_PROCESSING_VELOCITY,
+ UNINCLUDED_SEGMENT_CAPACITY,
+>;
runtime/common/runtime_apis.rsdiffbeforeafterboth--- a/runtime/common/runtime_apis.rs
+++ b/runtime/common/runtime_apis.rs
@@ -682,11 +682,10 @@
#[cfg(feature = "lookahead")]
impl cumulus_primitives_aura::AuraUnincludedSegmentApi<Block> for Runtime {
fn can_build_upon(
- _included_hash: <Block as BlockT>::Hash,
- _slot: cumulus_primitives_aura::Slot,
+ included_hash: <Block as BlockT>::Hash,
+ slot: cumulus_primitives_aura::Slot,
) -> bool {
- // FIXME: Limit velocity
- true
+ $crate::config::parachain::ConsensusHook::can_build_upon(included_hash, slot)
}
}