Consensus in Bitcoin Core

Naturally one might assume that all code related to consensus could be found in the src/consensus/ directory, however this is not entirely the case. Components of consensus-related code can be found across the Bitcoin Core codebase in a number of files, including but not limited to:

πŸ“‚ bitcoin
  πŸ“‚ src
    πŸ“‚ consensus
    πŸ“‚ script
      πŸ“„interpreter.cpp
    πŸ“„ validation.h
    πŸ“„ validation.cpp

Consensus-critical functions can also be found in proximity to code which could affect whether a node considers a transaction or block valid. This could extend to, for example, block storage database code.

An abbreviated list of some of the more notable consensus functions and variables is shown below.

Table 1. Some consensus functions and variables
File Objects

src/consensus/amount.h

COIN, MAX_MONEY, MoneyRange()

src/consensus/consensus.h

BLOCK{SIZE|WEIGHT|SIGOPS_COST}, COINBASE_MATURITY, WITNESS_SCALE_FACTOR, MIN_TX_WEIGHT

src/consensus/merkle.{h|cpp}

ComputeMerkleRoot(), BlockMerkleRoot(), BlockWitnessMerkleRoot()

src/consensus/params.h

BuriedDeployment, Params(buried blocks which are valid but known to fail default script verify checks, BIP height activations, PoW params)

src/consensus/tx_check.{h|cpp}

CheckTransaction()

src/consensus/tx_verify.{h|cpp}

CheckTxInputs(), Get{Legacy}SigOpCount(), IsFinalTx(), SequenceLock(s)()

src/consensus/validation.h

TxValidationResult (validation result reason), BlockValidationResult (validation result reason), ValidationState, Get{Transaction|Block|TransactionInput}Weight()