Johannes Hofmann
    • 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
    # Introduction Bitcoin blockchain analysis is ubiquitous today because the data is easily accessible to anyone. Blockchain data give rise to the many websites that provide statistics about the Bitcoin network such as the network's hashrate, transaction throughput and fees, and many more. For some investigations, however, the blockchain-based view can be too narrow. For one thing, blockchain data lacks precise transaction and block timestamps, rendering it useless for fine-grained analyses of transaction and block propagation in the network. For another, it misses transactions that did not make it into the blockchain, which provide crucial clues about the demand for block space, fee dynamics, replace-by-fee usage, and more. Also missing are invalid blocks and transactions sent in the network, which can be a basis for anomaly detection. Fortunately, comprehensive off-chain data sets can be extracted from Bitcoin Core nodes. Unfortunately, however, as of now there is no standardized way to collect the data in a robust and automated way. Multiple projects appear to profit in the collection of off-chain data, and it turns out that the overlap of the data each of the individual projects is seeking is rather high. Consequently it makes sense to try to pool efforts to create a generic way to collect off-chain data that allows users to easily customize what data to collect. So far, the projects are: - Monitoring the operational health of the Bitcoin network - Creating a public mempool data set Before starting with an actual implementation, this document attempts to reach consensus on **what** data should collectable and **how** to best collect it. # Relevant data In most cases the reconstruction of historical off-chain data is not possible, so a philosophy of overcollection should be followed (i.e., erring on the side of collecting too much vs. too little). The following table records what data people think should be collectable: each entry comprises a name, a short description and the project name that requires the data; in line with the overcollection philosophy, an explicit reason to collect a specific piece of data is not required. Note that the first part of the list focuses on transactions while the latter focuses on non-transaction data such as blocks. Feel free to extend the list. ## Transaction data | Name | Description | Required by | |--------------|---------------------------------------|------------------------| | timestamp | The timestamp the transaction event occured. | OpHealth, PublicData | | txid | The id of the transaction | OpHealth, PublicData | | tx event | Added to mempool, removed from mempool (including reason for removal) | OpHealth, PublicData | | tx event | Invalid transaction (including reason for invalidity) | OpHealth, P2P monitoring | | raw data | The raw transaction data. Compared to storing deserialized transaction data, recording raw data has the advantage of allowing to go back and fix errors caused by (infrequent!) failures of the witness detection heuristic. | OpHealth, PublicData | | tx metadata | Ancestor, descendant, and RBF data provided by the `getrawmempool` API call. In theory, this data can be reconstructed from a full historical data set but; however, in pratice, this can be expensive and error-prone, so the pragmatic solution is to waste some extra storage and record the state data provided by Bitcoin Core | OpHealth?, PublicData | | tx fees | While transaction fees can be computed when all parent transactions make it into the blockchain, querying all pervious outputs can be a time-consuming task. Directly storing the fee only takes up marginally more space. | OpHealth?, PublicData | ## Block Data | Name | Description | Required by | |--------------|---------------------------------------|------------------------| | timestamp | The timestamp the block event occured.| OpHealth | | block hash | The hash of the block | OpHealth | | block height | The height of the block. (Could also be extracted from the raw block) | OpHealth | | block event | valid block added to chain, chain reorg, invalid block (including reason for invalidity) | OpHealth | | raw data | The raw block data of blocks not recorded on-chain. | OpHealth | # Data collection approaches So far, the following approaches to collect some or all of the [relevant data](#relevant-data) have been identified. ## API-based data collection This approach is based on taking snapshots of a node's mempool state at regular intervals using the API call `getrawmempool`. Comparing successive snapshots yields the list of transactions added and removed from the mempool. Detailed transaction information for transactions added in the interval can be obtained using the `getrawtransaction` API call. Pros: - The resulting data set will be self-healing in case of downtime - Information might be missed during downtime, but even though the time between snapshots might increase significantly, both snapshots always represent valid mempool states, and data derived from them will be consistent Cons: - The following relevant data can not be collected with this approach: - Exact timestamp: Accuracy of timestamps is limited by the snapshotting frequency. Note: Due of the low performance of API calls and database operations (use of a database is recommended over e.g. a plain file to guarantee consistency of snapshots), the lowest, realistically possible sampling rate is in the range of hundreds of milliseconds or even seconds. - Invalid transactions and blocks are missing - The reason for removal of transactions from the mempool are missing - All transactions that were added to and removed from the mempool in the time between two successive snapshots will be missing. This includes some RBF transactions; data on transactions that were removed because they were included in a block can be reconstructed using blockchain data. - Querying large mempools (sevaral hundred MB) via `getrawmempool` can take a significany amount of time. Guaranteeing a minimum sampling rate might lead to undesirable hardware requirements ## ZMQ-based data collection This approach collects data from various ZMQs provided by Bitcoin Core. Pros: - Event notification is immediate - Exact timestamps - No missing data due to inadequate sampling as in the API-based approach Cons: - Data set can become inconsistent in case of downtime - Example: A transaction removed from the mempool during downtime will lead to the transaction to be stuck in a reconstruction of the mempool. Removal times can approximated for mined transactions using block timestamps, but not for transactions removed for other reasons. - For monitoring the operational health of the network, this should not be a problem, since a node that is down does not contribute to any health information. When it comes to the potential creation of a public mempool data set, it should not be a problem either, as data is collected in a decentralized way by multiple nodes, so as long at least one node is running, the resulting data set should be complete. - The following relevant data cannot be collected out of the box: - Invalid transactions and blocks, including reason for invalidity - Reasons for removal of transaction from mempool - Information provided by `getrawmempool` - In theory, it should be possible to make all data available via ZMQ by adding the necessary functionality to Bitcoin Core. An existing [patch](https://github.com/0xB10C/bitcoin-zmq-mempool-chain-events/blob/v23.0-zmce/PATCH.md) by 0xB10C already makes some of the relevant data availble. ## USDT-and-eBPF-based data collection This approach does not rely on an external tool to collect data from Bitcoin Core via some interface. Instead, it is based on adding tracepoints to the mempool and other subsystems of Bitcoin Core to enable logging all relevant data directly via Bitcoin Core. - Pros: - Can collect all relevant data - In case it gets merged, data collection can occur using vanilla Bitcoin Core - Cons - Probably most work - requires Linux hosts, and doesn't really play well with Docker and Co. - might require elevated privileges on host to hook into the tracepoints via the kernel - Want to avoid expensive computations (e.g. serialization of transactions) as these are executed even if we don't hook into the tracepoints - See https://github.com/bitcoin/bitcoin/blob/master/doc/tracing.md#no-expensive-computations-for-tracepoints - Could guard this with a hidden `-expensivetracepoints` runtime argument - Data set can become inconsistent in case of downtime - Same comments as for ZMQ-based approach apply

    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