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

Commit 0ab43bc

Browse files
gavofyorkggwpezxlckianenigma
authored
Non-Interactive Staking (#12610)
* Improve naming. * More improvements to naming * Fungible counterpart * Shared pot instead of reserve * Transferable receipts * Better naming * Use u128 for counterpart * Partial thawing * Docs * Remove AdminOrigin * Integrate into Kitchen Sink * Thaw throttling * Remove todo * Docs * Fix benchmarks * Building * Tests work * New benchmarks * Benchmarking tests * Test new defensive_saturating_* functions Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * fmt Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Formatting * Update frame/nis/src/lib.rs Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Apply suggestions from code review Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Events added * Fix kitchensink * Update frame/nis/src/lib.rs Co-authored-by: Xiliang Chen <xlchen1291@gmail.com> * Review niggles * Remove genesis build requirements * Grumbles * Fixes * Fixes * Fixes * Update frame/nis/src/lib.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Update primitives/runtime/src/traits.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Formatting * Fixes * Fix node genesis config Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fix node chain specs Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Use free asset ID as counterpart Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Account for rounding errors in fund_deficit bench Relaxes the check for the NIS account balance in the fund_deficit bench from equality from to checking for 99.999% equality. The exact deviation for the kitchensink runtime config is 1.24e-10 percent but could vary if the config is changed. Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * clippy Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * fmt Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fix * Rename * Fixes * Fixes * Formatting Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> Co-authored-by: Xiliang Chen <xlchen1291@gmail.com> Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
1 parent 62a85fb commit 0ab43bc

25 files changed

Lines changed: 2313 additions & 1666 deletions

File tree

Cargo.lock

Lines changed: 20 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ members = [
101101
"frame/examples/basic",
102102
"frame/examples/offchain-worker",
103103
"frame/executive",
104-
"frame/gilt",
104+
"frame/nis",
105105
"frame/grandpa",
106106
"frame/identity",
107107
"frame/im-online",

bin/node/cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ sc-sysinfo = { version = "6.0.0-dev", path = "../../../client/sysinfo" }
8484
frame-system = { version = "4.0.0-dev", path = "../../../frame/system" }
8585
frame-system-rpc-runtime-api = { version = "4.0.0-dev", path = "../../../frame/system/rpc/runtime-api" }
8686
pallet-transaction-payment = { version = "4.0.0-dev", path = "../../../frame/transaction-payment" }
87+
pallet-assets = { version = "4.0.0-dev", path = "../../../frame/assets/" }
8788
pallet-asset-tx-payment = { version = "4.0.0-dev", path = "../../../frame/transaction-payment/asset-tx-payment/" }
8889
pallet-im-online = { version = "4.0.0-dev", default-features = false, path = "../../../frame/im-online" }
8990

bin/node/cli/src/chain_spec.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,11 @@ pub fn testnet_genesis(
358358
max_members: 999,
359359
},
360360
vesting: Default::default(),
361-
assets: Default::default(),
362-
gilt: Default::default(),
361+
assets: pallet_assets::GenesisConfig {
362+
// This asset is used by the NIS pallet as counterpart currency.
363+
assets: vec![(9, get_account_id_from_seed::<sr25519::Public>("Alice"), true, 1)],
364+
..Default::default()
365+
},
363366
transaction_storage: Default::default(),
364367
transaction_payment: Default::default(),
365368
alliance: Default::default(),

bin/node/runtime/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pallet-election-provider-multi-phase = { version = "4.0.0-dev", default-features
6868
pallet-election-provider-support-benchmarking = { version = "4.0.0-dev", default-features = false, path = "../../../frame/election-provider-support/benchmarking", optional = true }
6969
pallet-elections-phragmen = { version = "5.0.0-dev", default-features = false, path = "../../../frame/elections-phragmen" }
7070
pallet-fast-unstake = { version = "4.0.0-dev", default-features = false, path = "../../../frame/fast-unstake" }
71-
pallet-gilt = { version = "4.0.0-dev", default-features = false, path = "../../../frame/gilt" }
71+
pallet-nis = { version = "4.0.0-dev", default-features = false, path = "../../../frame/nis" }
7272
pallet-grandpa = { version = "4.0.0-dev", default-features = false, path = "../../../frame/grandpa" }
7373
pallet-im-online = { version = "4.0.0-dev", default-features = false, path = "../../../frame/im-online" }
7474
pallet-indices = { version = "4.0.0-dev", default-features = false, path = "../../../frame/indices" }
@@ -144,7 +144,7 @@ std = [
144144
"pallet-elections-phragmen/std",
145145
"pallet-fast-unstake/std",
146146
"frame-executive/std",
147-
"pallet-gilt/std",
147+
"pallet-nis/std",
148148
"pallet-grandpa/std",
149149
"pallet-im-online/std",
150150
"pallet-indices/std",
@@ -223,7 +223,7 @@ runtime-benchmarks = [
223223
"pallet-election-provider-support-benchmarking/runtime-benchmarks",
224224
"pallet-elections-phragmen/runtime-benchmarks",
225225
"pallet-fast-unstake/runtime-benchmarks",
226-
"pallet-gilt/runtime-benchmarks",
226+
"pallet-nis/runtime-benchmarks",
227227
"pallet-grandpa/runtime-benchmarks",
228228
"pallet-identity/runtime-benchmarks",
229229
"pallet-im-online/runtime-benchmarks",
@@ -276,7 +276,7 @@ try-runtime = [
276276
"pallet-election-provider-multi-phase/try-runtime",
277277
"pallet-elections-phragmen/try-runtime",
278278
"pallet-fast-unstake/try-runtime",
279-
"pallet-gilt/try-runtime",
279+
"pallet-nis/try-runtime",
280280
"pallet-grandpa/try-runtime",
281281
"pallet-im-online/try-runtime",
282282
"pallet-indices/try-runtime",

bin/node/runtime/src/lib.rs

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ use frame_support::{
3232
pallet_prelude::Get,
3333
parameter_types,
3434
traits::{
35-
AsEnsureOriginWithArg, ConstBool, ConstU128, ConstU16, ConstU32, Currency, EitherOfDiverse,
36-
EqualPrivilegeOnly, Everything, Imbalance, InstanceFilter, KeyOwnerProofSystem,
37-
LockIdentifier, Nothing, OnUnbalanced, U128CurrencyToVote, WithdrawReasons,
35+
fungible::ItemOf, AsEnsureOriginWithArg, ConstBool, ConstU128, ConstU16, ConstU32,
36+
Currency, EitherOfDiverse, EqualPrivilegeOnly, Everything, Imbalance, InstanceFilter,
37+
KeyOwnerProofSystem, LockIdentifier, Nothing, OnUnbalanced, U128CurrencyToVote,
38+
WithdrawReasons,
3839
},
3940
weights::{
4041
constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},
@@ -53,6 +54,7 @@ use pallet_grandpa::{
5354
fg_primitives, AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList,
5455
};
5556
use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
57+
use pallet_nis::WithMaximumOf;
5658
use pallet_session::historical::{self as pallet_session_historical};
5759
pub use pallet_transaction_payment::{CurrencyAdapter, Multiplier, TargetedFeeAdjustment};
5860
use pallet_transaction_payment::{FeeDetails, RuntimeDispatchInfo};
@@ -1464,28 +1466,37 @@ parameter_types! {
14641466
pub const QueueCount: u32 = 300;
14651467
pub const MaxQueueLen: u32 = 1000;
14661468
pub const FifoQueueLen: u32 = 500;
1467-
pub const Period: BlockNumber = 30 * DAYS;
1468-
pub const MinFreeze: Balance = 100 * DOLLARS;
1469+
pub const NisBasePeriod: BlockNumber = 30 * DAYS;
1470+
pub const MinBid: Balance = 100 * DOLLARS;
1471+
pub const MinReceipt: Perquintill = Perquintill::from_percent(1);
14691472
pub const IntakePeriod: BlockNumber = 10;
1470-
pub const MaxIntakeBids: u32 = 10;
1473+
pub MaxIntakeWeight: Weight = MAXIMUM_BLOCK_WEIGHT / 10;
1474+
pub const ThawThrottle: (Perquintill, BlockNumber) = (Perquintill::from_percent(25), 5);
1475+
pub Target: Perquintill = Perquintill::zero();
1476+
pub const NisPalletId: PalletId = PalletId(*b"py/nis ");
14711477
}
14721478

1473-
impl pallet_gilt::Config for Runtime {
1479+
impl pallet_nis::Config for Runtime {
1480+
type WeightInfo = pallet_nis::weights::SubstrateWeight<Runtime>;
14741481
type RuntimeEvent = RuntimeEvent;
14751482
type Currency = Balances;
14761483
type CurrencyBalance = Balance;
1477-
type AdminOrigin = frame_system::EnsureRoot<AccountId>;
1484+
type FundOrigin = frame_system::EnsureSigned<AccountId>;
1485+
type Counterpart = ItemOf<Assets, ConstU32<9u32>, AccountId>;
1486+
type CounterpartAmount = WithMaximumOf<ConstU128<21_000_000_000_000_000_000u128>>;
14781487
type Deficit = ();
1479-
type Surplus = ();
14801488
type IgnoredIssuance = IgnoredIssuance;
1489+
type Target = Target;
1490+
type PalletId = NisPalletId;
14811491
type QueueCount = QueueCount;
14821492
type MaxQueueLen = MaxQueueLen;
14831493
type FifoQueueLen = FifoQueueLen;
1484-
type Period = Period;
1485-
type MinFreeze = MinFreeze;
1494+
type BasePeriod = NisBasePeriod;
1495+
type MinBid = MinBid;
1496+
type MinReceipt = MinReceipt;
14861497
type IntakePeriod = IntakePeriod;
1487-
type MaxIntakeBids = MaxIntakeBids;
1488-
type WeightInfo = pallet_gilt::weights::SubstrateWeight<Runtime>;
1498+
type MaxIntakeWeight = MaxIntakeWeight;
1499+
type ThawThrottle = ThawThrottle;
14891500
}
14901501

14911502
parameter_types! {
@@ -1668,7 +1679,7 @@ construct_runtime!(
16681679
Assets: pallet_assets,
16691680
Mmr: pallet_mmr,
16701681
Lottery: pallet_lottery,
1671-
Gilt: pallet_gilt,
1682+
Nis: pallet_nis,
16721683
Uniques: pallet_uniques,
16731684
TransactionStorage: pallet_transaction_storage,
16741685
VoterList: pallet_bags_list::<Instance1>,
@@ -1772,7 +1783,7 @@ mod benches {
17721783
[pallet_election_provider_support_benchmarking, EPSBench::<Runtime>]
17731784
[pallet_elections_phragmen, Elections]
17741785
[pallet_fast_unstake, FastUnstake]
1775-
[pallet_gilt, Gilt]
1786+
[pallet_nis, Nis]
17761787
[pallet_grandpa, Grandpa]
17771788
[pallet_identity, Identity]
17781789
[pallet_im_online, ImOnline]

bin/node/testing/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ frame-system = { version = "4.0.0-dev", path = "../../../frame/system" }
2222
node-executor = { version = "3.0.0-dev", path = "../executor" }
2323
node-primitives = { version = "2.0.0", path = "../primitives" }
2424
kitchensink-runtime = { version = "3.0.0-dev", path = "../runtime" }
25+
pallet-assets = { version = "4.0.0-dev", path = "../../../frame/assets" }
2526
pallet-asset-tx-payment = { version = "4.0.0-dev", path = "../../../frame/transaction-payment/asset-tx-payment" }
2627
pallet-transaction-payment = { version = "4.0.0-dev", path = "../../../frame/transaction-payment" }
2728
sc-block-builder = { version = "0.10.0-dev", path = "../../../client/block-builder" }

bin/node/testing/src/genesis.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
2121
use crate::keyring::*;
2222
use kitchensink_runtime::{
23-
constants::currency::*, wasm_binary_unwrap, AccountId, BabeConfig, BalancesConfig,
24-
GenesisConfig, GrandpaConfig, IndicesConfig, SessionConfig, SocietyConfig, StakerStatus,
25-
StakingConfig, SystemConfig, BABE_GENESIS_EPOCH_CONFIG,
23+
constants::currency::*, wasm_binary_unwrap, AccountId, AssetsConfig, BabeConfig,
24+
BalancesConfig, GenesisConfig, GrandpaConfig, IndicesConfig, SessionConfig, SocietyConfig,
25+
StakerStatus, StakingConfig, SystemConfig, BABE_GENESIS_EPOCH_CONFIG,
2626
};
2727
use sp_keyring::{Ed25519Keyring, Sr25519Keyring};
2828
use sp_runtime::Perbill;
@@ -88,8 +88,7 @@ pub fn config_endowed(code: Option<&[u8]>, extra_endowed: Vec<AccountId>) -> Gen
8888
treasury: Default::default(),
8989
society: SocietyConfig { members: vec![alice(), bob()], pot: 0, max_members: 999 },
9090
vesting: Default::default(),
91-
assets: Default::default(),
92-
gilt: Default::default(),
91+
assets: AssetsConfig { assets: vec![(9, alice(), true, 1)], ..Default::default() },
9392
transaction_storage: Default::default(),
9493
transaction_payment: Default::default(),
9594
alliance: Default::default(),

frame/gilt/src/benchmarking.rs

Lines changed: 0 additions & 131 deletions
This file was deleted.

0 commit comments

Comments
 (0)