Skip to content

Commit 1083228

Browse files
Merge #6732: backport: merge bitcoin#23497 (Add src/node/ and src/wallet/ code to node:: and wallet:: namespaces)
ab9ba84 refactor: complete migration of code to `wallet::` namespace (Kittywhiskers Van Gogh) 1c2d529 refactor: add `src/wallet/*` code to `wallet::` namespace (Kittywhiskers Van Gogh) 81c6880 refactor: complete migration of code to `node::` namespace (Kittywhiskers Van Gogh) ddbc294 refactor: add `src/node/*` to `node::` namespace (Kittywhiskers Van Gogh) 65cfaea refactor: add `src/node/context.*` to `node::` namespace (Kittywhiskers Van Gogh) e89e8a7 refactor: move `CBlockFileInfo::ToString` method where class is declared (Kittywhiskers Van Gogh) 7991bbb refactor: disambiguate presence of `cs_main` in global namespace (Kittywhiskers Van Gogh) Pull request description: ## Additional Information * [bitcoin#23497](bitcoin#23497) was merged upstream in v0.23. As of this writing, the backport backlog for v0.23 is at ~91% completion. This change, while conflict-prone, is long-overdue as we have been backporting pull requests from v0.24 onwards that assume these namespaces and so far we've simply "cut out" those portions to allow those backports to be completed. * This is not sustainable, especially with the work undertaken for `bitcoin-chainstate` (see [bitcoin#24304](bitcoin#24304) and onwards), that are invested in these separation of concerns. * Due to the increased usage of namespacing, to avoid potential `-Werror=thread-safety-analysis` issues (see below), the usage of `cs_main` needs to be disambiguated as being a part of the global namespace, to that effect, changes have been made to ensure that in Dash-specific code and anywhere else needed to quell compiler errors. <details> <summary>Build error:</summary> ``` wallet/test/wallet_tests.cpp:162:31: error: calling function 'GetBlockPos' requires holding mutex 'cs_main' exclusively [-Werror,-Wthread-safety-analysis] 162 | file_number = oldTip->GetBlockPos().nFile; | ^ wallet/test/wallet_tests.cpp:163:45: error: calling function 'PruneOneBlockFile' requires holding mutex 'cs_main' exclusively [-Werror,-Wthread-safety-analysis] 163 | Assert(m_node.chainman)->m_blockman.PruneOneBlockFile(file_number); | ^ wallet/test/wallet_tests.cpp:190:31: error: calling function 'GetBlockPos' requires holding mutex 'cs_main' exclusively [-Werror,-Wthread-safety-analysis] 190 | file_number = newTip->GetBlockPos().nFile; | ^ wallet/test/wallet_tests.cpp:191:45: error: calling function 'PruneOneBlockFile' requires holding mutex 'cs_main' exclusively [-Werror,-Wthread-safety-analysis] 191 | Assert(m_node.chainman)->m_blockman.PruneOneBlockFile(file_number); | ^ wallet/test/wallet_tests.cpp:227:31: error: calling function 'GetBlockPos' requires holding mutex 'cs_main' exclusively [-Werror,-Wthread-safety-analysis] 227 | file_number = oldTip->GetBlockPos().nFile; | ^ wallet/test/wallet_tests.cpp:228:45: error: calling function 'PruneOneBlockFile' requires holding mutex 'cs_main' exclusively [-Werror,-Wthread-safety-analysis] 228 | Assert(m_node.chainman)->m_blockman.PruneOneBlockFile(file_number); | ^ wallet/test/wallet_tests.cpp:386:34: error: calling function 'BlockIndex' requires holding mutex 'cs_main' exclusively [-Werror,-Wthread-safety-analysis] 386 | auto inserted = chainman.BlockIndex().emplace(std::piecewise_construct, std::make_tuple(GetRandHash()), std::make_tuple()); | ^` ``` </details> * Some commits have been split out to ease in the review process, due to the nature of changes, except for `NodeContext` (`node/context.{cpp,h}`), they could not be done on a file-to-file basis as it would create substantial diffs that would then be reverted in the next commit, which would make review _harder_. * Correctness of this pull request can be evaluated by comparing against [bitcoin#23497](bitcoin#23497), the `25.x` branch upstream for changes affecting upstream code not present during the backport ([source](https://github.com/bitcoin/bitcoin/tree/25.x)) and compiler output for Dash-specific code. ## Checklist - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas **(note: N/A)** - [x] I have added or updated relevant unit/integration/functional/e2e tests - [x] I have made corresponding changes to the documentation **(note: N/A)** - [x] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_ ACKs for top commit: PastaPastaPasta: utACK ab9ba84 UdjinM6: utACK ab9ba84 Tree-SHA512: 8ff2bcfd76d5170c3af38e2c7b60d5daf467793e84bfef8254f325d6919f637451045157fde73a1d35d5d378bfea47625f72ec250815fd2603bca1339d89f31e
2 parents a4fcaaa + ab9ba84 commit 1083228

File tree

220 files changed

+924
-344
lines changed

Some content is hidden

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

220 files changed

+924
-344
lines changed

src/bench/coin_selection.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@
1111

1212
#include <set>
1313

14+
using node::NodeContext;
15+
using wallet::CHANGE_LOWER;
16+
using wallet::CoinEligibilityFilter;
17+
using wallet::CoinSelectionParams;
18+
using wallet::COutput;
19+
using wallet::CreateDummyWalletDatabase;
20+
using wallet::CWallet;
21+
using wallet::CWalletTx;
22+
using wallet::OutputGroup;
23+
using wallet::TxStateInactive;
24+
1425
static void addCoin(const CAmount& nValue, const CWallet& wallet, std::vector<std::unique_ptr<CWalletTx>>& wtxs)
1526
{
1627
static int nextLockTime = 0;

src/bench/load_external.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static void LoadExternalBlockFile(benchmark::Bench& bench)
4040
// "wb+" is "binary, O_RDWR | O_CREAT | O_TRUNC".
4141
FILE* file{fsbridge::fopen(blkfile, "wb+")};
4242
// Make the test block file about 128 MB in length.
43-
for (size_t i = 0; i < MAX_BLOCKFILE_SIZE / ss.size(); ++i) {
43+
for (size_t i = 0; i < node::MAX_BLOCKFILE_SIZE / ss.size(); ++i) {
4444
if (fwrite(ss.data(), 1, ss.size(), file) != ss.size()) {
4545
throw std::runtime_error("write to test file failed\n");
4646
}

src/bench/wallet_balance.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414

1515
#include <optional>
1616

17+
using wallet::CreateMockWalletDatabase;
18+
using wallet::CWallet;
19+
using wallet::DBErrors;
20+
using wallet::WALLET_FLAG_DESCRIPTORS;
21+
1722
static void WalletBalance(benchmark::Bench& bench, const bool set_dirty, const bool add_mine, const uint32_t epoch_iters)
1823
{
1924
const auto test_setup = MakeNoLogFileContext<const TestingSetup>();

src/bitcoin-wallet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ MAIN_FUNCTION
112112
}
113113

114114
ECC_Start();
115-
if (!WalletTool::ExecuteWalletToolFunc(args, command->command)) {
115+
if (!wallet::WalletTool::ExecuteWalletToolFunc(args, command->command)) {
116116
return EXIT_FAILURE;
117117
}
118118
ECC_Stop();

src/bitcoind.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
#include <cstdio>
3232
#include <functional>
3333

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

src/chain.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,15 @@
44
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
55

66
#include <chain.h>
7+
#include <util/time.h>
78

89
#include <tinyformat.h>
910

11+
std::string CBlockFileInfo::ToString() const
12+
{
13+
return strprintf("CBlockFileInfo(blocks=%u, size=%u, heights=%u...%u, time=%s...%s)", nBlocks, nSize, nHeightFirst, nHeightLast, FormatISO8601Date(nTimeFirst), FormatISO8601Date(nTimeLast));
14+
}
15+
1016
std::string CBlockIndex::ToString() const
1117
{
1218
return strprintf("CBlockIndex(pprev=%p, nHeight=%d, merkle=%s, hashBlock=%s)",

src/coinjoin/client.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@
3333
#include <memory>
3434
#include <univalue.h>
3535

36+
using wallet::CCoinControl;
37+
using wallet::CompactTallyItem;
38+
using wallet::COutput;
39+
using wallet::CoinType;
40+
using wallet::CWallet;
41+
using wallet::ReserveDestination;
42+
3643
PeerMsgRet CCoinJoinClientQueueManager::ProcessMessage(const CNode& peer, CConnman& connman, PeerManager& peerman,
3744
std::string_view msg_type, CDataStream& vRecv)
3845
{
@@ -54,7 +61,7 @@ PeerMsgRet CCoinJoinClientQueueManager::ProcessDSQueue(const CNode& peer, CConnm
5461
vRecv >> dsq;
5562

5663
{
57-
LOCK(cs_main);
64+
LOCK(::cs_main);
5865
peerman.EraseObjectRequest(peer.GetId(), CInv(MSG_DSQ, dsq.GetHash()));
5966
}
6067

src/coinjoin/client.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class CoinJoinWalletManager {
9696
}
9797
}
9898

99-
void Add(const std::shared_ptr<CWallet>& wallet);
99+
void Add(const std::shared_ptr<wallet::CWallet>& wallet);
100100
void DoMaintenance(CConnman& connman);
101101

102102
void Remove(const std::string& name);
@@ -138,7 +138,7 @@ class CoinJoinWalletManager {
138138
class CCoinJoinClientSession : public CCoinJoinBaseSession
139139
{
140140
private:
141-
const std::shared_ptr<CWallet> m_wallet;
141+
const std::shared_ptr<wallet::CWallet> m_wallet;
142142
CCoinJoinClientManager& m_clientman;
143143
CDeterministicMNManager& m_dmnman;
144144
CMasternodeMetaMan& m_mn_metaman;
@@ -162,12 +162,12 @@ class CCoinJoinClientSession : public CCoinJoinBaseSession
162162

163163
/// Create denominations
164164
bool CreateDenominated(CAmount nBalanceToDenominate);
165-
bool CreateDenominated(CAmount nBalanceToDenominate, const CompactTallyItem& tallyItem, bool fCreateMixingCollaterals)
165+
bool CreateDenominated(CAmount nBalanceToDenominate, const wallet::CompactTallyItem& tallyItem, bool fCreateMixingCollaterals)
166166
EXCLUSIVE_LOCKS_REQUIRED(m_wallet->cs_wallet);
167167

168168
/// Split up large inputs or make fee sized inputs
169169
bool MakeCollateralAmounts();
170-
bool MakeCollateralAmounts(const CompactTallyItem& tallyItem, bool fTryDenominated)
170+
bool MakeCollateralAmounts(const wallet::CompactTallyItem& tallyItem, bool fTryDenominated)
171171
EXCLUSIVE_LOCKS_REQUIRED(m_wallet->cs_wallet);
172172

173173
bool CreateCollateralTransaction(CMutableTransaction& txCollateral, std::string& strReason)
@@ -200,7 +200,7 @@ class CCoinJoinClientSession : public CCoinJoinBaseSession
200200
void SetNull() override EXCLUSIVE_LOCKS_REQUIRED(cs_coinjoin);
201201

202202
public:
203-
explicit CCoinJoinClientSession(const std::shared_ptr<CWallet>& wallet, CCoinJoinClientManager& clientman,
203+
explicit CCoinJoinClientSession(const std::shared_ptr<wallet::CWallet>& wallet, CCoinJoinClientManager& clientman,
204204
CDeterministicMNManager& dmnman, CMasternodeMetaMan& mn_metaman,
205205
const CMasternodeSync& mn_sync, const llmq::CInstantSendManager& isman,
206206
const std::unique_ptr<CCoinJoinClientQueueManager>& queueman, bool is_masternode);
@@ -263,7 +263,7 @@ class CCoinJoinClientQueueManager : public CCoinJoinBaseManager
263263
class CCoinJoinClientManager
264264
{
265265
private:
266-
const std::shared_ptr<CWallet> m_wallet;
266+
const std::shared_ptr<wallet::CWallet> m_wallet;
267267
CDeterministicMNManager& m_dmnman;
268268
CMasternodeMetaMan& m_mn_metaman;
269269
const CMasternodeSync& m_mn_sync;
@@ -302,7 +302,7 @@ class CCoinJoinClientManager
302302
CCoinJoinClientManager(CCoinJoinClientManager const&) = delete;
303303
CCoinJoinClientManager& operator=(CCoinJoinClientManager const&) = delete;
304304

305-
explicit CCoinJoinClientManager(const std::shared_ptr<CWallet>& wallet, CDeterministicMNManager& dmnman,
305+
explicit CCoinJoinClientManager(const std::shared_ptr<wallet::CWallet>& wallet, CDeterministicMNManager& dmnman,
306306
CMasternodeMetaMan& mn_metaman, const CMasternodeSync& mn_sync,
307307
const llmq::CInstantSendManager& isman,
308308
const std::unique_ptr<CCoinJoinClientQueueManager>& queueman, bool is_masternode) :

src/coinjoin/coinjoin.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ bool CCoinJoinBaseSession::IsValidInOuts(CChainState& active_chainstate, const l
257257
nFees -= txout.nValue;
258258
}
259259

260-
CCoinsViewMemPool viewMemPool(WITH_LOCK(cs_main, return &active_chainstate.CoinsTip()), mempool);
260+
CCoinsViewMemPool viewMemPool(WITH_LOCK(::cs_main, return &active_chainstate.CoinsTip()), mempool);
261261

262262
for (const auto& txin : vin) {
263263
LogPrint(BCLog::COINJOIN, "CCoinJoinBaseSession::%s -- txin=%s\n", __func__, txin.ToString());
@@ -299,7 +299,7 @@ bool CCoinJoinBaseSession::IsValidInOuts(CChainState& active_chainstate, const l
299299
// but CoinJoin still requires ATMP with fee sanity checks so we need to implement them separately
300300
bool ATMPIfSaneFee(ChainstateManager& chainman, const CTransactionRef& tx, bool test_accept)
301301
{
302-
AssertLockHeld(cs_main);
302+
AssertLockHeld(::cs_main);
303303

304304
const MempoolAcceptResult result = chainman.ProcessTransaction(tx, /*test_accept=*/true);
305305
if (result.m_result_type != MempoolAcceptResult::ResultType::VALID) {
@@ -360,7 +360,7 @@ bool CoinJoin::IsCollateralValid(ChainstateManager& chainman, const llmq::CInsta
360360
LogPrint(BCLog::COINJOIN, "CoinJoin::IsCollateralValid -- %s", txCollateral.ToString()); /* Continued */
361361

362362
{
363-
LOCK(cs_main);
363+
LOCK(::cs_main);
364364
if (!ATMPIfSaneFee(chainman, MakeTransactionRef(txCollateral), /*test_accept=*/true)) {
365365
LogPrint(BCLog::COINJOIN, "CoinJoin::IsCollateralValid -- didn't pass ATMPIfSaneFee()\n");
366366
return false;

src/coinjoin/coinjoin.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,6 @@ class CDSTXManager
404404
};
405405

406406
bool ATMPIfSaneFee(ChainstateManager& chainman, const CTransactionRef& tx, bool test_accept = false)
407-
EXCLUSIVE_LOCKS_REQUIRED(cs_main);
407+
EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
408408

409409
#endif // BITCOIN_COINJOIN_COINJOIN_H

0 commit comments

Comments
 (0)