links-onepage.adoc == Exercises
-
What is the difference between contextual and context-free validation checks?
Click for answer
Contextual checks require some knowledge of the current "state", e.g. ChainState, chain tip or UTXO set.
Context-free checks only require the information required in the transaction itself.
For more info, see glozow’s notes on transaction "Validation and Submission to the Mempool".
-
What are some examples of each?
Click for answer
context-free:
-
tx.isCoinbase()
contextual:
-
-
In which function(s) do UTXO-related validity checks happen?
Click for answer
ConnectBlock()
-
What type of validation checks are
CheckBlockHeader()
andCheckBlock()
performing?Click for answer
context-free
-
Which class is in charge of managing the current blockchain?
Click for answer
ChainstateManager()
-
Which class is in charge of managing the UTXO set?
Click for answer
CCoinsViews()
-
Which functions are called when a longer chain is found that we need to re-org onto?
TODO
-
Are there any areas of the codebase where the same consensus or validation checks are performed twice?
Click for answer
Again see glozow’s notes for examples
-
Why does
CheckInputsFromMempoolAndCache
exist?Click for answer
To prevent us from re-checking the scripts of transactions already in our mempool during consensus validation on learning about a new block
-
Which function(s) are in charge of validating the merkle root of a block?
Click for answer
BlockMerkleRoot()
andBlockWitnessMerkleRoot()
construct a vector of merkle leaves, which is then passed toComputeMerkleRoot()
for calculation. -
Can you find any evidence (e.g. PRs) which have been made in an effort to modularize consensus code?
-
What is the function of
BlockManager()
?Click for answer
It manages the current most-work chaintip and pruning of unneeded blocks (
*.blk
) and associated undo (*.rev
) files -
What stops a malicious node from sending multiple invalid headers to try and use up a nodes' disk space? (hint: these might be stored in
BlockManager.m_failed_blocks
)Click for answer
Even invalid headers would need a valid proof of work which would be too costly to construct for a spammer
-
Which functions are responsible for writing consensus-valid blocks to disk?
Click for answer
src/node/blockstorage.h#SaveBlockToDisk
-
Are there any other components to Bitcoin Core which, similarly to the block storage database, are not themselves performing validation but can still be consensus-critical?
Not sure myself, sounds like an interesting question though!
-
In which module (and class) is signature verification handled?
Click for answer
src/script/interpreter.cpp#BaseSignatureChecker
-
Which function is used to calculate the Merkle root of a block, and from where is it called?
Click for answer
src/consensus/merkle.cpp#ComputeMerkleRoot
is used to compute the merkle root.It is called from
src/chainparams.cpp#CreateGenesisBlock
,src/miner.cpp#IncrementExtraNonce
&src/miner.cpp#RegenerateCommitments
and fromsrc/validation.cpp#CheckBlock
to validate incoming blocks. -
Practical question on Merkle root calculation
TODO, add more Exercises
-
Modify the code which is used to add new opcodes to a
CScript
without breaking consensus.
-