Skip to content

Commit

Permalink
Merge pull request #294 from jurteam/staging
Browse files Browse the repository at this point in the history
Staging -> Main
  • Loading branch information
Polkaverse authored Apr 3, 2024
2 parents fca27dd + 56bf5ca commit d3e128b
Show file tree
Hide file tree
Showing 3 changed files with 341 additions and 4 deletions.
4 changes: 3 additions & 1 deletion runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pallet-treasury = { version = "4.0.0-dev", default-features = false, git = "http
pallet-authorship = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" }
pallet-insecure-randomness-collective-flip = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" }
pallet-utility = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" }
pallet-session = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", default-features = false, branch = "release-polkadot-v1.2.0", features = ["historical"] }

frame-executive = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" }
sp-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" }
Expand Down Expand Up @@ -114,7 +115,8 @@ std = [
"pallet-treasury/std",
"pallet-authorship/std",
"pallet-insecure-randomness-collective-flip/std",
"sp-storage/std"
"sp-storage/std",
"pallet-session/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
Expand Down
58 changes: 55 additions & 3 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#[cfg(feature = "std")]
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));

mod validator_manager;

use frame_support::{
genesis_builder_helper::{build_config, create_default_config},
pallet_prelude::DispatchClass,
Expand All @@ -17,12 +19,16 @@ use frame_system::{
};
use hex_literal::hex;
use pallet_grandpa::AuthorityId as GrandpaId;
use pallet_session::historical as session_historical;
use sp_api::impl_runtime_apis;
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
traits::{AccountIdLookup, BlakeTwo256, Block as BlockT, IdentifyAccount, NumberFor, Verify},
traits::{
AccountIdLookup, BlakeTwo256, Block as BlockT, IdentifyAccount, NumberFor, OpaqueKeys,
Verify,
},
transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult, MultiSignature,
};
Expand Down Expand Up @@ -106,6 +112,8 @@ pub const MILLICENTS: Balance = 1_000_000_000;
pub const CENTS: Balance = 1_000 * MILLICENTS; // assume this is worth about a cent.
pub const DOLLARS: Balance = 100 * CENTS;

pub const DEFAULT_SESSION_PERIOD: u32 = 600;

pub const fn deposit(items: u32, bytes: u32) -> Balance {
items as Balance * 15 * CENTS + (bytes as Balance) * 6 * CENTS
}
Expand All @@ -122,7 +130,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
// `spec_version`, and `authoring_version` are the same between Wasm and native.
// This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use
// the compatible custom types.
spec_version: 129,
spec_version: 130,
impl_version: 1,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down Expand Up @@ -265,6 +273,43 @@ impl pallet_grandpa::Config for Runtime {
type EquivocationReportSystem = ();
}

parameter_types! {
pub const Offset: u32 = 0;
pub const SessionPeriod: u32 = DEFAULT_SESSION_PERIOD;
}

/// Special `ValidatorIdOf` implementation that is just returning the input as result.
pub struct ValidatorIdOf;
impl sp_runtime::traits::Convert<AccountId, Option<AccountId>> for ValidatorIdOf {
fn convert(a: AccountId) -> Option<AccountId> {
Some(a)
}
}

impl pallet_session::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type ValidatorId = <Self as frame_system::Config>::AccountId;
type ValidatorIdOf = ValidatorIdOf;
type ShouldEndSession = pallet_session::PeriodicSessions<SessionPeriod, Offset>;
type NextSessionRotation = pallet_session::PeriodicSessions<SessionPeriod, Offset>;
type SessionManager = pallet_session::historical::NoteHistoricalRoot<Self, ValidatorManager>;
type SessionHandler = <opaque::SessionKeys as OpaqueKeys>::KeyTypeIdProviders;
type Keys = opaque::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(Default::default())
}
}

impl pallet_session::historical::Config for Runtime {
type FullIdentification = ();
type FullIdentificationOf = FullIdentificationOf;
}

impl pallet_timestamp::Config for Runtime {
/// A timestamp: milliseconds since the unix epoch.
type Moment = u64;
Expand Down Expand Up @@ -332,6 +377,11 @@ impl pallet_transaction_payment::Config for Runtime {
type FeeMultiplierUpdate = ();
}

impl validator_manager::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type PrivilegedOrigin = EnsureRoot<AccountId>;
}

impl pallet_sudo::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type RuntimeCall = RuntimeCall;
Expand Down Expand Up @@ -589,7 +639,10 @@ construct_runtime!(
Assets: pallet_assets,
TransactionPayment: pallet_transaction_payment,
Sudo: pallet_sudo,
Historical: session_historical,
Session: pallet_session,
// Local Pallet
ValidatorManager: validator_manager,
TokenSwap: pallet_token_swap,
Community: pallet_community,
Proposal: pallet_proposal,
Expand All @@ -601,7 +654,6 @@ construct_runtime!(
Authorship: pallet_authorship,
Treasury: pallet_treasury,
Utility: pallet_utility,

Multisig: pallet_multisig::{Pallet, Call, Storage, Event<T>},
RandomnessCollectiveFlip: pallet_insecure_randomness_collective_flip,
}
Expand Down
Loading

0 comments on commit d3e128b

Please sign in to comment.