aboutsummaryrefslogtreecommitdiff
path: root/src/node
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2022-01-11 11:10:49 +0100
committerMarcoFalke <falke.marco@gmail.com>2022-01-11 11:11:00 +0100
commitc561f2f06ed25f08f7776ac41aeb2999ebe79550 (patch)
treeebd933b661b7cd1ca84e0ecaaac9020c72f952dd /src/node
parentfa74718414d7adb36095d277967d70c538a6ffdb (diff)
parente5b6aef61221b621ad77b5f075a16897e08835bf (diff)
downloadbitcoin-c561f2f06ed25f08f7776ac41aeb2999ebe79550.tar.xz
Merge bitcoin/bitcoin#23497: Add `src/node/` and `src/wallet/` code to `node::` and `wallet::` namespaces
e5b6aef61221b621ad77b5f075a16897e08835bf Move CBlockFileInfo::ToString method where class is declared (Russell Yanofsky) f7086fd8ff084ab0dd656d75b7485e59263bdfd8 Add src/wallet/* code to wallet:: namespace (Russell Yanofsky) 90fc8b089d591cabff60ee829a33f96c37fd27ba Add src/node/* code to node:: namespace (Russell Yanofsky) Pull request description: There are no code changes, this is just adding `namespace` and `using` declarations and `node::` or `wallet::` qualifiers in some places. Motivations for this change are: - To make it easier to see when node and wallet code is being accessed places where it shouldn't be. For example if GUI code is accessing node and wallet internals or if wallet and node code are referencing each other. - To make source code organization clearer ([#15732](https://github.com/bitcoin/bitcoin/issues/15732)), being able to know that `wallet::` code is in `src/wallet/`, `node::` code is in `src/node/`, `init::` code is in `src/init/`, `util::` code is in `src/util/`, etc. Reviewing with `git log -p -n1 -U0 --word-diff-regex=.` can be helpful to verify this is only updating declarations, not changing code. ACKs for top commit: achow101: ACK e5b6aef61221b621ad77b5f075a16897e08835bf MarcoFalke: Concept ACK e5b6aef61221b621ad77b5f075a16897e08835bf 🍨 Tree-SHA512: 3797745c90246794e2d55a2ee6e8b0ad5c811e4e03a242d3fdfeb68032f8787f0d48ed4097f6b7730f540220c0af99ef423cd9dbe7f76b2ec12e769a757a2c8d
Diffstat (limited to 'src/node')
-rw-r--r--src/node/blockstorage.cpp7
-rw-r--r--src/node/blockstorage.h2
-rw-r--r--src/node/caches.cpp2
-rw-r--r--src/node/caches.h2
-rw-r--r--src/node/chainstate.cpp2
-rw-r--r--src/node/chainstate.h8
-rw-r--r--src/node/coin.cpp2
-rw-r--r--src/node/coin.h5
-rw-r--r--src/node/coinstats.cpp2
-rw-r--r--src/node/coinstats.h8
-rw-r--r--src/node/context.cpp2
-rw-r--r--src/node/context.h2
-rw-r--r--src/node/interfaces.cpp12
-rw-r--r--src/node/miner.cpp2
-rw-r--r--src/node/miner.h2
-rw-r--r--src/node/minisketchwrapper.cpp2
-rw-r--r--src/node/minisketchwrapper.h2
-rw-r--r--src/node/psbt.cpp2
-rw-r--r--src/node/psbt.h2
-rw-r--r--src/node/transaction.cpp2
-rw-r--r--src/node/transaction.h5
-rw-r--r--src/node/utxo_snapshot.h2
22 files changed, 59 insertions, 18 deletions
diff --git a/src/node/blockstorage.cpp b/src/node/blockstorage.cpp
index 50c3059567..cbfdcb6f11 100644
--- a/src/node/blockstorage.cpp
+++ b/src/node/blockstorage.cpp
@@ -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;
@@ -474,11 +475,6 @@ void CleanupBlockRevFiles()
}
}
-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));
-}
-
CBlockFileInfo* BlockManager::GetBlockFileInfo(size_t n)
{
LOCK(cs_LastBlockFile);
@@ -940,3 +936,4 @@ void ThreadImport(ChainstateManager& chainman, std::vector<fs::path> vImportFile
} // End scope of CImportingNow
chainman.ActiveChainstate().LoadMempool(args);
}
+} // namespace node
diff --git a/src/node/blockstorage.h b/src/node/blockstorage.h
index b0485e5a00..78c9210892 100644
--- a/src/node/blockstorage.h
+++ b/src/node/blockstorage.h
@@ -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
diff --git a/src/node/caches.cpp b/src/node/caches.cpp
index 36254dc714..f168332ee6 100644
--- a/src/node/caches.cpp
+++ b/src/node/caches.cpp
@@ -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
diff --git a/src/node/caches.h b/src/node/caches.h
index 200f0b85b8..67388b91fd 100644
--- a/src/node/caches.h
+++ b/src/node/caches.h
@@ -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
diff --git a/src/node/chainstate.cpp b/src/node/chainstate.cpp
index 0274587e17..e21116dd7e 100644
--- a/src/node/chainstate.cpp
+++ b/src/node/chainstate.cpp
@@ -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
diff --git a/src/node/chainstate.h b/src/node/chainstate.h
index 4df917a281..279f187642 100644
--- a/src/node/chainstate.h
+++ b/src/node/chainstate.h
@@ -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
diff --git a/src/node/coin.cpp b/src/node/coin.cpp
index 78ab46f2e8..221854c5f6 100644
--- a/src/node/coin.cpp
+++ b/src/node/coin.cpp
@@ -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
diff --git a/src/node/coin.h b/src/node/coin.h
index 908850e2a5..3d534463e8 100644
--- a/src/node/coin.h
+++ b/src/node/coin.h
@@ -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
diff --git a/src/node/coinstats.cpp b/src/node/coinstats.cpp
index 68cc65d3ed..eed43a1bc7 100644
--- a/src/node/coinstats.cpp
+++ b/src/node/coinstats.cpp
@@ -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
diff --git a/src/node/coinstats.h b/src/node/coinstats.h
index 3b641200ad..aa771b18b0 100644
--- a/src/node/coinstats.h
+++ b/src/node/coinstats.h
@@ -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
diff --git a/src/node/context.cpp b/src/node/context.cpp
index 9afadd09a9..893c32f1bc 100644
--- a/src/node/context.cpp
+++ b/src/node/context.cpp
@@ -14,5 +14,7 @@
#include <txmempool.h>
#include <validation.h>
+namespace node {
NodeContext::NodeContext() {}
NodeContext::~NodeContext() {}
+} // namespace node
diff --git a/src/node/context.h b/src/node/context.h
index 8f5c50377d..644c997531 100644
--- a/src/node/context.h
+++ b/src/node/context.h
@@ -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
diff --git a/src/node/interfaces.cpp b/src/node/interfaces.cpp
index a0ee52f8e6..1a48957f0f 100644
--- a/src/node/interfaces.cpp
+++ b/src/node/interfaces.cpp
@@ -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
diff --git a/src/node/miner.cpp b/src/node/miner.cpp
index 8c3e7b7b65..7fe10ecabc 100644
--- a/src/node/miner.cpp
+++ b/src/node/miner.cpp
@@ -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
diff --git a/src/node/miner.h b/src/node/miner.h
index 38b7b4546b..c96da874a7 100644
--- a/src/node/miner.h
+++ b/src/node/miner.h
@@ -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
diff --git a/src/node/minisketchwrapper.cpp b/src/node/minisketchwrapper.cpp
index 572df63463..67e823cb68 100644
--- a/src/node/minisketchwrapper.cpp
+++ b/src/node/minisketchwrapper.cpp
@@ -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
diff --git a/src/node/minisketchwrapper.h b/src/node/minisketchwrapper.h
index a8aef68d01..a92912d9ed 100644
--- a/src/node/minisketchwrapper.h
+++ b/src/node/minisketchwrapper.h
@@ -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
diff --git a/src/node/psbt.cpp b/src/node/psbt.cpp
index 26023d5a4c..5a932f435d 100644
--- a/src/node/psbt.cpp
+++ b/src/node/psbt.cpp
@@ -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
diff --git a/src/node/psbt.h b/src/node/psbt.h
index 43fe293ad0..cbb3bd8201 100644
--- a/src/node/psbt.h
+++ b/src/node/psbt.h
@@ -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
diff --git a/src/node/transaction.cpp b/src/node/transaction.cpp
index d5681a0663..c7c8493f0c 100644
--- a/src/node/transaction.cpp
+++ b/src/node/transaction.cpp
@@ -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
diff --git a/src/node/transaction.h b/src/node/transaction.h
index 79f02958da..b7cf225636 100644
--- a/src/node/transaction.h
+++ b/src/node/transaction.h
@@ -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
diff --git a/src/node/utxo_snapshot.h b/src/node/utxo_snapshot.h
index 9b0df96a75..401d4baaeb 100644
--- a/src/node/utxo_snapshot.h
+++ b/src/node/utxo_snapshot.h
@@ -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