Age Manning
    • 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
    • Engagement control
    • 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 Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control 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
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # Lighthouse Peer Scoring The peer scoring implementation in Lighthouse is an initial version that was designed to be iterated upon based on data we collect from various networks. Take everything written here with a big grain of salt :). ## Overview All peers are associated with a score. A score is an f64 in the range `[-100,100]` although in the current implementation only negative scores exist, i.e peers can only have scores `[-100, 0]`. Initially we had envisaged positive scores, where peers get rewarded for certain behaviours, such as valid messages, connection time, useful blocks etc. We quickly realised that the complexity of the system was greatly increased with positive scores and so we have currently removed them (There's a section below for some thoughts about positive scores). The code in Lighthouse that handles the basic scores is [here](https://github.com/sigp/lighthouse/blob/master/beacon_node/eth2_libp2p/src/peer_manager/score.rs) There are currently three states a peer can be in, related to their score: - **Healthy**: Their score is > -20 (this is a normal peer with no restrictions) - **Disconnected**: -50 < Score <= -20 (If a peer transitions into this state we disconnect them. We allow them to reconnect but we remember their score. We may also re-dial these peers if the client would like more connected peers) - **Banned**: Score < -50 (A peer is banned. If its connected, we disconnect and do not allow reconnections. We don't dial or try to reconnect.) Peers currently get penalized for a variety of actions. To make things simple throughout the codebase there are 4 penalty actions which adjust a peer's score that a variety of events can fall under: - **Fatal** - The peer has done something really bad, we instantly ban and give it the minimum possible score. Things that are provable malicious (think bad signatures) or that we don't want to connect to the peer (its on the wrong fork). - **LowToleranceError** - The peer has done some thing bad. Not provably malicious but a behaviour that we really don't want to have in a connected peer (think not supporting protocols, bad encoding, not following spec etc). This subtracts 10 from the peer's score. - **MidToleranceError** - The peer has done something moderately bad. This subtracts 5 from the peer's score. - **HighToleranceError** - The peer has done a behaviour which isn't ideal and we penalize slightly. An example of this is a peer not responding to RPC requests in time. We subtract 1 from the peer's score. ## Score Decay Scores are not permanent. We don't want to penalize peers for all time. Thus all scores "decay" (i.e return to 0). This was designed for both positive and negative scores, but as we are only using negative scores at the moment, this brings negative scores back to 0. The decay is a simple exponential decay with a specified half-life. This is the time it takes for the score to decay to half it's value. The current implementation has a half-life of 600 seconds (10 minutes). This if a peer gets disconnected with a score of -20. After 10 minutes it's score will be -10 and be returned back to the healthy state. The decay logic is modified a little for banned peers however. If a peer gets banned, we wait a set amount of time before their score is eligible to start decaying. The current implementation sets this value to 1800 seconds (30 mins). Therefore if a peer gets banned, it stays banned for 30 minutes and then the standard half-life decay kicks in and the peer's score will slowly decay back to 0. Based on this logic, we never ban peers permanently, rather for a short period of time. ## Peer History We can't remember all peers and their score forever. We have a database that stores peers, but it only stores a maximum amount of `Disconnected` and `Banned` peers. Currently we keep a history of the most recent 500 disconnected peers and 1000 banned peers. In principle, if someone wanted to unban themselves they could connect to us 1000 times with new peers, that then get banned, to push out older peers. Although in order to do this they would need many IP addresses (see the IP banning section). ## Score Uses The score is used in various parts of Lighthouse. #### Accepting new connections A beacon node, based on their local resources can only support a finite number of peers (to handle all the rpc requests etc). By default, Lighthouse targets a peer count of 50. Lighthouse allows 10% on top of this for new peers to connect. This prevents the scenario where nodes in a testnet all connect amongst each other and prevent new connections making it harder for new nodes to join the network. This also allows us to cycle peers and find potentially better scored peers. As we allow extra peers to connect, we often end up with more peers than the target. Every 30 seconds we then prune the excess peers. The pruning process removes the lowest scoring peers. #### IP Banning If there are 5 of more banned peers who connected to us on the same IP, that IP becomes banned (until < 5 peers become unbanned). #### Sync Progression On some very weird connections and faulty client software etc has lead to some sync states where peers send us junk responses to sync (blocks by range) requests. The blocks can't be processed and the client has to determine if it should retry from different peers and figure out which peers are faulty. Without the scoring system, the sync algorithm would constantly try to re-download blocks from faulty peers in an endless loop. By penalizing peers that provide junk information during sync, we eventually ban or kick these peers allowing sync to either progress or eventually kick all its peers and remain idle. This was very handy during the Medalla chain explosion. The client, if left long enough, would eventually filter out and ban all peers on invalid software/incompatible chains, leaving it a collection of peers that it could progress and sync from. #### Potential Sync Choices (Not implemented) Depending on how we are scoring peers, it can be a measure of their bandwidth/reliability (peers get penalized for not responding to requests). We don't currently use it as such, but there was some thought about using the score to decide on best peers to download blocks from during sync. ### Examples of Scoring Penalties To give some more concrete examples of how peers get penalized in Lighthouse, I'll list some examples for the different peer action types: **Fatal** - Peer is on the wrong fork or wrong genesis etc. - Peer sent RPC data that is not spec (we would constantly fail requests, so we ban instantly) - Peer doesn't support Ping protocol - Peer responds with blocks that don't correspond to the requested hash **LowToleranceError** - A peer references an unknown block, but when trying to download the blocks ancestors the peer doesn't respond. - When syncing, we request blocks by range. If doing a finalized sync a peer sends us a chain of blocks which cannot be processed (i.e not canonical or diverges etc) and we request the same section of blocks from another peer who sends the correct information. We penalize the original peer with this action. - When syncing if a group of peers all provide a chain of blocks that cannot be processed and we try multiple times from different peers and the chain makes no sense. All peers in this group get penalized with this action. - If a peer doesn't respond to a ping or status in the RPC timeout - If a peer hits our rate limit for goodbye, metadata or status requests **MidToleranceError** - When doing parent lookups (a peer sent an attestation or block that references a block we don't know, we recursively download a chain of blocks from that peer until we reach our head) we try to download this chain. If the chain hits a certain limit, or one of the blocks fails processing, we penalize the peer with this action. - If a peer hits our rate limit for ping requests - If a peer sends us a bad blocks by range response and then after re-requesting sends the correct blocks by range response **HighToleranceError** - Peers not responding to blocks by range or blocks by root requests within the timeout - Various network dropouts or disconnections - We get rate-limited for our blocks by range or blocks by root requests - Sending invalid exits, slashings etc, which could be due to the state of our chain ### Positive Score Thoughts Positive scores bring in complexity in choices of what exact behaviours we want to encourage. Also, it adds avenues to game the system where peers can perform some actions to gain scores to negate some other bad behaviours. It also introduced complexity in how we cycle new peers that get connected to us. Currently, in the case that all peers are scored equally (0) and we need to prune excess peers, we randomly select peers to disconnect. With positive scores we run into the risk of getting positive scored peers that become "sticky" in the sense we are unlikely to cycle them as new peers coming into the system are likely to have lower scores. (We had considered giving new peers a median score of current peers, but didn't fully think through the implications.) We'd need to balance positive scores against the decay so it's not too easy for peers to get maximum scores and never get pruned.

    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