Key Source Files in Bitcoin
TL;DR
Navigating the Bitcoin Core
src/directory requires understanding key files likevalidation.cpp(consensus logic),net.cpp(networking), andpow.cpp(mining rules).
The src/ directory in the Bitcoin Core repository contains the C++ files that power the node. Here are a few of the most important files any new contributor should become familiar with:
Initialization and Main Loop
init.cpp: The primary initialization file. It parses command-line arguments, readsbitcoin.conf, sets up logging, initializes state variables, starts background threads, and orchestrates the startup sequence of the node.bitcoind.cpp: The specific entry point (main function) for thebitcoindheadless executable.
Validation and Consensus
validation.cpp(andvalidation.h): This is arguably the most critical file. It contains the logic for validating transactions (e.g.,AcceptToMemoryPool) and validating blocks (CheckBlockandConnectBlock).ConnectBlockis where the heavy context-dependent consensus checks reside.consensus/folder: Contains code purely related to Bitcoin consensus rules (the rules all nodes must agree on to stay on the same chain).
Peer-to-Peer Networking
net.cpp: Handles the lower-level socket connections to peers. It deals with finding nodes, maintaining connections, socket handlers, and banning misbehaving peers.net_processing.cpp: Contains the higher-level logic. It implements the functionProcessMessage(), interpreting individual P2P messages (likeGETDATA,INV,TX,BLOCK) exchanged between nodes.
Mempool
txmempool.cpp: Manages the memory pool, storing unconfirmed transactions waiting to be included in a block. Nodes can implement unique policies (different from consensus) regarding what they accept into their own mempool.