In the NodeContext structure there are two members named chainman and chain. chainman
is instance of ChainstateManager and chain is instance of interfaces::Chain. What is the differences between these two? What is the differences and why do we need both?
//! NodeContext struct containing references to chain state and connection
//! state.
//!
//! This is used by init, rpc, and test code to pass object references around
//! without needing to declare the same variables and parameters repeatedly, or
//! to use globals. More variables could be added to this struct (particularly
//! references to validation objects) to eliminate use of globals
//! and make code more modular and testable. The struct isn't intended to have
//! any member functions. It should just be a collection of references that can
//! be used without pulling in unwanted dependencies or functionality.
struct NodeContext {
//! libbitcoin_kernel context
std::unique_ptr<:context> kernel;
//! Init interface for initializing current process and connecting to other processes.
interfaces::Init* init{nullptr};
std::unique_ptr addrman;
std::unique_ptr connman;
std::unique_ptr mempool;
std::unique_ptr netgroupman;
std::unique_ptr fee_estimator;
std::unique_ptr peerman;
std::unique_ptr chainman;
std::unique_ptr banman;
ArgsManager* args{nullptr}; // Currently a raw pointer because the memory is not managed by this struct
std::unique_ptr<:chain> chain;
//! List of all chain clients (wallet processes or other client) connected to node.
std::vector<:unique_ptr>> chain_clients;
//! Reference to chain client that should used to load or create wallets
//! opened by the gui.
interfaces::WalletLoader* wallet_loader{nullptr};
std::unique_ptr scheduler;
std::function rpc_interruption_point = [] {};
//! Declare default constructor and destructor that are not inline, so code
//! instantiating the NodeContext struct doesn't need to #include class
//! definitions for all the unique_ptr members.
NodeContext();
~NodeContext();
};
My assumptions are:
ChainstateManagermanagesChainstates which arem_ibd_chainstateandm_snapshot_chainstate.Chainstatehas all data of a chain.
While interfaces::Chain is used for external components such as wallet, the only possible reason that comes to my mind is that the chain member is for external users of bitcoind. And by this fact, the implementation of interface::chain must be only a simple wrapper over the ChainstateManager, because I think all logic is implemented there.












