How starkware-bitcoin/bitcoin works
Project Type and Purpose
• Bitcoin Knots is a full-node cryptocurrency client (fork of Bitcoin Core) with P2P networking, on-disk blockchain storage, consensus/validation logic, wallet, RPC/CLI interfaces, and optional Qt GUI.
Top-Level Components to Sketch
a. Networking Layer (P2P)
• src/net.cpp, src/net_processing.cpp, src/peerman, src/ipc: handles peer discovery, gossip, message serialization, connection management.
• External service: Internet (other Bitcoin nodes).
b. Consensus & Validation
• src/consensus, src/validation, src/chainstate: enforces consensus rules, block & transaction validation, UTXO set maintenance.
c. Storage Layer
• src/txdb, src/dbwrapper, src/flatfile: on-disk block files (.blk/.idx), leveldb for UTXO, BerkeleyDB for wallet.
d. Node Kernel & Interfaces
• src/kernel, src/node: orchestrates interactions between networking, consensus, storage, and higher-level interfaces.
e. RPC & CLI Interfaces
• src/rpc, bitcoin-cli: JSON-RPC server listens on HTTP (or zmq), services client requests.
f. Wallet Subsystem
• src/wallet: BDB or SQLite backend, coin selection, key management, transaction creation, external signer hooks.
g. GUI (Optional)
• src/qt: Qt-based GUI front-end rendering wallet and node status, communicates with core via interfaces (onside or via RPC).
h. Libraries & Dependencies
• secp256k1 (elliptic-curve crypto), univalue (JSON), libevent (async I/O), ZeroMQ (notifications), LevelDB, BerkeleyDB.
Relationships & Data Flows
• P2P networking → Node Kernel → Consensus → Storage
• Consensus notifications → Wallet / GUI via interfaces or RPC callbacks
• RPC/CLI → Node Kernel (query chainstate, send transactions)
• Wallet → Consensus & Mempool (broadcasting TX) → P2P
• GUI → Wallet & Node Kernel (through interfaces layer or RPC)
• External libraries (crypto, DB) support core components
Architectural Patterns & Principles
• Layered architecture:
• Transport (P2P, IPC)
• Core logic (kernel, consensus, validation)
• Persistence (blockstore, UTXO, wallet DB)
• Interface/API (RPC, CLI, GUI)
• Modular C++ libraries (crypto/, primitives/, script/, consensus/)
• Interface segregation: src/interfaces defines abstract handlers for UI, wallet, mining, etc.
• Plugin-style external signer, ZeroMQ notifications.