feat(operator): 🏗️ Add Scheduler pallet (#24)

This commit is contained in:
Steve Degosserie 2025-04-02 21:28:30 +02:00 committed by GitHub
parent 8e05572222
commit 313ec724d8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 58 additions and 19 deletions

18
operator/Cargo.lock generated
View file

@ -1610,6 +1610,7 @@ dependencies = [
"pallet-mmr",
"pallet-multisig",
"pallet-preimage",
"pallet-scheduler",
"pallet-session",
"pallet-sudo",
"pallet-timestamp",
@ -5972,6 +5973,23 @@ dependencies = [
"sp-runtime",
]
[[package]]
name = "pallet-scheduler"
version = "39.0.0"
source = "git+https://github.com/paritytech/polkadot-sdk?branch=stable2409#43d7b1e329f50a37cbd67e15aae70c60556cbb59"
dependencies = [
"docify",
"frame-benchmarking",
"frame-support",
"frame-system",
"log",
"parity-scale-codec",
"scale-info",
"sp-io",
"sp-runtime",
"sp-weights",
]
[[package]]
name = "pallet-session"
version = "38.0.0"

View file

@ -87,6 +87,7 @@ pallet-balances = { git = "https://github.com/paritytech/polkadot-sdk", branch =
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-scheduler = { 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 }

View file

@ -28,6 +28,7 @@ pallet-balances.workspace = true
pallet-grandpa.workspace = true
pallet-multisig.workspace = true
pallet-preimage.workspace = true
pallet-scheduler.workspace = true
pallet-session.workspace = true
pallet-sudo.workspace = true
pallet-timestamp.workspace = true
@ -97,6 +98,7 @@ std = [
"pallet-multisig/std",
"pallet-mmr/std",
"pallet-preimage/std",
"pallet-scheduler/std",
"pallet-session/std",
"pallet-sudo/std",
"pallet-timestamp/std",
@ -146,6 +148,7 @@ runtime-benchmarks = [
"pallet-grandpa/runtime-benchmarks",
"pallet-multisig/runtime-benchmarks",
"pallet-preimage/runtime-benchmarks",
"pallet-scheduler/runtime-benchmarks",
"pallet-sudo/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
"pallet-utility/runtime-benchmarks",
@ -169,6 +172,7 @@ try-runtime = [
"pallet-grandpa/try-runtime",
"pallet-multisig/try-runtime",
"pallet-preimage/try-runtime",
"pallet-scheduler/try-runtime",
"pallet-session/try-runtime",
"pallet-sudo/try-runtime",
"pallet-timestamp/try-runtime",

View file

@ -27,8 +27,9 @@ frame_benchmarking::define_benchmarks!(
[frame_benchmarking, BaselineBench::<Runtime>]
[frame_system, SystemBench::<Runtime>]
[pallet_balances, Balances]
[pallet_preimage, Preimage]
[pallet_multisig, Multisig]
[pallet_preimage, Preimage]
[pallet_scheduler, Scheduler]
[pallet_timestamp, Timestamp]
[pallet_utility, Utility]
[pallet_sudo, Sudo]

View file

@ -23,32 +23,26 @@
//
// For more information, please refer to <http://unlicense.org>
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
use super::{
deposit, AccountId, Babe, Balance, Balances, BeefyMmrLeaf, Block, BlockNumber, Hash, Nonce,
PalletInfo, Runtime, RuntimeCall, RuntimeEvent, RuntimeFreezeReason, RuntimeHoldReason,
RuntimeOrigin, RuntimeTask, Session, System, EXISTENTIAL_DEPOSIT, SLOT_DURATION, VERSION,
deposit, AccountId, Babe, Balance, Balances, BeefyMmrLeaf, Block, BlockNumber, EvmChainId,
Hash, Historical, Nonce, OriginCaller, PalletInfo, Preimage, Runtime, RuntimeCall,
RuntimeEvent, RuntimeFreezeReason, RuntimeHoldReason, RuntimeOrigin, RuntimeTask, Session,
SessionKeys, System, Timestamp, ValidatorSet, EXISTENTIAL_DEPOSIT, SLOT_DURATION,
STORAGE_BYTE_FEE, SUPPLY_FACTOR, UNIT, VERSION,
};
// Substrate and Polkadot dependencies
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 datahaven_runtime_common::{
gas::WEIGHT_PER_GAS,
time::{EpochDurationInBlocks, MILLISECS_PER_BLOCK, MINUTES},
};
use frame_support::{
derive_impl, parameter_types,
traits::{
fungible::{Balanced, Credit, Inspect},
ConstU128, ConstU32, ConstU64, ConstU8, FindAuthor, KeyOwnerProofSystem, OnUnbalanced,
VariantCountOf,
fungible::{Balanced, Credit, HoldConsideration, Inspect},
ConstU128, ConstU32, ConstU64, ConstU8, EqualPrivilegeOnly, FindAuthor,
KeyOwnerProofSystem, LinearStoragePrice, OnUnbalanced, VariantCountOf,
},
weights::{
constants::{RocksDbWeight, WEIGHT_REF_TIME_PER_SECOND},
@ -279,6 +273,24 @@ impl pallet_multisig::Config for Runtime {
type WeightInfo = ();
}
parameter_types! {
pub MaximumSchedulerWeight: Weight = NORMAL_DISPATCH_RATIO * RuntimeBlockWeights::get().max_block;
pub const NoPreimagePostponement: Option<u32> = Some(10);
}
impl pallet_scheduler::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type RuntimeOrigin = RuntimeOrigin;
type PalletsOrigin = OriginCaller;
type RuntimeCall = RuntimeCall;
type MaximumWeight = MaximumSchedulerWeight;
type ScheduleOrigin = EnsureRoot<AccountId>;
type MaxScheduledPerBlock = ConstU32<50>;
type OriginPrivilegeCmp = EqualPrivilegeOnly;
type Preimages = Preimage;
type WeightInfo = ();
}
impl pallet_validator_set::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type AddRemoveOrigin = EnsureRoot<AccountId>;

View file

@ -258,6 +258,9 @@ mod runtime {
#[runtime::pallet_index(20)]
pub type Utility = pallet_utility;
#[runtime::pallet_index(21)]
pub type Scheduler = pallet_scheduler;
#[runtime::pallet_index(22)]
pub type Preimage = pallet_preimage;