Skip to content

Commit c561f2f

Browse files
author
MarcoFalke
committed
Merge bitcoin#23497: Add src/node/ and src/wallet/ code to node:: and wallet:: namespaces
e5b6aef Move CBlockFileInfo::ToString method where class is declared (Russell Yanofsky) f7086fd Add src/wallet/* code to wallet:: namespace (Russell Yanofsky) 90fc8b0 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 ([bitcoin#15732](bitcoin#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 e5b6aef MarcoFalke: Concept ACK e5b6aef 🍨 Tree-SHA512: 3797745c90246794e2d55a2ee6e8b0ad5c811e4e03a242d3fdfeb68032f8787f0d48ed4097f6b7730f540220c0af99ef423cd9dbe7f76b2ec12e769a757a2c8d
2 parents fa74718 + e5b6aef commit c561f2f

File tree

166 files changed

+580
-140
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

166 files changed

+580
-140
lines changed

src/bench/coin_selection.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,19 @@
1111

1212
#include <set>
1313

14+
using node::NodeContext;
15+
using wallet::AttemptSelection;
16+
using wallet::CInputCoin;
17+
using wallet::COutput;
18+
using wallet::CWallet;
19+
using wallet::CWalletTx;
20+
using wallet::CoinEligibilityFilter;
21+
using wallet::CoinSelectionParams;
22+
using wallet::CreateDummyWalletDatabase;
23+
using wallet::OutputGroup;
24+
using wallet::SelectCoinsBnB;
25+
using wallet::TxStateInactive;
26+
1427
static void addCoin(const CAmount& nValue, const CWallet& wallet, std::vector<std::unique_ptr<CWalletTx>>& wtxs)
1528
{
1629
static int nextLockTime = 0;

src/bench/wallet_balance.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414

1515
#include <optional>
1616

17+
using wallet::CWallet;
18+
using wallet::CreateMockWalletDatabase;
19+
using wallet::DBErrors;
20+
using wallet::GetBalance;
21+
using wallet::WALLET_FLAG_DESCRIPTORS;
22+
1723
static void WalletBalance(benchmark::Bench& bench, const bool set_dirty, const bool add_mine)
1824
{
1925
const auto test_setup = MakeNoLogFileContext<const TestingSetup>();

src/bitcoin-wallet.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ int main(int argc, char* argv[])
123123

124124
ECCVerifyHandle globalVerifyHandle;
125125
ECC_Start();
126-
if (!WalletTool::ExecuteWalletToolFunc(args, command->command)) {
126+
if (!wallet::WalletTool::ExecuteWalletToolFunc(args, command->command)) {
127127
return EXIT_FAILURE;
128128
}
129129
ECC_Stop();

src/bitcoind.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#include <functional>
3131
#include <optional>
3232

33+
using node::NodeContext;
34+
3335
const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr;
3436
UrlDecodeFn* const URL_DECODE = urlDecode;
3537

src/chain.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
55

66
#include <chain.h>
7+
#include <util/time.h>
8+
9+
std::string CBlockFileInfo::ToString() const
10+
{
11+
return strprintf("CBlockFileInfo(blocks=%u, size=%u, heights=%u...%u, time=%s...%s)", nBlocks, nSize, nHeightFirst, nHeightLast, FormatISO8601Date(nTimeFirst), FormatISO8601Date(nTimeLast));
12+
}
713

814
void CChain::SetTip(CBlockIndex *pindex) {
915
if (pindex == nullptr) {

src/dummywallet.cpp

+1-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include <walletinitinterface.h>
77

88
class ArgsManager;
9-
class CWallet;
109

1110
namespace interfaces {
1211
class Chain;
@@ -21,7 +20,7 @@ class DummyWalletInit : public WalletInitInterface {
2120
bool HasWalletSupport() const override {return false;}
2221
void AddWalletOptions(ArgsManager& argsman) const override;
2322
bool ParameterInteraction() const override {return true;}
24-
void Construct(NodeContext& node) const override {LogPrintf("No wallet support compiled in!\n");}
23+
void Construct(node::NodeContext& node) const override {LogPrintf("No wallet support compiled in!\n");}
2524
};
2625

2726
void DummyWalletInit::AddWalletOptions(ArgsManager& argsman) const
@@ -59,11 +58,6 @@ const WalletInitInterface& g_wallet_init_interface = DummyWalletInit();
5958

6059
namespace interfaces {
6160

62-
std::unique_ptr<Wallet> MakeWallet(const std::shared_ptr<CWallet>& wallet)
63-
{
64-
throw std::logic_error("Wallet function called in non-wallet build.");
65-
}
66-
6761
std::unique_ptr<WalletLoader> MakeWalletLoader(Chain& chain, ArgsManager& args)
6862
{
6963
throw std::logic_error("Wallet function called in non-wallet build.");

src/index/base.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include <validation.h> // For g_chainman
1515
#include <warnings.h>
1616

17+
using node::ReadBlockFromDisk;
18+
1719
constexpr uint8_t DB_BEST_BLOCK{'B'};
1820

1921
constexpr int64_t SYNC_LOG_INTERVAL = 30; // seconds

src/index/blockfilterindex.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include <node/blockstorage.h>
1010
#include <util/system.h>
1111

12+
using node::UndoReadFromDisk;
13+
1214
/* The index database stores three items for each block: the disk location of the encoded filter,
1315
* its dSHA256 hash, and the header. Those belonging to blocks on the active chain are indexed by
1416
* height, and those belonging to blocks that have been reorganized out of the active chain are

src/index/coinstatsindex.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
#include <undo.h>
1313
#include <validation.h>
1414

15+
using node::CCoinsStats;
16+
using node::GetBogoSize;
17+
using node::ReadBlockFromDisk;
18+
using node::TxOutSer;
19+
using node::UndoReadFromDisk;
20+
1521
static constexpr uint8_t DB_BLOCK_HASH{'s'};
1622
static constexpr uint8_t DB_BLOCK_HEIGHT{'t'};
1723
static constexpr uint8_t DB_MUHASH{'M'};

src/index/coinstatsindex.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class CoinStatsIndex final : public BaseIndex
5252
explicit CoinStatsIndex(size_t n_cache_size, bool f_memory = false, bool f_wipe = false);
5353

5454
// Look up stats for a specific block using CBlockIndex
55-
bool LookUpStats(const CBlockIndex* block_index, CCoinsStats& coins_stats) const;
55+
bool LookUpStats(const CBlockIndex* block_index, node::CCoinsStats& coins_stats) const;
5656
};
5757

5858
/// The global UTXO set hash object.

src/index/txindex.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include <util/system.h>
1010
#include <validation.h>
1111

12+
using node::OpenBlockFile;
13+
1214
constexpr uint8_t DB_TXINDEX{'t'};
1315

1416
std::unique_ptr<TxIndex> g_txindex;

src/init.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,22 @@
9595
#include <zmq/zmqrpc.h>
9696
#endif
9797

98+
using node::CacheSizes;
99+
using node::CalculateCacheSizes;
100+
using node::ChainstateLoadVerifyError;
101+
using node::ChainstateLoadingError;
102+
using node::CleanupBlockRevFiles;
103+
using node::DEFAULT_PRINTPRIORITY;
104+
using node::DEFAULT_STOPAFTERBLOCKIMPORT;
105+
using node::LoadChainstate;
106+
using node::NodeContext;
107+
using node::ThreadImport;
108+
using node::VerifyLoadedChainstate;
109+
using node::fHavePruned;
110+
using node::fPruneMode;
111+
using node::fReindex;
112+
using node::nPruneTarget;
113+
98114
static const bool DEFAULT_PROXYRANDOMIZE = true;
99115
static const bool DEFAULT_REST_ENABLE = false;
100116

src/init.h

+7-5
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@ static constexpr bool DEFAULT_DAEMON = false;
1616
static constexpr bool DEFAULT_DAEMONWAIT = false;
1717

1818
class ArgsManager;
19-
struct NodeContext;
2019
namespace interfaces {
2120
struct BlockAndHeaderTipInfo;
2221
}
22+
namespace node {
23+
struct NodeContext;
24+
} // namespace node
2325

2426
/** Interrupt threads */
25-
void Interrupt(NodeContext& node);
26-
void Shutdown(NodeContext& node);
27+
void Interrupt(node::NodeContext& node);
28+
void Shutdown(node::NodeContext& node);
2729
//!Initialize the logging infrastructure
2830
void InitLogging(const ArgsManager& args);
2931
//!Parameter interaction: change current parameters depending on various rules
@@ -55,13 +57,13 @@ bool AppInitLockDataDirectory();
5557
/**
5658
* Initialize node and wallet interface pointers. Has no prerequisites or side effects besides allocating memory.
5759
*/
58-
bool AppInitInterfaces(NodeContext& node);
60+
bool AppInitInterfaces(node::NodeContext& node);
5961
/**
6062
* Bitcoin core main initialization.
6163
* @note This should only be done after daemonization. Call Shutdown() if this function fails.
6264
* @pre Parameters should be parsed and config file should be read, AppInitLockDataDirectory should have been called.
6365
*/
64-
bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info = nullptr);
66+
bool AppInitMain(node::NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info = nullptr);
6567

6668
/**
6769
* Register all arguments with the ArgsManager

src/init/bitcoin-gui.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class BitcoinGuiInit : public interfaces::Init
3333
}
3434
std::unique_ptr<interfaces::Echo> makeEcho() override { return interfaces::MakeEcho(); }
3535
interfaces::Ipc* ipc() override { return m_ipc.get(); }
36-
NodeContext m_node;
36+
node::NodeContext m_node;
3737
std::unique_ptr<interfaces::Ipc> m_ipc;
3838
};
3939
} // namespace

src/init/bitcoin-node.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const char* EXE_NAME = "bitcoin-node";
2020
class BitcoinNodeInit : public interfaces::Init
2121
{
2222
public:
23-
BitcoinNodeInit(NodeContext& node, const char* arg0)
23+
BitcoinNodeInit(node::NodeContext& node, const char* arg0)
2424
: m_node(node),
2525
m_ipc(interfaces::MakeIpc(EXE_NAME, arg0, *this))
2626
{
@@ -35,14 +35,14 @@ class BitcoinNodeInit : public interfaces::Init
3535
}
3636
std::unique_ptr<interfaces::Echo> makeEcho() override { return interfaces::MakeEcho(); }
3737
interfaces::Ipc* ipc() override { return m_ipc.get(); }
38-
NodeContext& m_node;
38+
node::NodeContext& m_node;
3939
std::unique_ptr<interfaces::Ipc> m_ipc;
4040
};
4141
} // namespace
4242
} // namespace init
4343

4444
namespace interfaces {
45-
std::unique_ptr<Init> MakeNodeInit(NodeContext& node, int argc, char* argv[], int& exit_status)
45+
std::unique_ptr<Init> MakeNodeInit(node::NodeContext& node, int argc, char* argv[], int& exit_status)
4646
{
4747
auto init = std::make_unique<init::BitcoinNodeInit>(node, argc > 0 ? argv[0] : "");
4848
// Check if bitcoin-node is being invoked as an IPC server. If so, then

src/init/bitcoin-qt.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class BitcoinQtInit : public interfaces::Init
2929
return MakeWalletLoader(chain, *Assert(m_node.args));
3030
}
3131
std::unique_ptr<interfaces::Echo> makeEcho() override { return interfaces::MakeEcho(); }
32-
NodeContext m_node;
32+
node::NodeContext m_node;
3333
};
3434
} // namespace
3535
} // namespace init

src/init/bitcoind.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
#include <memory>
1414

15+
using node::NodeContext;
16+
1517
namespace init {
1618
namespace {
1719
class BitcoindInit : public interfaces::Init

src/interfaces/chain.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ enum class RBFTransactionState;
2828
struct bilingual_str;
2929
struct CBlockLocator;
3030
struct FeeCalculation;
31+
namespace node {
3132
struct NodeContext;
33+
} // namespace node
3234

3335
namespace interfaces {
3436

@@ -316,7 +318,7 @@ class ChainClient
316318
};
317319

318320
//! Return implementation of Chain interface.
319-
std::unique_ptr<Chain> MakeChain(NodeContext& node);
321+
std::unique_ptr<Chain> MakeChain(node::NodeContext& node);
320322

321323
} // namespace interfaces
322324

src/interfaces/init.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77

88
#include <memory>
99

10+
namespace node {
1011
struct NodeContext;
12+
} // namespace node
1113

1214
namespace interfaces {
1315
class Chain;
@@ -40,7 +42,7 @@ class Init
4042
//! status code to exit with. If this returns non-null, the caller can start up
4143
//! normally and use the Init object to spawn and connect to other processes
4244
//! while it is running.
43-
std::unique_ptr<Init> MakeNodeInit(NodeContext& node, int argc, char* argv[], int& exit_status);
45+
std::unique_ptr<Init> MakeNodeInit(node::NodeContext& node, int argc, char* argv[], int& exit_status);
4446

4547
//! Return implementation of Init interface for the wallet process.
4648
std::unique_ptr<Init> MakeWalletInit(int argc, char* argv[], int& exit_status);

src/interfaces/node.h

+9-5
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include <vector>
2323

2424
class BanMan;
25-
class CCoinControl;
2625
class CFeeRate;
2726
class CNodeStats;
2827
class Coin;
@@ -32,8 +31,13 @@ class proxyType;
3231
enum class SynchronizationState;
3332
enum class TransactionError;
3433
struct CNodeStateStats;
35-
struct NodeContext;
3634
struct bilingual_str;
35+
namespace node {
36+
struct NodeContext;
37+
} // namespace node
38+
namespace wallet {
39+
class CCoinControl;
40+
} // namespace wallet
3741

3842
namespace interfaces {
3943
class Handler;
@@ -242,12 +246,12 @@ class Node
242246

243247
//! Get and set internal node context. Useful for testing, but not
244248
//! accessible across processes.
245-
virtual NodeContext* context() { return nullptr; }
246-
virtual void setContext(NodeContext* context) { }
249+
virtual node::NodeContext* context() { return nullptr; }
250+
virtual void setContext(node::NodeContext* context) { }
247251
};
248252

249253
//! Return implementation of Node interface.
250-
std::unique_ptr<Node> MakeNode(NodeContext& context);
254+
std::unique_ptr<Node> MakeNode(node::NodeContext& context);
251255

252256
//! Block tip (could be a header or not, depends on the subscribed signal).
253257
struct BlockTip {

0 commit comments

Comments
 (0)