--- a/pallets/configuration/Cargo.toml +++ b/pallets/configuration/Cargo.toml @@ -16,8 +16,11 @@ sp-arithmetic = { workspace = true } sp-core = { workspace = true } sp-std = { workspace = true } +sp-io = { workspace = true } xcm = { workspace = true } +hex-literal = { workspace = true } + [features] default = ["std"] runtime-benchmarks = ["frame-benchmarking"] --- a/pallets/configuration/src/lib.rs +++ b/pallets/configuration/src/lib.rs @@ -43,15 +43,13 @@ mod pallet { use super::*; use frame_support::{ - traits::{Get}, - pallet_prelude::{ - StorageValue, ValueQuery, DispatchResult, IsType, Member, MaybeSerializeDeserialize, - }, + traits::Get, + pallet_prelude::*, log, dispatch::{Codec, fmt::Debug}, }; - use frame_system::{pallet_prelude::OriginFor, ensure_root}; - use sp_arithmetic::{FixedPointOperand, traits::AtLeast32BitUnsigned}; + use frame_system::{pallet_prelude::OriginFor, ensure_root, pallet_prelude::*}; + use sp_arithmetic::{FixedPointOperand, traits::AtLeast32BitUnsigned, Permill}; pub use crate::weights::WeightInfo; #[pallet::config] @@ -108,6 +106,47 @@ }, } + fn update_base_fee() { + let base_fee_per_gas: U256 = >::get().into(); + let elasticity: Permill = Permill::zero(); + // twox_128(BaseFee) ++ twox_128(BaseFeePerGas) + sp_io::storage::set( + &hex_literal::hex!("c1fef3b7207c11a52df13c12884e77263864ade243c642793ebcfe9e16f454ca"), + &base_fee_per_gas.encode(), + ); + // twox_128(BaseFee) ++ twox_128(Elasticity) + sp_io::storage::set( + &hex_literal::hex!("c1fef3b7207c11a52df13c12884e772609bc3a1e532c9cb85d57feed02cbff8e"), + &elasticity.encode(), + ); + } + + /// We update our default weights on every release + #[pallet::hooks] + impl Hooks> for Pallet { + fn on_runtime_upgrade() -> Weight { + update_base_fee::(); + T::DbWeight::get().reads_writes(1, 2) + } + } + + #[pallet::genesis_config] + pub struct GenesisConfig(PhantomData); + + #[cfg(feature = "std")] + impl Default for GenesisConfig { + fn default() -> Self { + Self(Default::default()) + } + } + + #[pallet::genesis_build] + impl GenesisBuild for GenesisConfig { + fn build(&self) { + update_base_fee::(); + } + } + #[pallet::error] pub enum Error { InconsistentConfiguration, @@ -178,6 +217,9 @@ } else { >::kill(); } + // This code should not be called in production, but why keep development in the + // inconsistent state + update_base_fee::(); Ok(()) }