diff options
author | Russell Yanofsky <russ@yanofsky.org> | 2019-09-17 18:28:03 -0400 |
---|---|---|
committer | Russell Yanofsky <russ@yanofsky.org> | 2019-10-28 10:30:51 -0400 |
commit | e6f4f895d5e42feaf7bfa5f41e80292aaa73cd7d (patch) | |
tree | 1c12f814ae2ac88316066d334274354c669d7aa5 /src/node | |
parent | 4d5448c76b71c9d91399c31b043237091be2e5e7 (diff) |
Pass NodeContext, ConnMan, BanMan references more places
So g_connman and g_banman globals can be removed next commit.
Diffstat (limited to 'src/node')
-rw-r--r-- | src/node/context.cpp | 10 | ||||
-rw-r--r-- | src/node/context.h | 17 | ||||
-rw-r--r-- | src/node/transaction.cpp | 3 | ||||
-rw-r--r-- | src/node/transaction.h | 5 |
4 files changed, 32 insertions, 3 deletions
diff --git a/src/node/context.cpp b/src/node/context.cpp new file mode 100644 index 0000000000..98cb061f19 --- /dev/null +++ b/src/node/context.cpp @@ -0,0 +1,10 @@ +// Copyright (c) 2019 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include <node/context.h> + +#include <interfaces/chain.h> + +NodeContext::NodeContext() {} +NodeContext::~NodeContext() {} diff --git a/src/node/context.h b/src/node/context.h index 3dd90ba961..f98550105d 100644 --- a/src/node/context.h +++ b/src/node/context.h @@ -13,11 +13,26 @@ class Chain; class ChainClient; } // namespace interfaces -//! Pointers to interfaces used during init and destroyed on shutdown. +//! 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 and mempool 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 { std::unique_ptr<interfaces::Chain> chain; std::vector<std::unique_ptr<interfaces::ChainClient>> chain_clients; + + //! 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(); }; #endif // BITCOIN_NODE_CONTEXT_H diff --git a/src/node/transaction.cpp b/src/node/transaction.cpp index 7783671a6c..2577c25598 100644 --- a/src/node/transaction.cpp +++ b/src/node/transaction.cpp @@ -6,6 +6,7 @@ #include <consensus/validation.h> #include <net.h> #include <net_processing.h> +#include <node/context.h> #include <util/validation.h> #include <validation.h> #include <validationinterface.h> @@ -13,7 +14,7 @@ #include <future> -TransactionError BroadcastTransaction(const CTransactionRef tx, std::string& err_string, const CAmount& max_tx_fee, bool relay, bool wait_callback) +TransactionError BroadcastTransaction(NodeContext& node, const CTransactionRef tx, std::string& err_string, const CAmount& max_tx_fee, bool relay, bool wait_callback) { // BroadcastTransaction can be called by either sendrawtransaction RPC or wallet RPCs. // g_connman is assigned both before chain clients and before RPC server is accepting calls, diff --git a/src/node/transaction.h b/src/node/transaction.h index a3e56544a7..35873d8376 100644 --- a/src/node/transaction.h +++ b/src/node/transaction.h @@ -9,6 +9,8 @@ #include <primitives/transaction.h> #include <util/error.h> +struct NodeContext; + /** * Submit a transaction to the mempool and (optionally) relay it to all P2P peers. * @@ -18,6 +20,7 @@ * NOT be set while cs_main, cs_mempool or cs_wallet are held to avoid * deadlock. * + * @param[in] node reference to node context * @param[in] tx the transaction to broadcast * @param[out] &err_string reference to std::string to fill with error string if available * @param[in] max_tx_fee reject txs with fees higher than this (if 0, accept any fee) @@ -25,6 +28,6 @@ * @param[in] wait_callback, wait until callbacks have been processed to avoid stale result due to a sequentially RPC. * return error */ -NODISCARD TransactionError BroadcastTransaction(CTransactionRef tx, std::string& err_string, const CAmount& max_tx_fee, bool relay, bool wait_callback); +NODISCARD TransactionError BroadcastTransaction(NodeContext& node, CTransactionRef tx, std::string& err_string, const CAmount& max_tx_fee, bool relay, bool wait_callback); #endif // BITCOIN_NODE_TRANSACTION_H |