git.delta.rocks / unique-network / refs/commits / f28d992941c5

difftreelog

feat update BaseFee storage from pallet-configuration

Yaroslav Bolyukin2023-06-16parent: #55ce0a6.patch.diff
in: master

2 files changed

modifiedpallets/configuration/Cargo.tomldiffbeforeafterboth
--- 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"]
modifiedpallets/configuration/src/lib.rsdiffbeforeafterboth
43mod pallet {43mod pallet {
44 use super::*;44 use super::*;
45 use frame_support::{45 use frame_support::{
46 traits::{Get},46 traits::Get,
47 pallet_prelude::{47 pallet_prelude::*,
48 StorageValue, ValueQuery, DispatchResult, IsType, Member, MaybeSerializeDeserialize,
49 },
50 log,48 log,
51 dispatch::{Codec, fmt::Debug},49 dispatch::{Codec, fmt::Debug},
52 };50 };
53 use frame_system::{pallet_prelude::OriginFor, ensure_root};51 use frame_system::{pallet_prelude::OriginFor, ensure_root, pallet_prelude::*};
54 use sp_arithmetic::{FixedPointOperand, traits::AtLeast32BitUnsigned};52 use sp_arithmetic::{FixedPointOperand, traits::AtLeast32BitUnsigned, Permill};
55 pub use crate::weights::WeightInfo;53 pub use crate::weights::WeightInfo;
5654
57 #[pallet::config]55 #[pallet::config]
108 },106 },
109 }107 }
108
109 fn update_base_fee<T: Config>() {
110 let base_fee_per_gas: U256 = <MinGasPriceOverride<T>>::get().into();
111 let elasticity: Permill = Permill::zero();
112 // twox_128(BaseFee) ++ twox_128(BaseFeePerGas)
113 sp_io::storage::set(
114 &hex_literal::hex!("c1fef3b7207c11a52df13c12884e77263864ade243c642793ebcfe9e16f454ca"),
115 &base_fee_per_gas.encode(),
116 );
117 // twox_128(BaseFee) ++ twox_128(Elasticity)
118 sp_io::storage::set(
119 &hex_literal::hex!("c1fef3b7207c11a52df13c12884e772609bc3a1e532c9cb85d57feed02cbff8e"),
120 &elasticity.encode(),
121 );
122 }
123
124 /// We update our default weights on every release
125 #[pallet::hooks]
126 impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
127 fn on_runtime_upgrade() -> Weight {
128 update_base_fee::<T>();
129 T::DbWeight::get().reads_writes(1, 2)
130 }
131 }
132
133 #[pallet::genesis_config]
134 pub struct GenesisConfig<T>(PhantomData<T>);
135
136 #[cfg(feature = "std")]
137 impl<T: Config> Default for GenesisConfig<T> {
138 fn default() -> Self {
139 Self(Default::default())
140 }
141 }
142
143 #[pallet::genesis_build]
144 impl<T: Config> GenesisBuild<T> for GenesisConfig<T> {
145 fn build(&self) {
146 update_base_fee::<T>();
147 }
148 }
110149
111 #[pallet::error]150 #[pallet::error]
112 pub enum Error<T> {151 pub enum Error<T> {
178 } else {217 } else {
179 <MinGasPriceOverride<T>>::kill();218 <MinGasPriceOverride<T>>::kill();
180 }219 }
220 // This code should not be called in production, but why keep development in the
221 // inconsistent state
222 update_base_fee::<T>();
181 Ok(())223 Ok(())
182 }224 }
183225