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

[Feature] P2 Staking Tracker #12744

Closed
wants to merge 37 commits into from
Closed
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
91dd322
[Enhancement] P2 Staking Tracker
ruseinov Nov 20, 2022
e8127c7
Staking interface changes
ruseinov Nov 20, 2022
c809c57
introducing stake-tracker pallet
ruseinov Nov 20, 2022
99bd9d7
some trait re-shuffling
ruseinov Nov 21, 2022
0d4a022
more trait fixes
ruseinov Nov 21, 2022
c5bb19c
more code
ruseinov Nov 22, 2022
5549a78
more tracking logic
ruseinov Nov 23, 2022
1666bdc
add reaped handling
ruseinov Nov 23, 2022
e7cfb35
implement ReadOnlySortedListProvider
ruseinov Nov 23, 2022
54b2e33
more import fixes
ruseinov Nov 23, 2022
da8f780
more import fixes
ruseinov Nov 23, 2022
c89d8ec
integrate EventListener into Staking
ruseinov Nov 23, 2022
7fcafe0
modify the EventListener interface for better Staking compat
ruseinov Nov 28, 2022
6689460
Merge remote-tracking branch 'origin/master' into ru/feature/pallet-s…
Nov 28, 2022
9f3e436
Merge remote-tracking branch 'origin/master' into ru/feature/pallet-s…
Nov 28, 2022
bed5ad4
generate bags, fix node-runtime
ruseinov Nov 28, 2022
84ec3d4
missing license
ruseinov Dec 8, 2022
f65e5bd
comment fixes
ruseinov Dec 8, 2022
c11877f
Merge branch 'master' into ru/feature/pallet-stake-tracker
ruseinov Dec 9, 2022
345585e
NominatorsHelper
ruseinov Dec 9, 2022
09550de
Introduce initial TargetList migration
ruseinov Dec 21, 2022
69b27c5
Merge branch 'master' into ru/feature/pallet-stake-tracker
ruseinov Dec 21, 2022
b9b4978
more todo
ruseinov Dec 21, 2022
1cd145a
nl
ruseinov Dec 23, 2022
3297703
revert a change
ruseinov Dec 23, 2022
c618967
fix add_era_stakers
ruseinov Dec 23, 2022
6b33afc
review comment fixes
ruseinov Dec 23, 2022
bd18275
add some comments, remove redundant debug_asserts in favour of try_state
ruseinov Dec 23, 2022
9c70db7
OnStakingUpdate void
ruseinov Dec 23, 2022
9b3fdf9
some reshuffling
ruseinov Dec 23, 2022
4a126cc
Merge branch 'master' into ru/feature/pallet-stake-tracker
ruseinov Jan 4, 2023
70fceb5
stake-tracker-migrations -> initializer
ruseinov Jan 4, 2023
9a90e4b
remove VoterList manipulations from Staking
ruseinov Jan 4, 2023
85529a3
fix old migration
ruseinov Jan 4, 2023
08118a4
fix migration
ruseinov Jan 4, 2023
ace54bb
Update frame/stake-tracker/src/lib.rs
ruseinov Jan 4, 2023
ea35228
Update frame/stake-tracker/src/lib.rs
ruseinov Jan 4, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ members = [
"frame/staking",
"frame/staking/reward-curve",
"frame/staking/reward-fn",
"frame/stake-tracker",
kianenigma marked this conversation as resolved.
Show resolved Hide resolved
"frame/stake-tracker/initializer",
"frame/state-trie-migration",
"frame/sudo",
"frame/root-offences",
Expand Down
2 changes: 2 additions & 0 deletions bin/node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ pallet-root-testing = { version = "1.0.0-dev", default-features = false, path =
pallet-session = { version = "4.0.0-dev", features = [ "historical" ], path = "../../../frame/session", default-features = false }
pallet-session-benchmarking = { version = "4.0.0-dev", path = "../../../frame/session/benchmarking", default-features = false, optional = true }
pallet-staking = { version = "4.0.0-dev", default-features = false, path = "../../../frame/staking" }
pallet-stake-tracker = {version = "4.0.0-dev", default-features = false, path = "../../../frame/stake-tracker"}
pallet-staking-reward-curve = { version = "4.0.0-dev", default-features = false, path = "../../../frame/staking/reward-curve" }
pallet-state-trie-migration = { version = "4.0.0-dev", default-features = false, path = "../../../frame/state-trie-migration" }
pallet-scheduler = { version = "4.0.0-dev", default-features = false, path = "../../../frame/scheduler" }
Expand Down Expand Up @@ -174,6 +175,7 @@ std = [
"sp-runtime/std",
"sp-staking/std",
"pallet-staking/std",
"pallet-stake-tracker/std",
"pallet-state-trie-migration/std",
"sp-session/std",
"pallet-sudo/std",
Expand Down
41 changes: 40 additions & 1 deletion bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,13 @@ impl pallet_staking::BenchmarkingConfig for StakingBenchmarkingConfig {
type MaxValidators = ConstU32<1000>;
}

impl pallet_stake_tracker::Config for Runtime {
type Currency = Balances;
type Staking = Staking;
type VoterList = VoterListTracker;
type TargetList = TargetList;
Comment on lines +559 to +560
Copy link
Contributor

Choose a reason for hiding this comment

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

the names in two lines are not consistent -- either both somethingTracker or neither.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The idea here is that the TargetList is not used in Staking yet, so we can start tracking it in staking-tracker and then passing it to Staking without any migrations.
Since VoterList already exists - I had to add a suffix.

}

impl pallet_staking::Config for Runtime {
type MaxNominations = MaxNominations;
type Currency = Balances;
Expand Down Expand Up @@ -586,6 +593,7 @@ impl pallet_staking::Config for Runtime {
type OnStakerSlash = NominationPools;
type WeightInfo = pallet_staking::weights::SubstrateWeight<Runtime>;
type BenchmarkingConfig = StakingBenchmarkingConfig;
type EventListener = StakeTracker;
}

impl pallet_fast_unstake::Config for Runtime {
Expand Down Expand Up @@ -750,7 +758,7 @@ impl pallet_election_provider_multi_phase::Config for Runtime {
}

parameter_types! {
pub const BagThresholds: &'static [u64] = &voter_bags::THRESHOLDS;
pub const BagThresholds: &'static [VoteWeight] = &voter_bags::THRESHOLDS;
}

type VoterBagsListInstance = pallet_bags_list::Instance1;
Expand All @@ -764,6 +772,33 @@ impl pallet_bags_list::Config<VoterBagsListInstance> for Runtime {
type WeightInfo = pallet_bags_list::weights::SubstrateWeight<Runtime>;
}

// A special VoterList instance used to test the StakeTracker.
type VoterBagsListTrackerInstance = pallet_bags_list::Instance3;
kianenigma marked this conversation as resolved.
Show resolved Hide resolved
impl pallet_bags_list::Config<VoterBagsListTrackerInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
// The voter bags-list is loosely kept up to date, and the real source of truth for the score
// of each node is the staking pallet.
type ScoreProvider = Staking;
type BagThresholds = BagThresholds;
type Score = VoteWeight;
type WeightInfo = pallet_bags_list::weights::SubstrateWeight<Runtime>;
}

parameter_types! {
pub const BagThresholdsBalances: &'static [Balance] = &voter_bags::THRESHOLDS_BALANCES;
}

// A TargetList, currently populated by StakeTracker, once this has been tested enough - this will
// be used by pallet-staking as a list of electable targets.
type TargetBagsListInstance = pallet_bags_list::Instance2;
impl pallet_bags_list::Config<TargetBagsListInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
type ScoreProvider = StakeTracker;
type BagThresholds = BagThresholdsBalances;
type Score = Balance;
type WeightInfo = pallet_bags_list::weights::SubstrateWeight<Runtime>;
}

parameter_types! {
pub const PostUnbondPoolsWindow: u32 = 4;
pub const NominationPoolsPalletId: PalletId = PalletId(*b"py/nopls");
Expand Down Expand Up @@ -1743,6 +1778,9 @@ construct_runtime!(
Nfts: pallet_nfts,
TransactionStorage: pallet_transaction_storage,
VoterList: pallet_bags_list::<Instance1>,
TargetList: pallet_bags_list::<Instance2>,
Copy link
Contributor

Choose a reason for hiding this comment

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

If these two instances are only going to be used by the stake-tracker, they could be better named things like StakeTrackerVoter and StakeTrackerTargets.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

VoterList is used in the original Staking. TargetList, once tested, will be passed to Staking as well. It kind of felt strange to be renaming this back and forth, as those lists shouldn't care who tracks them and neither should the Staking pallet.

Unfortunately I had to add an ugly VoterListTracker bags-list, but that will be dropped as soon as we have concluded that the original VoterList tracked by Staking and the new one are one and the same.

Let me know if this makes sense.

// A special VoterList tha is used just to see if the stake-tracker works correctly.
VoterListTracker: pallet_bags_list::<Instance3>,
StateTrieMigration: pallet_state_trie_migration,
ChildBounties: pallet_child_bounties,
Referenda: pallet_referenda,
Expand All @@ -1756,6 +1794,7 @@ construct_runtime!(
RankedPolls: pallet_referenda::<Instance2>,
RankedCollective: pallet_ranked_collective,
FastUnstake: pallet_fast_unstake,
StakeTracker: pallet_stake_tracker,
MessageQueue: pallet_message_queue,
}
);
Expand Down
Loading