Hello everyone and welcome to this new episode of Inside Bitcoin Code.
A special welcome to the new people that recently subscribed to this newsletter, I hope that you will enjoy what I write. A small suggestion for you: if you know nothing about coding, start reading the posts from Learn2Code to get some basic knowledge before diving in the real deal.
A huge thanks to each of the 146 subscribers of this newsletter and to those who decided to contribute with some sats to this project. It means the world to me!
Last episode was focused on cache memory allocation. Today we are going to continue our trip inside the initialization of Bitcoin Core finishing Step 7. [Code Link]
Let’s start!
User Shutdown Request
After launching loading of the chain state, the code check whether or not the user closes the process manually. A user could request to shutdown the node due to the fact that the LoadBlockIndex()
function could take several minute to complete. In case of shutdown, the initialization function returns false
.
if (ShutdownRequested(node)) {
LogInfo(”Shutdown requested. Exiting.”);
return false;
}
Peer Manager Initialization
Once the previous step has been completed, the program continues with the initialization of the PeerManager
object.
It first checks that ChainstateManager
and KernelNotifications
objects in the node
are defined.
ChainstateManager& chainman = *Assert(node.chainman);
auto& kernel_notifications{*Assert(node.notifications)};
Then, it checks that the PeerManager
object has not been initialized, yet.
assert(!node.peerman);
If everything goes smoothly, the software initialized the PeerManager
with the following inputs:
Connection manager object
CConnman
: Manages connections to other nodes.Address manager object
AddrMan
: Stores addresses of other nodes and info about their reputations.Ban manager object
BanMan
: Manages banned peers.Chainstate manager object
ChainstateManager
: Validates blocks and transactions from other peers.Mempool object
CTxMemPool
: Manages mempool operationsWarnings object
node::Warnings
: Handles the overall warning system.Peer manager options object
PeerManager::Options
: Configuration parameters.
node.peerman = PeerManager::make(*node.connman, *node.addrman,
node.banman.get(), chainman,
*node.mempool, *node.warnings,
peerman_opts);
Finally, the PeerManager
object is registered to receive events generated in validation and mempool.
validation_signals.RegisterValidationInterface(node.peerman.get());
Let’s keep in touch:
Check out my writings on btc++ insider edition
Try my new app Sats Tracker, an expense tracker app for people living in the Bitcoin standard.
Zap me a coffee and leave me a message: tuma@wallet.yakihonne.com