frequency-chain / frequency

Frequency: A Polkadot Parachain
https://www.frequency.xyz
Apache License 2.0
48 stars 18 forks source link

upsert staking history #1699 #1963

Closed shannonwells closed 2 months ago

shannonwells commented 2 months ago

Goal

The goal of this PR is to add and use storage for individual staking history so that rewards can be calculated and paid out.

Relates to #1699

Discussion

Checking for whether a stake Provider Boost has been done earlier than the history retention limit (in number of RewardEras) must be left for when rewards are claimed. The record needs to be kept around because it may still be valid for some eras. Examples:

  1. Stake an amount, wait until +1 > history limit then claim.
    • You have only 1 entry
    • There is no mechanism to automatically reap it
    • Need to keep the record around because we should pay out remaining eras.
  2. Stake an amount, change stake every era
    • No problem because if you are staking/unstaking every era the limit will be hit automatically.
  3. Stake an amount, wait limit/2, unstake full amount, wait until +1 > history limit then claim
    • Not much different from example 1. As long as there is nonzero stake within the era limit, the chain still needs to pay out those eras.
  4. Say history limit is 10. Stake an amount in era 10.
    • Unstake everything in era 12, so era 11 is eligible for a reward.
    • But try to claim in era 22.
    • you can't since are no valid eras to claim rewards for any more (history limit + 1), however, on this claim attempt since there is no more staking, all boost history storage can be deleted.

Checklist