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
6 changes: 6 additions & 0 deletions doc/release-notes-6296.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Updated settings
----------------

- `-maxuploadtarget` now allows human readable byte units [k|K|m|M|g|G|t|T].
E.g. `-maxuploadtarget=500g`. No whitespace, +- or fractions allowed.
Default is `M` if no suffix provided.
3 changes: 2 additions & 1 deletion src/Makefile.test.include
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,9 @@ BITCOIN_TESTS =\
test/script_p2sh_tests.cpp \
test/script_p2pk_tests.cpp \
test/script_p2pkh_tests.cpp \
test/script_tests.cpp \
test/script_parse_tests.cpp \
test/script_standard_tests.cpp \
test/script_tests.cpp \
test/scriptnum_tests.cpp \
test/serfloat_tests.cpp \
test/serialize_tests.cpp \
Expand Down
4 changes: 2 additions & 2 deletions src/bench/block_assemble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ static void AssembleBlock(benchmark::Bench& bench)
txs.at(b) = MakeTransactionRef(tx);
}
{
LOCK(::cs_main); // Required for ::AcceptToMemoryPool.
LOCK(::cs_main);

for (const auto& txr : txs) {
const MempoolAcceptResult res = ::AcceptToMemoryPool(test_setup->m_node.chainman->ActiveChainstate(), *test_setup->m_node.mempool, txr, false /* bypass_limits */);
const MempoolAcceptResult res = test_setup->m_node.chainman->ProcessTransaction(txr);
assert(res.m_result_type == MempoolAcceptResult::ResultType::VALID);
}
}
Expand Down
43 changes: 34 additions & 9 deletions src/bench/mempool_stress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <policy/policy.h>
#include <test/util/setup_common.h>
#include <txmempool.h>
#include <validation.h>

#include <vector>

Expand All @@ -26,14 +27,8 @@ struct Available {
Available(CTransactionRef& ref, size_t tx_count) : ref(ref), tx_count(tx_count){}
};

static void ComplexMemPool(benchmark::Bench& bench)
static std::vector<CTransactionRef> CreateOrderedCoins(FastRandomContext& det_rand, int childTxs, int min_ancestors)
{
int childTxs = 800;
if (bench.complexityN() > 1) {
childTxs = static_cast<int>(bench.complexityN());
}

FastRandomContext det_rand{true};
std::vector<Available> available_coins;
std::vector<CTransactionRef> ordered_coins;
// Create some base transactions
Expand All @@ -57,8 +52,10 @@ static void ComplexMemPool(benchmark::Bench& bench)
size_t idx = det_rand.randrange(available_coins.size());
Available coin = available_coins[idx];
uint256 hash = coin.ref->GetHash();
// biased towards taking just one ancestor, but maybe more
size_t n_to_take = det_rand.randrange(2) == 0 ? 1 : 1+det_rand.randrange(coin.ref->vout.size() - coin.vin_left);
// biased towards taking min_ancestors parents, but maybe more
size_t n_to_take = det_rand.randrange(2) == 0 ?
min_ancestors :
min_ancestors + det_rand.randrange(coin.ref->vout.size() - coin.vin_left);
for (size_t i = 0; i < n_to_take; ++i) {
tx.vin.emplace_back();
tx.vin.back().prevout = COutPoint(hash, coin.vin_left++);
Expand All @@ -77,6 +74,17 @@ static void ComplexMemPool(benchmark::Bench& bench)
ordered_coins.emplace_back(MakeTransactionRef(tx));
available_coins.emplace_back(ordered_coins.back(), tx_counter++);
}
return ordered_coins;
}

static void ComplexMemPool(benchmark::Bench& bench)
{
FastRandomContext det_rand{true};
int childTxs = 800;
if (bench.complexityN() > 1) {
childTxs = static_cast<int>(bench.complexityN());
}
std::vector<CTransactionRef> ordered_coins = CreateOrderedCoins(det_rand, childTxs, /* min_ancestors */ 1);
const auto testing_setup = MakeNoLogFileContext<const TestingSetup>(CBaseChainParams::MAIN);
CTxMemPool pool;
LOCK2(cs_main, pool.cs);
Expand All @@ -89,4 +97,21 @@ static void ComplexMemPool(benchmark::Bench& bench)
});
}

static void MempoolCheck(benchmark::Bench& bench)
{
FastRandomContext det_rand{true};
const int childTxs = bench.complexityN() > 1 ? static_cast<int>(bench.complexityN()) : 2000;
const std::vector<CTransactionRef> ordered_coins = CreateOrderedCoins(det_rand, childTxs, /* min_ancestors */ 5);
const auto testing_setup = MakeNoLogFileContext<const TestingSetup>(CBaseChainParams::MAIN, {"-checkmempool=1"});
CTxMemPool pool;
LOCK2(cs_main, pool.cs);
const CCoinsViewCache& coins_tip = testing_setup.get()->m_node.chainman->ActiveChainstate().CoinsTip();
for (auto& tx : ordered_coins) AddTx(tx, pool);

bench.run([&]() NO_THREAD_SAFETY_ANALYSIS {
pool.check(coins_tip, /* spendheight */ 2);
});
}

BENCHMARK(ComplexMemPool);
BENCHMARK(MempoolCheck);
16 changes: 9 additions & 7 deletions src/coinjoin/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,8 @@ bool CCoinJoinClientManager::CheckAutomaticBackup()
//
// Passively run mixing in the background to mix funds based on the given configuration.
//
bool CCoinJoinClientSession::DoAutomaticDenominating(CChainState& active_chainstate, CConnman& connman, CTxMemPool& mempool, bool fDryRun)
bool CCoinJoinClientSession::DoAutomaticDenominating(ChainstateManager& chainman, CConnman& connman,
const CTxMemPool& mempool, bool fDryRun)
{
if (m_is_masternode) return false; // no client-side mixing on masternodes
if (nState != POOL_STATE_IDLE) return false;
Expand Down Expand Up @@ -946,7 +947,7 @@ bool CCoinJoinClientSession::DoAutomaticDenominating(CChainState& active_chainst
return false;
}
} else {
if (!CoinJoin::IsCollateralValid(active_chainstate, mempool, CTransaction(txMyCollateral))) {
if (!CoinJoin::IsCollateralValid(chainman, mempool, CTransaction(txMyCollateral))) {
WalletCJLogPrint(m_wallet, "CCoinJoinClientSession::DoAutomaticDenominating -- invalid collateral, recreating...\n");
if (!CreateCollateralTransaction(txMyCollateral, strReason)) {
WalletCJLogPrint(m_wallet, "CCoinJoinClientSession::DoAutomaticDenominating -- create collateral error: %s\n", strReason);
Expand All @@ -973,7 +974,8 @@ bool CCoinJoinClientSession::DoAutomaticDenominating(CChainState& active_chainst
return false;
}

bool CCoinJoinClientManager::DoAutomaticDenominating(CChainState& active_chainstate, CConnman& connman, CTxMemPool& mempool, bool fDryRun)
bool CCoinJoinClientManager::DoAutomaticDenominating(ChainstateManager& chainman, CConnman& connman,
const CTxMemPool& mempool, bool fDryRun)
{
if (m_is_masternode) return false; // no client-side mixing on masternodes
if (!CCoinJoinClientOptions::IsEnabled() || !IsMixing()) return false;
Expand Down Expand Up @@ -1016,7 +1018,7 @@ bool CCoinJoinClientManager::DoAutomaticDenominating(CChainState& active_chainst
return false;
}

fResult &= session.DoAutomaticDenominating(active_chainstate, connman, mempool, fDryRun);
fResult &= session.DoAutomaticDenominating(chainman, connman, mempool, fDryRun);
}

return fResult;
Expand Down Expand Up @@ -1864,7 +1866,7 @@ void CCoinJoinClientQueueManager::DoMaintenance()
CheckQueue();
}

void CCoinJoinClientManager::DoMaintenance(CChainState& active_chainstate, CConnman& connman, CTxMemPool& mempool)
void CCoinJoinClientManager::DoMaintenance(ChainstateManager& chainman, CConnman& connman, const CTxMemPool& mempool)
{
if (!CCoinJoinClientOptions::IsEnabled()) return;
if (m_is_masternode) return; // no client-side mixing on masternodes
Expand All @@ -1878,7 +1880,7 @@ void CCoinJoinClientManager::DoMaintenance(CChainState& active_chainstate, CConn
CheckTimeout();
ProcessPendingDsaRequest(connman);
if (nDoAutoNextRun == nTick) {
DoAutomaticDenominating(active_chainstate, connman, mempool);
DoAutomaticDenominating(chainman, connman, mempool);
nDoAutoNextRun = nTick + COINJOIN_AUTO_TIMEOUT_MIN + GetRandInt(COINJOIN_AUTO_TIMEOUT_MAX - COINJOIN_AUTO_TIMEOUT_MIN);
}
}
Expand Down Expand Up @@ -1930,7 +1932,7 @@ void CoinJoinWalletManager::DoMaintenance()
{
LOCK(cs_wallet_manager_map);
for (auto& [_, clientman] : m_wallet_manager_map) {
clientman->DoMaintenance(m_chainstate, m_connman, m_mempool);
clientman->DoMaintenance(m_chainman, m_connman, m_mempool);
}
}

Expand Down
31 changes: 21 additions & 10 deletions src/coinjoin/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ class CCoinJoinClientQueueManager;
class CConnman;
class CDeterministicMN;
class CDeterministicMNManager;
class CNode;
class ChainstateManager;
class CMasternodeMetaMan;
class CMasternodeSync;
class CNode;
class CoinJoinWalletManager;
class CTxMemPool;

Expand Down Expand Up @@ -74,10 +75,17 @@ class CoinJoinWalletManager {
using wallet_name_cjman_map = std::map<const std::string, std::unique_ptr<CCoinJoinClientManager>>;

public:
CoinJoinWalletManager(CChainState& chainstate, CConnman& connman, CDeterministicMNManager& dmnman, CMasternodeMetaMan& mn_metaman, CTxMemPool& mempool,
const CMasternodeSync& mn_sync, const std::unique_ptr<CCoinJoinClientQueueManager>& queueman, bool is_masternode)
: m_chainstate(chainstate), m_connman(connman), m_dmnman(dmnman), m_mn_metaman(mn_metaman), m_mempool(mempool), m_mn_sync(mn_sync),
m_queueman(queueman), m_is_masternode{is_masternode}
CoinJoinWalletManager(ChainstateManager& chainman, CConnman& connman, CDeterministicMNManager& dmnman,
CMasternodeMetaMan& mn_metaman, const CTxMemPool& mempool, const CMasternodeSync& mn_sync,
const std::unique_ptr<CCoinJoinClientQueueManager>& queueman, bool is_masternode) :
m_chainman(chainman),
m_connman(connman),
m_dmnman(dmnman),
m_mn_metaman(mn_metaman),
m_mempool(mempool),
m_mn_sync(mn_sync),
m_queueman(queueman),
m_is_masternode{is_masternode}
{}

~CoinJoinWalletManager() {
Expand Down Expand Up @@ -112,11 +120,11 @@ class CoinJoinWalletManager {
};

private:
CChainState& m_chainstate;
ChainstateManager& m_chainman;
CConnman& m_connman;
CDeterministicMNManager& m_dmnman;
CMasternodeMetaMan& m_mn_metaman;
CTxMemPool& m_mempool;
const CTxMemPool& m_mempool;
const CMasternodeSync& m_mn_sync;
const std::unique_ptr<CCoinJoinClientQueueManager>& m_queueman;

Expand Down Expand Up @@ -202,7 +210,8 @@ class CCoinJoinClientSession : public CCoinJoinBaseSession
bool GetMixingMasternodeInfo(CDeterministicMNCPtr& ret) const;

/// Passively run mixing in the background according to the configuration in settings
bool DoAutomaticDenominating(CChainState& active_chainstate, CConnman& connman, CTxMemPool& mempool, bool fDryRun = false) EXCLUSIVE_LOCKS_REQUIRED(!cs_coinjoin);
bool DoAutomaticDenominating(ChainstateManager& chainman, CConnman& connman, const CTxMemPool& mempool,
bool fDryRun = false) EXCLUSIVE_LOCKS_REQUIRED(!cs_coinjoin);

/// As a client, submit part of a future mixing transaction to a Masternode to start the process
bool SubmitDenominate(CConnman& connman);
Expand Down Expand Up @@ -310,7 +319,8 @@ class CCoinJoinClientManager
bool GetMixingMasternodesInfo(std::vector<CDeterministicMNCPtr>& vecDmnsRet) const EXCLUSIVE_LOCKS_REQUIRED(!cs_deqsessions);

/// Passively run mixing in the background according to the configuration in settings
bool DoAutomaticDenominating(CChainState& active_chainstate, CConnman& connman, CTxMemPool& mempool, bool fDryRun = false) EXCLUSIVE_LOCKS_REQUIRED(!cs_deqsessions);
bool DoAutomaticDenominating(ChainstateManager& chainman, CConnman& connman, const CTxMemPool& mempool,
bool fDryRun = false) EXCLUSIVE_LOCKS_REQUIRED(!cs_deqsessions);

bool TrySubmitDenominate(const CService& mnAddr, CConnman& connman) EXCLUSIVE_LOCKS_REQUIRED(!cs_deqsessions);
bool MarkAlreadyJoinedQueueAsTried(CCoinJoinQueue& dsq) const EXCLUSIVE_LOCKS_REQUIRED(!cs_deqsessions);
Expand All @@ -326,7 +336,8 @@ class CCoinJoinClientManager

void UpdatedBlockTip(const CBlockIndex* pindex);

void DoMaintenance(CChainState& active_chainstate, CConnman& connman, CTxMemPool& mempool) EXCLUSIVE_LOCKS_REQUIRED(!cs_deqsessions);
void DoMaintenance(ChainstateManager& chainman, CConnman& connman, const CTxMemPool& mempool)
EXCLUSIVE_LOCKS_REQUIRED(!cs_deqsessions);

void GetJsonInfo(UniValue& obj) const EXCLUSIVE_LOCKS_REQUIRED(!cs_deqsessions);
};
Expand Down
15 changes: 8 additions & 7 deletions src/coinjoin/coinjoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,11 @@ bool CCoinJoinBaseSession::IsValidInOuts(CChainState& active_chainstate, const C

// Responsibility for checking fee sanity is moved from the mempool to the client (BroadcastTransaction)
// but CoinJoin still requires ATMP with fee sanity checks so we need to implement them separately
bool ATMPIfSaneFee(CChainState& active_chainstate, CTxMemPool& pool, const CTransactionRef &tx, bool test_accept) {
bool ATMPIfSaneFee(ChainstateManager& chainman, const CTransactionRef& tx, bool test_accept)
{
AssertLockHeld(cs_main);

const MempoolAcceptResult result = AcceptToMemoryPool(active_chainstate, pool, tx, /* bypass_limits */ false, /* test_accept */ true);
const MempoolAcceptResult result = chainman.ProcessTransaction(tx, /*test_accept=*/true);
if (result.m_result_type != MempoolAcceptResult::ResultType::VALID) {
/* Fetch fee and fast-fail if ATMP fails regardless */
return false;
Expand All @@ -322,11 +323,11 @@ bool ATMPIfSaneFee(CChainState& active_chainstate, CTxMemPool& pool, const CTran
/* Don't re-run ATMP if only doing test run */
return true;
}
return AcceptToMemoryPool(active_chainstate, pool, tx, /* bypass_limits */ false, test_accept).m_result_type == MempoolAcceptResult::ResultType::VALID;
return chainman.ProcessTransaction(tx, test_accept).m_result_type == MempoolAcceptResult::ResultType::VALID;
}

// check to make sure the collateral provided by the client is valid
bool CoinJoin::IsCollateralValid(CChainState& active_chainstate, CTxMemPool& mempool, const CTransaction& txCollateral)
bool CoinJoin::IsCollateralValid(ChainstateManager& chainman, const CTxMemPool& mempool, const CTransaction& txCollateral)
{
if (txCollateral.vout.empty()) return false;
if (txCollateral.nLockTime != 0) return false;
Expand All @@ -352,7 +353,7 @@ bool CoinJoin::IsCollateralValid(CChainState& active_chainstate, CTxMemPool& mem
return false;
}
nValueIn += mempoolTx->vout[txin.prevout.n].nValue;
} else if (GetUTXOCoin(active_chainstate, txin.prevout, coin)) {
} else if (GetUTXOCoin(chainman.ActiveChainstate(), txin.prevout, coin)) {
nValueIn += coin.out.nValue;
} else {
LogPrint(BCLog::COINJOIN, "CoinJoin::IsCollateralValid -- Unknown inputs in collateral transaction, txCollateral=%s", txCollateral.ToString()); /* Continued */
Expand All @@ -370,8 +371,8 @@ bool CoinJoin::IsCollateralValid(CChainState& active_chainstate, CTxMemPool& mem

{
LOCK(cs_main);
if (!ATMPIfSaneFee(active_chainstate, mempool, MakeTransactionRef(txCollateral), /*test_accept=*/true)) {
LogPrint(BCLog::COINJOIN, "CoinJoin::IsCollateralValid -- didn't pass AcceptToMemoryPool()\n");
if (!ATMPIfSaneFee(chainman, MakeTransactionRef(txCollateral), /*test_accept=*/true)) {
LogPrint(BCLog::COINJOIN, "CoinJoin::IsCollateralValid -- didn't pass ATMPIfSaneFee()\n");
return false;
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/coinjoin/coinjoin.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class CChainState;
class CConnman;
class CBLSPublicKey;
class CBlockIndex;
class ChainstateManager;
class CMasternodeSync;
class CTxMemPool;
class TxValidationState;
Expand Down Expand Up @@ -368,8 +369,7 @@ namespace CoinJoin
constexpr CAmount GetMaxPoolAmount() { return COINJOIN_ENTRY_MAX_SIZE * vecStandardDenominations.front(); }

/// If the collateral is valid given by a client
bool IsCollateralValid(CChainState& active_chainstate, CTxMemPool& mempool, const CTransaction& txCollateral);

bool IsCollateralValid(ChainstateManager& chainman, const CTxMemPool& mempool, const CTransaction& txCollateral);
}

class CDSTXManager
Expand Down Expand Up @@ -402,7 +402,7 @@ class CDSTXManager

};

bool ATMPIfSaneFee(CChainState& active_chainstate, CTxMemPool& pool,
const CTransactionRef &tx, bool test_accept = false) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
bool ATMPIfSaneFee(ChainstateManager& chainman, const CTransactionRef& tx, bool test_accept = false)
EXCLUSIVE_LOCKS_REQUIRED(cs_main);

#endif // BITCOIN_COINJOIN_COINJOIN_H
8 changes: 4 additions & 4 deletions src/coinjoin/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@
#endif // ENABLE_WALLET
#include <coinjoin/server.h>

CJContext::CJContext(CChainState& chainstate, CConnman& connman, CDeterministicMNManager& dmnman,
CJContext::CJContext(ChainstateManager& chainman, CConnman& connman, CDeterministicMNManager& dmnman,
CMasternodeMetaMan& mn_metaman, CTxMemPool& mempool,
const CActiveMasternodeManager* const mn_activeman, const CMasternodeSync& mn_sync,
std::unique_ptr<PeerManager>& peerman, bool relay_txes) :
dstxman{std::make_unique<CDSTXManager>()},
#ifdef ENABLE_WALLET
walletman{std::make_unique<CoinJoinWalletManager>(chainstate, connman, dmnman, mn_metaman, mempool, mn_sync,
queueman, /* is_masternode = */ mn_activeman != nullptr)},
walletman{std::make_unique<CoinJoinWalletManager>(chainman, connman, dmnman, mn_metaman, mempool, mn_sync, queueman,
/* is_masternode = */ mn_activeman != nullptr)},
queueman{relay_txes
? std::make_unique<CCoinJoinClientQueueManager>(connman, peerman, *walletman, dmnman, mn_metaman,
mn_sync, /* is_masternode = */ mn_activeman != nullptr)
: nullptr},
#endif // ENABLE_WALLET
server{std::make_unique<CCoinJoinServer>(chainstate, connman, dmnman, *dstxman, mn_metaman, mempool, mn_activeman,
server{std::make_unique<CCoinJoinServer>(chainman, connman, dmnman, *dstxman, mn_metaman, mempool, mn_activeman,
mn_sync, peerman)}
{}

Expand Down
4 changes: 2 additions & 2 deletions src/coinjoin/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@

class CActiveMasternodeManager;
class CBlockPolicyEstimator;
class CChainState;
class CCoinJoinServer;
class CConnman;
class CDeterministicMNManager;
class CDSTXManager;
class ChainstateManager;
class CMasternodeMetaMan;
class CMasternodeSync;
class CTxMemPool;
Expand All @@ -31,7 +31,7 @@ class CoinJoinWalletManager;
struct CJContext {
CJContext() = delete;
CJContext(const CJContext&) = delete;
CJContext(CChainState& chainstate, CConnman& connman, CDeterministicMNManager& dmnman,
CJContext(ChainstateManager& chainman, CConnman& connman, CDeterministicMNManager& dmnman,
CMasternodeMetaMan& mn_metaman, CTxMemPool& mempool, const CActiveMasternodeManager* const mn_activeman,
const CMasternodeSync& mn_sync, std::unique_ptr<PeerManager>& peerman, bool relay_txes);
~CJContext();
Expand Down
Loading
Loading