From 841e8bca9e48efcf2240b490d2837a5b1a0f0354 Mon Sep 17 00:00:00 2001 From: Steve Degosserie <723552+stiiifff@users.noreply.github.com> Date: Wed, 2 Apr 2025 19:14:23 +0200 Subject: [PATCH] =?UTF-8?q?feat(operator):=20=F0=9F=8F=97=EF=B8=8F=20Add?= =?UTF-8?q?=20Preimage=20pallet=20(#23)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Facundo Farall <37149322+ffarall@users.noreply.github.com> --- operator/Cargo.lock | 17 +++++++++++++++++ operator/Cargo.toml | 1 + operator/runtime/Cargo.toml | 5 ++++- operator/runtime/src/benchmarks.rs | 1 + operator/runtime/src/configs/mod.rs | 27 ++++++++++++++++++++++++++- operator/runtime/src/lib.rs | 3 +++ 6 files changed, 52 insertions(+), 2 deletions(-) diff --git a/operator/Cargo.lock b/operator/Cargo.lock index 7a943046..f72b6594 100644 --- a/operator/Cargo.lock +++ b/operator/Cargo.lock @@ -1609,6 +1609,7 @@ dependencies = [ "pallet-grandpa", "pallet-mmr", "pallet-multisig", + "pallet-preimage", "pallet-session", "pallet-sudo", "pallet-timestamp", @@ -5955,6 +5956,22 @@ dependencies = [ "sp-runtime", ] +[[package]] +name = "pallet-preimage" +version = "38.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?branch=stable2409#43d7b1e329f50a37cbd67e15aae70c60556cbb59" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-io", + "sp-runtime", +] + [[package]] name = "pallet-session" version = "38.0.0" diff --git a/operator/Cargo.toml b/operator/Cargo.toml index 204e5f2d..61c997af 100644 --- a/operator/Cargo.toml +++ b/operator/Cargo.toml @@ -86,6 +86,7 @@ pallet-babe = { git = "https://github.com/paritytech/polkadot-sdk", branch = "st pallet-balances = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2409", default-features = false } pallet-grandpa = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2409", default-features = false } pallet-multisig = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2409", default-features = false } +pallet-preimage = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2409", default-features = false } pallet-session = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2409", default-features = false } pallet-sudo = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2409", default-features = false } pallet-timestamp = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2409", default-features = false } diff --git a/operator/runtime/Cargo.toml b/operator/runtime/Cargo.toml index 85333e58..3e853cc8 100644 --- a/operator/runtime/Cargo.toml +++ b/operator/runtime/Cargo.toml @@ -27,6 +27,7 @@ pallet-babe.workspace = true pallet-balances.workspace = true pallet-grandpa.workspace = true pallet-multisig.workspace = true +pallet-preimage.workspace = true pallet-session.workspace = true pallet-sudo.workspace = true pallet-timestamp.workspace = true @@ -95,7 +96,7 @@ std = [ "pallet-grandpa/std", "pallet-multisig/std", "pallet-mmr/std", - "pallet-session/std", + "pallet-preimage/std", "pallet-session/std", "pallet-sudo/std", "pallet-timestamp/std", @@ -144,6 +145,7 @@ runtime-benchmarks = [ "pallet-balances/runtime-benchmarks", "pallet-grandpa/runtime-benchmarks", "pallet-multisig/runtime-benchmarks", + "pallet-preimage/runtime-benchmarks", "pallet-sudo/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", "pallet-utility/runtime-benchmarks", @@ -166,6 +168,7 @@ try-runtime = [ "pallet-balances/try-runtime", "pallet-grandpa/try-runtime", "pallet-multisig/try-runtime", + "pallet-preimage/try-runtime", "pallet-session/try-runtime", "pallet-sudo/try-runtime", "pallet-timestamp/try-runtime", diff --git a/operator/runtime/src/benchmarks.rs b/operator/runtime/src/benchmarks.rs index 1c7c5afc..71a6da76 100644 --- a/operator/runtime/src/benchmarks.rs +++ b/operator/runtime/src/benchmarks.rs @@ -27,6 +27,7 @@ frame_benchmarking::define_benchmarks!( [frame_benchmarking, BaselineBench::] [frame_system, SystemBench::] [pallet_balances, Balances] + [pallet_preimage, Preimage] [pallet_multisig, Multisig] [pallet_timestamp, Timestamp] [pallet_utility, Utility] diff --git a/operator/runtime/src/configs/mod.rs b/operator/runtime/src/configs/mod.rs index 4ee76ed4..d6baeee2 100644 --- a/operator/runtime/src/configs/mod.rs +++ b/operator/runtime/src/configs/mod.rs @@ -26,6 +26,9 @@ use crate::EvmChainId; use crate::OriginCaller; use crate::Timestamp; +use crate::STORAGE_BYTE_FEE; +use crate::SUPPLY_FACTOR; +use crate::UNIT; use crate::{Historical, SessionKeys, ValidatorSet}; // Local module imports @@ -38,6 +41,8 @@ use super::{ use codec::{Decode, Encode}; use datahaven_runtime_common::gas::WEIGHT_PER_GAS; use datahaven_runtime_common::time::{EpochDurationInBlocks, MILLISECS_PER_BLOCK, MINUTES}; +use frame_support::traits::fungible::HoldConsideration; +use frame_support::traits::LinearStoragePrice; use frame_support::{ derive_impl, parameter_types, traits::{ @@ -233,7 +238,27 @@ impl pallet_balances::Config for Runtime { type FreezeIdentifier = RuntimeFreezeReason; type MaxFreezes = VariantCountOf; type RuntimeHoldReason = RuntimeHoldReason; - type RuntimeFreezeReason = RuntimeHoldReason; + type RuntimeFreezeReason = RuntimeFreezeReason; +} + +parameter_types! { + pub const PreimageBaseDeposit: Balance = 5 * UNIT * SUPPLY_FACTOR ; + pub const PreimageByteDeposit: Balance = STORAGE_BYTE_FEE; + pub const PreimageHoldReason: RuntimeHoldReason = + RuntimeHoldReason::Preimage(pallet_preimage::HoldReason::Preimage); +} + +impl pallet_preimage::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Currency = Balances; + type ManagerOrigin = EnsureRoot; + type Consideration = HoldConsideration< + AccountId, + Balances, + PreimageHoldReason, + LinearStoragePrice, + >; + type WeightInfo = (); } parameter_types! { diff --git a/operator/runtime/src/lib.rs b/operator/runtime/src/lib.rs index 354f573d..3048c9d4 100644 --- a/operator/runtime/src/lib.rs +++ b/operator/runtime/src/lib.rs @@ -258,6 +258,9 @@ mod runtime { #[runtime::pallet_index(20)] pub type Utility = pallet_utility; + #[runtime::pallet_index(22)] + pub type Preimage = pallet_preimage; + #[runtime::pallet_index(24)] pub type Multisig = pallet_multisig;