Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provider Boosting implementation #1694

Draft
wants to merge 65 commits into
base: main
Choose a base branch
from

Commits on Jul 23, 2024

  1. some words

    shannonwells committed Jul 23, 2024
    Configuration menu
    Copy the full SHA
    ac64e47 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    8f9b426 View commit details
    Browse the repository at this point in the history
  3. updates to design docs to use a capacity rewards interface

    Prototypes, make check working
    shannonwells committed Jul 23, 2024
    Configuration menu
    Copy the full SHA
    042c7c7 View commit details
    Browse the repository at this point in the history
  4. make check and make test working

    updates to impl design doc
    shannonwells committed Jul 23, 2024
    Configuration menu
    Copy the full SHA
    82ea1b8 View commit details
    Browse the repository at this point in the history
  5. remove economic model design doc until further notice

    refinements to design doc
    shannonwells committed Jul 23, 2024
    Configuration menu
    Copy the full SHA
    0dbcb90 View commit details
    Browse the repository at this point in the history
  6. Implement Staking Reward Eras basics (#1589)

    Implement the basic functionality of tracking and rotating Reward Era. Closes #1567
    Does not include anything to do with the Reward Pool.
    
    - [x] Chain spec updated
    - [x] Design doc(s) updated
    - [x] Tests added
    shannonwells committed Jul 23, 2024
    Configuration menu
    Copy the full SHA
    076c6ff View commit details
    Browse the repository at this point in the history
  7. Feat/staking rewards rewards provider #1572 (#1598)

    The goal of this PR is to implement a really basic version of the
    StakingRewardsProvider in the Capacity pallet and in the test mock,
    neither of which is actively used.
    
    Closes #1572
    
    Does not include anything to do with setting and storing RewardPoolInfo
    when each new Era starts.
    
    - [x] Design doc(s) updated
    - [x] Tests added
    shannonwells committed Jul 23, 2024
    Configuration menu
    Copy the full SHA
    e871a27 View commit details
    Browse the repository at this point in the history
  8. Configuration menu
    Copy the full SHA
    7cfc638 View commit details
    Browse the repository at this point in the history
  9. Configuration menu
    Copy the full SHA
    4e6465b View commit details
    Browse the repository at this point in the history
  10. * Refactor staking type to go in StakingTargetDetails

    * Make some functions pass by reference (performance)
    * fix broken tests & calls
    shannonwells committed Jul 23, 2024
    Configuration menu
    Copy the full SHA
    928dc4c View commit details
    Browse the repository at this point in the history
  11. Configuration menu
    Copy the full SHA
    71b51d8 View commit details
    Browse the repository at this point in the history
  12. * Check from/to aren't the same when retargeting

    * Performance: move non-db checks to top when retargeting
    * Lots more tests
    * Fix a bug where we weren't setting the staking type on a retarget
    * Remove staking type from StakingAccountDetails
    * Fix broken tests from last commit
    shannonwells committed Jul 23, 2024
    Configuration menu
    Copy the full SHA
    e6c22e8 View commit details
    Browse the repository at this point in the history
  13. Feat/reward pool history (#1710)

    The goal of this PR is to implement storage of reward pool history.
    
    Closes #1710
    shannonwells committed Jul 23, 2024
    Configuration menu
    Copy the full SHA
    699471d View commit details
    Browse the repository at this point in the history
  14. Feat/split stake extrinsic #1699 (#1717)

    The goal of this PR is to split the `stake` extrinsic into two: `stake` and `provider_boost`
    Closes #1707
    shannonwells committed Jul 23, 2024
    Configuration menu
    Copy the full SHA
    4a29295 View commit details
    Browse the repository at this point in the history
  15. Feat/split storage #1726 (#1744)

    The goal of this PR is to split up storage of boosting and maximized staking accounts,
    as well as store retarget history separately, which can store retargeting events for
    any type of staking.
    
    Closes #1726
    
    * Lots of rattle, causing several helper functions to be split up -
    rather than having a bunch of conditionals due to type differences.
    * In the interest of limiting the size of this PR/merge into the branch
    I left a lot of TODOs for when reward pool updates on a
    stake/boost/unstake is resumed
    shannonwells committed Jul 23, 2024
    Configuration menu
    Copy the full SHA
    ef48e8e View commit details
    Browse the repository at this point in the history
  16. Configuration menu
    Copy the full SHA
    318c4ce View commit details
    Browse the repository at this point in the history
  17. updates after rebase

    shannonwells committed Jul 23, 2024
    Configuration menu
    Copy the full SHA
    169e0a4 View commit details
    Browse the repository at this point in the history
  18. Configuration menu
    Copy the full SHA
    1414262 View commit details
    Browse the repository at this point in the history
  19. Set ProviderBoost capacity generated and fix tests (#1947)

    * set the amount of capacity generated by a provider boost to the final amount, 50% of what is generated by MaximizedCapacity staking.
    * Also Fixes some tests broken from the last rebase with main.
    Closes #1569
    shannonwells committed Jul 23, 2024
    Configuration menu
    Copy the full SHA
    cd0e239 View commit details
    Browse the repository at this point in the history
  20. Update reward pool on provider_boost or unstake #1699 (#1948)

    The goal of this PR is to update the StakingRewardPool on a `provider_boost` or `unstake` extrinsic call.
    
    Closes #1699
    
    Also includes a bunch of lint changes
    
    - [x] Design doc(s) updated
    - [x] Tests added
    - [x] Benchmarks corrected and updated
    - [x] Weights updated
    shannonwells committed Jul 23, 2024
    Configuration menu
    Copy the full SHA
    85d1d90 View commit details
    Browse the repository at this point in the history
  21. Implement rewards calculation formula #1941 (#1956)

    The goal of this PR is to implement (but not really use yet) the chosen
    formula for calculation of a reward in a single Provider Boost Reward
    Era.
    
    Closes #1941
    shannonwells committed Jul 23, 2024
    Configuration menu
    Copy the full SHA
    b2360de View commit details
    Browse the repository at this point in the history
  22. updates after rebase

    shannonwells committed Jul 23, 2024
    Configuration menu
    Copy the full SHA
    fb7c153 View commit details
    Browse the repository at this point in the history
  23. upsert staking history #1699 (#1963)

    The goal of this PR is to add and use storage for individual staking history so that rewards can be calculated and paid out.  Benchmarks run to update capacity weights.
    
    Relates to #1699
    shannonwells committed Jul 23, 2024
    Configuration menu
    Copy the full SHA
    5354673 View commit details
    Browse the repository at this point in the history
  24. Chores/update capacity benchmarks #1949 (#1966)

    The goal of this PR is to update the benchmark for `on_initialize` to include the weight when a new RewardEra must be created.
    
    Closes #1949
    shannonwells committed Jul 23, 2024
    Configuration menu
    Copy the full SHA
    b94bd78 View commit details
    Browse the repository at this point in the history
  25. Feat/check unclaimed rewards 1969 (#1972)

    The goal of this PR is to implement `list_unclaimed_rewards`, and also
    one that is lighter weight, `has_unclaimed_rewards`, which returns a
    `bool` and which `unstake` extrinsic uses. Unstake now fails if there
    are any unclaimed rewards.
    
    Closes #1969
    Closes #1578
    shannonwells committed Jul 23, 2024
    Configuration menu
    Copy the full SHA
    863e26a View commit details
    Browse the repository at this point in the history
  26. Configuration menu
    Copy the full SHA
    69f5198 View commit details
    Browse the repository at this point in the history
  27. Configuration menu
    Copy the full SHA
    869cb1a View commit details
    Browse the repository at this point in the history
  28. Feat/reward pool refactor #1976 (#2005)

    The goal of this PR is to implement a "chunk" version of the overall
    reward pool history to reduce read/write load and hence weight for
    transactions and `on_initialize` when a new `RewardEra` needs to start.
    
    Part of #1976
    
    Co-authored-by: Wil Wade <wil.wade@amplica.io>
    shannonwells and wilwade committed Jul 23, 2024
    Configuration menu
    Copy the full SHA
    b9466a8 View commit details
    Browse the repository at this point in the history
  29. Revise Provider Boost implementation design doc #2016 (#2020)

    # Goal
    The goal of this PR is to review and update the implementation design doc in light of the chosen economic model, and to reflect some changes in behavior.  Review of the design doc also fed back into the code itself. Some code
    is no longer needed.
    
    Closes #2016 
    ---------
    
    Co-authored-by: Aramik <aramikm@gmail.com>
    shannonwells and aramikm committed Jul 23, 2024
    Configuration menu
    Copy the full SHA
    078d412 View commit details
    Browse the repository at this point in the history
  30. E2e for new extrinsics (#2067)

    The goal of this PR is to add some e2e tests for the `provider_boost` extrinsic, and update the `change_staking_target` extrinsic after a rebase with main.
    shannonwells committed Jul 23, 2024
    Configuration menu
    Copy the full SHA
    07599e9 View commit details
    Browse the repository at this point in the history
  31. Refactor reward era (#2069)

    # Goal
    The goal of this PR is primarily to pull RewardEra out of the Capacity Config and make it the same type everywhere.
    
    Other changes in this PR that were incidental to this refactor
    * I renamed staking_events in testing_utils, because it captures all the events from the pallet.
    * I pulled out RewardEraLength into constants so it could be different for different environments.
    
    Related to #1970
    shannonwells committed Jul 23, 2024
    Configuration menu
    Copy the full SHA
    0b35226 View commit details
    Browse the repository at this point in the history
  32. claim_staking_rewards extrinsic (#2080)

    The goal of this PR is to implement the claim_staking_rewards extrinsic, its benchmarks, and tests.
    
    Closes #1970
    shannonwells committed Jul 23, 2024
    Configuration menu
    Copy the full SHA
    6ed6217 View commit details
    Browse the repository at this point in the history
  33. updates after rebase

    shannonwells committed Jul 23, 2024
    Configuration menu
    Copy the full SHA
    f70d1aa View commit details
    Browse the repository at this point in the history
  34. Capacity runtime api with list_unclaimed_rewards endpoint (#2088)

    # Goal
    The goal of this PR is to implement a capacity runtime api for the `list_unclaimed_rewards` endpoint.
    
    Following the current recommendation of Parity, there is no custom RPC matching this runtime API endpoint; instead, use state.call to access the endpoint. For examples using either Observable or APIPromise, see the e2e tests.
    
    Closes #1698
    shannonwells committed Jul 23, 2024
    Configuration menu
    Copy the full SHA
    6a2a150 View commit details
    Browse the repository at this point in the history
  35. Configuration menu
    Copy the full SHA
    233496b View commit details
    Browse the repository at this point in the history
  36. please the linter

    shannonwells committed Jul 23, 2024
    Configuration menu
    Copy the full SHA
    fe94fcf View commit details
    Browse the repository at this point in the history
  37. Configuration menu
    Copy the full SHA
    ae0236b View commit details
    Browse the repository at this point in the history
  38. Configuration menu
    Copy the full SHA
    ffb5a7f View commit details
    Browse the repository at this point in the history
  39. Remove TODO since it's already been addressed.

    Add a minor test case to unstaking tests
    Add new extrinsics to Capacity README
    shannonwells committed Jul 23, 2024
    Configuration menu
    Copy the full SHA
    78ee1ca View commit details
    Browse the repository at this point in the history

Commits on Jul 30, 2024

  1. Configuration menu
    Copy the full SHA
    8e26370 View commit details
    Browse the repository at this point in the history
  2. Bump Spec Version

    wilwade committed Jul 30, 2024
    Configuration menu
    Copy the full SHA
    276fbf1 View commit details
    Browse the repository at this point in the history
  3. Fix e2e funding sources

    wilwade committed Jul 30, 2024
    Configuration menu
    Copy the full SHA
    4cf9e2f View commit details
    Browse the repository at this point in the history
  4. Update other spec version

    wilwade committed Jul 30, 2024
    Configuration menu
    Copy the full SHA
    c842471 View commit details
    Browse the repository at this point in the history
  5. e2e test formatting

    wilwade committed Jul 30, 2024
    Configuration menu
    Copy the full SHA
    bc111d7 View commit details
    Browse the repository at this point in the history
  6. Merge remote-tracking branch 'origin/main' into feat/capacity-staking…

    …-rewards-impl
    
    # Conflicts:
    #	runtime/frequency/src/lib.rs
    wilwade committed Jul 30, 2024
    Configuration menu
    Copy the full SHA
    2d8cc0f View commit details
    Browse the repository at this point in the history

Commits on Jul 31, 2024

  1. Merge remote-tracking branch 'origin/main' into feat/capacity-staking…

    …-rewards-impl
    
    # Conflicts:
    #	runtime/frequency/src/lib.rs
    wilwade committed Jul 31, 2024
    Configuration menu
    Copy the full SHA
    b7bed08 View commit details
    Browse the repository at this point in the history

Commits on Aug 2, 2024

  1. Merge remote-tracking branch 'origin/main' into feat/capacity-staking…

    …-rewards-impl
    
    # Conflicts:
    #	e2e/package-lock.json
    #	pallets/capacity/src/weights.rs
    #	runtime/frequency/src/lib.rs
    wilwade committed Aug 2, 2024
    Configuration menu
    Copy the full SHA
    5ee47ab View commit details
    Browse the repository at this point in the history
  2. Formatting

    wilwade committed Aug 2, 2024
    Configuration menu
    Copy the full SHA
    c68a698 View commit details
    Browse the repository at this point in the history
  3. Fix cargo deny

    wilwade committed Aug 2, 2024
    Configuration menu
    Copy the full SHA
    5b7b213 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    29e68c4 View commit details
    Browse the repository at this point in the history
  5. Bug fix capacity e2e test (#2110)

    # Goal
    The goal of this PR is to fix a flaky e2e test for
    `capacityRuntimeApi.listUnclaimedRewards`
    
    # Discussion
    
    - Remove redundant definitions in api-augment for Capacity
    - Updated the test to not be dependent on starting just before an era
    wilwade committed Aug 2, 2024
    Configuration menu
    Copy the full SHA
    b45c8c2 View commit details
    Browse the repository at this point in the history

Commits on Aug 5, 2024

  1. Update e2e/capacity/change_staking_target.test.ts

    Co-authored-by: Puneet Saraswat <61435908+saraswatpuneet@users.noreply.github.com>
    shannonwells and saraswatpuneet committed Aug 5, 2024
    Configuration menu
    Copy the full SHA
    35dc097 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    9ec30fb View commit details
    Browse the repository at this point in the history
  3. Fix Typo in e2e test

    wilwade committed Aug 5, 2024
    Configuration menu
    Copy the full SHA
    40f3910 View commit details
    Browse the repository at this point in the history
  4. Boosting: removed added getters (#2112)

    # Goal
    The goal of this PR is to removed added getters
    
    Related to #2105
    aramikm committed Aug 5, 2024
    Configuration menu
    Copy the full SHA
    65df923 View commit details
    Browse the repository at this point in the history
  5. Merge remote-tracking branch 'origin/main' into feat/capacity-staking…

    …-rewards-impl
    
    # Conflicts:
    #	designdocs/provider_boosting_implementation.md
    #	pallets/capacity/src/lib.rs
    #	pallets/capacity/src/tests/stake_and_deposit_tests.rs
    #	pallets/capacity/src/tests/unstaking_tests.rs
    #	pallets/capacity/src/tests/withdraw_unstaked_tests.rs
    wilwade committed Aug 5, 2024
    Configuration menu
    Copy the full SHA
    556fe38 View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    2223e4a View commit details
    Browse the repository at this point in the history
  7. Formatting fixes

    wilwade committed Aug 5, 2024
    Configuration menu
    Copy the full SHA
    6d94da0 View commit details
    Browse the repository at this point in the history
  8. Fixing passkey test

    Passkey check only balance not nonce and don't pre-fund it
    
    Working consistently
    wilwade committed Aug 5, 2024
    Configuration menu
    Copy the full SHA
    14271c8 View commit details
    Browse the repository at this point in the history

Commits on Aug 6, 2024

  1. booster: feedback 1 (#2114)

    # Goal
    The goal of this PR is to address some feedbacks
    
    - added feature flags for test only methods
    - added a constant
    - small refactor
    aramikm committed Aug 6, 2024
    Configuration menu
    Copy the full SHA
    eb68e65 View commit details
    Browse the repository at this point in the history
  2. some minor refactoring

    aramikm committed Aug 6, 2024
    Configuration menu
    Copy the full SHA
    3480405 View commit details
    Browse the repository at this point in the history
  3. Make RewardEras zero-indexed (#2115)

    # Goal
    Reward eras were 1-indexed but this made things too confusing.
    shannonwells committed Aug 6, 2024
    Configuration menu
    Copy the full SHA
    56df16d View commit details
    Browse the repository at this point in the history
  4. adding more checks

    aramikm committed Aug 6, 2024
    Configuration menu
    Copy the full SHA
    c2bef19 View commit details
    Browse the repository at this point in the history
  5. * New alias for ChunkIndex = u32

    * Use unwrap_or_default for getting a reward pool chunk
    * warning for inserting a new chunk failure
    * code golf
    * linting in e2e
    * remove unnecessary change in helpers
    shannonwells committed Aug 6, 2024
    Configuration menu
    Copy the full SHA
    abe5066 View commit details
    Browse the repository at this point in the history

Commits on Aug 26, 2024

  1. [Capacity] MinimumStakingAmount is not enforced if a stake already ex…

    …ists for a different provider (#2136)
    
    ## Summary
    
    A user can stake to multiple providers, but the minimum staking amount
    is enforced only for the first staking action that the user submits.
    
    ## Issue details
    
    During the staking process, both for the `stake` and `provider_boost`
    extrinsics, a minimum staking amount should be enforced by the
    `Runtime::MinimumStakingAmount` parameter.
    
    The current implementation of
    [ensure_can_stake](https://github.com/frequency-chain/frequency/blob/9ef58185f2230aaf92dc166fb8eade56a78e4cf3/pallets/capacity/src/lib.rs#L638)
    verifies if the amount that the account is staking in total (the current
    active staking and the new staking amount) is greater than the
    `MinimumStakingAmount`:
    
    ```rust
    let new_active_staking_amount = staking_details
    	.active
    	.checked_add(&stakable_amount)
    	.ok_or(ArithmeticError::Overflow)?;
    
    ensure!(
    	new_active_staking_amount >= T::MinimumStakingAmount::get(),
    	Error::<T>::StakingAmountBelowMinimum
    );
    ```
    
    This implies that the user has to stake the `MinimumStakingAmount` only
    when they first submit a stake for a provider, all the subsequent
    staking requests being accepted even with the amount of 1.
    
    ## Risk
    
    The current implementation does not follow the intended use-case, as
    described in the design documentation.
    An attacker could stake the minimum required amount to a provider, and
    then stake 1 token to each of the other available providers, underpaying
    for the storage that they use. This can cause a storage bloating,
    slowing down the network in the long run.
    
    ## Mitigation
    
    The `ensure_can_stake` function should verify that the `stakable_amount`
    is greater than `MinimumStakingAmount`, instead of verifying the
    `new_active_staking_amount`.
    
    Closes #2135 
    
    # Discussion
    
    - `ensure_can_stake` updated to remove the addition of the existing
    stakes and check `stakable_amount`
    - `get_stakable_amount_for` updated to use `reducible_balance` as
    recommended by parity when using the `fungible` trait.
    `reducible_balance` requires an Existential Deposit, so the unit test
    values were updated.
    - `/designdocs/capacity.md` updated to the latest code, and reflects
    changes in language due to replacing `lock`s with `freeze`s.
    - CI Checks are not running on this branch, but the unit tests and e2e
    tests passed in local.
    
    # Checklist
    - [ ] Updated Pallet Readme?
    - [ ] Updated js/api-augment for Custom RPC OR Runtime API?
    - [x] Design doc(s) updated?
    - [ ] Unit Tests added?
    - [ ] e2e Tests added?
    - [ ] Benchmarks added?
    - [x] Spec version incremented?
    
    ---------
    
    Co-authored-by: Wil Wade <wil.wade@amplica.io>
    Co-authored-by: Shannon Wells <shannonwells@users.noreply.github.com>
    3 people committed Aug 26, 2024
    Configuration menu
    Copy the full SHA
    e3ae518 View commit details
    Browse the repository at this point in the history