Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/bench/coin_selection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@

#include <set>

using node::NodeContext;
using wallet::CHANGE_LOWER;
using wallet::CoinEligibilityFilter;
using wallet::CoinSelectionParams;
using wallet::COutput;
using wallet::CreateDummyWalletDatabase;
using wallet::CWallet;
using wallet::CWalletTx;
using wallet::OutputGroup;
using wallet::TxStateInactive;

static void addCoin(const CAmount& nValue, const CWallet& wallet, std::vector<std::unique_ptr<CWalletTx>>& wtxs)
{
static int nextLockTime = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/bench/load_external.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static void LoadExternalBlockFile(benchmark::Bench& bench)
// "wb+" is "binary, O_RDWR | O_CREAT | O_TRUNC".
FILE* file{fsbridge::fopen(blkfile, "wb+")};
// Make the test block file about 128 MB in length.
for (size_t i = 0; i < MAX_BLOCKFILE_SIZE / ss.size(); ++i) {
for (size_t i = 0; i < node::MAX_BLOCKFILE_SIZE / ss.size(); ++i) {
if (fwrite(ss.data(), 1, ss.size(), file) != ss.size()) {
throw std::runtime_error("write to test file failed\n");
}
Expand Down
5 changes: 5 additions & 0 deletions src/bench/wallet_balance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@

#include <optional>

using wallet::CreateMockWalletDatabase;
using wallet::CWallet;
using wallet::DBErrors;
using wallet::WALLET_FLAG_DESCRIPTORS;

static void WalletBalance(benchmark::Bench& bench, const bool set_dirty, const bool add_mine, const uint32_t epoch_iters)
{
const auto test_setup = MakeNoLogFileContext<const TestingSetup>();
Expand Down
2 changes: 1 addition & 1 deletion src/bitcoin-wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ MAIN_FUNCTION
}

ECC_Start();
if (!WalletTool::ExecuteWalletToolFunc(args, command->command)) {
if (!wallet::WalletTool::ExecuteWalletToolFunc(args, command->command)) {
return EXIT_FAILURE;
}
ECC_Stop();
Expand Down
2 changes: 2 additions & 0 deletions src/bitcoind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include <cstdio>
#include <functional>

using node::NodeContext;

const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr;
UrlDecodeFn* const URL_DECODE = urlDecode;

Expand Down
6 changes: 6 additions & 0 deletions src/chain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <chain.h>
#include <util/time.h>

#include <tinyformat.h>

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));
}

std::string CBlockIndex::ToString() const
{
return strprintf("CBlockIndex(pprev=%p, nHeight=%d, merkle=%s, hashBlock=%s)",
Expand Down
9 changes: 8 additions & 1 deletion src/coinjoin/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@
#include <memory>
#include <univalue.h>

using wallet::CCoinControl;
using wallet::CompactTallyItem;
using wallet::COutput;
using wallet::CoinType;
using wallet::CWallet;
using wallet::ReserveDestination;

PeerMsgRet CCoinJoinClientQueueManager::ProcessMessage(const CNode& peer, CConnman& connman, PeerManager& peerman,
std::string_view msg_type, CDataStream& vRecv)
{
Expand All @@ -54,7 +61,7 @@ PeerMsgRet CCoinJoinClientQueueManager::ProcessDSQueue(const CNode& peer, CConnm
vRecv >> dsq;

{
LOCK(cs_main);
LOCK(::cs_main);
peerman.EraseObjectRequest(peer.GetId(), CInv(MSG_DSQ, dsq.GetHash()));
}

Expand Down
14 changes: 7 additions & 7 deletions src/coinjoin/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class CoinJoinWalletManager {
}
}

void Add(const std::shared_ptr<CWallet>& wallet);
void Add(const std::shared_ptr<wallet::CWallet>& wallet);
void DoMaintenance(CConnman& connman);

void Remove(const std::string& name);
Expand Down Expand Up @@ -138,7 +138,7 @@ class CoinJoinWalletManager {
class CCoinJoinClientSession : public CCoinJoinBaseSession
{
private:
const std::shared_ptr<CWallet> m_wallet;
const std::shared_ptr<wallet::CWallet> m_wallet;
CCoinJoinClientManager& m_clientman;
CDeterministicMNManager& m_dmnman;
CMasternodeMetaMan& m_mn_metaman;
Expand All @@ -162,12 +162,12 @@ class CCoinJoinClientSession : public CCoinJoinBaseSession

/// Create denominations
bool CreateDenominated(CAmount nBalanceToDenominate);
bool CreateDenominated(CAmount nBalanceToDenominate, const CompactTallyItem& tallyItem, bool fCreateMixingCollaterals)
bool CreateDenominated(CAmount nBalanceToDenominate, const wallet::CompactTallyItem& tallyItem, bool fCreateMixingCollaterals)
EXCLUSIVE_LOCKS_REQUIRED(m_wallet->cs_wallet);

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

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

public:
explicit CCoinJoinClientSession(const std::shared_ptr<CWallet>& wallet, CCoinJoinClientManager& clientman,
explicit CCoinJoinClientSession(const std::shared_ptr<wallet::CWallet>& wallet, CCoinJoinClientManager& clientman,
CDeterministicMNManager& dmnman, CMasternodeMetaMan& mn_metaman,
const CMasternodeSync& mn_sync, const llmq::CInstantSendManager& isman,
const std::unique_ptr<CCoinJoinClientQueueManager>& queueman, bool is_masternode);
Expand Down Expand Up @@ -263,7 +263,7 @@ class CCoinJoinClientQueueManager : public CCoinJoinBaseManager
class CCoinJoinClientManager
{
private:
const std::shared_ptr<CWallet> m_wallet;
const std::shared_ptr<wallet::CWallet> m_wallet;
CDeterministicMNManager& m_dmnman;
CMasternodeMetaMan& m_mn_metaman;
const CMasternodeSync& m_mn_sync;
Expand Down Expand Up @@ -302,7 +302,7 @@ class CCoinJoinClientManager
CCoinJoinClientManager(CCoinJoinClientManager const&) = delete;
CCoinJoinClientManager& operator=(CCoinJoinClientManager const&) = delete;

explicit CCoinJoinClientManager(const std::shared_ptr<CWallet>& wallet, CDeterministicMNManager& dmnman,
explicit CCoinJoinClientManager(const std::shared_ptr<wallet::CWallet>& wallet, CDeterministicMNManager& dmnman,
CMasternodeMetaMan& mn_metaman, const CMasternodeSync& mn_sync,
const llmq::CInstantSendManager& isman,
const std::unique_ptr<CCoinJoinClientQueueManager>& queueman, bool is_masternode) :
Expand Down
6 changes: 3 additions & 3 deletions src/coinjoin/coinjoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ bool CCoinJoinBaseSession::IsValidInOuts(CChainState& active_chainstate, const l
nFees -= txout.nValue;
}

CCoinsViewMemPool viewMemPool(WITH_LOCK(cs_main, return &active_chainstate.CoinsTip()), mempool);
CCoinsViewMemPool viewMemPool(WITH_LOCK(::cs_main, return &active_chainstate.CoinsTip()), mempool);

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

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

{
LOCK(cs_main);
LOCK(::cs_main);
if (!ATMPIfSaneFee(chainman, MakeTransactionRef(txCollateral), /*test_accept=*/true)) {
LogPrint(BCLog::COINJOIN, "CoinJoin::IsCollateralValid -- didn't pass ATMPIfSaneFee()\n");
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/coinjoin/coinjoin.h
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,6 @@ class CDSTXManager
};

bool ATMPIfSaneFee(ChainstateManager& chainman, const CTransactionRef& tx, bool test_accept = false)
EXCLUSIVE_LOCKS_REQUIRED(cs_main);
EXCLUSIVE_LOCKS_REQUIRED(::cs_main);

#endif // BITCOIN_COINJOIN_COINJOIN_H
3 changes: 3 additions & 0 deletions src/coinjoin/interfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
#include <memory>
#include <string>

using node::NodeContext;
using wallet::CWallet;

namespace coinjoin {
namespace {

Expand Down
6 changes: 3 additions & 3 deletions src/coinjoin/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ PeerMsgRet CCoinJoinServer::ProcessDSQUEUE(const CNode& peer, CDataStream& vRecv
vRecv >> dsq;

{
LOCK(cs_main);
LOCK(::cs_main);
Assert(m_peerman)->EraseObjectRequest(peer.GetId(), CInv(MSG_DSQ, dsq.GetHash()));
}

Expand Down Expand Up @@ -327,7 +327,7 @@ void CCoinJoinServer::CommitFinalTransaction()

{
// See if the transaction is valid
TRY_LOCK(cs_main, lockMain);
TRY_LOCK(::cs_main, lockMain);
mempool.PrioritiseTransaction(hashTx, 0.1 * COIN);
if (!lockMain || !ATMPIfSaneFee(m_chainman, finalTransaction)) {
LogPrint(BCLog::COINJOIN, "CCoinJoinServer::CommitFinalTransaction -- ATMPIfSaneFee() error: Transaction not valid\n");
Expand Down Expand Up @@ -460,7 +460,7 @@ void CCoinJoinServer::ChargeRandomFees() const

void CCoinJoinServer::ConsumeCollateral(const CTransactionRef& txref) const
{
LOCK(cs_main);
LOCK(::cs_main);
if (!ATMPIfSaneFee(m_chainman, txref)) {
LogPrint(BCLog::COINJOIN, "%s -- ATMPIfSaneFee failed\n", __func__);
} else {
Expand Down
11 changes: 9 additions & 2 deletions src/coinjoin/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@

#include <numeric>

using wallet::CompactTallyItem;
using wallet::CRecipient;
using wallet::CWallet;
using wallet::FEATURE_COMPRPUBKEY;
using wallet::GetDiscardRate;
using wallet::WalletBatch;

inline unsigned int GetSizeOfCompactSizeDiff(uint64_t nSizePrev, uint64_t nSizeNew)
{
assert(nSizePrev <= nSizeNew);
Expand Down Expand Up @@ -273,7 +280,7 @@ bool CTransactionBuilder::Commit(bilingual_str& strResult)

CTransactionRef tx;
{
LOCK2(m_wallet.cs_wallet, cs_main);
LOCK2(m_wallet.cs_wallet, ::cs_main);
FeeCalculation fee_calc_out;
if (!CreateTransaction(m_wallet, vecSend, tx, nFeeRet, nChangePosRet, strResult, coinControl, fee_calc_out)) {
return false;
Expand Down Expand Up @@ -312,7 +319,7 @@ bool CTransactionBuilder::Commit(bilingual_str& strResult)
}

{
LOCK2(m_wallet.cs_wallet, cs_main);
LOCK2(m_wallet.cs_wallet, ::cs_main);
m_wallet.CommitTransaction(tx, {}, {});
}

Expand Down
20 changes: 10 additions & 10 deletions src/coinjoin/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ struct bilingual_str;
class CKeyHolder
{
private:
ReserveDestination reserveDestination;
wallet::ReserveDestination reserveDestination;
CTxDestination dest;

public:
explicit CKeyHolder(CWallet* pwalletIn);
explicit CKeyHolder(wallet::CWallet* pwalletIn);
CKeyHolder(CKeyHolder&&) = delete;
CKeyHolder& operator=(CKeyHolder&&) = delete;
void KeepKey();
Expand All @@ -33,7 +33,7 @@ class CKeyHolderStorage
std::vector<std::unique_ptr<CKeyHolder> > storage GUARDED_BY(cs_storage);

public:
CScript AddKey(CWallet* pwalletIn) EXCLUSIVE_LOCKS_REQUIRED(!cs_storage);
CScript AddKey(wallet::CWallet* pwalletIn) EXCLUSIVE_LOCKS_REQUIRED(!cs_storage);
void KeepAll() EXCLUSIVE_LOCKS_REQUIRED(!cs_storage);
void ReturnAll() EXCLUSIVE_LOCKS_REQUIRED(!cs_storage);
};
Expand All @@ -47,14 +47,14 @@ class CTransactionBuilderOutput
/// Used for amount updates
CTransactionBuilder* pTxBuilder{nullptr};
/// Reserve key where the amount of this output will end up
ReserveDestination dest;
wallet::ReserveDestination dest;
/// Amount this output will receive
CAmount nAmount{0};
/// ScriptPubKey of this output
CScript script;

public:
CTransactionBuilderOutput(CTransactionBuilder* pTxBuilderIn, CWallet& wallet, CAmount nAmountIn);
CTransactionBuilderOutput(CTransactionBuilder* pTxBuilderIn, wallet::CWallet& wallet, CAmount nAmountIn);
CTransactionBuilderOutput(CTransactionBuilderOutput&&) = delete;
CTransactionBuilderOutput& operator=(CTransactionBuilderOutput&&) = delete;
/// Get the scriptPubKey of this output
Expand All @@ -77,15 +77,15 @@ class CTransactionBuilderOutput
class CTransactionBuilder
{
/// Wallet the transaction will be build for
CWallet& m_wallet;
wallet::CWallet& m_wallet;
/// See CTransactionBuilder() for initialization
CCoinControl coinControl;
wallet::CCoinControl coinControl;
/// Dummy since we anyway use tallyItem's destination as change destination in coincontrol.
/// Its a member just to make sure ReturnKey can be called in destructor just in case it gets generated/kept
/// somewhere in CWallet code.
ReserveDestination dummyReserveDestination;
wallet::ReserveDestination dummyReserveDestination;
/// Contains all utxos available to generate this transactions. They are all from the same address.
CompactTallyItem tallyItem;
wallet::CompactTallyItem tallyItem;
/// Contains the number of bytes required for a transaction with only the inputs of tallyItems, no outputs
int nBytesBase{0};
/// Contains the number of bytes required to add one output
Expand All @@ -100,7 +100,7 @@ class CTransactionBuilder
friend class CTransactionBuilderOutput;

public:
CTransactionBuilder(CWallet& wallet, const CompactTallyItem& tallyItemIn);
CTransactionBuilder(wallet::CWallet& wallet, const wallet::CompactTallyItem& tallyItemIn);
~CTransactionBuilder();
/// Check it would be possible to add a single output with the amount nAmount. Returns true if its possible and false if not.
bool CouldAddOutput(CAmount nAmountOutput) const EXCLUSIVE_LOCKS_REQUIRED(!cs_outputs);
Expand Down
8 changes: 6 additions & 2 deletions src/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@ class ChainstateManager;
class CTxMemPool;
class CBlockPolicyEstimator;
struct LLMQContext;
namespace node {
struct NodeContext;
} // namespace node
namespace wallet {
struct WalletContext;
} // namespace wallet

using CoreContext = std::variant<std::monostate,
std::reference_wrapper<ArgsManager>,
std::reference_wrapper<NodeContext>,
std::reference_wrapper<WalletContext>,
std::reference_wrapper<node::NodeContext>,
std::reference_wrapper<wallet::WalletContext>,
std::reference_wrapper<CTxMemPool>,
std::reference_wrapper<ChainstateManager>,
std::reference_wrapper<CBlockPolicyEstimator>,
Expand Down
Loading
Loading