node::NodeContext

NodeContext struct containing references to chain state and connection state.

Synopsis

Declared in <node/context.h>

struct NodeContext;

Description

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.

Member Functions

NameDescription
NodeContext [constructor]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 [destructor]Destroy the node context and release its owned members.

Data Members

NameDescription
addrman Address manager tracking known peer addresses.
args Parsed command-line and configuration arguments (memory not owned by this struct).
background_init_thread Background thread that performs the remainder of node initialization.
banman Tracks and persists banned and discouraged peers.
chain Interface giving access to the node's chain state.
chain_clients List of all chain clients (wallet processes or other client) connected to node.
chainman Owns and coordinates the active and background chainstates.
connman Manages the node's peer-to-peer network connections.
ecc_context Owns the process-wide libsecp256k1 signing and verification context.
exit_status Process exit status, set to a failure value when a fatal error occurs.
fee_estimator_man Tracks fee-rate estimates derived from observed transactions.
indexes Active optional block-chain indexes (memory not owned by this struct).
init Init interface for initializing current process and connecting to other processes.
kernel libbitcoin_kernel context
mempool The node's memory pool of unconfirmed transactions.
mining Reference to chain client that should used to load or create wallets opened by the gui.
mining_args Mining options used to create block templates. This value member is an exception to the dependency guidance above because BlockCreateOptions is a minimal dependency. It could be moved to the BlockTemplateCache proposed in bitcoin/bitcoin#33421.
netgroupman Maps peer addresses to network groups for connection bucketing.
notifications Issues blocking calls about sync status, errors and warnings
peerman Drives peer-to-peer message processing and per-peer state.
rpc_interruption_point Hook invoked at interruption points during long-running RPCs.
scheduler Runs deferred and recurring background tasks.
shutdown_request Function to request a shutdown.
shutdown_signal Interrupt object used to track whether node shutdown was requested.
tor_controller Manages the node's Tor hidden service and control connection.
validation_signals Issues calls about blocks and transactions
wallet_loader Interface used to load or create wallets, owned elsewhere.
warnings Manages all the node warnings

Non-Member Functions

NameDescription
BroadcastTransactionSubmit a transaction to the mempool and (optionally) relay it to all P2P peers.
FindCoinsLook up unspent output information. Returns coins in the mempool and in the current chain UTXO set. Iterates through all the keys in the map and populates the values.
::AppInitInterfacesInitialize node and wallet interface pointers. Has no prerequisites or side effects besides allocating memory.
::AppInitMainBitcoin core main initialization.
::CreateUTXOSnapshotHelper to create UTXO snapshots given a chainstate and a file handle.
::EnsureAddrmanGet the address manager from a node context, asserting it is present.
::EnsureAnyNodeContextExtract the node context from an opaque RPC context, asserting it is present.
::EnsureArgsmanGet the argument manager from a node context, asserting it is present.
::EnsureBanmanGet the ban manager from a node context, asserting it is present.
::EnsureChainmanGet the chainstate manager from a node context, asserting it is present.
::EnsureConnmanGet the connection manager from a node context, asserting it is present.
::EnsureFeeEstimatorManGet the fee estimator from a node context, asserting it is present.
::EnsureMemPoolGet the mempool from a node context, asserting it is present.
::EnsureMiningGet the mining interface from a node context, asserting it is present.
::EnsurePeermanGet the peer manager from a node context, asserting it is present.
::InitContextInitialize node context shutdown and args variables.
::InterruptInterrupt threads
::ShutdownShut down the node, stopping threads and releasing resources.
::ShutdownRequestedReturn whether node shutdown was requested.
::StartIndexBackgroundSyncValidates requirements to run the indexes and spawns each index initial sync thread