difftreelog
fix(inflation) BlockNumberProvider
in: master
2 files changed
pallets/inflation/src/lib.rsdiffbeforeafterboth70 + Mutate<Self::AccountId>;70 + Mutate<Self::AccountId>;71 type TreasuryAccountId: Get<Self::AccountId>;71 type TreasuryAccountId: Get<Self::AccountId>;727273 // The block number provider73 // The block number provider, which should be callable from `on_initialize` hook.74 type BlockNumberProvider: BlockNumberProvider<BlockNumber = BlockNumberFor<Self>>;74 type OnInitializeBlockNumberProvider: BlockNumberProvider<BlockNumber = BlockNumberFor<Self>>;757576 /// Number of blocks that pass between treasury balance updates due to inflation76 /// Number of blocks that pass between treasury balance updates due to inflation77 #[pallet::constant]77 #[pallet::constant]118 };118 };119119120 let block_interval: u32 = T::InflationBlockInterval::get().try_into().unwrap_or(0);120 let block_interval: u32 = T::InflationBlockInterval::get().try_into().unwrap_or(0);121 let current_relay_block = T::BlockNumberProvider::current_block_number();121 let current_relay_block = T::OnInitializeBlockNumberProvider::current_block_number();122 let next_inflation: BlockNumberFor<T> = <NextInflationBlock<T>>::get();122 let next_inflation: BlockNumberFor<T> = <NextInflationBlock<T>>::get();123 add_weight(1, 0, Weight::from_parts(5_000_000, 0));123 add_weight(1, 0, Weight::from_parts(5_000_000, 0));124124runtime/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::AccountIdConversion;
+use sp_runtime::traits::{BlockNumberProvider, AccountIdConversion};
use up_common::{
constants::*,
types::{AccountId, Balance, BlockNumber},
@@ -105,12 +105,33 @@
pub const InflationBlockInterval: BlockNumber = 100; // every time per how many blocks inflation is applied
}
+/// Pallet-inflation needs block number in on_initialize, where there is no `validation_data` exists yet
+pub struct OnInitializeBlockNumberProvider;
+impl BlockNumberProvider for OnInitializeBlockNumberProvider {
+ type BlockNumber = BlockNumber;
+
+ fn current_block_number() -> Self::BlockNumber {
+ 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()
+
+ // ParachainSystem.LastRelayChainBlockNumber
+ let Some(encoded) = storage::get(&hex!("45323df7cc47150b3930e2666b0aa313a2bca190d36bd834cc73a38fc213ecbd")) else {
+ // First parachain block
+ return Default::default()
+ };
+ BlockNumber::decode(&mut encoded.as_ref()).expect("typeof(RelayBlockNumber) == typeof(BlockNumber) == u32; qed")
+ }
+}
+
/// Used for the pallet inflation
impl pallet_inflation::Config for Runtime {
type Currency = Balances;
type TreasuryAccountId = TreasuryAccountId;
type InflationBlockInterval = InflationBlockInterval;
- type BlockNumberProvider = RelayChainBlockNumberProvider<Runtime>;
+ type OnInitializeBlockNumberProvider = OnInitializeBlockNumberProvider;
}
impl pallet_unique::Config for Runtime {