Skip to content

Commit

Permalink
runtime: enable staking on mainnet (#1479)
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianFranzen authored Feb 5, 2025
1 parent b66a88f commit b2add7f
Show file tree
Hide file tree
Showing 17 changed files with 472 additions and 536 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 2 additions & 16 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,7 @@ impl Default for GenesisKeysConfig {
use AccountKeyring::*;

GenesisKeysConfig {
admins: vec![
Alice.into(),
Bob.into(),
Charlie.into(),
Dave.into(),
Eve.into(),
Ferdie.into(),
],
admins: vec![Eve.into(), Ferdie.into()],
bootstraps: vec![(
Alice.to_raw_public().unchecked_into(),
Ed25519Keyring::Alice.to_raw_public().unchecked_into(),
Expand All @@ -98,14 +91,7 @@ impl Default for GenesisKeysConfig {
// TODO: Would be better to assign individual controllers
controller: None,
endowments: vec![],
stakes: vec![
AliceStash.into(),
BobStash.into(),
CharlieStash.into(),
DaveStash.into(),
EveStash.into(),
FerdieStash.into(),
],
stakes: vec![Alice.into(), Bob.into(), Charlie.into(), Dave.into()],
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions node/src/chains/internal.keys.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"admins": [
"an65ZUosuFfPTLJ6jRiotRwEBWxfjE3ZA3rN9khAEuEBbP1vN",
"an9CbHiXeALyA5pDGQNfJ8YKF5k8eW5YTHWRsn8ZBEH8tano9",
"an5jsJBqi2whFgKyZqBcgS7iY7qjvG1DGVuQsaVcGZaVu7uio"
"an9CbHiXeALyA5pDGQNfJ8YKF5k8eW5YTHWRsn8ZBEH8tano9"
],
"bootstraps": [
[
Expand Down
16 changes: 7 additions & 9 deletions pallets/governance/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,31 @@ pub mod pallet {

use polkadot_sdk::pallet_balances;
use polkadot_sdk::{frame_support, frame_system};
//use polkadot_sdk::{pallet_staking, sp_runtime};
use polkadot_sdk::{pallet_staking, sp_runtime};

use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;

// Additional custom imports
use frame_system::{RawOrigin, WeightInfo as SystemWeights};

//use pallet_staking::{ConfigOp, WeightInfo as StakingWeights};
//use sp_runtime::{Perbill, Percent};
use pallet_staking::{ConfigOp, WeightInfo as StakingWeights};
use sp_runtime::{Perbill, Percent};

// Useful coupling shorthands
//type CurrencyBalanceOf<T> = <T as pallet_staking::Config>::CurrencyBalance;
type CurrencyBalanceOf<T> = <T as pallet_staking::Config>::CurrencyBalance;

#[pallet::pallet]
pub struct Pallet<T>(_);

#[pallet::config]
pub trait Config: polkadot_sdk::frame_system::Config + pallet_balances::Config
//+ pallet_staking::Config
pub trait Config:
polkadot_sdk::frame_system::Config + pallet_balances::Config + pallet_staking::Config
{
/// Allowed origin for system calls
type SystemAdmin: EnsureOrigin<Self::RuntimeOrigin>;
// Allowed origin for staking calls
//type StakingAdmin: EnsureOrigin<Self::RuntimeOrigin>;
type StakingAdmin: EnsureOrigin<Self::RuntimeOrigin>;
}

#[pallet::call]
Expand All @@ -61,7 +61,6 @@ pub mod pallet {
frame_system::Pallet::<T>::authorize_upgrade(RawOrigin::Root.into(), code_hash)
}

/*
// Wrapper around staking pallet calls
#[pallet::call_index(1)]
#[pallet::weight(<T as pallet_staking::Config>::WeightInfo::set_validator_count())]
Expand Down Expand Up @@ -101,6 +100,5 @@ pub mod pallet {
max_staked_rewards,
)
}
*/
}
}
2 changes: 1 addition & 1 deletion pallets/governance/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl pallet_staking::Config for Test {

impl pallet_governance::Config for Test {
type SystemAdmin = EnsureSignedBy<SystemAdmin, AccountId>;
//type StakingAdmin = EnsureSignedBy<StakingAdmin, AccountId>;
type StakingAdmin = EnsureSignedBy<StakingAdmin, AccountId>;
}

// Build genesis storage according to the mock runtime.
Expand Down
2 changes: 1 addition & 1 deletion primitives/src/currency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ pub const NANOANLOG: Balance = MICROANLOG / 1000; // 10^3
pub const TOCK: Balance = NANOANLOG / 1000; // 1

/// Total issuance at genesis
pub const TOTAL_ISSUANCE: Balance = 90_570_710 * ANLOG;
pub const TOTAL_ISSUANCE: Balance = 90_570_710_000 * ANLOG;
4 changes: 4 additions & 0 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ separator = "0.4.1"
[dependencies]
log = { workspace = true }

hex-literal = "0.4.1"
smallvec = "1.8.0"

scale-codec = { workspace = true, features = [ "max-encoded-len" ] }
Expand Down Expand Up @@ -48,11 +49,13 @@ polkadot-sdk = { workspace = true, features = [
"pallet-child-bounties",
"pallet-collective",
"pallet-election-provider-multi-phase",
"pallet-delegated-staking",
"pallet-grandpa",
"pallet-identity",
"pallet-im-online",
"pallet-membership",
"pallet-multisig",
"pallet-nomination-pools",
"pallet-offences",
"pallet-preimage",
"pallet-proxy",
Expand Down Expand Up @@ -151,6 +154,7 @@ runtime-benchmarks = [
"polkadot-sdk/frame-benchmarking",
"polkadot-sdk/frame-system-benchmarking",
"polkadot-sdk/pallet-election-provider-support-benchmarking",
"polkadot-sdk/pallet-nomination-pools-benchmarking",
"polkadot-sdk/pallet-offences-benchmarking",
"polkadot-sdk/pallet-session-benchmarking",

Expand Down
3 changes: 3 additions & 0 deletions runtime/src/apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ impl_runtime_apis! {
// issues. To get around that, we separated the Session benchmarks into its own crate,
// which is why we need these two lines below.
use pallet_session_benchmarking::Pallet as SessionBench;
use pallet_nomination_pools_benchmarking::Pallet as NominationPoolsBench;
use pallet_offences_benchmarking::Pallet as OffencesBench;
use pallet_election_provider_support_benchmarking::Pallet as EPSBench;
use frame_system_benchmarking::Pallet as SystemBench;
Expand All @@ -419,12 +420,14 @@ impl_runtime_apis! {
// issues. To get around that, we separated the Session benchmarks into its own crate,
// which is why we need these two lines below.
use pallet_session_benchmarking::Pallet as SessionBench;
use pallet_nomination_pools_benchmarking::Pallet as NominationPoolsBench;
use pallet_offences_benchmarking::Pallet as OffencesBench;
use pallet_election_provider_support_benchmarking::Pallet as EPSBench;
use frame_system_benchmarking::Pallet as SystemBench;
use baseline::Pallet as BaselineBench;

impl pallet_session_benchmarking::Config for Runtime {}
impl pallet_nomination_pools_benchmarking::Config for Runtime {}
impl pallet_offences_benchmarking::Config for Runtime {}
impl pallet_election_provider_support_benchmarking::Config for Runtime {}
impl frame_system_benchmarking::Config for Runtime {}
Expand Down
1 change: 1 addition & 0 deletions runtime/src/benches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ polkadot_sdk::frame_benchmarking::define_benchmarks!(
[pallet_members, Members]
[pallet_multisig, Multisig]
[pallet_networks, Networks]
[pallet_nomination_pools, NominationPoolsBench::<Runtime>]
[pallet_offences, OffencesBench::<Runtime>]
[pallet_preimage, Preimage]
[pallet_proxy, Proxy]
Expand Down
48 changes: 1 addition & 47 deletions runtime/src/configs/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,20 @@ use frame_support::parameter_types;
use sp_runtime::{impl_opaque_keys, traits::OpaqueKeys, transaction_validity::TransactionPriority};

// Local module imports
#[cfg(not(feature = "testnet"))]
use crate::ValidatorManager;
use crate::{
weights, AccountId, AuthorityDiscovery, Babe, BondingDuration, EpochDuration,
ExpectedBlockTime, Grandpa, Historical, ImOnline, MaxAuthorities, MaxNominators, Runtime,
RuntimeEvent, SessionsPerEra,
};
#[cfg(feature = "testnet")]
use crate::{Balance, Offences, Session, Staking};
#[cfg(feature = "testnet")]
use frame_support::traits::KeyOwnerProofSystem;
#[cfg(feature = "testnet")]
use sp_core::crypto::KeyTypeId;

/// ## <a id="config.Authorship">`Authorship` Config</a>
///
/// Tracks block authorship
impl pallet_authorship::Config for Runtime {
type FindAuthor = pallet_session::FindAccountFromAuthorIndex<Self, Babe>;
#[cfg(not(feature = "testnet"))]
type EventHandler = ImOnline;
#[cfg(feature = "testnet")]
type EventHandler = (Staking, ImOnline);
}

Expand All @@ -51,44 +43,24 @@ impl<T> sp_runtime::traits::Convert<T, Option<T>> for IdentityValidator {
}
}

/// ## <a id="config.Session">`Session`] Config</a>
/// ## <a id="config.Session">[`Session`] Config</a>
///
/// Tracks session keys
impl pallet_session::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type ValidatorId = AccountId;
#[cfg(not(feature = "testnet"))]
type ValidatorIdOf = IdentityValidator;
#[cfg(feature = "testnet")]
type ValidatorIdOf = pallet_staking::StashOf<Self>;
type ShouldEndSession = Babe;
type NextSessionRotation = Babe;
#[cfg(not(feature = "testnet"))]
type SessionManager = pallet_session::historical::NoteHistoricalRoot<Self, ValidatorManager>;
#[cfg(feature = "testnet")]
type SessionManager = pallet_session::historical::NoteHistoricalRoot<Self, Staking>;
type SessionHandler = <SessionKeys as OpaqueKeys>::KeyTypeIdProviders;
type Keys = SessionKeys;
type WeightInfo = pallet_session::weights::SubstrateWeight<Runtime>;
}

pub struct FullIdentificationOf;
impl sp_runtime::traits::Convert<AccountId, Option<()>> for FullIdentificationOf {
fn convert(_: AccountId) -> Option<()> {
Some(())
}
}

/// ## <a id="config.Historical">[`Historical`] Config</a>
///
/// Tracks historical session
#[cfg(not(feature = "testnet"))]
impl pallet_session::historical::Config for Runtime {
type FullIdentification = ();
type FullIdentificationOf = FullIdentificationOf;
}

#[cfg(feature = "testnet")]
impl pallet_session::historical::Config for Runtime {
type FullIdentification = pallet_staking::Exposure<AccountId, Balance>;
type FullIdentificationOf = pallet_staking::ExposureOf<Runtime>;
Expand All @@ -110,21 +82,12 @@ impl pallet_babe::Config for Runtime {
type EpochDuration = EpochDuration;
type ExpectedBlockTime = ExpectedBlockTime;
type EpochChangeTrigger = pallet_babe::ExternalTrigger;
#[cfg(not(feature = "testnet"))]
type DisabledValidators = ();
#[cfg(feature = "testnet")]
type DisabledValidators = Session;
type WeightInfo = ();
type MaxAuthorities = MaxAuthorities;
type MaxNominators = MaxNominators;
#[cfg(not(feature = "testnet"))]
type KeyOwnerProof = sp_core::Void;
#[cfg(feature = "testnet")]
type KeyOwnerProof =
<Historical as KeyOwnerProofSystem<(KeyTypeId, pallet_babe::AuthorityId)>>::Proof;
#[cfg(not(feature = "testnet"))]
type EquivocationReportSystem = ();
#[cfg(feature = "testnet")]
type EquivocationReportSystem =
pallet_babe::EquivocationReportSystem<Self, Offences, Historical, ReportLongevity>;
}
Expand All @@ -142,14 +105,8 @@ impl pallet_grandpa::Config for Runtime {
type MaxAuthorities = MaxAuthorities;
type MaxNominators = MaxNominators;
type MaxSetIdSessionEntries = MaxSetIdSessionEntries;
#[cfg(not(feature = "testnet"))]
type KeyOwnerProof = sp_core::Void;
#[cfg(feature = "testnet")]
type KeyOwnerProof =
<Historical as KeyOwnerProofSystem<(KeyTypeId, sp_consensus_grandpa::AuthorityId)>>::Proof;
#[cfg(not(feature = "testnet"))]
type EquivocationReportSystem = ();
#[cfg(feature = "testnet")]
type EquivocationReportSystem =
pallet_grandpa::EquivocationReportSystem<Self, Offences, Historical, ReportLongevity>;
}
Expand All @@ -169,9 +126,6 @@ impl pallet_im_online::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type NextSessionRotation = Babe;
type ValidatorSet = Historical;
#[cfg(not(feature = "testnet"))]
type ReportUnresponsiveness = ();
#[cfg(feature = "testnet")]
type ReportUnresponsiveness = Offences;
type UnsignedPriority = ImOnlineUnsignedPriority;
type WeightInfo = weights::pallet_im_online::WeightInfo<Runtime>;
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/configs/funding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ parameter_types! {
pub const TipFindersFee: Percent = Percent::from_percent(20);
pub const TipReportDepositBase: Balance = 1 * ANLOG;
pub const DataDepositPerByte: Balance = deposit(0,1);
pub const TreasuryPalletId: PalletId = PalletId(*b"py/trsry");
pub const TreasuryPalletId: PalletId = PalletId(*b"timetrsy");
pub const MaximumReasonLength: u32 = 300;
pub const MaxApprovals: u32 = 100;
pub const MaxBalance: Balance = Balance::MAX;
Expand Down
10 changes: 2 additions & 8 deletions runtime/src/configs/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,19 +132,13 @@ impl pallet_governance::Config for Runtime {
/// Default admin origin for system related governance
type SystemAdmin = EnsureRootOrHalfTechnical;
// Default admin origin for staking related governance
//type StakingAdmin = EnsureRootOrHalfTechnical;
type StakingAdmin = EnsureRootOrHalfTechnical;
}

#[cfg(feature = "testnet")]
impl pallet_governance::Config for Runtime {
/// Development admin origin for all system calls
type SystemAdmin = EnsureRootOrTechnicalMember;
// Development admin origin for all staking calls
//type StakingAdmin = EnsureRootOrTechnicalMember;
}

#[cfg(not(feature = "testnet"))]
impl pallet_validators::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type PrivilegedOrigin = EnsureRootOrHalfTechnical;
type StakingAdmin = EnsureRootOrTechnicalMember;
}
1 change: 0 additions & 1 deletion runtime/src/configs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ pub mod funding;
pub mod governance;
#[cfg(feature = "testnet")]
pub mod services;
#[cfg(feature = "testnet")]
pub mod staking;
pub mod tokenomics;
pub mod utilities;
Expand Down
Loading

0 comments on commit b2add7f

Please sign in to comment.