What are interesting parts of the Bitcoin Core codebase?

Archived from the original topic ↗

I have a super smart friend who I’m trying to nerd-snipe into getting interested in working on Bitcoin Core. My super sneaky plan is to point him to some particularly juicy parts of the codebase to try to pique his interests.

Does anyone have any favorite parts of the Bitcoin Core codebase? They could be particularly elegant, do something particularly impressive, or be particularly interesting theoretically. I’ll definitely also point him to libsecp256k1!

Feb '24created
Mar '24last reply
8replies
6users

P2P is the most interesting part of bitcoin core

I like the EvalScript code in script/interpreter.cpp, it’s a simple stack based language that you can build your own interpreter for to learn how it works. Fun exercise!

What’s your favorite file or function?

Nice, great suggestion!

That’s a great discussion! I’ll definitely link him there. Anything in the existing codebase, like a file or function, which is particularly interesting?

↳ in reply to #5

I find the most interesting parts are in validation.cpp. In particular, the re-org logic and rolling back ConectBlock/DisconnectBlock, AcceptBlock, AcceptBlockHeader.

There are several interesting cases around DoS preventions in mempool related functions. Basically, what happens when there is new block in validation.cpp. There is also an integration test in python feature_block.py that tests lots of interesting scenarios hitting codepaths in validation.cpp.

Second, interpreter.cpp and scripting engine. miniscript.cpp is also is an interesting dive in itself.

P2P messages sent by bitcoin nodes and service flags: bitcoin/src/protocol.cpp at baed5edeb611d949982c849461949c645f8998a7 · bitcoin/bitcoin · GitHub

Interesting functions:

HasAllDesirableServiceFlags()
Misbehaving()
MaybePunishNodeForBlock()
MaybePunishNodeForTx()
ProcessCompactBlockTxns()
ProcessMessage()
MaybeDiscourageAndDisconnect()
AttemptToEvictConnection()
ReattemptInitialBroadcast()

Process used to relay transactions for better privacy in section Message: inventory is interesting as well.

↳ in reply to #5

Yes, the function would be BlockAssembler::addPackageTxs, which is the transaction selection algorithm for the next block in the chain, taking the presumed best transactions from the mempool.

ProcessMessage is cool to study. You can see how P2P messages are processed, etc. From this function, you can find many other interesting functions.