btcd

repository·master·Indexed 27 days ago

https://github.com/btcsuite/btcd

An alternative full node Bitcoin implementation written in Go, designed to follow Bitcoin Core's consensus rules exactly. It serves as a high-performance daemon for blockchain validation and transaction relaying. The project includes several specialized packages such as btcec for secp256k1 elliptic curve cryptography, hdkeychain for BIP0032 hierarchical deterministic keys, and btcjson for JSON-RPC marshalling.

Tokens
46.8K
Snippets
108
Records
364
Agent score
91%

What's inside btcd

  1. Overview of supported blockchain indexers

    master

    The indexers package provides optional indexes to enhance the information available via RPC interfaces. It supports two primary index types:

    1. Transaction-by-hash (txbyhashidx) Index: Maps a transaction hash to the specific block containing it, including the offset and length within the serialized block.
    2. Transaction-by-address (txbyaddridx) Index: Maps every address to all transactions that either credit or debit that address. Note: This index requires the txbyhashidx index to be enabled/installed.
  2. Overview of the blockchain package

    master

    The blockchain package implements Bitcoin block handling and chain selection rules. It is designed to be used as a standalone package for any project requiring the processing of blocks into the Bitcoin blockchain.

    Key functionalities include:

    • Block validation (proof of work, timestamps, merkle roots, etc.)
    • Orphan block management
    • Chain reorganization and side-chain handling
    • Transaction script verification and coinbase maturity checks
    • Difficulty retarget rule verification
  3. Overview of the wire package

    master
    The wire package implements the Bitcoin wire protocol, allowing projects to interface with Bitcoin peers. It handles the encoding and decoding of message headers, which include the network identifier, message type, size, and checksum. The package provides a generic Message interface and concrete implementations for most supported Bitcoin messages, abstracting away the complexities of marshalling and unmarshalling.
  4. Overview of the connmgr package

    master

    The connmgr package provides a generic Bitcoin network connection manager designed to maintain a pool of active P2P connections. It handles common connection concerns including:

    • Maintaining a target number of outbound connections.
    • Sourcing peers and performing TOR lookups.
    • Managing bans and limiting maximum connections.
    • Handling connection failures and retrying new addresses from a source.
    • Providing notifications for connection and disconnection events.
    • Supporting permanent connections with increasing backoff retry timers.
    • Allowing connections to be restricted to specific addresses.
    • Providing mechanisms to disconnect or remove established connections.
  5. Overview of the peer package

    master

    The peer package provides a concurrent-safe base for creating and managing Bitcoin network peers. It builds upon the wire package to simplify the creation of fully functional nodes, such as full validating nodes, Simplified Payment Verification (SPV) nodes, or proxies.

    Key features include:

    • Full Duplex Communication: Handles reading and writing of Bitcoin protocol messages.
    • Handshake Management: Automatic handling of the initial handshake and protocol version negotiation.
    • Message Queueing: Asynchronous outbound message queueing with optional notifications upon sending.
    • Flexible Configuration: Allows customization of user agent, Bitcoin network, service support signalling, and maximum protocol version. The caller retains control over establishing incoming and outgoing connections.
    • Protocol Efficiency: Includes inventory message batching, send trickling, and automatic periodic keep-alive pings/pongs.
    • Bloom Filter Support: Proper handling of bloom filter commands based on protocol version and support flags.
    • Peer Statistics: Provides snapshottable statistics including bytes read/written, remote address, user agent, and negotiated protocol version.
    • Helper Functions: Includes specialized helpers for sending addr, getblocks, getheaders, and reject messages with built-in duplicate filtering and address randomization.
  6. Overview of btcd JSON-RPC API

    master

    btcd provides a JSON-RPC API compatible with the original bitcoind/bitcoin-qt.

    Key architectural differences:

    • Service Separation: Unlike bitcoind, btcd splits wallet and chain services into independent processes. Direct calls to btcd only provide chain-related RPCs. For wallet-related RPCs, use btcwallet.
    • Security: btcd is secure by default; RPC connections use TLS by default.
    • Transports: Supports both HTTP POST and Websockets. Websockets are the preferred transport for btcd RPC and are used by btcwallet for inter-process communication.

    Websocket Endpoint: wss://your_ip_or_domain:8334/ws

  7. Overview of hdkeychain features

    master

    The hdkeychain package provides a full implementation of BIP0032 for Bitcoin hierarchical deterministic (HD) extended keys. Key capabilities include:

    • BIP0032 Compliance: Full implementation including support for multi-layer derivation and audits use cases.
    • Unified Key Types: Uses a single type for both private and public extended keys.
    • Seed Generation: Provides convenient, cryptographically secure seed generation.
    • Master Node Creation: Simple methods for creating master nodes.
    • Serialization: Easy serialization and deserialization for both private and public extended keys.
    • Custom Networks: Supports custom networks via registration with chaincfg.
    • Integration: Seamlessly integrates with btcec (optimized for secp256k1) and btcutil types to obtain underlying EC pubkeys, EC privkeys, and Bitcoin addresses for signing transactions or generating payment scripts.
  8. Overview of txscript

    master
    The txscript package implements the Bitcoin transaction script language. It is a stack-based, FORTH-like language used in Bitcoin transactions. The package is designed to be used as a standalone library for any project that needs to create, validate, or manipulate Bitcoin transaction scripts.
  9. Overview of the mempool package

    master

    The mempool package provides a policy-enforced, in-memory pool of fully validated Bitcoin transactions. It is designed to be used as a standalone component for projects that need to manage unmined transactions that adhere to both consensus rules and a configurable acceptance policy.

    Key capabilities include:

    • Validation: Rejects non-fully-spent duplicates, coinbase transactions, double spends (against the chain or other pool transactions), and invalid transactions according to consensus rules.
    • Orphan Support: Manages transactions that spend from unknown outputs with configurable limits and automatic promotion once dependencies are met.
    • Policy Enforcement: Allows filtering transactions based on 'standard' requirements, priority, fee thresholds, and rate limiting.
    • Metadata Tracking: Tracks timestamps, block height, fees, and starting priority for each transaction.
    • Manual Removal: Supports recursive removal of dependent transactions.
  10. Overview of Websocket JSON-RPC Notifications

    master
    btcd uses standard JSON-RPC notifications via Websockets to notify clients of changes without requiring polling. Notifications are identified by the method field and include data in the params field. Note that notifications do not contain an id field.
  11. Overview of btcd

    master

    btcd is a full node Bitcoin implementation written in Go. It is designed to download, validate, and serve the blockchain using the exact consensus rules used by Bitcoin Core.

    Key Characteristics:

    • Consensus Compatibility: Uses the same rules (including consensus bugs) as Bitcoin Core to prevent blockchain forks.
    • Transaction Management: Relays newly mined blocks, maintains a transaction pool, and relays individual transactions.
    • Strict Validation: Includes strict checks for "standard" transactions based on miner requirements.
    • No Built-in Wallet: Unlike Bitcoin Core, btcd does NOT include wallet functionality. It is intended to be used alongside separate wallet projects like btcwallet or Paymetheus to manage payments.
  12. Overview of the btcd database package

    master

    The database package provides block and metadata storage for Bitcoin data. It is designed to allow btcd to support different database backends.

    Important Note for Developers: This package is primarily intended for btcd internal use. Because most database backends only allow one entity to have the database open at a time, a client application should typically not access this package directly. Instead, for programmatic access to Bitcoin data, use the rpcclient package to interact with the btcd JSON-RPC API.