HackMD
  • Prime
    Prime  Full-text search on all paid plans
    Search anywhere and reach everything in a Workspace with Prime plan.
    Got it
      • Create new note
      • Create a note from template
    • Prime  Full-text search on all paid plans
      Prime  Full-text search on all paid plans
      Search anywhere and reach everything in a Workspace with Prime plan.
      Got it
      • Sharing Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • 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
      • More (Comment, Invitee)
      • Publishing
        Everyone on the web can find and read all notes of this public team.
        After the note is published, everyone on the web can find and read this note.
        See all published notes on profile page.
      • Commenting Enable
        Disabled Forbidden Owners Signed-in users Everyone
      • Permission
        • Forbidden
        • Owners
        • Signed-in users
        • Everyone
      • Invitee
      • No invitee
      • Options
      • Versions and GitHub Sync
      • Transfer ownership
      • Delete this note
      • Template
      • Save as template
      • Insert from template
      • Export
      • Dropbox
      • Google Drive
      • Gist
      • Import
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
      • Download
      • Markdown
      • HTML
      • Raw HTML
    Menu Sharing Create Help
    Create Create new note Create a note from template
    Menu
    Options
    Versions and GitHub Sync Transfer ownership Delete this note
    Export
    Dropbox Google Drive Gist
    Import
    Dropbox Google Drive Gist Clipboard
    Download
    Markdown HTML Raw HTML
    Back
    Sharing
    Sharing Link copied
    /edit
    View mode
    • Edit mode
    • View mode
    • Book mode
    • Slide mode
    Edit mode View mode Book mode Slide mode
    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
    More (Comment, Invitee)
    Publishing
    Everyone on the web can find and read all notes of this public team.
    After the note is published, everyone on the web can find and read this note.
    See all published notes on profile page.
    More (Comment, Invitee)
    Commenting Enable
    Disabled Forbidden Owners Signed-in users Everyone
    Permission
    Owners
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Invitee
    No invitee
       owned this note    owned this note      
    Published Linked with GitHub
    Like BookmarkBookmarked
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # Substrate's NPoS overview ### Introduction to NPoS NPoS is a very difficult problem to solve in a blockchain context. The reason for that is that we want a sovereign algorithm, be it our currently used `phragmen` or not, to solve the problem of NPoS for us offchain, and resubmit the solution back to the chain. The problem of NPoS can be summarized as: given an input graph of nominations, find a distribution of stake for each nominator so that some objectives are optimized. As an example, say Alice nominates Bob, Charlie and Dave. Bob and Charlie are in the active validator set. How should Alice's stake be divided between them? What about Dave? To contrast the simplicity of DPoS, such a problem does not exist there, since each nominator backs only one account. Even if you can back multiple accounts, your stake is split between them equally, or based on some pre-defined order. This is basically the same as splitting your funds into multiple accounts. Current objectives of NPoS in substrate (and consequently polkadot and any other use of `sp-npos-elections` crate) is set to be: - the backing stake of the least-backed elected validator, which should be maximized. - the sum of backing stake of all elected validators, which should be maximized. - the sum squared of backing stake of all elected validators, which should be minimized. For a more extensive detail about all of this, see [this talk](https://www.youtube.com/watch?v=MjOvVhc1oXw). For any additional question, feel free to ask @kianenigma in github or [Polkadot's watercooler](https://app.element.io/#/room/!FdCojkeGzZLSEoiecf:web3.foundation?via=matrix.parity.io&via=matrix.org&via=web3.foundation) chat. --------- ### Current Solutions We have a set of algorithms that solve the NPoS problem, optimize it further, and reduce its size, all of which are packed nicely in `sp-npos-election`. In the runtime, we have a dedicated pallet that does our multi-phase, offchain-oriented, election process, named `pallet-election-provider(-multi-phase)`, as described in [#6242](https://github.com/paritytech/substrate/issues/6242). pallet-staking will only use the election pallet and does not deal with details of the election itself. An important part of the current system is that the pallet-staking and pallet-election-provider don't keep up with each other's changes, and this is intentional. At some point, pallet-staking will need to provide a snapshot of its nominators and validators (or a subset thereof) to pallet-election-provider. Form this point onwards, the two pallets can work independently. This design decision has multiple benefits for us. Most importantly, we can use the snapshot as a **source of index-lookup** for all nominators and validators. In all solutions computed and submitted offchain, we never use account ids, but rather the much more efficient index in snapshot (compare a 4 byte u32 with 32 byte account id.). ### Bottlenecks With this overview of the system in mind, let's look at the main bottlenecks: 1. **Snapshot creation**: This happens `on_initialize`, and can easily cause a heavy block. More importantly, there is a strict limit on how much memory each block can use, so we surely can never iterate a massive number of nominators in a single block. 2. **Solution Submission**: A solution that is being submitted must also not reach neither the block size limit, not the block memory limit. The latter is the real bottleneck with low congestion. 3. **Solution Verification**: The solution needs to be verified at some point. This needs to happen **against the snapshot**, and is thus again a memory intense operation. The solution to all of this, and our direction of movement is towards doing all of this over multple blocks. The snapshot will be taken over multiple blocks, and the outcome snapshot will be a map of `page-index -> snapshot-page`, instead of one big flat snapshot. The solution will need to take this into account. It needs to provide nominator indices in a way that is understandable, to the chain. Instead of identifying a nominator by a single index, each nominator is now identifiable by a `(page, index)` tuple. Similarly, the solution verification also needs to take this into account, and verify each page of the solution against its corresponding page in the snapshot. Finally, the partial solutions need to be amalgamated into a single one.

    Import from clipboard

    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 lost their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template is not available.


    Upgrade

    All
    • All
    • Team
    No template found.

    Create custom template


    Upgrade

    Delete template

    Do you really want to delete this template?

    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

    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

    Tutorials

    Book Mode Tutorial

    Slide Mode Tutorial

    YAML Metadata

    Contacts

    Facebook

    Twitter

    Feedback

    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

    Versions and GitHub Sync

    Sign in to link this note to GitHub Learn more
    This note is not linked with GitHub Learn more
     
    Add badge Pull Push GitHub Link Settings
    Upgrade now

    Version named by    

    More Less
    • Edit
    • Delete

    Note content is identical to the latest version.
    Compare with
      Choose a version
      No search result
      Version not found

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

         Sign in to GitHub

        HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.

        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
        Available push count

        Upgrade

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Upgrade

        Danger Zone

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

        Syncing

        Push failed

        Push successfully