Jacob Kaufmann
    • 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
    • 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
    • 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 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
  • 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
    2
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # Chain History Storage Network This document is a preliminary specification for a networking protocol that supports on-demand availability of Ethereum chain history data. ## Overview Chain history data consists of historical block headers and block bodies, where a block body consists of transactions and transaction receipts. The data stored in the chain history storage network will support the following [eth](https://github.com/ethereum/devp2p/blob/master/caps/eth.md) protocol requests: * `GetBlockHeaders (0x03)` * `GetBlockBodies (0x05)` * `GetReceipts (0x0f)` The chain history storage network is a [Kademlia](https://pdos.csail.mit.edu/~petar/papers/maymounkov-kademlia-lncs.pdf) DHT that forms an overlay network on top of a [Discovery v5](https://github.com/ethereum/devp2p/blob/master/discv5/discv5-wire.md) network. The history network uses the following protocol messages from the Discovery v5 network: * `PING (0x01)` * `PONG (0x02)` * `FINDNODE (0x03)` * `NODES (0x04)` * `TALKREQ (0x05)` * `TALKRESP (0x06)` The `TALKREQ` and `TALKRESP` protocol messages are application-level messages whose contents are specific to the history protocol. We specify these messages below. The history protocol uses the node table structure from the Discovery v5 network and the lookup algorithm from section 2.3 of the Kademlia paper. ### Data Types: * Block headers * Block bodies * Transactions * Receipts Lookups: * Block header by block header hash * Block body by block header hash * Block receipts by block header hash This specification does not support block lookups by number or transaction lookups by hash. To support these lookups, we will require a specification for a block header accumulator so that we can return the canonical block for a given height or the transaction for a given hash included in some canonical block. ### Data Bridge Participants in the `eth` protocol are responsible for injecting data into the network. These nodes act as a bridge between the `eth` protocol and the chain history network. Once the data is present within the network, that data is distributed to nodes "close" to that data. We define a notion of distance between some node and some data item below. ### Data Completeness In order to ensure that the network holds the entirety of the chain history, a separate process searches for missing data. Upon discovery of some missing data, that node issues a request to a bridge node for that data. The bridge node responds with the data, and it is distributed in the same way that new history is distributed. ## Specification ### Distance Nodes in the history network are represented by their [EIP-778 Ethereum Node Record (ENR)](https://eips.ethereum.org/EIPS/eip-778) from the Discovery v5 network. A node's `node-id` is derived according to the node's identity scheme, which is specified in the node's ENR. A node's `node-id` represents its address in the DHT. The `node-id` is a 32-byte identifier. We define the `distance` function that maps a pair of `node-id` values to a 256-bit unsigned integer identically to the Discovery v5 network. ``` distance(n1, n2) = n1 XOR n2 ``` Similarly, we define a `logdistance` function identically to the Discovery v5 network. ``` logdistance(n1, n2) = log2(distance(n1, n2)) ``` ### Content: Keys and Values The chain history DHT stores the following data items: * Block headers * Block bodies * Receipts Each of these data items are represented as a key-value pair. Denote the key for a data item by `content-key`. Denote the value for an item as `content`. We derive a `content-id` from the `content-key` as `H(content-key)` where `H` denotes the [placeholder] hash function, which outputs 32-byte values. The `content-id` represents the key in the DHT that we use for `distance` calculations. All `content-key` values are encoded and decoded according to SSZ sedes. #### Block Header ``` content-key = Container(chain-id: uint16, content-type: uint8, block-hash: Bytes32) content-type = 0x01 ``` #### Block Body ``` content-key = Container(chain-id: uint16, content-type: uint8, block-hash: Bytes32) content-type = 0x02 ``` #### Receipts ``` content-key = Container(chain-id: uint16, content-type: uint8, block-hash: Bytes32) content-type = 0x03 ``` ### Radius We define a `distance` function that maps a `node-id` and `content-id` pair to a 256-bit unsigned integer identically to the `distance` function for pairs of `node-id` values. Each node specifies a `radius` value, a 256-bit unsigned integer that represents the data that a node is "interested" in. ``` interested(node, content) = distance(node.id, content.id) <= node.radius ``` A node is expected to maintain `radius` information for each node in its local node table. A node's `radius` value may fluctuate as the contents of its local key-value store change. ### Protocol Messages All protocol messages are transmitted via the `TALKREQ` and `TALKRESP` messages defined by the Discovery v5 protocol. Below is the general message encoding for all `TALKREQ` messages. ``` protocol = portal-history request = protocol-message-type || protocol-message protocol-message-type = uint8 protocol-message = byte array ``` Below is the general message encoding for all `TALKRESP` messages. ``` response = protocol-message-type || protocol-message protocol-message-type = uint8 protocol-message = byte array ``` All `protocol-message` values are encoded and decoded according to SSZ sedes. If the size of a message would exceed the max packet size of 1280 bytes, then the transmission of the message contents would occur over [uTP](https://github.com/ethereum/stateless-ethereum-specs/blob/master/discv5-utp.md). uTP connections are initiated with randomly generated connection IDs. Upon sending a message with some `connection-id`, the sender should initiate a uTP stream using `connection-id`. Upon receiving a message that contains some `connection-id`, the recipient should listen for an incoming uTP connection with `connection-id`. NOTE: The `Offer`/`Accept`/`Store` messages do not conform to the request/response paradigm of Discovery v5. We plan to propose a change to the base protocol definition to loosen the language. #### Ping (0x01) Communicate `radius` information of the sender, and request `radius` information of the recipient. ``` protocol-message-type = 0x01 protocol-message = Container(radius: uint256) ``` #### Pong (0x02) In response to a `Ping` message, communicate `radius` information of the sender. ``` protocol-message-type = 0x02 protocol-message = Container(radius: uint256) ``` #### FindNode (0x03) Request a list of ENR values for nodes whose `logdistance` from the recipient's `node-id` is equal to one of the specified values. ``` protocol-message-type = 0x03 protocol-message = Container(distances: List[uint8, 256]) ``` Each element of `distances` **MUST** be unique. A zero value in the `distances` list represents a request for the recipient's ENR value. #### FoundNodes (0x04) In response to a `FindNode` message, communicate a list of RLP-encoded ENR values for nodes whose `logdistance` value satisfies the request. ``` protocol-message-type = 0x04 protocol-message = Container(total: uint8, enrs: List[Bytes, 32]) ``` The recipient may know of more than 32 nodes that satisfy the request. In this case, the recipient will need to send multiple `FoundNodes` messages in response to the `FindNode` message. Here, `total` denotes the total number of `FoundNodes` messages that the sender of the `FindNode` message should expect in response. Each ENR **MUST** be unique to some `node-id`. Each ENR **MUST** correspond to an element in the `distances` field of the `FindNode` request. #### FindContent (0x05) Request the data for `content` with `content-key`, or a list of ENR values for nodes whose `distance` from `content-id` is smaller than that of the recipient. The encoding of `content-key` for all possible data items is specified above. ``` protocol-message-type = 0x05 protocol-message = Container(content-key: Bytes) ``` #### FoundContent (0x06) In response to a `FindContent` message, communicate one of the following: * A connection ID for a uTP stream to transmit the requested data * A list of RLP-encoded ENR values with maximum length of 32 * A byte-array that encodes the requested data ``` protocol-message-type = 0x06 protocol-message = Container(connection-id: Bytes4, enrs: List[Bytes, 32], content: Bytes) ``` If the node does not hold the requested content, and the node does not know of any nodes with eligible ENR values, then the node should return `connection-id` as a zero byte array, `enrs` as an empty list and `content` as an empty byte-array. #### Offer (0x07) Communicate to the recipient that the data for `content-key` is available for transmission. ``` protocol-message-type = 0x07 protocol-message = Container(content-key: Bytes) ``` #### Accept (0x08) In response to a `Offer` message, request the data for `content-key`. ``` protocol-message-type = 0x08 protocol-message = Container(content-key: Bytes) ``` If a node transmits a `Accept` message, then we expect that node to store the corresponding data locally following the subsequent `Store` message. #### Store (0x09) In response to a `Accept` message, communicate one of the following: * A connection ID for a uTP stream to transmit the requested data * A byte-array that encodes the requested data ``` protocol-message-type = 0x09 protocol-message = Container(connection-id: Bytes4, content: Bytes) ``` ## Algorithms and Data Structures ### Node State We adapt the node state from the Discovery v5 protocol. Assume identical definitions for the replication parameter $k$ and a node's $k$-bucket table. Also assume that the routing table follows the structure and evolution described in section 2.4 of the Kademlia paper. Nodes keep information about other nodes in a routing table of $k$-buckets. This routing table is distinct from the node's underlying Discovery v5 routing table. A node associates the following tuple with each entry in its routing table: ``` node-entry := (node-id, radius, ip, udp) ``` The `radius` value is the only node information specific to the overlay protocol. This information is refreshed by the `Ping` and `Pong` protocol messages. A node should regularly refresh the information it keeps about its neighbors. We follow section 4.1 of the Kademlia paper to improve efficiency of these refreshes. A node delays `Ping` checks until it has a useful message to send to its neighbor. When a node discovers some previously unknown node, and the corresponding $k$-bucket is full, the newly discovered node is put into a replacement cache sorted by time last seen. If a node in the $k$-bucket fails a liveness check, and the replacement cache for that bucket is non-empty, then that node is replaced by the most recently seen node in the replacement cache. Consider a node in some $k$-bucket to be "stale" if it fails to respond to $\beta$ messages in a row, where $\beta$ is a system parameter. $\beta$ may be a function of the number of previous successful liveness checks or of the age of the neighbor. If the $k$-bucket is not full, and the corresponding replacement cache is empty, then stale nodes should only be flagged and not removed. This ensures that a node who goes offline temporarily does not void its $k$-buckets. ### Lookup We use the lookup algorithm described in section 2.3 of the Kademlia paper. A "node lookup" is the execution of the algorithm to find the $k$ closest nodes to some `node-id`. A "content lookup" is the execution of the algorithm to find the data for `content-id` or the $k$ closest nodes to `content-id`. A `FindNode` request corresponds to a node lookup, and a `FindContent` request corresponds to a content lookup . The lookup algorithm is also used to identify nodes that should receive `Offer` messages to store some data. ### Joining the Network We follow the join procedure described in the Kademlia paper. In order to join the network, a node $u$ must know some node $v$ who is already participating in the network. Node $u$ inserts $v$ into the appropriate $k$-bucket and then sends a `FindNode` request to $v$ for its own node ID. Then, node $u$ refreshes all $k$-buckets with distances further than its closest neighbor. To refresh a bucket, a node selects a random node ID in the bucket's range and performs a `FindNode` for that ID. ### Finding Nodes A node's routing table is initially populated by the `FindNode` messages that the node sends when it joins the network. Following the join phase, a node's $k$-buckets are generally kept fresh by network traffic. When a node learns of a new contact (through node lookups), it attempts to insert the contact into the appropriate $k$-bucket. A node keeps track of the last node lookup it performed for each $k$-bucket, and it will regularly refresh any $k$-buckets with no recent lookups. ### Finding Content To find a piece of content for `content-id`, a node performs a content lookup via `FindContent`. If the lookup succeeds, then the requestor sends a `Offer` message for the content to the closest node it observed that did not return the value and whose `radius` contains `content-id`. ### Storing Content To store a piece of content with key `content-id`, a node performs a lookup to find the $k$ closest nodes with radii that contain `content-id`. Then the node sends `Offer` RPCs to those nodes. For any node that responds to the `Offer` RPC with a `Accept` RPC, the local node responds with a `Store` RPC for the content. The network cannot make guarantees about the storage of particular content. A lazy node may ignore all `Offer` RPCs. A malicious node may send `Accept` RPCs and ignore the `Store` RPCs. The offer-accept mechanism is in place to require that nodes explicitly accept some data before another node attempts to transmit that data. The mechanism prevents the unnecessary consumption of bandwidth in the presence of lazy nodes. However, it does not defend against malicious nodes who accept offers for data with no intent to store it.

    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