How bitcoin-core/gui works
Project Type & Purpose
• Full-stack, peer-to-peer cryptocurrency node with multiple interfaces (daemon, CLI, GUI, RPC, REST, ZMQ) plus wallet and test harnesses.
• Core responsibilities: connect to P2P network, validate/relay blocks & transactions, maintain chainstate & mempool, provide mining support, wallet management, and expose APIs.
Main Architectural Layers & Components
A. Persisted Storage
– Block & undo files on disk (flatfile.cpp)
– Chainstate DB (LevelDB under src/leveldb)
– Wallet DB (BerkeleyDB or SQLite under src/wallet)
B. Core Kernel & Consensus
– Consensus rules & validation (src/consensus/, src/validation.cpp)
– Chainstate manager (src/kernel/)
– Mempool & policy (src/mempool*, src/policy/)
– Script engine & interpreter (src/script/)
– Cryptography & hashing (src/crypto/, secp256k1/, minisketch/)
C. Networking & IPC
– P2P networking stack (src/net*, src/connman.cpp)
– I2P integration (src/i2p/)
– Tor control (src/torcontrol.cpp)
– IPC (libmultiprocess under src/ipc/)
– ZMQ publish/subscribe (src/zmq/)
D. Service Interfaces
– RPC server (HTTP+JSON-RPC in src/rpc/)
– REST interface (src/httpserver.cpp + src/rest.cpp)
– CLI tools: bitcoin-cli, bitcoin-tx, bitcoin-wallet (src/*.cpp)
– GUI front-end (Qt) (src/qt/)
E. Wallet & External Signers
– Wallet logic & coin selection (src/wallet/)
– PSBT & external signer support (src/external_signer.cpp)
Interactions & Data Flows
1. P2P messages arrive → Net message parser (src/net.cpp) → Peer manager (connman)
2. New blocks/tx dispatched to validation module → consensus rules → chainstate & mempool update
3. Persistence layer writes block files & LevelDB chainstate
4. On chain updates, notification interfaces fire (internal pub/sub via libmultiprocess or ZMQ)
5. RPC/REST endpoints call into the same node interfaces → return JSON results
6. GUI (bitcoin-qt) embeds node or connects via IPC/RPC to daemon
7. CLI tools invoke RPC over HTTP or via IPC socket
Architectural Patterns & Principles
• Layered architecture: storage → core logic → networking/IPC → service interfaces → client UIs
• Modular libraries: crypto, consensus, script, network, kernel, wallet, util
• Separation of concerns:
– Chainstate and validation insulated from networking
– Interface adapters (RPC/REST/ZMQ) sit atop node logic
– GUI isolated in Qt module, communicates via well-defined IPC or in-process calls
• Use of message-passing (libmultiprocess) for multiprocess isolation of GUI/node
Final Checklist
– Clear, unique labels on all major components
– Arrowed lines showing direction of message or data flow