Skip to content

Commit

Permalink
feat: Finish splitting Runtime config (#440)
Browse files Browse the repository at this point in the history
* chore(kreivo-runtime): finish splitting runtime config

* change(kreivo-runtime): move `contracts` to its own folder, in preparation to adding `ChainExtensions` config

* fix: fmt

* chore: re-sort imports and cut down unused imports

* fix: fmt

* fix(kreivo-runtime): re-export `DAYS`, `HOURS` and `MINUTES` from `runtime_constants`
  • Loading branch information
pandres95 authored Jan 20, 2025
1 parent 4c334ef commit 9de8242
Show file tree
Hide file tree
Showing 23 changed files with 466 additions and 454 deletions.
8 changes: 7 additions & 1 deletion runtime/kreivo/src/apis.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
use super::*;

use sp_api::impl_runtime_apis;
use sp_runtime::ExtrinsicInclusionMode;
use sp_core::OpaqueMetadata;
use sp_runtime::{
traits::Block as BlockT,
transaction_validity::{InvalidTransaction, TransactionSource, TransactionValidity},
ApplyExtrinsicResult, ExtrinsicInclusionMode,
};
use sp_version::RuntimeVersion;

impl_runtime_apis! {
Expand Down
105 changes: 105 additions & 0 deletions runtime/kreivo/src/config/collator_support.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
use super::*;

use frame_support::traits::EitherOfDiverse;
use pallet_xcm::IsVoiceOfBody;

// #[runtime::pallet_index(20)]
// pub type Authorship
impl pallet_authorship::Config for Runtime {
type FindAuthor = pallet_session::FindAccountFromAuthorIndex<Self, Aura>;
type EventHandler = (CollatorSelection,);
}

// #[runtime::pallet_index(21)]
// pub type CollatorSelection
parameter_types! {
pub const PotId: PalletId = PalletId(*b"PotStake");
pub const MaxCandidates: u32 = 1000;
pub const MinEligibleCollators: u32 = 1;
pub const MaxInvulnerables: u32 = 100;
// StakingAdmin pluralistic body.
pub const StakingAdminBodyId: BodyId = BodyId::Defense;
}

/// We allow root and the StakingAdmin to execute privileged collator selection
/// operations.
pub type CollatorSelectionUpdateOrigin =
EitherOfDiverse<EnsureRoot<AccountId>, EnsureXcm<IsVoiceOfBody<RelayLocation, StakingAdminBodyId>>>;

impl pallet_collator_selection::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Currency = Balances;
type UpdateOrigin = CollatorSelectionUpdateOrigin;
type PotId = PotId;
type MaxCandidates = MaxCandidates;
type MinEligibleCollators = MinEligibleCollators;
type MaxInvulnerables = MaxInvulnerables;
// should be a multiple of session or things will get inconsistent
type KickThreshold = Period;
type ValidatorId = <Self as frame_system::Config>::AccountId;
type ValidatorIdOf = pallet_collator_selection::IdentityCollator;
type ValidatorRegistration = Session;
type WeightInfo = ();
}

// #[runtime::pallet_index(22)]
// pub type Session
parameter_types! {
pub const Period: u32 = 6 * HOURS;
pub const Offset: u32 = 0;
}

impl pallet_session::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type ValidatorId = <Self as frame_system::Config>::AccountId;
// we don't have stash and controller, thus we don't need the convert as well.
type ValidatorIdOf = pallet_collator_selection::IdentityCollator;
type ShouldEndSession = pallet_session::PeriodicSessions<Period, Offset>;
type NextSessionRotation = pallet_session::PeriodicSessions<Period, Offset>;
type SessionManager = CollatorSelection;
// Essentially just Aura, but let's be pedantic.
type SessionHandler = <SessionKeys as sp_runtime::traits::OpaqueKeys>::KeyTypeIdProviders;
type Keys = SessionKeys;
type WeightInfo = ();
}

// #[runtime::pallet_index(23)]
// pub type Aura

/// `SLOT_DURATION` is picked up by `pallet_timestamp` which is in turn picked
/// up by `pallet_aura` to implement `fn slot_duration()`.
///
/// Change this to adjust the block time.
pub const MILLISECONDS_PER_BLOCK: u64 = 6_000;
pub const SLOT_DURATION: u64 = MILLISECONDS_PER_BLOCK;

impl pallet_aura::Config for Runtime {
type AuthorityId = AuraId;
type MaxAuthorities = ConstU32<100_000>;
type DisabledValidators = ();
type AllowMultipleBlocksPerSlot = ConstBool<true>;
type SlotDuration = ConstU64<SLOT_DURATION>;
}

// #[runtime::pallet_index(24)]
// pub type AuraExt
impl cumulus_pallet_aura_ext::Config for Runtime {}

mod async_backing_params {
/// Maximum number of blocks simultaneously accepted by the Runtime, not yet
/// included into the relay chain.
pub(crate) const UNINCLUDED_SEGMENT_CAPACITY: u32 = 3;
/// How many parachain blocks are processed by the relay chain per parent.
/// Limits the number of blocks authored per slot.
pub(crate) const BLOCK_PROCESSING_VELOCITY: u32 = 1;
/// Relay chain slot duration, in milliseconds.
pub(crate) const RELAY_CHAIN_SLOT_DURATION_MILLIS: u32 = 6_000;
}

/// Aura consensus hook
pub type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook<
Runtime,
{ async_backing_params::RELAY_CHAIN_SLOT_DURATION_MILLIS },
{ async_backing_params::BLOCK_PROCESSING_VELOCITY },
{ async_backing_params::UNINCLUDED_SEGMENT_CAPACITY },
>;
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ use frame_system::EnsureSigned;
use pallet_ranked_collective::{TallyOf, Votes};
use sp_core::ConstU128;

pub type KreivoTracksInstance = pallet_referenda_tracks::Instance1;
pub type KreivoReferendaInstance = pallet_referenda::Instance1;

impl pallet_referenda::Config<KreivoReferendaInstance> for Runtime {
type WeightInfo = pallet_referenda::weights::SubstrateWeight<Self>;
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type WeightInfo = pallet_referenda::weights::SubstrateWeight<Self>;
type Scheduler = Scheduler;
type Currency = Balances;
type SubmitOrigin = EnsureSigned<AccountId>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,25 @@ impl pallet_ranked_collective::Config<KreivoCollectiveInstance> for Runtime {

type AddOrigin = EnsureNever<()>;

type RemoveOrigin = Self::DemoteOrigin;

// Initially, members of kreivo collective are promoted via governance action
// In the future, it's expected to have an auxilliary pallet to observe the
// In the future, it's expected to have an auxiliary pallet to observe the
// criteria for ranking
type PromoteOrigin = EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>;

type RemoveOrigin = Self::DemoteOrigin;

// Initially, members of kreivo collective are demoted via governance action
// In the future, it's expected to have an auxilliary pallet to observe the
// In the future, it's expected to have an auxiliary pallet to observe the
// criteria for ranking
type DemoteOrigin = EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>;

type ExchangeOrigin = EnsureRoot<AccountId>;
type MemberSwappedHandler = ();

type Polls = KreivoReferenda;

type MinRankOfClass = AtLeastRank<1>;
type MaxMemberCount = ();
type MemberSwappedHandler = ();
type VoteWeight = pallet_ranked_collective::Linear;
type MaxMemberCount = ();

#[cfg(feature = "runtime-benchmarks")]
type BenchmarkSetup = CollectiveBenchmarkSetup;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
use super::*;

use frame_system::EnsureRootWithSuccess;
use sp_runtime::traits::Verify;

use pallet_nfts::PalletFeatures;
use virto_common::MembershipId;

parameter_types! {
pub MembershipsPalletFeatures: PalletFeatures = PalletFeatures::all_enabled();
pub const MaxDeadlineDuration: BlockNumber = 12 * 30 * DAYS;
pub const MetadataDepositBase: Balance = 0;
pub const AttributeDepositBase: Balance = 0;
pub const DepositPerByte: Balance = 0;
}

pub type CommunityMembershipsInstance = pallet_nfts::Instance2;

// From https://github.com/polkadot-fellows/runtimes/blob/main/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs#L810
Expand All @@ -20,26 +31,26 @@ impl pallet_nfts::Config<CommunityMembershipsInstance> for Runtime {

type CollectionDeposit = ();
type ItemDeposit = ();
type MetadataDepositBase = NftsMetadataDepositBase;
type AttributeDepositBase = NftsAttributeDepositBase;
type DepositPerByte = NftsDepositPerByte;
type MetadataDepositBase = MetadataDepositBase;
type AttributeDepositBase = AttributeDepositBase;
type DepositPerByte = DepositPerByte;

type StringLimit = ConstU32<256>;
type KeyLimit = ConstU32<64>;
type ValueLimit = ConstU32<256>;
type ApprovalsLimit = ConstU32<20>;
type ItemAttributesApprovalsLimit = ConstU32<30>;
type MaxTips = ConstU32<10>;
type MaxDeadlineDuration = NftsMaxDeadlineDuration;
type MaxDeadlineDuration = MaxDeadlineDuration;
type MaxAttributesPerCall = ConstU32<10>;
type Features = NftsPalletFeatures;
type Features = MembershipsPalletFeatures;

type OffchainSignature = Signature;
type OffchainPublic = <Signature as Verify>::Signer;
type WeightInfo = pallet_nfts::weights::SubstrateWeight<Runtime>;

#[cfg(feature = "runtime-benchmarks")]
type Helper = NftsBenchmarksHelper;

type WeightInfo = pallet_nfts::weights::SubstrateWeight<Runtime>;
}

#[cfg(feature = "runtime-benchmarks")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use sp_runtime::{morph_types, traits::AccountIdConversion};
use virto_common::{CommunityId, MembershipId};

use fc_traits_memberships::{NonFungiblesMemberships, WithHooks};

pub mod governance;
mod kreivo_memberships;
pub mod memberships;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
use super::*;

use frame_support::{
traits::{ConstU8, WithdrawReasons},
weights::ConstantMultiplier,
};

use polkadot_runtime_common::SlowAdjustingFeeUpdate;
use runtime_common::impls::AssetsToBlockAuthor;

use fc_traits_gas_tank::{NonFungibleGasTank, SelectNonFungibleItem};
use pallet_asset_tx_payment::FungiblesAdapter;
use pallet_assets::BalanceToAssetBalance;
use pallet_transaction_payment::FungibleAdapter;
use runtime_common::impls::AssetsToBlockAuthor;
use virto_common::MembershipId;

#[cfg(not(feature = "runtime-benchmarks"))]
Expand All @@ -20,21 +27,21 @@ parameter_types! {
}

impl pallet_balances::Config for Runtime {
type MaxLocks = ConstU32<50>;
/// The type for recording an account's balance.
type Balance = Balance;
/// The ubiquitous event type.
type RuntimeEvent = RuntimeEvent;
type RuntimeHoldReason = RuntimeHoldReason;
type RuntimeFreezeReason = RuntimeFreezeReason;
type WeightInfo = pallet_balances::weights::SubstrateWeight<Runtime>;
/// The type for recording an account's balance.
type Balance = Balance;
type DustRemoval = ();
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = System;
type WeightInfo = pallet_balances::weights::SubstrateWeight<Runtime>;
type MaxReserves = ConstU32<50>;
type ReserveIdentifier = [u8; 8];
type RuntimeHoldReason = RuntimeHoldReason;
type FreezeIdentifier = RuntimeFreezeReason;
type MaxLocks = ConstU32<50>;
type MaxReserves = ConstU32<50>;
type MaxFreezes = ConstU32<256>;
type RuntimeFreezeReason = RuntimeFreezeReason;
}

// #[runtime::pallet_index(11)]
Expand All @@ -56,8 +63,8 @@ impl pallet_transaction_payment::Config for Runtime {
// #[runtime::pallet_index(12)]
// pub type AssetsFreezer
impl pallet_assets_freezer::Config<KreivoAssetsInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
type RuntimeFreezeReason = RuntimeFreezeReason;
type RuntimeEvent = RuntimeEvent;
}

// #[runtime::pallet_index(13)]
Expand All @@ -81,6 +88,7 @@ pub type KreivoAssetsCall = pallet_assets::Call<Runtime, KreivoAssetsInstance>;
impl pallet_assets::Config<KreivoAssetsInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
type Balance = Balance;
type RemoveItemsLimit = frame_support::traits::ConstU32<1000>;
type AssetId = FungibleAssetLocation;
type AssetIdParameter = FungibleAssetLocation;
type Currency = Balances;
Expand All @@ -89,20 +97,19 @@ impl pallet_assets::Config<KreivoAssetsInstance> for Runtime {
type CreateOrigin = AsEnsureOriginWithArg<NeverEnsureOrigin<AccountId>>;
#[cfg(feature = "runtime-benchmarks")]
type CreateOrigin = EnsureSigned<AccountId>;
type RuntimeHoldReason = RuntimeHoldReason;
type ForceOrigin = AssetsForceOrigin;
type AssetDeposit = AssetDeposit;
type AssetAccountDeposit = AssetAccountDeposit;
type MetadataDepositBase = MetadataDepositBase;
type MetadataDepositPerByte = MetadataDepositPerByte;
type ApprovalDeposit = ApprovalDeposit;
type StringLimit = AssetsStringLimit;
type MaxHolds = frame_support::traits::ConstU32<50>;
type Freezer = AssetsFreezer;
type Extra = ();
type WeightInfo = weights::pallet_assets::WeightInfo<Runtime>;
type CallbackHandle = ();
type AssetAccountDeposit = AssetAccountDeposit;
type RemoveItemsLimit = frame_support::traits::ConstU32<1000>;
type MaxHolds = frame_support::traits::ConstU32<50>;
type RuntimeHoldReason = RuntimeHoldReason;
type WeightInfo = weights::pallet_assets::WeightInfo<Runtime>;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = ();
}
Expand Down
56 changes: 56 additions & 0 deletions runtime/kreivo/src/config/governance/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
use super::*;

pub mod origins;

use crate::{Balances, Runtime, RuntimeEvent};
use frame_support::parameter_types;
use frame_support::traits::tokens::{PayFromAccount, UnityAssetBalanceConversion};
pub use origins::*;
use parachains_common::Balance;
use sp_runtime::{traits::IdentityLookup, Permill};

// #[runtime::pallet_index(50)]
// pub type Treasury
parameter_types! {
pub const ProposalBond: Permill = Permill::from_percent(5);
pub const ProposalBondMinimum: Balance = 2000 * CENTS;
pub const ProposalBondMaximum: Balance = GRAND;
pub const SpendPeriod: BlockNumber = 6 * DAYS;
pub const TreasuryPalletId: PalletId = PalletId(*b"py/trsry");
pub const TipCountdown: BlockNumber = DAYS;
pub const TipFindersFee: Percent = Percent::from_percent(20);
pub const TipReportDepositBase: Balance = 100 * CENTS;
pub const DataDepositPerByte: Balance = CENTS;
pub const MaxApprovals: u32 = 100;
pub const MaxAuthorities: u32 = 100_000;
pub const MaxKeys: u32 = 10_000;
pub const MaxPeerInHeartbeats: u32 = 10_000;
pub const MaxPeerDataEncodingSize: u32 = 1_000;
pub TreasuryAccount: AccountId = Treasury::account_id();
pub const PayoutSpendPeriod: BlockNumber = 30 * DAYS;
}

impl pallet_treasury::Config for Runtime {
type Currency = Balances;
type RejectOrigin = frame_system::EnsureRoot<Self::AccountId>;
type RuntimeEvent = RuntimeEvent;
type SpendPeriod = SpendPeriod;
type Burn = ();
type PalletId = TreasuryPalletId;
type BurnDestination = ();
type WeightInfo = pallet_treasury::weights::SubstrateWeight<Runtime>;
type SpendFunds = ();
type MaxApprovals = MaxApprovals;
type SpendOrigin = frame_support::traits::NeverEnsureOrigin<Balance>;
type AssetKind = ();
type Beneficiary = Self::AccountId;
type BeneficiaryLookup = IdentityLookup<Self::Beneficiary>;
type Paymaster = PayFromAccount<Balances, TreasuryAccount>;
type BalanceConverter = UnityAssetBalanceConversion;
type PayoutPeriod = PayoutSpendPeriod;
#[cfg(feature = "runtime-benchmarks")]
/// TODO: fix this benchmark helper in next release. We can proceed with the
/// empty implementation. type BenchmarkHelper =
/// polkadot_runtime_common::impls::benchmarks::TreasuryArguments;
type BenchmarkHelper = ();
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

//! Custom origins for governance interventions.
pub use pallet_custom_origins::*;

#[frame_support::pallet]
pub mod pallet_custom_origins {
use frame_support::pallet_prelude::*;
Expand Down
Loading

0 comments on commit 9de8242

Please sign in to comment.