Gonçalo Pestana
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    ## `TargetList` sorted by approvals stake ➡️ Implementation at https://github.com/paritytech/polkadot-sdk/pull/1933 We want to maintain the list of staking targets sorted by their approvals stake and ensure that the list is *updated and sorted at all times*. The [stake tracker pallet](https://github.com/paritytech/polkadot-sdk/pull/1654) implements the `OnStakingUpdate` interface and will be used as the event handler that keeps both `VoterList` and `SortedList` (both implemented as bags lists) up to date. It is important to keep the target list up to date with regard to the approvals stake when the number so that in case the number of registered validators is larger than the number of validators that are However, updating the approvals stakes at the time of rewards (i.e. `Call::payout_stakers`) may be infeasible given the computation and storage writes required to keep the approvals up to date. Note that for each nominator payout, *all* the nominated validators need to get their approvals stake score up dated. **Complexity**: Assuming that the approvals stakes are *all* updated at the time of rewards, a call to `payout_stakers` touching `N` (unbounded) nominators, each nominating `V` validators (bounded by the max nominations per nominator) requires `O(N * V)` approval votes updates. Since `N` is unbounded, this is an issue. ### Option 1. Update validators' approvals stake from nominator rewards lazily For each ledger update related to _nominator_ rewards, the approvals stakes of the nominated validators are not updated automatically. Instead, a reward counter in the nominator's ledger, `approvals_queued`, is updated. The nominator rewards that have not been tallied as target approvals score will be kept in the ledger as queued approvals rewards counter. The `approvals_queued` are settled and added to the validator's approvals score of the nominated whenever an action is performed on a nominator's ledger (`nominate`, etc). ```rust= pub struct StakingLedger<T: Config> { // ... approvals_queued: Balance, // probably better to keep track of this *outside* of the ledger, tbd } impl<T: Config> StakingLedger<T> { fn increase_queued_approvals(mut self, Balance) {} fn reset_queued_approvals(mut self) {} } ``` In addition, we could expose a way for validators to explicitly request the settement of queued approvals from a bounded vec of nominators through an extrinsic. **Complexity**: With this design, a call to `payout_stakers` touching `N` (unbounded) nominators, each nominating `V` validators (bounded by the max nominations per nominator) requires `O(1)` approval votes updates (the validator that is being rewarded only). When a nominator ledger is updated, there are `O(V)` score updates. Since `V` is bounded, we're gold. **Advantages** - The target approvals score will *eventually* be updated implicitly; - The difference of approvals across validators due to the queued approvals will most likely spread out evenly across all the validators, which is fair and will potentially lead to a relative correct sorting of the targets list. - Lazily updating the approvals score helps spreading the blockspace required to update the approvals scores; - Less fees for caller of `stakers_payout` to pay, compared to full stakes update. - Eventual update of the approvals happens implicitly without requiring extra actions from any staker. **Disadvantages** - The approvals score will be slightly out of date (but the diff will spread out and balance relatively evenly across the most popular validators); - The nominator actions where the queued approvals are settled will be more expensive (perhaps we could selectively remove the fees to pay related to the queued approvals settlement, while still accounting for the block weight required to update the approvals score). ### Option 2. Let anyone update the approvals stake of validators Expose an extrinsic where anyone could pay for a approvals score update of a validator given a bounded list of nominators. This way, the approvals score will be based on a subset of nominators only. The validator has the incentives to call the `set_approvals` when their current score is lower than the potential one. ```rust= impl<T: Config> Pallet<T> { #[pallet::call_index(X)] #[pallet::weight(T::WeightInfo::set_aprovals())] pub fn set_approvals( origin: OriginFor<T>, target: AccountId, nominations: BoundedVec<T::AccountId, T::SomeMax>, ) -> DispatchResult { let mut approvals_score: Balance = Zero::zero(); for nominator in nominations.into_iter() { // if nominator is exposed to target, add staked // ledger funds to the `approvals_score` accumulator. } <T::TargetList as SortedListProvider>::set_score_of( target, approvals_score, ); } } ``` **Disadvantages**: - The validator has no incentive to call `set_approvals` when the new score is *lower* than the current one in the list; - Depending on the long tail of nominatied stake, it's possible that a large part of the approvals stake is left out of the calculation due to the limits of the number of nominators that can be accounted for. In this case, validators with skewed nominations (i.e. fewer nominators with large stake) will have an advantage. This may add preverse centralization incentivizes. ### Option 3. Require validators to explicitly and periodically request the update of their approvals We can create a game where the validators are required/incentivized to update their approvals score even when their score degrades by *requiring* them to request an update to the approvals score. The approvals score can have a TTL that invalidates/zeroes the approvals score after a given time. This way, if the validator does not explicitly request to update the approvals score, it will be put at the end of the queue. **Disadvantages**: - To ensure the TTL, the validator's score in the target list needs to be implicitly updated to 0 whenever the `Call::set_approvals` was not called within the TTL. This may be expensive and take a long time to sync the approvals score of the no-show validators. - If there are too many "no-shows", i.e. a considerable number of good validators do not call `Call::set_approvals` on time, the economic security of the chain will be affected (since those vaidators would be dropped to the tail of the list and not selected for election, although the real approvals score would be high). There are some ways we could automate the call to set approvals through tooling, but it may be dangerous to piggy back economic security on tooling. ### Option Long term - Staking parachain In the future, with the rewrite of staking pallet and the increase in blockspace in the context of the staking parachain, we may be able to process `stakers_payout` (or similar) on idle and/or periodically and design a mechanism where the approvals score can be reasonably updated automatically. --- (from the PR @ [c7ad6bf3fe2fc60e074f4b9dfb7384dba3f6baa8](https://github.com/paritytech/polkadot-sdk/pull/1933/commits/c7ad6bf3fe2fc60e074f4b9dfb7384dba3f6baa8), removed) ## Deferring updates at nominator payout Updating the approvals stakes in `TargetList` at the time of reward payout (i.e. `Call::payout_stakers`) may be infeasible given the computation and storage writes required to keep the approvals up to date. Note that for each nominator payout, *all* the nominated targets need to get their approvals stake score updated. In this scenario, the complexity of a `payout_stakers` can easily blow up: > **Complexity**: Assuming that the approvals stakes are *all* updated at the time of rewards, a call to `payout_stakers` touching `N` (unbounded) nominators, each nominating `V` validators (bounded by the max nominations per nominator) requires `O(N * V)` approval votes updates. Since `N` is unbounded, this is an issue. **Solution**: The solution is to buffer the updates to the target list when nominators are being paid out. Notice, however, that the nominator's staking ledger is *always* updated at the time of payout. Thus, there will be a slight inconsistency between the staking ledgers and the target list score state. The inconsistency will be settled eventually, per staking ledger, in one of two ways: 1) manually by calling an extrinsic `Call::settle_untracked_stake` or 2) automatically when a stash with inconsistencies changes the state of its ledger/nominations. A new storage item, `UntrackedStake`, keeps track of the last stake of a stash which has been reflected in both target list and ledger. ```rust /// Map from all the stashes with untracked stakes and the latest synced stake between the ledger /// and the event listeners. /// /// Untracked stake is the ledger stake that hasn't been propagated to `T::EventListeners`. #[pallet::storage] pub type UntrackedStake<T: Config> = StorageMap<_, Blake2_128Concat, T::AccountId, Stake<BalanceOf<T>>>; ``` At the time of settling the buffered untracked stake of a stash, the `OnStakingUpdate::on_stake_update` is called, where the previous stake is the one stored in the `UntrackedStake` storage item. This will update the target and voter list and bring it up to sync with the ledger's state. ```rust <T::EventListeners as OnStakingUpdate<T::AccountId, BalanceOf<T>>>:::on_stake_update(&ledger.stash, Some(untracked_stake)); ``` With the new design, the complexity of calling `payout_stakers` remains reasonable: > **Complexity**: With this design, a call to `payout_stakers` touching `N` (unbounded) nominators, each nominating `V` validators (bounded by the max nominations per nominator) requires `O(1)` approval votes updates (the validator that is being rewarded only). When a nominator ledger is updated, there are `O(V)` score updates. Since `V` is bounded, we're gold. --- ![](https://hackmd.io/_uploads/r1O8hbGlp.jpg)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully