Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
d723499
wip: poc
wischli Jul 20, 2022
82da1d9
refactor: extrinsics and inherents
wischli Jul 28, 2022
03cd34d
refactor: remove storage redundancy
wischli Jul 29, 2022
766c777
tests: fix existing ones for staking
wischli Jul 29, 2022
791ef9c
tests: 80%
wischli Aug 1, 2022
38e92dd
feat: rm delegate_another_candidate and more
wischli Aug 1, 2022
d8bb955
docs: remove deprecated weight
wischli Aug 1, 2022
24dc4bf
Apply suggestions from code review
wischli Aug 2, 2022
7789cda
tests: 100%
wischli Aug 2, 2022
870b534
fix: benchmarks
wischli Aug 3, 2022
8926e4c
feat: remove multiple delegations (#391)
wischli Aug 8, 2022
3dd9c6d
Merge remote-tracking branch 'origin/wf/1930-staking-refactor' into w…
wischli Aug 8, 2022
05f520e
Merge branch 'develop' into wf/1930-staking-refactor
wischli Aug 8, 2022
f8c1419
Apply suggestions from code review
wischli Aug 9, 2022
ad13650
fix: suggestions from @ntn-x2 review
wischli Aug 9, 2022
adbcd46
fmt
wischli Aug 9, 2022
ddebe3a
fix: typos
wischli Aug 9, 2022
28e47ef
Merge remote-tracking branch 'origin/develop' into wf/1930-staking-re…
wischli Aug 10, 2022
7b9fda3
fix: docker file
wischli Aug 11, 2022
3e21d0c
Merge remote-tracking branch 'origin/develop' into wf/1930-staking-re…
wischli Sep 7, 2022
e70c044
feat: add staking rewards runtime api
wischli Sep 8, 2022
b1de42a
docs: add new extrinsics to staking header
wischli Sep 8, 2022
6f73296
feat: add staking rates api
wischli Sep 8, 2022
20fd523
tests: add api
wischli Sep 8, 2022
0f8160b
fix: unify staking runtime api
wischli Sep 9, 2022
420170d
refactor: stricter claiming
wischli Sep 15, 2022
25f1878
Merge remote-tracking branch 'origin/develop' into wf/1930-staking-re…
wischli Sep 15, 2022
a3b2631
fix: easy suggestions from code review
wischli Sep 16, 2022
e703493
tests: comp api claim with claiming
wischli Sep 19, 2022
02eb407
stlye: fmt
wischli Sep 19, 2022
dfbd9e3
Merge remote-tracking branch 'origin/develop' into wf/1930-staking-re…
wischli Oct 27, 2022
bc0890f
Merge remote-tracking branch 'origin/develop' into wf/1930-staking-re…
wischli Oct 28, 2022
36e4abd
tests: add safety check to API rewards
wischli Oct 31, 2022
56a5539
style: fmt
wischli Oct 31, 2022
98eab08
Merge branch 'develop' into wf/1930-staking-refactor
wischli Oct 31, 2022
30044dd
feat: write delegator state migration
wischli Sep 16, 2022
30be731
refactor: Delegator interface functions
wischli Nov 1, 2022
55c6ac3
refactor: rm Option for Delegator.owner
wischli Nov 1, 2022
cd9684e
style: apply turbofish to staking
wischli Nov 1, 2022
f459050
fix: replace RewardCount with two counters
wischli Nov 2, 2022
39e3716
refactor: rm col input for del stake adjustment
wischli Nov 2, 2022
9102cfb
Update pallets/parachain-staking/src/lib.rs
wischli Nov 3, 2022
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
Prev Previous commit
Next Next commit
refactor: remove storage redundancy
  • Loading branch information
wischli committed Jul 29, 2022
commit 03cd34d88be046723c0041a3ad3c17281d38efb5
34 changes: 8 additions & 26 deletions pallets/parachain-staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,9 @@ pub mod pallet {
/// The staking reward being unlocked does not exist.
/// Max unlocking requests reached.
NoMoreUnstaking,
/// There is no pending reward change.
NoPendingRewardChange,
/// The reward rate cannot be adjusted yet as an entire year has not
/// passed.
TooEarly,
/// Provided staked value is zero. Should never be thrown.
StakeNotFound,
/// Cannot unlock when Unstaked is empty.
Expand Down Expand Up @@ -539,8 +540,6 @@ pub mod pallet {
fn on_initialize(now: T::BlockNumber) -> frame_support::weights::Weight {
let mut post_weight = <T as Config>::WeightInfo::on_initialize_no_action();
let mut round = <Round<T>>::get();
let year = now / T::BLOCKS_PER_YEAR;
let last_update = LastRewardReduction::<T>::get();

// check for round update
if round.should_update(now) {
Expand All @@ -552,11 +551,6 @@ pub mod pallet {
Self::deposit_event(Event::NewRound(round.first, round.current));
post_weight = <T as Config>::WeightInfo::on_initialize_round_update();
}
// check for annual update of staking reward rates
if year > last_update {
PendingRewardChange::<T>::put(true);
post_weight = post_weight.saturating_add(T::DbWeight::get().writes(1));
}
// check for network reward and mint
// on success, mint each block
if now > T::NetworkRewardStart::get() {
Expand Down Expand Up @@ -687,11 +681,6 @@ pub mod pallet {
#[pallet::getter(fn rewards)]
pub(crate) type Rewards<T: Config> = StorageMap<_, Twox64Concat, T::AccountId, BalanceOf<T>, ValueQuery>;

// TODO: Docs
#[pallet::storage]
#[pallet::getter(fn pending_reward_change)]
pub(crate) type PendingRewardChange<T: Config> = StorageValue<_, bool, OptionQuery>;

pub type GenesisStaker<T> = Vec<(
<T as frame_system::Config>::AccountId,
Option<<T as frame_system::Config>::AccountId>,
Expand Down Expand Up @@ -2114,25 +2103,20 @@ pub mod pallet {
/// delegators. Moreover, sets rewards for all collators and delegators
/// before adjusting the inflation.
///
/// Requires PendingRewardChange to be set to Some(true) which happens
/// once per year in `on_initialize`.
///
/// Emits `RoundInflationSet`.
// TODO: benchmark
#[pallet::weight(0)]
pub fn execute_pending_reward_change(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
ensure_signed(origin)?;

ensure!(
PendingRewardChange::<T>::get() == Some(true),
Error::<T>::NoPendingRewardChange
);

// Calculate new inflation based on last year
let now = frame_system::Pallet::<T>::block_number();
let year = now / T::BLOCKS_PER_YEAR;
let inflation = InflationConfig::<T>::get();
let last_update = LastRewardReduction::<T>::get();

ensure!(year > last_update, Error::<T>::TooEarly);

// Calculate new inflation based on last year
let inflation = InflationConfig::<T>::get();
// collator reward rate decreases by 2% p.a. of the previous one
let c_reward_rate = inflation.collator.reward_rate.annual * Perquintill::from_percent(98);
// delegator reward rate should be 6% in 2nd year and 0% afterwards
Expand All @@ -2158,8 +2142,6 @@ pub mod pallet {
CandidatePool::<T>::iter().for_each(|(id, state)| {
Self::inc_collator_reward(&id, state.stake);
});
// reset pending reward change
PendingRewardChange::<T>::put(false);

// update inflation config
InflationConfig::<T>::put(new_inflation.clone());
Expand Down