Add src/node/* code to node:: namespace

This commit is contained in:
Russell Yanofsky 2021-11-12 10:06:00 -05:00
parent 4ada74206a
commit 90fc8b089d
77 changed files with 283 additions and 61 deletions

View file

@ -11,6 +11,8 @@
#include <set>
using node::NodeContext;
static void addCoin(const CAmount& nValue, const CWallet& wallet, std::vector<std::unique_ptr<CWalletTx>>& wtxs)
{
static int nextLockTime = 0;

View file

@ -30,6 +30,8 @@
#include <functional>
#include <optional>
using node::NodeContext;
const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr;
UrlDecodeFn* const URL_DECODE = urlDecode;

View file

@ -21,7 +21,7 @@ public:
bool HasWalletSupport() const override {return false;}
void AddWalletOptions(ArgsManager& argsman) const override;
bool ParameterInteraction() const override {return true;}
void Construct(NodeContext& node) const override {LogPrintf("No wallet support compiled in!\n");}
void Construct(node::NodeContext& node) const override {LogPrintf("No wallet support compiled in!\n");}
};
void DummyWalletInit::AddWalletOptions(ArgsManager& argsman) const

View file

@ -14,6 +14,8 @@
#include <validation.h> // For g_chainman
#include <warnings.h>
using node::ReadBlockFromDisk;
constexpr uint8_t DB_BEST_BLOCK{'B'};
constexpr int64_t SYNC_LOG_INTERVAL = 30; // seconds

View file

@ -9,6 +9,8 @@
#include <node/blockstorage.h>
#include <util/system.h>
using node::UndoReadFromDisk;
/* The index database stores three items for each block: the disk location of the encoded filter,
* its dSHA256 hash, and the header. Those belonging to blocks on the active chain are indexed by
* height, and those belonging to blocks that have been reorganized out of the active chain are

View file

@ -12,6 +12,12 @@
#include <undo.h>
#include <validation.h>
using node::CCoinsStats;
using node::GetBogoSize;
using node::ReadBlockFromDisk;
using node::TxOutSer;
using node::UndoReadFromDisk;
static constexpr uint8_t DB_BLOCK_HASH{'s'};
static constexpr uint8_t DB_BLOCK_HEIGHT{'t'};
static constexpr uint8_t DB_MUHASH{'M'};

View file

@ -52,7 +52,7 @@ public:
explicit CoinStatsIndex(size_t n_cache_size, bool f_memory = false, bool f_wipe = false);
// Look up stats for a specific block using CBlockIndex
bool LookUpStats(const CBlockIndex* block_index, CCoinsStats& coins_stats) const;
bool LookUpStats(const CBlockIndex* block_index, node::CCoinsStats& coins_stats) const;
};
/// The global UTXO set hash object.

View file

@ -9,6 +9,8 @@
#include <util/system.h>
#include <validation.h>
using node::OpenBlockFile;
constexpr uint8_t DB_TXINDEX{'t'};
std::unique_ptr<TxIndex> g_txindex;

View file

@ -95,6 +95,22 @@
#include <zmq/zmqrpc.h>
#endif
using node::CacheSizes;
using node::CalculateCacheSizes;
using node::ChainstateLoadVerifyError;
using node::ChainstateLoadingError;
using node::CleanupBlockRevFiles;
using node::DEFAULT_PRINTPRIORITY;
using node::DEFAULT_STOPAFTERBLOCKIMPORT;
using node::LoadChainstate;
using node::NodeContext;
using node::ThreadImport;
using node::VerifyLoadedChainstate;
using node::fHavePruned;
using node::fPruneMode;
using node::fReindex;
using node::nPruneTarget;
static const bool DEFAULT_PROXYRANDOMIZE = true;
static const bool DEFAULT_REST_ENABLE = false;

View file

@ -16,14 +16,16 @@ static constexpr bool DEFAULT_DAEMON = false;
static constexpr bool DEFAULT_DAEMONWAIT = false;
class ArgsManager;
struct NodeContext;
namespace interfaces {
struct BlockAndHeaderTipInfo;
}
namespace node {
struct NodeContext;
} // namespace node
/** Interrupt threads */
void Interrupt(NodeContext& node);
void Shutdown(NodeContext& node);
void Interrupt(node::NodeContext& node);
void Shutdown(node::NodeContext& node);
//!Initialize the logging infrastructure
void InitLogging(const ArgsManager& args);
//!Parameter interaction: change current parameters depending on various rules
@ -55,13 +57,13 @@ bool AppInitLockDataDirectory();
/**
* Initialize node and wallet interface pointers. Has no prerequisites or side effects besides allocating memory.
*/
bool AppInitInterfaces(NodeContext& node);
bool AppInitInterfaces(node::NodeContext& node);
/**
* Bitcoin core main initialization.
* @note This should only be done after daemonization. Call Shutdown() if this function fails.
* @pre Parameters should be parsed and config file should be read, AppInitLockDataDirectory should have been called.
*/
bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info = nullptr);
bool AppInitMain(node::NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info = nullptr);
/**
* Register all arguments with the ArgsManager

View file

@ -33,7 +33,7 @@ public:
}
std::unique_ptr<interfaces::Echo> makeEcho() override { return interfaces::MakeEcho(); }
interfaces::Ipc* ipc() override { return m_ipc.get(); }
NodeContext m_node;
node::NodeContext m_node;
std::unique_ptr<interfaces::Ipc> m_ipc;
};
} // namespace

View file

@ -20,7 +20,7 @@ const char* EXE_NAME = "bitcoin-node";
class BitcoinNodeInit : public interfaces::Init
{
public:
BitcoinNodeInit(NodeContext& node, const char* arg0)
BitcoinNodeInit(node::NodeContext& node, const char* arg0)
: m_node(node),
m_ipc(interfaces::MakeIpc(EXE_NAME, arg0, *this))
{
@ -35,14 +35,14 @@ public:
}
std::unique_ptr<interfaces::Echo> makeEcho() override { return interfaces::MakeEcho(); }
interfaces::Ipc* ipc() override { return m_ipc.get(); }
NodeContext& m_node;
node::NodeContext& m_node;
std::unique_ptr<interfaces::Ipc> m_ipc;
};
} // namespace
} // namespace init
namespace interfaces {
std::unique_ptr<Init> MakeNodeInit(NodeContext& node, int argc, char* argv[], int& exit_status)
std::unique_ptr<Init> MakeNodeInit(node::NodeContext& node, int argc, char* argv[], int& exit_status)
{
auto init = std::make_unique<init::BitcoinNodeInit>(node, argc > 0 ? argv[0] : "");
// Check if bitcoin-node is being invoked as an IPC server. If so, then

View file

@ -29,7 +29,7 @@ public:
return MakeWalletLoader(chain, *Assert(m_node.args));
}
std::unique_ptr<interfaces::Echo> makeEcho() override { return interfaces::MakeEcho(); }
NodeContext m_node;
node::NodeContext m_node;
};
} // namespace
} // namespace init

View file

@ -12,6 +12,8 @@
#include <memory>
using node::NodeContext;
namespace init {
namespace {
class BitcoindInit : public interfaces::Init

View file

@ -28,7 +28,9 @@ enum class RBFTransactionState;
struct bilingual_str;
struct CBlockLocator;
struct FeeCalculation;
namespace node {
struct NodeContext;
} // namespace node
namespace interfaces {
@ -316,7 +318,7 @@ public:
};
//! Return implementation of Chain interface.
std::unique_ptr<Chain> MakeChain(NodeContext& node);
std::unique_ptr<Chain> MakeChain(node::NodeContext& node);
} // namespace interfaces

View file

@ -7,7 +7,9 @@
#include <memory>
namespace node {
struct NodeContext;
} // namespace node
namespace interfaces {
class Chain;
@ -40,7 +42,7 @@ public:
//! status code to exit with. If this returns non-null, the caller can start up
//! normally and use the Init object to spawn and connect to other processes
//! while it is running.
std::unique_ptr<Init> MakeNodeInit(NodeContext& node, int argc, char* argv[], int& exit_status);
std::unique_ptr<Init> MakeNodeInit(node::NodeContext& node, int argc, char* argv[], int& exit_status);
//! Return implementation of Init interface for the wallet process.
std::unique_ptr<Init> MakeWalletInit(int argc, char* argv[], int& exit_status);

View file

@ -32,8 +32,10 @@ class proxyType;
enum class SynchronizationState;
enum class TransactionError;
struct CNodeStateStats;
struct NodeContext;
struct bilingual_str;
namespace node {
struct NodeContext;
} // namespace node
namespace interfaces {
class Handler;
@ -242,12 +244,12 @@ public:
//! Get and set internal node context. Useful for testing, but not
//! accessible across processes.
virtual NodeContext* context() { return nullptr; }
virtual void setContext(NodeContext* context) { }
virtual node::NodeContext* context() { return nullptr; }
virtual void setContext(node::NodeContext* context) { }
};
//! Return implementation of Node interface.
std::unique_ptr<Node> MakeNode(NodeContext& context);
std::unique_ptr<Node> MakeNode(node::NodeContext& context);
//! Block tip (could be a header or not, depends on the subscribed signal).
struct BlockTip {

View file

@ -45,6 +45,12 @@
#include <optional>
#include <typeinfo>
using node::ReadBlockFromDisk;
using node::ReadRawBlockFromDisk;
using node::fImporting;
using node::fPruneMode;
using node::fReindex;
/** How long to cache transactions in mapRelay for normal relay */
static constexpr auto RELAY_TX_CACHE_TIME = 15min;
/** How long a transaction has to be in the mempool before it can unconditionally be relayed (even when not in mapRelay). */

View file

@ -21,6 +21,7 @@
#include <util/system.h>
#include <validation.h>
namespace node {
std::atomic_bool fImporting(false);
std::atomic_bool fReindex(false);
bool fHavePruned = false;
@ -472,12 +473,14 @@ void CleanupBlockRevFiles()
remove(item.second);
}
}
} // namespace node
std::string CBlockFileInfo::ToString() const
{
return strprintf("CBlockFileInfo(blocks=%u, size=%u, heights=%u...%u, time=%s...%s)", nBlocks, nSize, nHeightFirst, nHeightLast, FormatISO8601Date(nTimeFirst), FormatISO8601Date(nTimeLast));
}
namespace node {
CBlockFileInfo* BlockManager::GetBlockFileInfo(size_t n)
{
LOCK(cs_LastBlockFile);
@ -939,3 +942,4 @@ void ThreadImport(ChainstateManager& chainman, std::vector<fs::path> vImportFile
} // End scope of CImportingNow
chainman.ActiveChainstate().LoadMempool(args);
}
} // namespace node

View file

@ -29,6 +29,7 @@ namespace Consensus {
struct Params;
}
namespace node {
static constexpr bool DEFAULT_STOPAFTERBLOCKIMPORT{false};
/** The pre-allocation chunk size for blk?????.dat files (since 0.8) */
@ -185,5 +186,6 @@ bool ReadRawBlockFromDisk(std::vector<uint8_t>& block, const CBlockIndex* pindex
bool UndoReadFromDisk(CBlockUndo& blockundo, const CBlockIndex* pindex);
void ThreadImport(ChainstateManager& chainman, std::vector<fs::path> vImportFiles, const ArgsManager& args);
} // namespace node
#endif // BITCOIN_NODE_BLOCKSTORAGE_H

View file

@ -8,6 +8,7 @@
#include <util/system.h>
#include <validation.h>
namespace node {
CacheSizes CalculateCacheSizes(const ArgsManager& args, size_t n_indexes)
{
int64_t nTotalCache = (args.GetIntArg("-dbcache", nDefaultDbCache) << 20);
@ -30,3 +31,4 @@ CacheSizes CalculateCacheSizes(const ArgsManager& args, size_t n_indexes)
sizes.coins = nTotalCache; // the rest goes to in-memory cache
return sizes;
}
} // namespace node

View file

@ -10,6 +10,7 @@
class ArgsManager;
namespace node {
struct CacheSizes {
int64_t block_tree_db;
int64_t coins_db;
@ -18,5 +19,6 @@ struct CacheSizes {
int64_t filter_index;
};
CacheSizes CalculateCacheSizes(const ArgsManager& args, size_t n_indexes = 0);
} // namespace node
#endif // BITCOIN_NODE_CACHES_H

View file

@ -8,6 +8,7 @@
#include <node/blockstorage.h>
#include <validation.h>
namespace node {
std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
ChainstateManager& chainman,
CTxMemPool* mempool,
@ -156,3 +157,4 @@ std::optional<ChainstateLoadVerifyError> VerifyLoadedChainstate(ChainstateManage
return std::nullopt;
}
} // namespace node

View file

@ -10,11 +10,12 @@
#include <optional>
class ChainstateManager;
namespace Consensus {
struct Params;
}
class CTxMemPool;
namespace Consensus {
struct Params;
} // namespace Consensus
namespace node {
enum class ChainstateLoadingError {
ERROR_LOADING_BLOCK_DB,
ERROR_BAD_GENESIS_BLOCK,
@ -81,5 +82,6 @@ std::optional<ChainstateLoadVerifyError> VerifyLoadedChainstate(ChainstateManage
unsigned int check_blocks,
unsigned int check_level,
std::function<int64_t()> get_unix_time_seconds);
} // namespace node
#endif // BITCOIN_NODE_CHAINSTATE_H

View file

@ -8,6 +8,7 @@
#include <txmempool.h>
#include <validation.h>
namespace node {
void FindCoins(const NodeContext& node, std::map<COutPoint, Coin>& coins)
{
assert(node.mempool);
@ -22,3 +23,4 @@ void FindCoins(const NodeContext& node, std::map<COutPoint, Coin>& coins)
}
}
}
} // namespace node

View file

@ -9,6 +9,8 @@
class COutPoint;
class Coin;
namespace node {
struct NodeContext;
/**
@ -19,6 +21,7 @@ struct NodeContext;
* @param[in] node The node context to use for lookup
* @param[in,out] coins map to fill
*/
void FindCoins(const NodeContext& node, std::map<COutPoint, Coin>& coins);
void FindCoins(const node::NodeContext& node, std::map<COutPoint, Coin>& coins);
} // namespace node
#endif // BITCOIN_NODE_COIN_H

View file

@ -17,6 +17,7 @@
#include <map>
namespace node {
// Database-independent metric indicating the UTXO set size
uint64_t GetBogoSize(const CScript& script_pub_key)
{
@ -181,3 +182,4 @@ static void FinalizeHash(MuHash3072& muhash, CCoinsStats& stats)
stats.hashSerialized = out;
}
static void FinalizeHash(std::nullptr_t, CCoinsStats& stats) {}
} // namespace node

View file

@ -15,9 +15,12 @@
#include <cstdint>
#include <functional>
class BlockManager;
class CCoinsView;
namespace node {
class BlockManager;
} // namespace node
namespace node {
enum class CoinStatsHashType {
HASH_SERIALIZED,
MUHASH,
@ -71,10 +74,11 @@ struct CCoinsStats {
};
//! Calculate statistics about the unspent transaction output set
bool GetUTXOStats(CCoinsView* view, BlockManager& blockman, CCoinsStats& stats, const std::function<void()>& interruption_point = {}, const CBlockIndex* pindex = nullptr);
bool GetUTXOStats(CCoinsView* view, node::BlockManager& blockman, CCoinsStats& stats, const std::function<void()>& interruption_point = {}, const CBlockIndex* pindex = nullptr);
uint64_t GetBogoSize(const CScript& script_pub_key);
CDataStream TxOutSer(const COutPoint& outpoint, const Coin& coin);
} // namespace node
#endif // BITCOIN_NODE_COINSTATS_H

View file

@ -14,5 +14,7 @@
#include <txmempool.h>
#include <validation.h>
namespace node {
NodeContext::NodeContext() {}
NodeContext::~NodeContext() {}
} // namespace node

View file

@ -26,6 +26,7 @@ class Init;
class WalletLoader;
} // namespace interfaces
namespace node {
//! NodeContext struct containing references to chain state and connection
//! state.
//!
@ -62,5 +63,6 @@ struct NodeContext {
NodeContext();
~NodeContext();
};
} // namespace node
#endif // BITCOIN_NODE_CONTEXT_H

View file

@ -249,8 +249,8 @@ public:
bool isInitialBlockDownload() override {
return chainman().ActiveChainstate().IsInitialBlockDownload();
}
bool getReindex() override { return ::fReindex; }
bool getImporting() override { return ::fImporting; }
bool getReindex() override { return node::fReindex; }
bool getImporting() override { return node::fImporting; }
void setNetworkActive(bool active) override
{
if (m_context->connman) {
@ -649,9 +649,9 @@ public:
bool havePruned() override
{
LOCK(cs_main);
return ::fHavePruned;
return node::fHavePruned;
}
bool isReadyToBroadcast() override { return !::fImporting && !::fReindex && !isInitialBlockDownload(); }
bool isReadyToBroadcast() override { return !node::fImporting && !node::fReindex && !isInitialBlockDownload(); }
bool isInitialBlockDownload() override {
return chainman().ActiveChainstate().IsInitialBlockDownload();
}
@ -729,6 +729,6 @@ public:
} // namespace node
namespace interfaces {
std::unique_ptr<Node> MakeNode(NodeContext& context) { return std::make_unique<node::NodeImpl>(context); }
std::unique_ptr<Chain> MakeChain(NodeContext& context) { return std::make_unique<node::ChainImpl>(context); }
std::unique_ptr<Node> MakeNode(node::NodeContext& context) { return std::make_unique<node::NodeImpl>(context); }
std::unique_ptr<Chain> MakeChain(node::NodeContext& context) { return std::make_unique<node::ChainImpl>(context); }
} // namespace interfaces

View file

@ -26,6 +26,7 @@
#include <algorithm>
#include <utility>
namespace node {
int64_t UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev)
{
int64_t nOldTime = pblock->nTime;
@ -464,3 +465,4 @@ void IncrementExtraNonce(CBlock* pblock, const CBlockIndex* pindexPrev, unsigned
pblock->vtx[0] = MakeTransactionRef(std::move(txCoinbase));
pblock->hashMerkleRoot = BlockMerkleRoot(*pblock);
}
} // namespace node

View file

@ -23,6 +23,7 @@ class CScript;
namespace Consensus { struct Params; };
namespace node {
static const bool DEFAULT_PRINTPRIORITY = false;
struct CBlockTemplate
@ -206,5 +207,6 @@ int64_t UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParam
/** Update an old GenerateCoinbaseCommitment from CreateNewBlock after the block txs have changed */
void RegenerateCommitments(CBlock& block, ChainstateManager& chainman);
} // namespace node
#endif // BITCOIN_NODE_MINER_H

View file

@ -16,6 +16,7 @@
#include <utility>
#include <vector>
namespace node {
namespace {
static constexpr uint32_t BITS = 32;
@ -75,3 +76,4 @@ Minisketch MakeMinisketch32FP(size_t max_elements, uint32_t fpbits)
{
return Minisketch::CreateFP(BITS, Minisketch32Implementation(), max_elements, fpbits);
}
} // namespace node

View file

@ -10,9 +10,11 @@
#include <cstddef>
#include <cstdint>
namespace node {
/** Wrapper around Minisketch::Minisketch(32, implementation, capacity). */
Minisketch MakeMinisketch32(size_t capacity);
/** Wrapper around Minisketch::CreateFP. */
Minisketch MakeMinisketch32FP(size_t max_elements, uint32_t fpbits);
} // namespace node
#endif // BITCOIN_NODE_MINISKETCHWRAPPER_H

View file

@ -12,6 +12,7 @@
#include <numeric>
namespace node {
PSBTAnalysis AnalyzePSBT(PartiallySignedTransaction psbtx)
{
// Go through each input and build status
@ -147,3 +148,4 @@ PSBTAnalysis AnalyzePSBT(PartiallySignedTransaction psbtx)
return result;
}
} // namespace node

View file

@ -9,6 +9,7 @@
#include <optional>
namespace node {
/**
* Holds an analysis of one input from a PSBT
*/
@ -52,5 +53,6 @@ struct PSBTAnalysis {
* @return A PSBTAnalysis with information about the provided PSBT.
*/
PSBTAnalysis AnalyzePSBT(PartiallySignedTransaction psbtx);
} // namespace node
#endif // BITCOIN_NODE_PSBT_H

View file

@ -16,6 +16,7 @@
#include <future>
namespace node {
static TransactionError HandleATMPError(const TxValidationState& state, std::string& err_string_out)
{
err_string_out = state.ToString();
@ -153,3 +154,4 @@ CTransactionRef GetTransaction(const CBlockIndex* const block_index, const CTxMe
}
return nullptr;
}
} // namespace node

View file

@ -12,11 +12,13 @@
class CBlockIndex;
class CTxMemPool;
struct NodeContext;
namespace Consensus {
struct Params;
}
namespace node {
struct NodeContext;
/** Maximum fee rate for sendrawtransaction and testmempoolaccept RPC calls.
* Also used by the GUI when broadcasting a completed PSBT.
* By default, a transaction with a fee rate higher than this will be rejected
@ -57,5 +59,6 @@ static const CFeeRate DEFAULT_MAX_RAW_TX_FEE_RATE{COIN / 10};
* @returns The tx if found, otherwise nullptr
*/
CTransactionRef GetTransaction(const CBlockIndex* const block_index, const CTxMemPool* const mempool, const uint256& hash, const Consensus::Params& consensusParams, uint256& hashBlock);
} // namespace node
#endif // BITCOIN_NODE_TRANSACTION_H

View file

@ -9,6 +9,7 @@
#include <uint256.h>
#include <serialize.h>
namespace node {
//! Metadata describing a serialized version of a UTXO set from which an
//! assumeutxo CChainState can be constructed.
class SnapshotMetadata
@ -32,5 +33,6 @@ public:
SERIALIZE_METHODS(SnapshotMetadata, obj) { READWRITE(obj.m_base_blockhash, obj.m_coins_count); }
};
} // namespace node
#endif // BITCOIN_NODE_UTXO_SNAPSHOT_H

View file

@ -76,6 +76,8 @@ Q_DECLARE_METATYPE(CAmount)
Q_DECLARE_METATYPE(SynchronizationState)
Q_DECLARE_METATYPE(uint256)
using node::NodeContext;
static void RegisterMetaTypes()
{
// Register meta types used for QMetaObject::invokeMethod and Qt::QueuedConnection

View file

@ -17,6 +17,9 @@
#include <iostream>
using node::AnalyzePSBT;
using node::DEFAULT_MAX_RAW_TX_FEE_RATE;
using node::PSBTAnalysis;
PSBTOperationsDialog::PSBTOperationsDialog(
QWidget* parent, WalletModel* wallet_model, ClientModel* client_model) : QDialog(parent, GUIUtil::dialog_flags),

View file

@ -39,6 +39,8 @@ Q_IMPORT_PLUGIN(QAndroidPlatformIntegrationPlugin)
#endif
#endif
using node::NodeContext;
const std::function<void(const std::string&)> G_TEST_LOG_FUN{};
// This is all you need to run all the tests

View file

@ -32,6 +32,11 @@
#include <univalue.h>
using node::GetTransaction;
using node::IsBlockPruned;
using node::NodeContext;
using node::ReadBlockFromDisk;
static const size_t MAX_GETUTXOS_OUTPOINTS = 15; //allow a max of 15 outpoints to be queried at once
static constexpr unsigned int MAX_REST_HEADERS_RESULTS = 2000;

View file

@ -56,6 +56,16 @@
#include <memory>
#include <mutex>
using node::BlockManager;
using node::CCoinsStats;
using node::CoinStatsHashType;
using node::GetUTXOStats;
using node::IsBlockPruned;
using node::NodeContext;
using node::ReadBlockFromDisk;
using node::SnapshotMetadata;
using node::UndoReadFromDisk;
struct CUpdatedBlock
{
uint256 hash;
@ -1112,7 +1122,7 @@ static RPCHelpMan pruneblockchain()
},
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
{
if (!fPruneMode)
if (!node::fPruneMode)
throw JSONRPCError(RPC_MISC_ERROR, "Cannot prune blocks because node is not in prune mode.");
ChainstateManager& chainman = EnsureAnyChainman(request.context);
@ -1565,8 +1575,8 @@ RPCHelpMan getblockchaininfo()
obj.pushKV("initialblockdownload", active_chainstate.IsInitialBlockDownload());
obj.pushKV("chainwork", tip->nChainWork.GetHex());
obj.pushKV("size_on_disk", chainman.m_blockman.CalculateCurrentUsage());
obj.pushKV("pruned", fPruneMode);
if (fPruneMode) {
obj.pushKV("pruned", node::fPruneMode);
if (node::fPruneMode) {
const CBlockIndex* block = tip;
CHECK_NONFATAL(block);
while (block->pprev && (block->pprev->nStatus & BLOCK_HAVE_DATA)) {
@ -1579,7 +1589,7 @@ RPCHelpMan getblockchaininfo()
bool automatic_pruning{args.GetIntArg("-prune", 0) != 1};
obj.pushKV("automatic_pruning", automatic_pruning);
if (automatic_pruning) {
obj.pushKV("prune_target_size", nPruneTarget);
obj.pushKV("prune_target_size", node::nPruneTarget);
}
}

View file

@ -22,7 +22,9 @@ class CBlockIndex;
class CChainState;
class CTxMemPool;
class UniValue;
namespace node {
struct NodeContext;
} // namespace node
static constexpr int NUM_GETBLOCKSTATS_PERCENTILES = 5;
@ -57,7 +59,7 @@ void CalculatePercentilesByWeight(CAmount result[NUM_GETBLOCKSTATS_PERCENTILES],
* @return a UniValue map containing metadata about the snapshot.
*/
UniValue CreateUTXOSnapshot(
NodeContext& node,
node::NodeContext& node,
CChainState& chainstate,
CAutoFile& afile,
const fs::path& path,

View file

@ -41,6 +41,13 @@
#include <memory>
#include <stdint.h>
using node::BlockAssembler;
using node::CBlockTemplate;
using node::IncrementExtraNonce;
using node::NodeContext;
using node::RegenerateCommitments;
using node::UpdateTime;
/**
* Return average network hashes per second based on the last 'lookup' blocks,
* or from the last difficulty change if 'lookup' is nonpositive.

View file

@ -35,6 +35,8 @@
#include <univalue.h>
using node::NodeContext;
static RPCHelpMan validateaddress()
{
return RPCHelpMan{

View file

@ -32,6 +32,8 @@
#include <univalue.h>
using node::NodeContext;
const std::vector<std::string> CONNECTION_TYPE_DOC{
"outbound-full-relay (default automatic connections)",
"block-relay-only (does not relay transactions or addresses)",

View file

@ -45,6 +45,15 @@
#include <univalue.h>
using node::AnalyzePSBT;
using node::BroadcastTransaction;
using node::DEFAULT_MAX_RAW_TX_FEE_RATE;
using node::FindCoins;
using node::GetTransaction;
using node::NodeContext;
using node::PSBTAnalysis;
using node::ReadBlockFromDisk;
static void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry, CChainState& active_chainstate)
{
// Call into TxToUniv() in bitcoin-common to decode the transaction hex.

View file

@ -15,6 +15,8 @@
#include <any>
using node::NodeContext;
NodeContext& EnsureAnyNodeContext(const std::any& context)
{
auto node_context = util::AnyPtr<NodeContext>(context);

View file

@ -13,18 +13,20 @@ class CConnman;
class CTxMemPool;
class ChainstateManager;
class PeerManager;
namespace node {
struct NodeContext;
} // namespace node
NodeContext& EnsureAnyNodeContext(const std::any& context);
CTxMemPool& EnsureMemPool(const NodeContext& node);
node::NodeContext& EnsureAnyNodeContext(const std::any& context);
CTxMemPool& EnsureMemPool(const node::NodeContext& node);
CTxMemPool& EnsureAnyMemPool(const std::any& context);
ArgsManager& EnsureArgsman(const NodeContext& node);
ArgsManager& EnsureArgsman(const node::NodeContext& node);
ArgsManager& EnsureAnyArgsman(const std::any& context);
ChainstateManager& EnsureChainman(const NodeContext& node);
ChainstateManager& EnsureChainman(const node::NodeContext& node);
ChainstateManager& EnsureAnyChainman(const std::any& context);
CBlockPolicyEstimator& EnsureFeeEstimator(const NodeContext& node);
CBlockPolicyEstimator& EnsureFeeEstimator(const node::NodeContext& node);
CBlockPolicyEstimator& EnsureAnyFeeEstimator(const std::any& context);
CConnman& EnsureConnman(const NodeContext& node);
PeerManager& EnsurePeerman(const NodeContext& node);
CConnman& EnsureConnman(const node::NodeContext& node);
PeerManager& EnsurePeerman(const node::NodeContext& node);
#endif // BITCOIN_RPC_SERVER_UTIL_H

View file

@ -16,6 +16,10 @@
#include <boost/test/unit_test.hpp>
using node::BlockAssembler;
using node::CBlockTemplate;
using node::IncrementExtraNonce;
BOOST_AUTO_TEST_SUITE(blockfilter_index_tests)
struct BuildChainTestingSetup : public TestChain100Setup {

View file

@ -11,6 +11,8 @@
#include <chrono>
using node::CCoinsStats;
using node::CoinStatsHashType;
BOOST_AUTO_TEST_SUITE(coinstatsindex_tests)

View file

@ -26,6 +26,10 @@
#include <string>
#include <vector>
using node::CCoinsStats;
using node::CoinStatsHashType;
using node::GetUTXOStats;
namespace {
const TestingSetup* g_setup;
const Coin EMPTY_COIN{};

View file

@ -33,6 +33,8 @@
#include <test/fuzz/fuzz.h>
using node::SnapshotMetadata;
void initialize_deserialize()
{
// Fuzzers using pubkey must hold an ECCVerifyHandle.

View file

@ -12,6 +12,8 @@
#include <map>
#include <numeric>
using node::MakeMinisketch32;
FUZZ_TARGET(minisketch)
{
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};

View file

@ -18,6 +18,10 @@
#include <string>
#include <vector>
using node::AnalyzePSBT;
using node::PSBTAnalysis;
using node::PSBTInputAnalysis;
void initialize_psbt()
{
static const ECCVerifyHandle verify_handle;

View file

@ -14,6 +14,8 @@
#include <validation.h>
#include <validationinterface.h>
using node::BlockAssembler;
namespace {
const TestingSetup* g_setup;

View file

@ -13,6 +13,8 @@
#include <validation.h>
#include <validationinterface.h>
using node::SnapshotMetadata;
namespace {
const std::vector<std::shared_ptr<CBlock>>* g_chain;

View file

@ -24,6 +24,9 @@
#include <boost/test/unit_test.hpp>
using node::BlockAssembler;
using node::CBlockTemplate;
namespace miner_tests {
struct MinerTestingSetup : public TestingSetup {
void TestPackageSelection(const CChainParams& chainparams, const CScript& scriptPubKey, const std::vector<CTransactionRef>& txFirst) EXCLUSIVE_LOCKS_REQUIRED(::cs_main, m_node.mempool->cs);

View file

@ -11,6 +11,8 @@
#include <utility>
using node::MakeMinisketch32;
BOOST_AUTO_TEST_SUITE(minisketch_tests)
BOOST_AUTO_TEST_CASE(minisketch_test)

View file

@ -8,6 +8,8 @@
#include <node/blockstorage.h>
#include <validation.h>
using node::ReadBlockFromDisk;
using node::UndoReadFromDisk;
bool ComputeFilter(BlockFilterType filter_type, const CBlockIndex* block_index, BlockFilter& filter)
{

View file

@ -16,7 +16,7 @@
#include <boost/test/unit_test.hpp>
const auto NoMalleation = [](CAutoFile& file, SnapshotMetadata& meta){};
const auto NoMalleation = [](CAutoFile& file, node::SnapshotMetadata& meta){};
/**
* Create and activate a UTXO snapshot, optionally providing a function to
@ -24,7 +24,7 @@ const auto NoMalleation = [](CAutoFile& file, SnapshotMetadata& meta){};
*/
template<typename F = decltype(NoMalleation)>
static bool
CreateAndActivateUTXOSnapshot(NodeContext& node, const fs::path root, F malleation = NoMalleation)
CreateAndActivateUTXOSnapshot(node::NodeContext& node, const fs::path root, F malleation = NoMalleation)
{
// Write out a snapshot to the test's tempdir.
//
@ -43,7 +43,7 @@ CreateAndActivateUTXOSnapshot(NodeContext& node, const fs::path root, F malleati
//
FILE* infile{fsbridge::fopen(snapshot_path, "rb")};
CAutoFile auto_infile{infile, SER_DISK, CLIENT_VERSION};
SnapshotMetadata metadata;
node::SnapshotMetadata metadata;
auto_infile >> metadata;
malleation(auto_infile, metadata);

View file

@ -16,6 +16,9 @@
#include <validation.h>
#include <versionbits.h>
using node::BlockAssembler;
using node::NodeContext;
CTxIn generatetoaddress(const NodeContext& node, const std::string& address)
{
const auto dest = DecodeDestination(address);

View file

@ -13,18 +13,20 @@ class CBlock;
class CChainParams;
class CScript;
class CTxIn;
namespace node {
struct NodeContext;
} // namespace node
/** Create a blockchain, starting from genesis */
std::vector<std::shared_ptr<CBlock>> CreateBlockChain(size_t total_height, const CChainParams& params);
/** Returns the generated coin */
CTxIn MineBlock(const NodeContext&, const CScript& coinbase_scriptPubKey);
CTxIn MineBlock(const node::NodeContext&, const CScript& coinbase_scriptPubKey);
/** Prepare a block to be mined */
std::shared_ptr<CBlock> PrepareBlock(const NodeContext&, const CScript& coinbase_scriptPubKey);
std::shared_ptr<CBlock> PrepareBlock(const node::NodeContext&, const CScript& coinbase_scriptPubKey);
/** RPC-like helper function, returns the generated coin */
CTxIn generatetoaddress(const NodeContext&, const std::string& address);
CTxIn generatetoaddress(const node::NodeContext&, const std::string& address);
#endif // BITCOIN_TEST_UTIL_MINING_H

View file

@ -43,6 +43,14 @@
#include <functional>
using node::BlockAssembler;
using node::CalculateCacheSizes;
using node::LoadChainstate;
using node::RegenerateCommitments;
using node::VerifyLoadedChainstate;
using node::fPruneMode;
using node::fReindex;
const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr;
UrlDecodeFn* const URL_DECODE = nullptr;

View file

@ -76,7 +76,7 @@ static constexpr CAmount CENT{1000000};
*/
struct BasicTestingSetup {
ECCVerifyHandle globalVerifyHandle;
NodeContext m_node;
node::NodeContext m_node;
explicit BasicTestingSetup(const std::string& chainName = CBaseChainParams::MAIN, const std::vector<const char*>& extra_args = {});
~BasicTestingSetup();
@ -90,7 +90,7 @@ struct BasicTestingSetup {
* initialization behaviour.
*/
struct ChainTestingSetup : public BasicTestingSetup {
CacheSizes m_cache_sizes{};
node::CacheSizes m_cache_sizes{};
explicit ChainTestingSetup(const std::string& chainName = CBaseChainParams::MAIN, const std::vector<const char*>& extra_args = {});
~ChainTestingSetup();

View file

@ -19,6 +19,8 @@
#include <thread>
using node::BlockAssembler;
namespace validation_block_tests {
struct MinerTestingSetup : public RegTestingSetup {
std::shared_ptr<CBlock> Block(const uint256& prev_hash);

View file

@ -20,6 +20,8 @@
#include <boost/test/unit_test.hpp>
using node::SnapshotMetadata;
BOOST_FIXTURE_TEST_SUITE(validation_chainstatemanager_tests, ChainTestingSetup)
//! Basic tests for ChainstateManager.

View file

@ -9,6 +9,8 @@
#include <boost/test/unit_test.hpp>
using node::BlockManager;
BOOST_FIXTURE_TEST_SUITE(validation_flush_tests, ChainTestingSetup)
//! Test utilities for detecting when we need to flush the coins cache based

View file

@ -62,6 +62,25 @@
#include <boost/algorithm/string/replace.hpp>
using node::BLOCKFILE_CHUNK_SIZE;
using node::BlockManager;
using node::BlockMap;
using node::CBlockIndexWorkComparator;
using node::CCoinsStats;
using node::CoinStatsHashType;
using node::GetUTXOStats;
using node::OpenBlockFile;
using node::ReadBlockFromDisk;
using node::SnapshotMetadata;
using node::UNDOFILE_CHUNK_SIZE;
using node::UndoReadFromDisk;
using node::UnlinkPrunedFiles;
using node::fHavePruned;
using node::fImporting;
using node::fPruneMode;
using node::fReindex;
using node::nPruneTarget;
#define MICRO 0.000001
#define MILLI 0.001

View file

@ -43,12 +43,14 @@ class CBlockTreeDB;
class CChainParams;
class CTxMemPool;
class ChainstateManager;
class SnapshotMetadata;
struct ChainTxData;
struct DisconnectedBlockTransactions;
struct PrecomputedTransactionData;
struct LockPoints;
struct AssumeutxoData;
namespace node {
class SnapshotMetadata;
} // namespace node
/** Default for -minrelaytxfee, minimum relay fee for transactions */
static const unsigned int DEFAULT_MIN_RELAY_TX_FEE = 1000;
@ -476,7 +478,7 @@ protected:
public:
//! Reference to a BlockManager instance which itself is shared across all
//! CChainState instances.
BlockManager& m_blockman;
node::BlockManager& m_blockman;
/** Chain parameters for this chainstate */
const CChainParams& m_params;
@ -488,7 +490,7 @@ public:
explicit CChainState(
CTxMemPool* mempool,
BlockManager& blockman,
node::BlockManager& blockman,
ChainstateManager& chainman,
std::optional<uint256> from_snapshot_blockhash = std::nullopt);
@ -535,7 +537,7 @@ public:
* chainstates) and as good as our current tip or better. Entries may be failed,
* though, and pruning nodes may be missing the data for the block.
*/
std::set<CBlockIndex*, CBlockIndexWorkComparator> setBlockIndexCandidates;
std::set<CBlockIndex*, node::CBlockIndexWorkComparator> setBlockIndexCandidates;
//! @returns A reference to the in-memory cache of the UTXO set.
CCoinsViewCache& CoinsTip() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
@ -803,13 +805,13 @@ private:
bool m_snapshot_validated{false};
CBlockIndex* m_best_invalid;
friend bool BlockManager::LoadBlockIndex(const Consensus::Params&, ChainstateManager&);
friend bool node::BlockManager::LoadBlockIndex(const Consensus::Params&, ChainstateManager&);
//! Internal helper for ActivateSnapshot().
[[nodiscard]] bool PopulateAndValidateSnapshot(
CChainState& snapshot_chainstate,
CAutoFile& coins_file,
const SnapshotMetadata& metadata);
const node::SnapshotMetadata& metadata);
/**
* If a block header hasn't already been seen, call CheckBlockHeader on it, ensure
@ -826,7 +828,7 @@ public:
std::thread m_load_block;
//! A single BlockManager instance is shared across each constructed
//! chainstate to avoid duplicating block metadata.
BlockManager m_blockman GUARDED_BY(::cs_main);
node::BlockManager m_blockman GUARDED_BY(::cs_main);
/**
* In order to efficiently track invalidity of headers, we keep the set of
@ -886,7 +888,7 @@ public:
//! - Move the new chainstate to `m_snapshot_chainstate` and make it our
//! ChainstateActive().
[[nodiscard]] bool ActivateSnapshot(
CAutoFile& coins_file, const SnapshotMetadata& metadata, bool in_memory);
CAutoFile& coins_file, const node::SnapshotMetadata& metadata, bool in_memory);
//! The most-work chain.
CChainState& ActiveChainstate() const;
@ -894,7 +896,7 @@ public:
int ActiveHeight() const { return ActiveChain().Height(); }
CBlockIndex* ActiveTip() const { return ActiveChain().Tip(); }
BlockMap& BlockIndex() EXCLUSIVE_LOCKS_REQUIRED(::cs_main)
node::BlockMap& BlockIndex() EXCLUSIVE_LOCKS_REQUIRED(::cs_main)
{
return m_blockman.m_block_index;
}

View file

@ -23,6 +23,8 @@
#include <wallet/wallet.h>
#include <walletinitinterface.h>
using node::NodeContext;
class WalletInit : public WalletInitInterface
{
public:

View file

@ -30,6 +30,9 @@
#include <boost/test/unit_test.hpp>
#include <univalue.h>
using node::MAX_BLOCKFILE_SIZE;
using node::UnlinkPrunedFiles;
RPCHelpMan importmulti();
RPCHelpMan dumpwallet();
RPCHelpMan importwallet();

View file

@ -7,7 +7,9 @@
class ArgsManager;
namespace node {
struct NodeContext;
} // namespace node
class WalletInitInterface {
public:
@ -18,7 +20,7 @@ public:
/** Check wallet parameter interaction */
virtual bool ParameterInteraction() const = 0;
/** Add wallets that should be opened to list of chain clients. */
virtual void Construct(NodeContext& node) const = 0;
virtual void Construct(node::NodeContext& node) const = 0;
virtual ~WalletInitInterface() {}
};

View file

@ -23,6 +23,8 @@
#include <string>
#include <utility>
using node::ReadBlockFromDisk;
static std::multimap<std::string, CZMQAbstractPublishNotifier*> mapPublishNotifiers;
static const char *MSG_HASHBLOCK = "hashblock";