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

Refactor staking ledger #14582

Open
wants to merge 49 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
0c41dd3
Refactors StakingLedger to own module
gpestana Jul 12, 2023
cc12800
Refactors set_lock and remove_lock calls into StakingLedger methods; …
gpestana Jul 13, 2023
9ab1ba2
re-exposes Pallet::<T>::ledger which calls into StakingLedger methods
gpestana Jul 14, 2023
78f4ff6
Fixes benchmarks
gpestana Jul 14, 2023
8c4d2b0
Improves docs
gpestana Jul 17, 2023
2f34a49
Fixes rust docs
gpestana Jul 17, 2023
7382216
Improves expect message for controller
gpestana Jul 17, 2023
acb71b3
Encapsulates Bond mutations and reads into StakingLedger
gpestana Jul 18, 2023
f4b1062
Refactors leftover calls to Bonded and Ledger under StakingLedger
gpestana Jul 18, 2023
f1942b6
Further refactors
gpestana Jul 19, 2023
f01d214
Refactors staking ledger API; Adds documentation
gpestana Jul 20, 2023
b8a785d
Pallet::ledger now accepts a StakingAccount which can be a controller…
gpestana Jul 20, 2023
be0c582
nits
gpestana Jul 20, 2023
cfc4f2b
Simplifies logic and removes the StakingLedgerStatus; Adds ledger tests
gpestana Jul 26, 2023
eb3e731
Removes ledger.bond; fixes benchmarks
gpestana Jul 28, 2023
df90343
Adds ledger.bond again as syntatic sugar for ledger.update
gpestana Jul 29, 2023
f091fac
Adds tests for ledger.bond
gpestana Jul 29, 2023
7fefcef
Update frame/staking/src/pallet/impls.rs
gpestana Jul 29, 2023
9cb56cc
Update frame/staking/src/ledger.rs
gpestana Jul 29, 2023
2acb835
Update frame/staking/src/lib.rs
gpestana Jul 30, 2023
1198297
Refactors staking ledger get to result; other nits
gpestana Jul 31, 2023
283ab0b
nit
gpestana Jul 31, 2023
9e59fcc
Update frame/staking/src/ledger.rs
gpestana Jul 31, 2023
c56fa7e
Update frame/staking/src/pallet/impls.rs
gpestana Jul 31, 2023
2e0f050
Simplifies code and adds some comment nits
gpestana Jul 31, 2023
7bfe9cd
".git/.scripts/commands/fmt/fmt.sh"
Jul 31, 2023
2cd73bc
restart CI jobs
gpestana Jul 31, 2023
61928bc
Merge remote-tracking branch 'origin/master' into gpestana/staking-le…
Jul 31, 2023
d5c7ee3
Fixes EPM e2e tests
gpestana Jul 31, 2023
10fa2b3
Fixes rust docs warning
gpestana Jul 31, 2023
fe27f2c
Update frame/staking/src/ledger.rs
gpestana Aug 1, 2023
1929868
Update frame/staking/src/ledger.rs
gpestana Aug 1, 2023
fceeaa9
Update frame/staking/src/ledger.rs
gpestana Aug 1, 2023
55a1598
Update frame/staking/src/ledger.rs
gpestana Aug 1, 2023
47ff62e
Update frame/staking/src/pallet/impls.rs
gpestana Aug 1, 2023
c9850b1
Update frame/staking/src/pallet/impls.rs
gpestana Aug 1, 2023
778bc00
Adds license and mod rust docs to ledger
gpestana Aug 1, 2023
f788884
Update frame/staking/src/ledger.rs
gpestana Aug 1, 2023
5309a86
Update frame/staking/src/ledger.rs
gpestana Aug 1, 2023
90c2187
".git/.scripts/commands/fmt/fmt.sh"
Aug 1, 2023
ed99af2
addresses PR comments pt1
gpestana Aug 7, 2023
ad9b5ac
Update frame/staking/src/ledger.rs
gpestana Aug 7, 2023
e1093e5
addresses PR comments pt2
gpestana Aug 7, 2023
17abac8
improvements pt3. ledger consume itself on update
gpestana Aug 7, 2023
3060341
Merge branch 'master' into gpestana/staking-ledger-ref
gpestana Aug 10, 2023
c26b8e5
Moves back StakingLedger main impl to src/lib.rs to improve diff
gpestana Aug 10, 2023
c07a79f
adds tracking issue for moving StakingLedger impl
gpestana Aug 10, 2023
aee88cc
rollback to previous impl to decrease diff
gpestana Aug 10, 2023
073ec37
nit
gpestana Aug 10, 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
10 changes: 5 additions & 5 deletions frame/election-provider-multi-phase/test-staking-e2e/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ fn ledger_consistency_active_balance_below_ed() {
ExtBuilder::default().staking(StakingExtBuilder::default()).build_offchainify();

ext.execute_with(|| {
assert_eq!(Staking::ledger(&11).unwrap().active, 1000);
assert_eq!(Staking::ledger(11.into()).unwrap().active, 1000);

// unbonding total of active stake fails because the active ledger balance would fall
// below the `MinNominatorBond`.
Expand All @@ -356,13 +356,13 @@ fn ledger_consistency_active_balance_below_ed() {

// the active balance of the ledger entry is 0, while total balance is 1000 until
// `withdraw_unbonded` is called.
assert_eq!(Staking::ledger(&11).unwrap().active, 0);
assert_eq!(Staking::ledger(&11).unwrap().total, 1000);
assert_eq!(Staking::ledger(11.into()).unwrap().active, 0);
assert_eq!(Staking::ledger(11.into()).unwrap().total, 1000);

// trying to withdraw the unbonded balance won't work yet because not enough bonding
// eras have passed.
assert_ok!(Staking::withdraw_unbonded(RuntimeOrigin::signed(11), 0));
assert_eq!(Staking::ledger(&11).unwrap().total, 1000);
assert_eq!(Staking::ledger(11.into()).unwrap().total, 1000);

// tries to reap stash after chilling, which fails since the stash total balance is
// above ED.
Expand All @@ -384,6 +384,6 @@ fn ledger_consistency_active_balance_below_ed() {
pool_state,
);
assert_ok!(Staking::withdraw_unbonded(RuntimeOrigin::signed(11), 0));
assert_eq!(Staking::ledger(&11), None);
assert!(Staking::ledger(11.into()).is_err());
});
}
2 changes: 1 addition & 1 deletion frame/session/benchmarking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ fn check_membership_proof_setup<T: Config>(
use rand::{RngCore, SeedableRng};

let validator = T::Lookup::lookup(who).unwrap();
let controller = pallet_staking::Pallet::<T>::bonded(validator).unwrap();
let controller = pallet_staking::Pallet::<T>::bonded(&validator).unwrap();

let keys = {
let mut keys = [0u8; 128];
Expand Down
16 changes: 8 additions & 8 deletions frame/staking/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use frame_support::{
};
use sp_runtime::{
traits::{Bounded, One, StaticLookup, TrailingZeroInput, Zero},
Perbill, Percent,
Perbill, Percent, Saturating,
};
use sp_staking::{currency_to_vote::CurrencyToVote, SessionIndex};
use sp_std::prelude::*;
Expand Down Expand Up @@ -685,13 +685,13 @@ benchmarks! {
let stash = scenario.origin_stash1;

add_slashing_spans::<T>(&stash, s);
let l = StakingLedger {
stash: stash.clone(),
active: T::Currency::minimum_balance() - One::one(),
total: T::Currency::minimum_balance() - One::one(),
unlocking: Default::default(),
claimed_rewards: Default::default(),
};
let l = StakingLedger::<T>::new(
stash.clone(),
T::Currency::minimum_balance() - One::one(),
T::Currency::minimum_balance() - One::one(),
Default::default(),
Default::default(),
);
Ledger::<T>::insert(&controller, l);

assert!(Bonded::<T>::contains_key(&stash));
Expand Down
Loading