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
before · pallets/configuration/Cargo.toml
1[package]2edition = "2021"3name = "pallet-configuration"4version = "0.2.0"56[dependencies]7# Note: `package = "parity-scale-codec"` must be supplied since the `Encode` macro searches for it.8codec = { workspace = true, package = "parity-scale-codec" }910fp-evm = { workspace = true }11frame-benchmarking = { workspace = true, optional = true }12frame-support = { workspace = true }13frame-system = { workspace = true }14scale-info = { workspace = true }15smallvec = { workspace = true }16sp-arithmetic = { workspace = true }17sp-core = { workspace = true }18sp-std = { workspace = true }19xcm = { workspace = true }2021[features]22default = ["std"]23runtime-benchmarks = ["frame-benchmarking"]24std = [25	"codec/std",26	"fp-evm/std",27	"frame-benchmarking/std",28	"frame-support/std",29	"frame-system/std",30	"sp-arithmetic/std",31	"sp-core/std",32	"sp-std/std",33]34try-runtime = ["frame-support/try-runtime"]
after · pallets/configuration/Cargo.toml
1[package]2edition = "2021"3name = "pallet-configuration"4version = "0.2.0"56[dependencies]7# Note: `package = "parity-scale-codec"` must be supplied since the `Encode` macro searches for it.8codec = { workspace = true, package = "parity-scale-codec" }910fp-evm = { workspace = true }11frame-benchmarking = { workspace = true, optional = true }12frame-support = { workspace = true }13frame-system = { workspace = true }14scale-info = { workspace = true }15smallvec = { workspace = true }16sp-arithmetic = { workspace = true }17sp-core = { workspace = true }18sp-std = { workspace = true }19sp-io = { workspace = true }20xcm = { workspace = true }2122hex-literal = { workspace = true }2324[features]25default = ["std"]26runtime-benchmarks = ["frame-benchmarking"]27std = [28	"codec/std",29	"fp-evm/std",30	"frame-benchmarking/std",31	"frame-support/std",32	"frame-system/std",33	"sp-arithmetic/std",34	"sp-core/std",35	"sp-std/std",36]37try-runtime = ["frame-support/try-runtime"]
modifiedpallets/configuration/src/lib.rsdiffbeforeafterboth
--- 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<T: Config>() {
+		let base_fee_per_gas: U256 = <MinGasPriceOverride<T>>::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<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
+		fn on_runtime_upgrade() -> Weight {
+			update_base_fee::<T>();
+			T::DbWeight::get().reads_writes(1, 2)
+		}
+	}
+
+	#[pallet::genesis_config]
+	pub struct GenesisConfig<T>(PhantomData<T>);
+
+	#[cfg(feature = "std")]
+	impl<T: Config> Default for GenesisConfig<T> {
+		fn default() -> Self {
+			Self(Default::default())
+		}
+	}
+
+	#[pallet::genesis_build]
+	impl<T: Config> GenesisBuild<T> for GenesisConfig<T> {
+		fn build(&self) {
+			update_base_fee::<T>();
+		}
+	}
+
 	#[pallet::error]
 	pub enum Error<T> {
 		InconsistentConfiguration,
@@ -178,6 +217,9 @@
 			} else {
 				<MinGasPriceOverride<T>>::kill();
 			}
+			// This code should not be called in production, but why keep development in the
+			// inconsistent state
+			update_base_fee::<T>();
 			Ok(())
 		}