Vishal Chintham
    • 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

      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.
      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

    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.
    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
    Allow multiple delegators to participate in the same stake pool in order to collect the minimum stake required to join the validator set. Delegators are rewarded out of the validator rewards proportionally to their stake and provided the same stake-management API as the stake pool owner. The main accounting logic in the delegation pool contract handles the following: 1. Tracks how much stake each delegator owns, privately deposited as well as earned. Accounting individual delegator stakes is achieved through the shares-based pool defined at <code>aptos_std::pool_u64</code>, hence delegators own shares rather than absolute stakes into the delegation pool. 2. Tracks rewards earned by the stake pool, implicitly by the delegation one, in the meantime and distribute them accordingly. 3. Tracks lockup cycles on the stake pool in order to separate inactive stake (not earning rewards) from pending_inactive stake (earning rewards) and allow its delegators to withdraw the former. 4. Tracks how much commission fee has to be paid to the operator out of incoming rewards before distributing them to the internal pool_u64 pools. In order to distinguish between stakes in different states and route rewards accordingly, separate pool_u64 pools are used for individual stake states: 1. one of <code>active</code> + <code>pending_active</code> stake 2. one of <code>inactive</code> stake FOR each past observed lockup cycle (OLC) on the stake pool 3. one of <code>pending_inactive</code> stake scheduled during this ongoing OLC As stake-state transitions and rewards are computed only at the stake pool level, the delegation pool gets outdated. To mitigate this, at any interaction with the delegation pool, a process of synchronization to the underlying stake pool is executed before the requested operation itself. At synchronization: - stake deviations between the two pools are actually the rewards produced in the meantime. - the commission fee is extracted from the rewards, the remaining stake is distributed to the internal pool_u64 pools and then the commission stake used to buy shares for operator. - if detecting that the lockup expired on the stake pool, the delegation pool will isolate its pending_inactive stake (now inactive) and create a new pool_u64 to host future pending_inactive stake scheduled this newly started lockup. Detecting a lockup expiration on the stake pool resumes to detecting new inactive stake. Accounting main invariants: - each stake-management operation (add/unlock/reactivate/withdraw) and operator change triggers the synchronization process before executing its own function. - each OLC maps to one or more real lockups on the stake pool, but not the opposite. Actually, only a real lockup with 'activity' (which inactivated some unlocking stake) triggers the creation of a new OLC. - unlocking and/or unlocked stake originating from different real lockups are never mixed together into the same pool_u64. This invalidates the accounting of which rewards belong to whom. - no delegator can have unlocking and/or unlocked stake (pending withdrawals) in different OLCs. This ensures delegators do not have to keep track of the OLCs when they unlocked. When creating a new pending withdrawal, the existing one is executed (withdrawn) if is already inactive. - <code>add_stake</code> fees are always refunded, but only after the epoch when they have been charged ends. - withdrawing pending_inactive stake (when validator had gone inactive before its lockup expired) does not inactivate any stake additional to the requested one to ensure OLC would not advance indefinitely. - the pending withdrawal exists at an OLC iff delegator owns some shares within the shares pool of that OLC. Example flow: <ol> <li>A node operator creates a delegation pool by calling <code>initialize_delegation_pool</code> and sets its commission fee to 0% (for simplicity). A stake pool is created with no initial stake and owned by a resource account controlled by the delegation pool.</li> <li>Delegator A adds 100 stake which is converted to 100 shares into the active pool_u64</li> <li>Operator joins the validator set as the stake pool has now the minimum stake</li> <li>The stake pool earned rewards and now has 200 active stake. A's active shares are worth 200 coins as the commission fee is 0%.</li> <li></li> <ol> <li>A requests <code>unlock</code> for 100 stake</li> <li>Synchronization detects 200 - 100 active rewards which are entirely (0% commission) added to the active pool.</li> <li>100 coins = (100 * 100) / 200 = 50 shares are redeemed from the active pool and exchanged for 100 shares into the pending_inactive one on A's behalf</li> </ol> <li>Delegator B adds 200 stake which is converted to (200 * 50) / 100 = 100 shares into the active pool</li> <li>The stake pool earned rewards and now has 600 active and 200 pending_inactive stake.</li> <li></li> <ol> <li>A requests <code>reactivate_stake</code> for 100 stake</li> <li> Synchronization detects 600 - 300 active and 200 - 100 pending_inactive rewards which are both entirely distributed to their corresponding pools </li> <li> 100 coins = (100 * 100) / 200 = 50 shares are redeemed from the pending_inactive pool and exchanged for (100 * 150) / 600 = 25 shares into the active one on A's behalf </li> </ol> <li>The lockup expires on the stake pool, inactivating the entire pending_inactive stake</li> <li></li> <ol> <li>B requests <code>unlock</code> for 100 stake</li> <li> Synchronization detects no active or pending_inactive rewards, but 0 -> 100 inactive stake on the stake pool, so it advances the observed lockup cycle and creates a pool_u64 for the new lockup, hence allowing previous pending_inactive shares to be redeemed</li> <li> 100 coins = (100 * 175) / 700 = 25 shares are redeemed from the active pool and exchanged for 100 shares into the new pending_inactive one on B's behalf </li> </ol> <li>The stake pool earned rewards and now has some pending_inactive rewards.</li> <li></li> <ol> <li>A requests <code>withdraw</code> for its entire inactive stake</li> <li> Synchronization detects no new inactive stake, but some pending_inactive rewards which are distributed to the (2nd) pending_inactive pool </li> <li> A's 50 shares = (50 * 100) / 50 = 100 coins are redeemed from the (1st) inactive pool and 100 stake is transferred to A </li> </ol> </ol>

    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

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    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