Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Next Next commit
Integrate NIS into Kusama/Rococo
  • Loading branch information
gavofyork committed Nov 27, 2022
commit a1b7d9f24f4c703b4e9d01cbe9f2ed3fd6424dc7
462 changes: 265 additions & 197 deletions Cargo.lock

Large diffs are not rendered by default.

243 changes: 243 additions & 0 deletions Cargo.toml

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,7 +767,7 @@ fn kusama_staging_testnet_config_genesis(wasm_binary: &[u8]) -> kusama::GenesisC
configuration: kusama::ConfigurationConfig {
config: default_parachains_host_configuration(),
},
gilt: Default::default(),
nis: Default::default(),
paras: Default::default(),
xcm_pallet: Default::default(),
nomination_pools: Default::default(),
Expand Down Expand Up @@ -1073,7 +1073,7 @@ fn rococo_staging_testnet_config_genesis(wasm_binary: &[u8]) -> rococo_runtime::
configuration: rococo_runtime::ConfigurationConfig {
config: default_parachains_host_configuration(),
},
gilt: Default::default(),
nis: Default::default(),
registrar: rococo_runtime::RegistrarConfig {
next_free_para_id: polkadot_primitives::v2::LOWEST_PUBLIC_ID,
},
Expand Down Expand Up @@ -1466,7 +1466,7 @@ pub fn kusama_testnet_genesis(
configuration: kusama::ConfigurationConfig {
config: default_parachains_host_configuration(),
},
gilt: Default::default(),
nis: Default::default(),
paras: Default::default(),
xcm_pallet: Default::default(),
nomination_pools: Default::default(),
Expand Down Expand Up @@ -1629,7 +1629,7 @@ pub fn rococo_testnet_genesis(
..default_parachains_host_configuration()
},
},
gilt: Default::default(),
nis: Default::default(),
paras: rococo_runtime::ParasConfig { paras: vec![] },
registrar: rococo_runtime::RegistrarConfig {
next_free_para_id: polkadot_primitives::v2::LOWEST_PUBLIC_ID,
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
78 changes: 53 additions & 25 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, WithdrawReasons, StorageMapShim,
},
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::{OpaqueMetadata, ConstU128};
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 @@ -1022,7 +1023,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 @@ -1236,33 +1237,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
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::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;
pub const MinBid: Balance = 100 * QUID;
pub MinReceipt: Perquintill = Perquintill::from_rational(1u64, 10_000_000u64);
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();
pub const NisPalletId: PalletId = PalletId(*b"py/nis ");
}

impl pallet_gilt::Config for Runtime {
impl pallet_nis::Config for Runtime {
type WeightInfo = pallet_nis::weights::SubstrateWeight<Runtime>;
type RuntimeEvent = RuntimeEvent;
type Currency = Balances;
type CurrencyBalance = Balance;
type AdminOrigin = EnsureRoot<AccountId>;
type Deficit = (); // Mint
type Surplus = (); // Burn
type FundOrigin = frame_system::EnsureSigned<AccountId>;
type Counterpart = NisCounterpartBalances;
type CounterpartAmount = WithMaximumOf<ConstU128<21_000_000_000_000_000_000u128>>;
type Deficit = (); // Mint
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 @@ -1376,8 +1401,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;
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
2 changes: 1 addition & 1 deletion runtime/kusama/src/weights/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ 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_nis;
pub mod pallet_identity;
pub mod pallet_im_online;
pub mod pallet_indices;
Expand Down
119 changes: 0 additions & 119 deletions runtime/kusama/src/weights/pallet_gilt.rs

This file was deleted.

1 change: 0 additions & 1 deletion runtime/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,6 @@ impl pallet_staking::EraPayout<Balance> for EraPayout {

runtime_common::impls::era_payout(
total_staked,
// Polkadot has no notion of gilts, the entire issuance is non-guilt.
total_issuance,
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this also be "active balance", as of your new PR?

Copy link
Contributor

Choose a reason for hiding this comment

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

IMO no, I considered this too. The era_payout should still consider balances in Crowdloans/Auctions/etc. as part of the total issuance, as they are part of the network, but people have chosen to use them for something outside of Staking. The Active balance is for the ability to be "active" with those funds at a given time (contributing to a crowdloan means you are willing to not be able to be active with them for the duration of the lease).

MAX_ANNUAL_INFLATION,
Perquintill::from_rational(era_duration_millis, MILLISECONDS_PER_YEAR),
Expand Down
Loading