Skip to content

Commit dff6b9a

Browse files
authored
add: pallet-scheduler in demo runtime (#1067)
1 parent 81f980a commit dff6b9a

File tree

6 files changed

+157
-6
lines changed

6 files changed

+157
-6
lines changed

Cargo.lock

Lines changed: 52 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,9 @@ substrate-frame-rpc-system = { default-features = false, git = "https://github.c
259259
substrate-prometheus-endpoint = { package = "substrate-prometheus-endpoint", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2509" }
260260
substrate-test-runtime-client = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2509" }
261261
substrate-wasm-builder = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2509" }
262+
pallet-scheduler = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2509" }
263+
pallet-preimage = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2509" }
264+
pallet-parameters = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2509" }
262265

263266
raw-scripts = { git = "https://github.com/input-output-hk/partner-chains-smart-contracts.git", tag = "v8.2.0" }
264267
# local dependencies

demo/node/src/staging.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use partner_chains_demo_runtime::{
66
RuntimeGenesisConfig, SessionCommitteeManagementConfig, SessionConfig, SidechainConfig,
77
SudoConfig, SystemConfig, TestHelperPalletConfig,
88
};
9-
use sc_service::ChainType;
9+
use sc_service::{ChainType, Properties};
1010
use sidechain_domain::*;
1111
use sp_core::bytes::from_hex;
1212
use sp_core::{ed25519, sr25519};
@@ -105,6 +105,13 @@ pub fn staging_config() -> Result<ChainSpec, envy::Error> {
105105
staging_endowed_accounts(),
106106
true,
107107
)?)
108+
.with_properties({
109+
let mut properties = Properties::new();
110+
properties.insert("tokenSymbol".into(), "UNIT".into());
111+
properties.insert("tokenDecimals".into(), 12.into());
112+
properties.insert("ss58Format".into(), 42.into());
113+
properties
114+
})
108115
.build())
109116
}
110117

demo/node/src/testnet.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use partner_chains_demo_runtime::{
55
RuntimeGenesisConfig, SessionCommitteeManagementConfig, SessionConfig, SidechainConfig,
66
SudoConfig, SystemConfig, TestHelperPalletConfig,
77
};
8-
use sc_service::ChainType;
8+
use sc_service::{ChainType, Properties};
99
use sidechain_domain::*;
1010
use sidechain_slots::SlotsPerEpoch;
1111
use sp_core::bytes::from_hex;
@@ -61,6 +61,13 @@ pub fn development_config() -> Result<ChainSpec, envy::Error> {
6161
],
6262
true,
6363
)?)
64+
.with_properties({
65+
let mut properties = Properties::new();
66+
properties.insert("tokenSymbol".into(), "UNIT".into());
67+
properties.insert("tokenDecimals".into(), 12.into());
68+
properties.insert("ss58Format".into(), 42.into());
69+
properties
70+
})
6471
.build())
6572
}
6673

@@ -156,6 +163,13 @@ pub fn local_testnet_config() -> Result<ChainSpec, envy::Error> {
156163
testnet_endowed_accounts(),
157164
true,
158165
)?)
166+
.with_properties({
167+
let mut properties = Properties::new();
168+
properties.insert("tokenSymbol".into(), "UNIT".into());
169+
properties.insert("tokenDecimals".into(), 12.into());
170+
properties.insert("ss58Format".into(), 42.into());
171+
properties
172+
})
159173
.build())
160174
}
161175

demo/runtime/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ sp-storage = { workspace = true }
5757
sp-weights = { workspace = true }
5858
authority-selection-inherents = { workspace = true }
5959

60+
pallet-scheduler = { workspace = true }
61+
pallet-preimage = { workspace = true }
62+
pallet-parameters = { workspace = true }
63+
6064
hex-literal = { workspace = true }
6165

6266
# Used for the node template's RPCs

demo/runtime/src/lib.rs

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ use authority_selection_inherents::{
1515
AuthoritySelectionInputs, CommitteeMember, PermissionedCandidateDataError,
1616
RegistrationDataError, StakeError, select_authorities, validate_permissioned_candidate_data,
1717
};
18+
use frame_support::dynamic_params::{dynamic_pallet_params, dynamic_params};
1819
use frame_support::genesis_builder_helper::{build_state, get_preset};
1920
use frame_support::inherent::ProvideInherent;
21+
use frame_support::traits::LinearStoragePrice;
22+
use frame_support::traits::fungible::HoldConsideration;
2023
use frame_support::weights::constants::RocksDbWeight as RuntimeDbWeight;
2124
use frame_support::{
2225
BoundedVec, construct_runtime, parameter_types,
@@ -294,6 +297,10 @@ impl pallet_timestamp::Config for Runtime {
294297

295298
/// Existential deposit.
296299
pub const EXISTENTIAL_DEPOSIT: u128 = 500;
300+
pub const UNITS: Balance = 1_000_000_000_000;
301+
pub const fn deposit(items: u32, bytes: u32) -> Balance {
302+
items as Balance * UNITS + (bytes as Balance) * UNITS / 10
303+
}
297304

298305
impl pallet_balances::Config for Runtime {
299306
type MaxLocks = ConstU32<50>;
@@ -648,6 +655,71 @@ impl pallet_partner_chains_bridge::Config for Runtime {
648655
type BenchmarkHelper = ();
649656
}
650657

658+
impl pallet_parameters::Config for Runtime {
659+
type RuntimeEvent = RuntimeEvent;
660+
type RuntimeParameters = RuntimeParameters;
661+
type AdminOrigin = EnsureRoot<AccountId>;
662+
type WeightInfo = ();
663+
}
664+
665+
parameter_types! {
666+
pub MaximumSchedulerWeight: Weight = Perbill::from_percent(80) *
667+
BlockWeights::get().max_block;
668+
pub const MaxScheduledPerBlock: u32 = 50;
669+
}
670+
671+
impl pallet_scheduler::Config for Runtime {
672+
type RuntimeOrigin = RuntimeOrigin;
673+
type RuntimeEvent = RuntimeEvent;
674+
type PalletsOrigin = OriginCaller;
675+
type RuntimeCall = RuntimeCall;
676+
type MaximumWeight = MaximumSchedulerWeight;
677+
type ScheduleOrigin = EnsureRoot<AccountId>;
678+
type MaxScheduledPerBlock = MaxScheduledPerBlock;
679+
type WeightInfo = ();
680+
type OriginPrivilegeCmp = frame_support::traits::EqualPrivilegeOnly;
681+
type Preimages = Preimage;
682+
type BlockNumberProvider = frame_system::Pallet<Runtime>;
683+
}
684+
685+
parameter_types! {
686+
pub const PreimageHoldReason: RuntimeHoldReason = RuntimeHoldReason::Preimage(pallet_preimage::HoldReason::Preimage);
687+
}
688+
689+
impl pallet_preimage::Config for Runtime {
690+
type WeightInfo = ();
691+
type RuntimeEvent = RuntimeEvent;
692+
type Currency = Balances;
693+
type ManagerOrigin = EnsureRoot<AccountId>;
694+
type Consideration = HoldConsideration<
695+
AccountId,
696+
Balances,
697+
PreimageHoldReason,
698+
LinearStoragePrice<
699+
dynamic_params::preimage::BaseDeposit,
700+
dynamic_params::preimage::ByteDeposit,
701+
Balance,
702+
>,
703+
>;
704+
}
705+
706+
#[dynamic_params(RuntimeParameters, pallet_parameters::Parameters::<Runtime>)]
707+
pub mod dynamic_params {
708+
use super::*;
709+
710+
#[dynamic_pallet_params]
711+
#[codec(index = 0)]
712+
pub mod preimage {
713+
use super::*;
714+
715+
#[codec(index = 0)]
716+
pub static BaseDeposit: Balance = deposit(2, 64);
717+
718+
#[codec(index = 1)]
719+
pub static ByteDeposit: Balance = deposit(0, 1);
720+
}
721+
}
722+
651723
// Create the runtime by composing the FRAME pallets that were previously configured.
652724
construct_runtime!(
653725
pub struct Runtime {
@@ -674,6 +746,9 @@ construct_runtime!(
674746
Session: pallet_session exclude_parts { Call },
675747
GovernedMap: pallet_governed_map,
676748
Bridge: pallet_partner_chains_bridge,
749+
Parameters: pallet_parameters,
750+
Preimage: pallet_preimage,
751+
Scheduler: pallet_scheduler,
677752
TestHelperPallet: crate::test_helper_pallet,
678753
}
679754
);

0 commit comments

Comments
 (0)