Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Introduce NIS functionality into Kusama/Rococo #6352

Merged
merged 14 commits into from
Dec 5, 2022
395 changes: 198 additions & 197 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions node/service/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -767,10 +767,10 @@ fn kusama_staging_testnet_config_genesis(wasm_binary: &[u8]) -> kusama::GenesisC
configuration: kusama::ConfigurationConfig {
config: default_parachains_host_configuration(),
},
gilt: Default::default(),
paras: Default::default(),
xcm_pallet: Default::default(),
nomination_pools: Default::default(),
nis_counterpart_balances: Default::default(),
}
}

Expand Down Expand Up @@ -1073,11 +1073,11 @@ fn rococo_staging_testnet_config_genesis(wasm_binary: &[u8]) -> rococo_runtime::
configuration: rococo_runtime::ConfigurationConfig {
config: default_parachains_host_configuration(),
},
gilt: Default::default(),
registrar: rococo_runtime::RegistrarConfig {
next_free_para_id: polkadot_primitives::v2::LOWEST_PUBLIC_ID,
},
xcm_pallet: Default::default(),
nis_counterpart_balances: Default::default(),
}
}

Expand Down Expand Up @@ -1466,10 +1466,10 @@ pub fn kusama_testnet_genesis(
configuration: kusama::ConfigurationConfig {
config: default_parachains_host_configuration(),
},
gilt: Default::default(),
paras: Default::default(),
xcm_pallet: Default::default(),
nomination_pools: Default::default(),
nis_counterpart_balances: Default::default(),
}
}

Expand Down Expand Up @@ -1629,12 +1629,12 @@ pub fn rococo_testnet_genesis(
..default_parachains_host_configuration()
},
},
gilt: Default::default(),
paras: rococo_runtime::ParasConfig { paras: vec![] },
registrar: rococo_runtime::RegistrarConfig {
next_free_para_id: polkadot_primitives::v2::LOWEST_PUBLIC_ID,
},
xcm_pallet: Default::default(),
nis_counterpart_balances: Default::default(),
}
}

Expand Down
10 changes: 5 additions & 5 deletions runtime/common/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ where

pub fn era_payout(
total_staked: Balance,
non_gilt_issuance: Balance,
total_stakable: Balance,
max_annual_inflation: Perquintill,
period_fraction: Perquintill,
auctioned_slots: u64,
Expand All @@ -79,17 +79,17 @@ pub fn era_payout(
// amount that we expect to be taken up with auctions.
let ideal_stake = Perquintill::from_percent(75).saturating_sub(auction_proportion);

let stake = Perquintill::from_rational(total_staked, non_gilt_issuance);
let stake = Perquintill::from_rational(total_staked, total_stakable);
let falloff = Perquintill::from_percent(5);
let adjustment = compute_inflation(stake, ideal_stake, falloff);
let staking_inflation =
min_annual_inflation.saturating_add(delta_annual_inflation * adjustment);

let max_payout = period_fraction * max_annual_inflation * non_gilt_issuance;
let staking_payout = (period_fraction * staking_inflation) * non_gilt_issuance;
let max_payout = period_fraction * max_annual_inflation * total_stakable;
let staking_payout = (period_fraction * staking_inflation) * total_stakable;
let rest = max_payout.saturating_sub(staking_payout);

let other_issuance = non_gilt_issuance.saturating_sub(total_staked);
let other_issuance = total_stakable.saturating_sub(total_staked);
if total_staked > other_issuance {
let _cap_rest = Perquintill::from_rational(other_issuance, total_staked) * staking_payout;
// We don't do anything with this, but if we wanted to, we could introduce a cap on the
Expand Down
8 changes: 4 additions & 4 deletions runtime/kusama/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pallet-election-provider-multi-phase = { git = "https://github.com/paritytech/su
pallet-fast-unstake = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
frame-executive = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
pallet-grandpa = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
pallet-gilt = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
pallet-nis = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
pallet-identity = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
pallet-im-online = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
pallet-indices = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
Expand Down Expand Up @@ -150,7 +150,7 @@ std = [
"pallet-election-provider-multi-phase/std",
"pallet-fast-unstake/std",
"pallet-democracy/std",
"pallet-gilt/std",
"pallet-nis/std",
"pallet-grandpa/std",
"pallet-identity/std",
"pallet-im-online/std",
Expand Down Expand Up @@ -216,7 +216,7 @@ runtime-benchmarks = [
"pallet-election-provider-multi-phase/runtime-benchmarks",
"pallet-election-provider-support-benchmarking/runtime-benchmarks",
"pallet-fast-unstake/runtime-benchmarks",
"pallet-gilt/runtime-benchmarks",
"pallet-nis/runtime-benchmarks",
"pallet-grandpa/runtime-benchmarks",
"pallet-identity/runtime-benchmarks",
"pallet-im-online/runtime-benchmarks",
Expand Down Expand Up @@ -267,7 +267,7 @@ try-runtime = [
"pallet-election-provider-multi-phase/try-runtime",
"pallet-fast-unstake/try-runtime",
"pallet-democracy/try-runtime",
"pallet-gilt/try-runtime",
"pallet-nis/try-runtime",
"pallet-grandpa/try-runtime",
"pallet-identity/try-runtime",
"pallet-im-online/try-runtime",
Expand Down
76 changes: 52 additions & 24 deletions runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
// `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256.
#![recursion_limit = "256"]

use pallet_nis::WithMaximumOf;
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
use primitives::v2::{
AccountId, AccountIndex, Balance, BlockNumber, CandidateEvent, CommittedCandidateReceipt,
Expand Down Expand Up @@ -53,7 +54,7 @@ use frame_support::{
construct_runtime, parameter_types,
traits::{
ConstU32, Contains, EitherOf, EitherOfDiverse, InstanceFilter, KeyOwnerProofSystem,
LockIdentifier, PrivilegeCmp, WithdrawReasons,
LockIdentifier, PrivilegeCmp, StorageMapShim, WithdrawReasons,
},
weights::ConstantMultiplier,
PalletId, RuntimeDebug,
Expand All @@ -63,7 +64,7 @@ use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId};
use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
use pallet_session::historical as session_historical;
use pallet_transaction_payment::{CurrencyAdapter, FeeDetails, RuntimeDispatchInfo};
use sp_core::OpaqueMetadata;
use sp_core::{ConstU128, OpaqueMetadata};
use sp_mmr_primitives as mmr;
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
Expand Down Expand Up @@ -537,7 +538,7 @@ impl pallet_staking::EraPayout<Balance> for EraPayout {

runtime_common::impls::era_payout(
total_staked,
Gilt::issuance().non_gilt,
Nis::issuance().other,
MAX_ANNUAL_INFLATION,
Perquintill::from_rational(era_duration_millis, MILLISECONDS_PER_YEAR),
auctioned_slots,
Expand Down Expand Up @@ -1027,7 +1028,7 @@ impl InstanceFilter<RuntimeCall> for ProxyType {
RuntimeCall::Scheduler(..) |
RuntimeCall::Proxy(..) |
RuntimeCall::Multisig(..) |
RuntimeCall::Gilt(..) |
RuntimeCall::Nis(..) |
RuntimeCall::Registrar(paras_registrar::Call::register {..}) |
RuntimeCall::Registrar(paras_registrar::Call::deregister {..}) |
// Specifically omitting Registrar `swap`
Expand Down Expand Up @@ -1246,33 +1247,57 @@ impl auctions::Config for Runtime {
type WeightInfo = weights::runtime_common_auctions::WeightInfo<Runtime>;
}

type NisCounterpartInstance = pallet_balances::Instance2;
impl pallet_balances::Config<NisCounterpartInstance> for Runtime {
Comment on lines +1250 to +1251
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand the instantiation macro correctly, other mentions of pallet_balances without a declared instance (e.g. in the frame system config) will know that those refer to the pallet_balances::Config without an explicit Instance and not this one?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, this will work properly. It's best to explicitly specify pallet instances when there are more than one though.

type Balance = Balance;
type DustRemoval = ();
type RuntimeEvent = RuntimeEvent;
type ExistentialDeposit = ConstU128<10_000_000_000>; // One KTC cent
gavofyork marked this conversation as resolved.
Show resolved Hide resolved
type AccountStore = StorageMapShim<
pallet_balances::Account<Runtime, NisCounterpartInstance>,
frame_system::Provider<Runtime>,
AccountId,
pallet_balances::AccountData<u128>,
>;
type MaxLocks = ConstU32<4>;
type MaxReserves = ConstU32<4>;
type ReserveIdentifier = [u8; 8];
type WeightInfo = weights::pallet_balances_nis_counterpart_balances::WeightInfo<Runtime>;
}

parameter_types! {
pub IgnoredIssuance: Balance = Treasury::pot();
pub const QueueCount: u32 = 300;
pub const MaxQueueLen: u32 = 1000;
pub const FifoQueueLen: u32 = 250;
pub const GiltPeriod: BlockNumber = 30 * DAYS;
pub const MinFreeze: Balance = 10_000 * CENTS;
pub const NisBasePeriod: BlockNumber = 30 * DAYS;
gavofyork marked this conversation as resolved.
Show resolved Hide resolved
pub const MinBid: Balance = 100 * QUID;
pub MinReceipt: Perquintill = Perquintill::from_rational(1u64, 10_000_000u64);
gavofyork marked this conversation as resolved.
Show resolved Hide resolved
pub const IntakePeriod: BlockNumber = 5 * MINUTES;
pub const MaxIntakeBids: u32 = 100;
pub MaxIntakeWeight: Weight = MAXIMUM_BLOCK_WEIGHT / 10;
pub const ThawThrottle: (Perquintill, BlockNumber) = (Perquintill::from_percent(25), 5);
pub storage NisTarget: Perquintill = Perquintill::zero();
gavofyork marked this conversation as resolved.
Show resolved Hide resolved
pub const NisPalletId: PalletId = PalletId(*b"py/nis ");
}

impl pallet_gilt::Config for Runtime {
impl pallet_nis::Config for Runtime {
type WeightInfo = weights::pallet_nis::WeightInfo<Runtime>;
type RuntimeEvent = RuntimeEvent;
type Currency = Balances;
type CurrencyBalance = Balance;
type AdminOrigin = EnsureRoot<AccountId>;
type FundOrigin = frame_system::EnsureSigned<AccountId>;
type Counterpart = NisCounterpartBalances;
type CounterpartAmount = WithMaximumOf<ConstU128<21_000_000_000_000_000_000u128>>;
type Deficit = (); // Mint
type Surplus = (); // Burn
type IgnoredIssuance = IgnoredIssuance;
type QueueCount = QueueCount;
type MaxQueueLen = MaxQueueLen;
type FifoQueueLen = FifoQueueLen;
type Period = GiltPeriod;
type MinFreeze = MinFreeze;
type Target = NisTarget;
type PalletId = NisPalletId;
type QueueCount = ConstU32<300>;
type MaxQueueLen = ConstU32<1000>;
type FifoQueueLen = ConstU32<250>;
type BasePeriod = NisBasePeriod;
type MinBid = MinBid;
type MinReceipt = MinReceipt;
type IntakePeriod = IntakePeriod;
type MaxIntakeBids = MaxIntakeBids;
type WeightInfo = weights::pallet_gilt::WeightInfo<Runtime>;
type MaxIntakeWeight = MaxIntakeWeight;
type ThawThrottle = ThawThrottle;
}

parameter_types! {
Expand Down Expand Up @@ -1386,8 +1411,10 @@ construct_runtime! {
// Election pallet. Only works with staking, but placed here to maintain indices.
ElectionProviderMultiPhase: pallet_election_provider_multi_phase::{Pallet, Call, Storage, Event<T>, ValidateUnsigned} = 37,

// Gilts pallet.
Gilt: pallet_gilt::{Pallet, Call, Storage, Event<T>, Config} = 38,
// NIS pallet.
Nis: pallet_nis::{Pallet, Call, Storage, Event<T>} = 38,
// pub type NisCounterpartInstance = pallet_balances::Instance2;
gavofyork marked this conversation as resolved.
Show resolved Hide resolved
NisCounterpartBalances: pallet_balances::<Instance2> = 45,

// Provides a semi-sorted list of nominators for staking.
VoterList: pallet_bags_list::<Instance1>::{Pallet, Call, Storage, Event<T>} = 39,
Expand Down Expand Up @@ -1477,7 +1504,7 @@ mod benches {
define_benchmarks!(
// Polkadot
// NOTE: Make sure to prefix these with `runtime_common::` so
// the that path resolves correctly in the generated file.
// that the path resolves correctly in the generated file.
[runtime_common::auctions, Auctions]
[runtime_common::crowdloan, Crowdloan]
[runtime_common::claims, Claims]
Expand All @@ -1492,6 +1519,7 @@ mod benches {
[runtime_parachains::ump, Ump]
// Substrate
[pallet_balances, Balances]
[pallet_balances, NisCounterpartBalances]
[pallet_bags_list, VoterList]
[frame_benchmarking::baseline, Baseline::<Runtime>]
[pallet_bounties, Bounties]
Expand All @@ -1504,7 +1532,7 @@ mod benches {
[pallet_election_provider_multi_phase, ElectionProviderMultiPhase]
[frame_election_provider_support, ElectionProviderBench::<Runtime>]
[pallet_fast_unstake, FastUnstake]
[pallet_gilt, Gilt]
[pallet_nis, Nis]
[pallet_identity, Identity]
[pallet_im_online, ImOnline]
[pallet_indices, Indices]
Expand Down
3 changes: 2 additions & 1 deletion runtime/kusama/src/weights/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub mod frame_election_provider_support;
pub mod frame_system;
pub mod pallet_bags_list;
pub mod pallet_balances;
pub mod pallet_balances_nis_counterpart_balances;
pub mod pallet_bounties;
pub mod pallet_child_bounties;
pub mod pallet_collective_council;
Expand All @@ -28,12 +29,12 @@ pub mod pallet_democracy;
pub mod pallet_election_provider_multi_phase;
pub mod pallet_elections_phragmen;
pub mod pallet_fast_unstake;
pub mod pallet_gilt;
pub mod pallet_identity;
pub mod pallet_im_online;
pub mod pallet_indices;
pub mod pallet_membership;
pub mod pallet_multisig;
pub mod pallet_nis;
pub mod pallet_nomination_pools;
pub mod pallet_preimage;
pub mod pallet_proxy;
Expand Down
Loading