Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
104 commits
Select commit Hold shift + click to select a range
2f0a914
[Feature] StakeTracker P1 - VotersList
ruseinov Jan 5, 2023
29e1f66
add stake-tracker
ruseinov Jan 5, 2023
71ad9ab
fmt
ruseinov Jan 5, 2023
c4c5248
make staking tests work with stake-tracker
ruseinov Jan 5, 2023
58bfb70
ignore obsolete test
ruseinov Jan 6, 2023
66d6f5a
clarification
ruseinov Jan 6, 2023
0de90d4
fix tests/benches feature-gated
ruseinov Jan 6, 2023
ad54a95
StakeTracker to node
ruseinov Jan 6, 2023
3b1d926
more fixes
ruseinov Jan 6, 2023
16bd6b1
more fixes
ruseinov Jan 6, 2023
938c4df
more fixes
ruseinov Jan 6, 2023
74a2a48
fix some build errs
ruseinov Jan 8, 2023
d829b91
doc fixes
ruseinov Jan 8, 2023
2ea7d05
fix nom-pools benches
ruseinov Jan 8, 2023
1344c24
Update primitives/staking/src/lib.rs
ruseinov Jan 9, 2023
32f50d2
Update primitives/staking/src/lib.rs
ruseinov Jan 9, 2023
c3a7bd6
Update primitives/staking/src/lib.rs
ruseinov Jan 9, 2023
4ce30ed
Update frame/staking/src/pallet/mod.rs
ruseinov Jan 9, 2023
2d28217
Update frame/staking/src/pallet/mod.rs
ruseinov Jan 9, 2023
44b318f
Update primitives/staking/src/currency_to_vote.rs
ruseinov Jan 9, 2023
a34aaab
Merge remote-tracking branch 'origin/master' into ru/feature/stake-tr…
Jan 9, 2023
8838a07
fix OnStakingUpdate occurrences
ruseinov Jan 9, 2023
7d36dc9
add mock
ruseinov Jan 11, 2023
3446f0e
fixes
ruseinov Jan 11, 2023
ead8b81
remove defenisive, s, some tests
ruseinov Jan 12, 2023
387b7b4
basic tests finished
ruseinov Jan 12, 2023
9e561e9
still unsure what to do with un-decodables
ruseinov Jan 13, 2023
363eb6f
more comments
ruseinov Jan 13, 2023
2c6275e
fix migrations
kianenigma Jan 15, 2023
fc14202
Add NotDecodable error and tests
ruseinov Jan 16, 2023
a0db07f
fix try-runtime migration build
ruseinov Jan 17, 2023
978076a
Merge remote-tracking branch 'origin/master' into ru/feature/stake-tr…
Jan 17, 2023
504695e
unused import fix
ruseinov Jan 17, 2023
5361a95
test fixes
ruseinov Jan 17, 2023
78094f2
some more fixes
ruseinov Jan 17, 2023
7925732
Merge remote-tracking branch 'origin/master' into ru/feature/stake-tr…
Jan 19, 2023
561eb2b
fix unused
ruseinov Jan 19, 2023
1fffe7f
Revert "fix unused"
ruseinov Jan 19, 2023
a1a27d7
Merge remote-tracking branch 'origin/master' into ru/feature/stake-tr…
Jan 24, 2023
ad60934
Merge branch 'master' into ru/feature/stake-tracker-voter
ruseinov Jan 30, 2023
2002537
Update frame/stake-tracker/src/mock.rs
ruseinov Jan 31, 2023
6108362
Update frame/stake-tracker/Cargo.toml
ruseinov Feb 1, 2023
f92dfb7
Update frame/stake-tracker/Cargo.toml
ruseinov Feb 1, 2023
533703a
Merge branch 'master' into ru/feature/stake-tracker-voter
ruseinov Feb 10, 2023
d6069c3
fmt
ruseinov Feb 10, 2023
edbcf89
get rid of ReadOnlySortedListProvider
ruseinov Feb 10, 2023
16671da
fix some errs
ruseinov Feb 10, 2023
aff4599
revert weird random change
ruseinov Feb 10, 2023
f15bd1c
more redundant import removals
ruseinov Feb 10, 2023
85e863d
more fixes
ruseinov Feb 10, 2023
3b816b8
more fixes
ruseinov Feb 10, 2023
676a7a9
more fixes
ruseinov Feb 10, 2023
54a5a6a
more fixes
ruseinov Feb 11, 2023
7e042ac
little fix
ruseinov Feb 11, 2023
3295a29
no more panics
ruseinov Feb 11, 2023
3f6b5b9
implement OnStakingUpdate for tuples
ruseinov Feb 11, 2023
489b71c
minor fixes
ruseinov Feb 11, 2023
aec8879
introduce a testing framework for OnStakingUpdate
ruseinov Feb 11, 2023
6bf3fcb
more small fixes
ruseinov Feb 11, 2023
c049653
re-order methods
ruseinov Feb 12, 2023
c987805
integration tests for events
ruseinov Feb 12, 2023
e6676f7
import fix
ruseinov Feb 12, 2023
e3ae48f
fix clippy
ruseinov Feb 12, 2023
06cd68c
sort out read-only lists
ruseinov Feb 12, 2023
391b0b4
fix feature gates
ruseinov Feb 12, 2023
7780763
Merge remote-tracking branch 'origin/master' into ru/feature/stake-tr…
Feb 15, 2023
2d1fe57
Update frame/stake-tracker/src/lib.rs
ruseinov Feb 17, 2023
435d72b
address some review comments
ruseinov Feb 17, 2023
501243b
add some docs
ruseinov Feb 17, 2023
21a90ce
Merge remote-tracking branch 'origin/master' into ru/feature/stake-tr…
Feb 17, 2023
8360474
revert reorder
ruseinov Feb 17, 2023
355145e
fix beefy tests
ruseinov Feb 17, 2023
84f8d8f
address some review comments
ruseinov Feb 19, 2023
17d0fbb
adjust docs
ruseinov Feb 19, 2023
c2d8ad4
more doc updates
ruseinov Feb 19, 2023
3f286e1
fix typo
ruseinov Feb 19, 2023
0246d7b
fix docs
ruseinov Feb 19, 2023
41b3c29
Merge branch 'master' into ru/feature/stake-tracker-voter
ruseinov Feb 22, 2023
d1b783c
Update frame/stake-tracker/src/lib.rs
ruseinov Feb 26, 2023
e12473f
Merge remote-tracking branch 'origin/master' into ru/feature/stake-tr…
Feb 26, 2023
5736950
Merge remote-tracking branch 'origin/master' into ru/feature/stake-tr…
Mar 5, 2023
7d136f9
Merge remote-tracking branch 'origin/master' into ru/feature/stake-tr…
Mar 11, 2023
9332d75
address some of the PR comments
ruseinov Mar 13, 2023
f143653
defensive unstake
ruseinov Mar 13, 2023
605816d
re-arrange testing events
ruseinov Mar 13, 2023
66cd197
Merge branch 'master' into ru/feature/stake-tracker-voter
ruseinov Mar 13, 2023
a7250dd
fixup stake-tracker tests
ruseinov Mar 14, 2023
0cb3222
reinstate migration changes
ruseinov Mar 14, 2023
d79ac49
basic OnStakingUpdate staking tests
ruseinov Mar 14, 2023
9eb705a
more fixes
ruseinov Mar 14, 2023
6a305f8
more fixes
ruseinov Mar 14, 2023
20f02e9
rm deprecated
ruseinov Mar 14, 2023
9f28619
fix comment
ruseinov Mar 14, 2023
8bbfd2b
on_stake_update defensive tests
ruseinov Mar 14, 2023
f8dabaa
more defensive tests
ruseinov Mar 14, 2023
32509ad
fix rustdoc again
ruseinov Mar 15, 2023
ef6bbc3
Merge remote-tracking branch 'origin/master' into ru/feature/stake-tr…
Mar 18, 2023
69e70f9
fix balances
ruseinov Mar 18, 2023
9ad762b
address comments
ruseinov Mar 18, 2023
03154ec
remove unnecessary loops
ruseinov Mar 21, 2023
ecf831e
fix some event-handlers to be fired post-action
ruseinov Mar 21, 2023
4fd1c49
fix do_add_nominator
ruseinov Mar 21, 2023
78d8d6f
Merge remote-tracking branch 'origin/master' into ru/feature/stake-tr…
Mar 22, 2023
855100a
Merge remote-tracking branch 'origin/master' into ru/feature/stake-tr…
Mar 30, 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
28 changes: 28 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ members = [
"frame/session/benchmarking",
"frame/society",
"frame/staking",
"frame/stake-tracker",
"frame/staking/reward-curve",
"frame/staking/reward-fn",
"frame/staking/runtime-api",
Expand Down
3 changes: 3 additions & 0 deletions bin/node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ pallet-salary = { version = "4.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-staking-runtime-api = { version = "4.0.0-dev", default-features = false, path = "../../../frame/staking/runtime-api" }
pallet-state-trie-migration = { version = "4.0.0-dev", default-features = false, path = "../../../frame/state-trie-migration" }
Expand Down Expand Up @@ -184,6 +185,7 @@ std = [
"sp-runtime/std",
"sp-staking/std",
"pallet-staking/std",
"pallet-stake-tracker/std",
"pallet-staking-runtime-api/std",
"pallet-state-trie-migration/std",
"pallet-salary/std",
Expand Down Expand Up @@ -326,6 +328,7 @@ try-runtime = [
"pallet-salary/try-runtime",
"pallet-session/try-runtime",
"pallet-staking/try-runtime",
"pallet-stake-tracker/try-runtime",
"pallet-state-trie-migration/try-runtime",
"pallet-scheduler/try-runtime",
"pallet-society/try-runtime",
Expand Down
10 changes: 9 additions & 1 deletion bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -586,14 +586,21 @@ impl pallet_staking::Config for Runtime {
type OffendingValidatorsThreshold = OffendingValidatorsThreshold;
type ElectionProvider = ElectionProviderMultiPhase;
type GenesisElectionProvider = onchain::OnChainExecution<OnChainSeqPhragmen>;
type VoterList = VoterList;
type VoterList = pallet_stake_tracker::TrackedList<AccountId, VoterList>;
// This a placeholder, to be introduced in the next PR as an instance of bags-list
type TargetList = pallet_staking::UseValidatorsMap<Self>;
type MaxUnlockingChunks = ConstU32<32>;
type HistoryDepth = HistoryDepth;
type OnStakerSlash = NominationPools;
type WeightInfo = pallet_staking::weights::SubstrateWeight<Runtime>;
type BenchmarkingConfig = StakingBenchmarkingConfig;
type EventListeners = StakeTracker;
}

impl pallet_stake_tracker::Config for Runtime {
type Currency = Balances;
type Staking = Staking;
type VoterList = VoterList;
}

impl pallet_fast_unstake::Config for Runtime {
Expand Down Expand Up @@ -1763,6 +1770,7 @@ construct_runtime!(
AssetTxPayment: pallet_asset_tx_payment,
ElectionProviderMultiPhase: pallet_election_provider_multi_phase,
Staking: pallet_staking,
StakeTracker: pallet_stake_tracker,
Session: pallet_session,
Democracy: pallet_democracy,
Council: pallet_collective::<Instance1>,
Expand Down
1 change: 1 addition & 0 deletions frame/babe/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ impl pallet_staking::Config for Test {
type OnStakerSlash = ();
type BenchmarkingConfig = pallet_staking::TestBenchmarkingConfig;
type WeightInfo = ();
type EventListeners = ();
}

impl pallet_offences::Config for Test {
Expand Down
1 change: 1 addition & 0 deletions frame/bags-list/remote-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ targets = ["x86_64-unknown-linux-gnu"]
# frame
pallet-staking = { path = "../../staking", version = "4.0.0-dev" }
pallet-bags-list = { path = "../../bags-list", version = "4.0.0-dev", features = ["fuzz"] }

frame-election-provider-support = { path = "../../election-provider-support", version = "4.0.0-dev" }
frame-system = { path = "../../system", version = "4.0.0-dev" }
frame-support = { path = "../../support", version = "4.0.0-dev" }
Expand Down
3 changes: 1 addition & 2 deletions frame/bags-list/remote-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

//! Utilities for remote-testing pallet-bags-list.

use frame_election_provider_support::ScoreProvider;
use frame_election_provider_support::{ScoreProvider, SortedListProvider};
use pallet_bags_list::Instance1;
use sp_std::prelude::*;

Expand Down Expand Up @@ -51,7 +51,6 @@ pub fn display_and_check_bags<Runtime: RuntimeT<Instance1>>(
currency_unit: u64,
currency_name: &'static str,
) {
use frame_election_provider_support::SortedListProvider;
use frame_support::traits::Get;

let min_nominator_bond = <pallet_staking::MinNominatorBond<Runtime>>::get();
Expand Down
2 changes: 1 addition & 1 deletion frame/bags-list/remote-tests/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
//! Test to check the migration of the voter bag.

use crate::{RuntimeT, LOG_TARGET};
use frame_election_provider_support::SortedListProvider;
use frame_support::traits::PalletInfoAccess;
use pallet_staking::Nominators;
use remote_externalities::{Builder, Mode, OnlineConfig};
Expand Down Expand Up @@ -48,7 +49,6 @@ pub async fn execute<Runtime, Block>(
let pre_migrate_nominator_count = <Nominators<Runtime>>::iter().count() as u32;
log::info!(target: LOG_TARGET, "Nominator count: {}", pre_migrate_nominator_count);

use frame_election_provider_support::SortedListProvider;
// run the actual migration
let moved = <Runtime as pallet_staking::Config>::VoterList::unsafe_regenerate(
Copy link
Contributor

Choose a reason for hiding this comment

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

the previous code seems more correct to me. This test is testing the re-generation of pallet_staking::Config::VoterList. We don't care if it is backed by what..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For this we'll need to move unsafe_regenerate to ReadOnly interface, which I guess is far, since it's an unsafe method.

pallet_staking::Nominators::<Runtime>::iter().map(|(n, _)| n),
Expand Down
52 changes: 26 additions & 26 deletions frame/bags-list/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,45 +328,35 @@ impl<T: Config<I>, I: 'static> SortedListProvider<T::AccountId> for Pallet<T, I>
List::<T, I>::contains(id)
}

fn on_insert(id: T::AccountId, score: T::Score) -> Result<(), ListError> {
List::<T, I>::insert(id, score)
}

fn get_score(id: &T::AccountId) -> Result<T::Score, ListError> {
List::<T, I>::get_score(id)
}

fn on_update(id: &T::AccountId, new_score: T::Score) -> Result<(), ListError> {
Pallet::<T, I>::do_rebag(id, new_score).map(|_| ())
#[cfg(feature = "try-runtime")]
fn try_state() -> Result<(), &'static str> {
Self::do_try_state()
}

fn on_remove(id: &T::AccountId) -> Result<(), ListError> {
List::<T, I>::remove(id)
fn on_insert(id: T::AccountId, score: T::Score) -> Result<(), ListError> {
List::<T, I>::insert(id, score)
}

fn unsafe_regenerate(
all: impl IntoIterator<Item = T::AccountId>,
score_of: Box<dyn Fn(&T::AccountId) -> T::Score>,
) -> u32 {
// NOTE: This call is unsafe for the same reason as SortedListProvider::unsafe_regenerate.
// I.e. because it can lead to many storage accesses.
// So it is ok to call it as caller must ensure the conditions.
List::<T, I>::unsafe_regenerate(all, score_of)
fn on_update(id: &T::AccountId, new_score: T::Score) -> Result<(), ListError> {
Pallet::<T, I>::do_rebag(id, new_score).map(|_| ())
}

#[cfg(feature = "try-runtime")]
fn try_state() -> Result<(), &'static str> {
Self::do_try_state()
fn on_remove(id: &T::AccountId) -> Result<(), ListError> {
List::<T, I>::remove(id)
}

fn unsafe_clear() {
// NOTE: This call is unsafe for the same reason as SortedListProvider::unsafe_clear.
// I.e. because it can lead to many storage accesses.
// So it is ok to call it as caller must ensure the conditions.
List::<T, I>::unsafe_clear()
}
frame_election_provider_support::runtime_benchmarks_or_test_enabled! {
fn unsafe_clear() {
// NOTE: This call is unsafe for the same reason as SortedListProvider::unsafe_clear.
// I.e. because it can lead to many storage accesses.
// So it is ok to call it as caller must ensure the conditions.
List::<T, I>::unsafe_clear()
}

frame_election_provider_support::runtime_benchmarks_enabled! {
fn score_update_worst_case(who: &T::AccountId, is_increase: bool) -> Self::Score {
use frame_support::traits::Get as _;
let thresholds = T::BagThresholds::get();
Expand All @@ -388,6 +378,16 @@ impl<T: Config<I>, I: 'static> SortedListProvider<T::AccountId> for Pallet<T, I>
}
}
}

fn unsafe_regenerate(
all: impl IntoIterator<Item = T::AccountId>,
score_of: Box<dyn Fn(&T::AccountId) -> T::Score>,
) -> u32 {
// NOTE: This call is unsafe for the same reason as SortedListProvider::unsafe_regenerate.
// I.e. because it can lead to many storage accesses.
// So it is ok to call it as caller must ensure the conditions.
List::<T, I>::unsafe_regenerate(all, score_of)
}
}

impl<T: Config<I>, I: 'static> ScoreProvider<T::AccountId> for Pallet<T, I> {
Expand Down
1 change: 1 addition & 0 deletions frame/beefy/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ impl pallet_staking::Config for Test {
type OnStakerSlash = ();
type BenchmarkingConfig = pallet_staking::TestBenchmarkingConfig;
type WeightInfo = ();
type EventListeners = ();
}

impl pallet_offences::Config for Test {
Expand Down
24 changes: 13 additions & 11 deletions frame/election-provider-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,10 +476,10 @@ where
/// This is generic over `AccountId` and it can represent a validator, a nominator, or any other
/// entity.
///
/// The scores (see [`Self::Score`]) are ascending, the higher, the better.
///
/// Something that implements this trait will do a best-effort sort over ids, and thus can be
/// used on the implementing side of [`ElectionDataProvider`].
///
/// The scores (see [`Self::Score`]) are ascending, the higher, the better.
pub trait SortedListProvider<AccountId> {
/// The list's error type.
type Error: sp_std::fmt::Debug;
Expand All @@ -501,6 +501,13 @@ pub trait SortedListProvider<AccountId> {
/// Return true if the list already contains `id`.
fn contains(id: &AccountId) -> bool;

/// Get the score of `id`.
fn get_score(id: &AccountId) -> Result<Self::Score, Self::Error>;

/// Check internal state of list. Only meant for debugging.
#[cfg(feature = "try-runtime")]
fn try_state() -> Result<(), &'static str>;
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be feature gated by try-runtime.

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 thing is that this was ported from the original SortedListProvider and it definitely was not feature-gated there. And I've seen more occurrences of that in the codebase, perhaps in BagsList.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, it was missing all around bags-list. So now that's feature-gated it breaks a bunch of things. Going to be fixed as part of this PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably have fn try_state() in a separate trait and then SortedListProvider can inherit that trait.


/// Hook for inserting a new id.
///
/// Implementation should return an error if duplicate item is being inserted.
Expand All @@ -513,9 +520,6 @@ pub trait SortedListProvider<AccountId> {
/// Returns `Ok(())` iff it successfully updates an item, an `Err(_)` otherwise.
fn on_update(id: &AccountId, score: Self::Score) -> Result<(), Self::Error>;

/// Get the score of `id`.
fn get_score(id: &AccountId) -> Result<Self::Score, Self::Error>;

/// Same as `on_update`, but incorporate some increased score.
fn on_increase(id: &AccountId, additional: Self::Score) -> Result<(), Self::Error> {
let old_score = Self::get_score(id)?;
Expand Down Expand Up @@ -560,16 +564,13 @@ pub trait SortedListProvider<AccountId> {
///
/// This function should never be called in production settings because it can lead to an
/// unbounded amount of storage accesses.
#[cfg(any(feature = "runtime-benchmarks", test))]
fn unsafe_clear();

/// Check internal state of the list. Only meant for debugging.
#[cfg(feature = "try-runtime")]
fn try_state() -> Result<(), &'static str>;

/// If `who` changes by the returned amount they are guaranteed to have a worst case change
/// in their list position.
#[cfg(feature = "runtime-benchmarks")]
fn score_update_worst_case(_who: &AccountId, _is_increase: bool) -> Self::Score;
#[cfg(any(feature = "runtime-benchmarks", test))]
fn score_update_worst_case(who: &AccountId, is_increase: bool) -> Self::Score;
}

/// Something that can provide the `Score` of an account. Similar to [`ElectionProvider`] and
Expand Down Expand Up @@ -675,3 +676,4 @@ pub type BoundedSupportsOf<E> = BoundedSupports<

sp_core::generate_feature_enabled_macro!(runtime_benchmarks_enabled, feature = "runtime-benchmarks", $);
sp_core::generate_feature_enabled_macro!(runtime_benchmarks_or_fuzz_enabled, any(feature = "runtime-benchmarks", feature = "fuzzing"), $);
sp_core::generate_feature_enabled_macro!(runtime_benchmarks_or_test_enabled, any(feature = "runtime-benchmarks", test), $);
1 change: 1 addition & 0 deletions frame/fast-unstake/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ impl pallet_staking::Config for Runtime {
type OnStakerSlash = ();
type BenchmarkingConfig = pallet_staking::TestBenchmarkingConfig;
type WeightInfo = ();
type EventListeners = ();
}

pub struct BalanceToU256;
Expand Down
1 change: 1 addition & 0 deletions frame/grandpa/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ impl pallet_staking::Config for Test {
type OnStakerSlash = ();
type BenchmarkingConfig = pallet_staking::TestBenchmarkingConfig;
type WeightInfo = ();
type EventListeners = ();
}

impl pallet_offences::Config for Test {
Expand Down
1 change: 1 addition & 0 deletions frame/nomination-pools/benchmarking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ frame-support = { version = "4.0.0-dev", default-features = false, path = "../..
frame-system = { version = "4.0.0-dev", default-features = false, path = "../../system" }
pallet-bags-list = { version = "4.0.0-dev", default-features = false, path = "../../bags-list" }
pallet-staking = { version = "4.0.0-dev", default-features = false, path = "../../staking" }
pallet-stake-tracker = { version = "4.0.0-dev", default-features = false, path = "../../stake-tracker" }
pallet-nomination-pools = { version = "1.0.0", default-features = false, path = "../" }

# Substrate Primitives
Expand Down
4 changes: 2 additions & 2 deletions frame/nomination-pools/benchmarking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -684,12 +684,12 @@ frame_benchmarking::benchmarks! {
.collect();

assert_ok!(T::Staking::nominate(&pool_account, validators));
assert!(T::Staking::nominations(Pools::<T>::create_bonded_account(1)).is_some());
assert!(T::Staking::nominations(&Pools::<T>::create_bonded_account(1)).is_some());

whitelist_account!(depositor);
}:_(RuntimeOrigin::Signed(depositor.clone()), 1)
verify {
assert!(T::Staking::nominations(Pools::<T>::create_bonded_account(1)).is_none());
assert!(T::Staking::nominations(&Pools::<T>::create_bonded_account(1)).is_none());
}

set_commission {
Expand Down
8 changes: 8 additions & 0 deletions frame/nomination-pools/benchmarking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@ impl pallet_staking::Config for Runtime {
type OnStakerSlash = Pools;
type BenchmarkingConfig = pallet_staking::TestBenchmarkingConfig;
type WeightInfo = ();
type EventListeners = StakeTracker;
}

impl pallet_stake_tracker::Config for Runtime {
Copy link
Contributor

Choose a reason for hiding this comment

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

We can technically still use VoterList directly as well, no? AFAIR, bags-list pallet still implements SortedListProvider.

I think we should either remove the implementation, or for tests and occasions where it doesn't matter too much, use the old one, essentially not needing to add pallet_stake_tracker into the equation.

Although, frankly, I am now a bit confused myself about when to use which, if both are options.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we can use VoterList directly here. StakeTracker is needed, because without it benchmark tests fail, it has been introduced for a reason.
Basically we can use VoterList directly everywhere, but it seems like a good idea to actually wrap it with TrackedList abstraction for good usage examples, that way the users are going to have a better understanding. It would be even better if we could restrict staking to that type for both VoterList and TargetList, but then it needs to be moved to primitives.

type Currency = Balances;
type Staking = Staking;
type VoterList = VoterList;
}

parameter_types! {
Expand Down Expand Up @@ -188,6 +195,7 @@ frame_support::construct_runtime!(
Staking: pallet_staking::{Pallet, Call, Config<T>, Storage, Event<T>},
VoterList: pallet_bags_list::<Instance1>::{Pallet, Call, Storage, Event<T>},
Pools: pallet_nomination_pools::{Pallet, Call, Storage, Event<T>},
StakeTracker: pallet_stake_tracker::{Pallet, Storage},
}
);

Expand Down
Loading