← index

What are interesting parts of the Bitcoin Core codebase?

An archive of delvingbitcoin.org · view original topic →

Casey Rodarmor · #1 ·

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!

/dev/fd0 · #2 ·

P2P is the most interesting part of bitcoin core

recent798 · #3 ·

Mempool design is an interesting theoretical problem. For instance, Mempool Incentive Compatibility

Moreover, privacy and DoS resistance in general are areas with open research questions. For instance, P2P attacks | Bitcoin Core Onboarding

William Casarin · #4 ·

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!

Casey Rodarmor · #5 ·

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?

Sanket Kanjalkar · #6 · · 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.

/dev/fd0 · #7 ·

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.

recent798 · #8 · · 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.

Bruno Garcia · #9 ·

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