Skip to content

Commit

Permalink
Add src/node/* code to node:: namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanofsky committed Jan 7, 2022
1 parent 4ada742 commit 90fc8b0
Show file tree
Hide file tree
Showing 77 changed files with 283 additions and 61 deletions.
2 changes: 2 additions & 0 deletions src/bench/coin_selection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/bitcoind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/dummywallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class DummyWalletInit : public WalletInitInterface {
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
Expand Down
2 changes: 2 additions & 0 deletions src/index/base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/index/blockfilterindex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/index/coinstatsindex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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'};
Expand Down
2 changes: 1 addition & 1 deletion src/index/coinstatsindex.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class CoinStatsIndex final : public BaseIndex
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.
Expand Down
2 changes: 2 additions & 0 deletions src/index/txindex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 16 additions & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
12 changes: 7 additions & 5 deletions src/init.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/init/bitcoin-gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class BitcoinGuiInit : public interfaces::Init
}
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
Expand Down
6 changes: 3 additions & 3 deletions src/init/bitcoin-node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand All @@ -35,14 +35,14 @@ class BitcoinNodeInit : public interfaces::Init
}
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
Expand Down
2 changes: 1 addition & 1 deletion src/init/bitcoin-qt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class BitcoinQtInit : public interfaces::Init
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
Expand Down
2 changes: 2 additions & 0 deletions src/init/bitcoind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

#include <memory>

using node::NodeContext;

namespace init {
namespace {
class BitcoindInit : public interfaces::Init
Expand Down
4 changes: 3 additions & 1 deletion src/interfaces/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ enum class RBFTransactionState;
struct bilingual_str;
struct CBlockLocator;
struct FeeCalculation;
namespace node {
struct NodeContext;
} // namespace node

namespace interfaces {

Expand Down Expand Up @@ -316,7 +318,7 @@ class ChainClient
};

//! Return implementation of Chain interface.
std::unique_ptr<Chain> MakeChain(NodeContext& node);
std::unique_ptr<Chain> MakeChain(node::NodeContext& node);

} // namespace interfaces

Expand Down
4 changes: 3 additions & 1 deletion src/interfaces/init.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

#include <memory>

namespace node {
struct NodeContext;
} // namespace node

namespace interfaces {
class Chain;
Expand Down Expand Up @@ -40,7 +42,7 @@ class Init
//! 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);
Expand Down
10 changes: 6 additions & 4 deletions src/interfaces/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -242,12 +244,12 @@ class Node

//! 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 {
Expand Down
6 changes: 6 additions & 0 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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). */
Expand Down
4 changes: 4 additions & 0 deletions src/node/blockstorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -939,3 +942,4 @@ void ThreadImport(ChainstateManager& chainman, std::vector<fs::path> vImportFile
} // End scope of CImportingNow
chainman.ActiveChainstate().LoadMempool(args);
}
} // namespace node
2 changes: 2 additions & 0 deletions src/node/blockstorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) */
Expand Down Expand Up @@ -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
2 changes: 2 additions & 0 deletions src/node/caches.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
2 changes: 2 additions & 0 deletions src/node/caches.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

class ArgsManager;

namespace node {
struct CacheSizes {
int64_t block_tree_db;
int64_t coins_db;
Expand All @@ -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
2 changes: 2 additions & 0 deletions src/node/chainstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <node/blockstorage.h>
#include <validation.h>

namespace node {
std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
ChainstateManager& chainman,
CTxMemPool* mempool,
Expand Down Expand Up @@ -156,3 +157,4 @@ std::optional<ChainstateLoadVerifyError> VerifyLoadedChainstate(ChainstateManage

return std::nullopt;
}
} // namespace node
8 changes: 5 additions & 3 deletions src/node/chainstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
2 changes: 2 additions & 0 deletions src/node/coin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -22,3 +23,4 @@ void FindCoins(const NodeContext& node, std::map<COutPoint, Coin>& coins)
}
}
}
} // namespace node
Loading

0 comments on commit 90fc8b0

Please sign in to comment.