difftreelog
fix(inflation) BlockNumberProvider
in: master
2 files changed
pallets/inflation/src/lib.rsdiffbeforeafterboth--- a/pallets/inflation/src/lib.rs
+++ b/pallets/inflation/src/lib.rs
@@ -70,8 +70,8 @@
+ Mutate<Self::AccountId>;
type TreasuryAccountId: Get<Self::AccountId>;
- // The block number provider
- type BlockNumberProvider: BlockNumberProvider<BlockNumber = BlockNumberFor<Self>>;
+ // The block number provider, which should be callable from `on_initialize` hook.
+ type OnInitializeBlockNumberProvider: BlockNumberProvider<BlockNumber = BlockNumberFor<Self>>;
/// Number of blocks that pass between treasury balance updates due to inflation
#[pallet::constant]
@@ -118,7 +118,7 @@
};
let block_interval: u32 = T::InflationBlockInterval::get().try_into().unwrap_or(0);
- let current_relay_block = T::BlockNumberProvider::current_block_number();
+ let current_relay_block = T::OnInitializeBlockNumberProvider::current_block_number();
let next_inflation: BlockNumberFor<T> = <NextInflationBlock<T>>::get();
add_weight(1, 0, Weight::from_parts(5_000_000, 0));
runtime/common/config/pallets/mod.rsdiffbeforeafterboth21 traits::{ConstU32, ConstU64, Currency},21 traits::{ConstU32, ConstU64, Currency},22};22};23use sp_arithmetic::Perbill;23use sp_arithmetic::Perbill;24use sp_runtime::traits::AccountIdConversion;24use sp_runtime::traits::{BlockNumberProvider, AccountIdConversion};25use up_common::{25use up_common::{26 constants::*,26 constants::*,27 types::{AccountId, Balance, BlockNumber},27 types::{AccountId, Balance, BlockNumber},105 pub const InflationBlockInterval: BlockNumber = 100; // every time per how many blocks inflation is applied105 pub const InflationBlockInterval: BlockNumber = 100; // every time per how many blocks inflation is applied106}106}107108/// Pallet-inflation needs block number in on_initialize, where there is no `validation_data` exists yet109pub struct OnInitializeBlockNumberProvider;110impl BlockNumberProvider for OnInitializeBlockNumberProvider {111 type BlockNumber = BlockNumber;112113 fn current_block_number() -> Self::BlockNumber {114 use parity_scale_codec::Decode;115 use hex_literal::hex;116 use sp_io::storage;117 // TODO: Replace with the following code after https://github.com/paritytech/polkadot-sdk/commit/3ea497b5a0fdda252f9c5a3c257cfaf8685f02fd lands118 // <cumulus_pallet_parachain_system::Pallet<Runtime>>::last_relay_block_number()119120 // ParachainSystem.LastRelayChainBlockNumber121 let Some(encoded) = storage::get(&hex!("45323df7cc47150b3930e2666b0aa313a2bca190d36bd834cc73a38fc213ecbd")) else {122 // First parachain block123 return Default::default()124 };125 BlockNumber::decode(&mut encoded.as_ref()).expect("typeof(RelayBlockNumber) == typeof(BlockNumber) == u32; qed")126 }127}107128108/// Used for the pallet inflation129/// Used for the pallet inflation109impl pallet_inflation::Config for Runtime {130impl pallet_inflation::Config for Runtime {110 type Currency = Balances;131 type Currency = Balances;111 type TreasuryAccountId = TreasuryAccountId;132 type TreasuryAccountId = TreasuryAccountId;112 type InflationBlockInterval = InflationBlockInterval;133 type InflationBlockInterval = InflationBlockInterval;113 type BlockNumberProvider = RelayChainBlockNumberProvider<Runtime>;134 type OnInitializeBlockNumberProvider = OnInitializeBlockNumberProvider;114}135}115136116impl pallet_unique::Config for Runtime {137impl pallet_unique::Config for Runtime {