diff --git a/ci/lint/04_install.sh b/ci/lint/04_install.sh index 542c5b52e3fc..e7758a8c5799 100755 --- a/ci/lint/04_install.sh +++ b/ci/lint/04_install.sh @@ -6,6 +6,10 @@ export LC_ALL=C +travis_retry sudo apt update && sudo apt install -y clang-format-9 +sudo update-alternatives --install /usr/bin/clang-format clang-format $(which clang-format-9 ) 100 +sudo update-alternatives --install /usr/bin/clang-format-diff clang-format-diff $(which clang-format-diff-9) 100 + travis_retry pip3 install codespell==1.17.1 travis_retry pip3 install flake8==3.8.3 travis_retry pip3 install vulture==2.3 diff --git a/src/Makefile.am b/src/Makefile.am index f181677e7211..2e58ef28ef2f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -141,6 +141,7 @@ BITCOIN_CORE_H = \ cachemap.h \ cachemultimap.h \ blockfilter.h \ + bloom.h \ chain.h \ chainparams.h \ chainparamsbase.h \ @@ -149,6 +150,7 @@ BITCOIN_CORE_H = \ clientversion.h \ coinjoin/coinjoin.h \ coinjoin/client.h \ + coinjoin/common.h \ coinjoin/context.h \ coinjoin/options.h \ coinjoin/server.h \ @@ -169,6 +171,7 @@ BITCOIN_CORE_H = \ cuckoocache.h \ ctpl_stl.h \ cxxtimer.hpp \ + dbwrapper.h \ deploymentinfo.h \ deploymentstatus.h \ evo/assetlocktx.h \ @@ -210,12 +213,12 @@ BITCOIN_CORE_H = \ indirectmap.h \ init.h \ interfaces/chain.h \ + interfaces/coinjoin.h \ interfaces/handler.h \ interfaces/node.h \ interfaces/wallet.h \ key.h \ key_io.h \ - dbwrapper.h \ limitedmap.h \ llmq/blockprocessor.h \ llmq/chainlocks.h \ @@ -259,7 +262,9 @@ BITCOIN_CORE_H = \ node/coin.h \ node/coinstats.h \ node/context.h \ + node/psbt.h \ node/transaction.h \ + node/ui_interface.h \ node/utxo_snapshot.h \ noui.h \ outputtype.h \ @@ -305,13 +310,12 @@ BITCOIN_CORE_H = \ support/lockedpool.h \ sync.h \ timestampindex.h \ - threadsafety.h \ threadinterrupt.h \ + threadsafety.h \ timedata.h \ torcontrol.h \ txdb.h \ txmempool.h \ - ui_interface.h \ undo.h \ unordered_lru_cache.h \ util/bip32.h \ @@ -326,8 +330,6 @@ BITCOIN_CORE_H = \ util/hasher.h \ util/hash_type.h \ util/irange.h \ - util/spanparsing.h \ - util/system.h \ util/asmap.h \ util/getuniquepath.h \ util/macros.h \ @@ -342,20 +344,22 @@ BITCOIN_CORE_H = \ util/ranges_set.h \ util/sock.h \ util/string.h \ + util/spanparsing.h \ + util/system.h \ util/time.h \ util/thread.h \ util/threadnames.h \ util/trace.h \ util/translation.h \ - util/vector.h \ + util/ui_change_type.h \ util/url.h \ util/vector.h \ validation.h \ validationinterface.h \ versionbits.h \ - walletinitinterface.h \ wallet/bdb.h \ wallet/coincontrol.h \ + wallet/coinselection.h \ wallet/context.h \ wallet/crypter.h \ wallet/db.h \ @@ -370,7 +374,7 @@ BITCOIN_CORE_H = \ wallet/walletdb.h \ wallet/wallettool.h \ wallet/walletutil.h \ - wallet/coinselection.h \ + walletinitinterface.h \ warnings.h \ zmq/zmqabstractnotifier.h \ zmq/zmqnotificationinterface.h \ @@ -402,7 +406,6 @@ libbitcoin_server_a_SOURCES = \ chain.cpp \ coinjoin/coinjoin.cpp \ coinjoin/context.cpp \ - coinjoin/options.cpp \ coinjoin/server.cpp \ consensus/tx_verify.cpp \ dbwrapper.cpp \ @@ -421,6 +424,14 @@ libbitcoin_server_a_SOURCES = \ evo/specialtx.cpp \ evo/specialtxman.cpp \ flatfile.cpp \ + governance/classes.cpp \ + governance/exceptions.cpp \ + governance/governance.cpp \ + governance/object.cpp \ + governance/validators.cpp \ + governance/vote.cpp \ + governance/votedb.cpp \ + gsl/assert.cpp \ httprpc.cpp \ httpserver.cpp \ i2p.cpp \ @@ -429,14 +440,6 @@ libbitcoin_server_a_SOURCES = \ index/coinstatsindex.cpp \ index/txindex.cpp \ init.cpp \ - governance/governance.cpp \ - governance/classes.cpp \ - governance/exceptions.cpp \ - governance/object.cpp \ - governance/validators.cpp \ - governance/vote.cpp \ - governance/votedb.cpp \ - gsl/assert.cpp \ llmq/quorums.cpp \ llmq/blockprocessor.cpp \ llmq/commitment.cpp \ @@ -468,7 +471,9 @@ libbitcoin_server_a_SOURCES = \ node/coinstats.cpp \ node/context.cpp \ node/interfaces.cpp \ + node/psbt.cpp \ node/transaction.cpp \ + node/ui_interface.cpp \ noui.cpp \ policy/fees.cpp \ policy/policy.cpp \ @@ -494,7 +499,6 @@ libbitcoin_server_a_SOURCES = \ torcontrol.cpp \ txdb.cpp \ txmempool.cpp \ - ui_interface.cpp \ validation.cpp \ validationinterface.cpp \ versionbits.cpp \ @@ -525,7 +529,7 @@ libbitcoin_wallet_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(SQLITE_CFLAG libbitcoin_wallet_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) libbitcoin_wallet_a_SOURCES = \ coinjoin/client.cpp \ - coinjoin/options.cpp \ + coinjoin/interfaces.cpp \ coinjoin/util.cpp \ hdchain.cpp \ wallet/coincontrol.cpp \ @@ -735,6 +739,8 @@ libbitcoin_util_a_SOURCES = \ bls/bls_ies.h \ bls/bls_worker.cpp \ bls/bls_worker.h \ + coinjoin/common.cpp \ + coinjoin/options.cpp \ support/lockedpool.cpp \ chainparamsbase.cpp \ clientversion.cpp \ @@ -870,9 +876,7 @@ endif # https://eli.thegreenplace.net/2013/07/09/library-order-in-static-linking#circular-dependency) dash_wallet_LDADD = \ $(LIBBITCOIN_WALLET_TOOL) \ - $(LIBBITCOIN_SERVER) \ $(LIBBITCOIN_WALLET) \ - $(LIBBITCOIN_SERVER) \ $(LIBBITCOIN_COMMON) \ $(LIBBITCOIN_CONSENSUS) \ $(LIBBITCOIN_UTIL) \ diff --git a/src/banman.cpp b/src/banman.cpp index c7e9cb674476..8f216ab8a05f 100644 --- a/src/banman.cpp +++ b/src/banman.cpp @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include #include diff --git a/src/bench/coin_selection.cpp b/src/bench/coin_selection.cpp index 3d379efd078b..05709f4b4a19 100644 --- a/src/bench/coin_selection.cpp +++ b/src/bench/coin_selection.cpp @@ -31,7 +31,7 @@ static void CoinSelection(benchmark::Bench& bench) { NodeContext node; auto chain = interfaces::MakeChain(node); - CWallet wallet(chain.get(), "", CreateDummyWalletDatabase()); + CWallet wallet(chain.get(), /*coinjoin_loader=*/ nullptr, "", CreateDummyWalletDatabase()); wallet.SetupLegacyScriptPubKeyMan(); std::vector> wtxs; LOCK(wallet.cs_wallet); @@ -64,7 +64,7 @@ static void CoinSelection(benchmark::Bench& bench) typedef std::set CoinSet; static NodeContext testNode; static auto testChain = interfaces::MakeChain(testNode); -static CWallet testWallet(testChain.get(), "", CreateDummyWalletDatabase()); +static CWallet testWallet(testChain.get(), /*coinjoin_loader=*/ nullptr, "", CreateDummyWalletDatabase()); std::vector> wtxn; // Copied from src/wallet/test/coinselector_tests.cpp diff --git a/src/bench/wallet_balance.cpp b/src/bench/wallet_balance.cpp index b8c81a293f2c..8f0264b72c24 100644 --- a/src/bench/wallet_balance.cpp +++ b/src/bench/wallet_balance.cpp @@ -24,7 +24,7 @@ static void WalletBalance(benchmark::Bench& bench, const bool set_dirty, const b }; const auto& ADDRESS_WATCHONLY = ADDRESS_B58T_UNSPENDABLE; - CWallet wallet{test_setup.m_node.chain.get(), "", CreateMockWalletDatabase()}; + CWallet wallet{test_setup.m_node.chain.get(), test_setup.m_node.coinjoin_loader.get(), "", CreateMockWalletDatabase()}; { wallet.SetupLegacyScriptPubKeyMan(); bool first_run; diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index def1807316e8..d56eb01afaf0 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -14,9 +14,9 @@ #include #include #include +#include #include #include -#include #include #include #include diff --git a/src/coinjoin/client.cpp b/src/coinjoin/client.cpp index f20d51a39805..bf9776103f80 100644 --- a/src/coinjoin/client.cpp +++ b/src/coinjoin/client.cpp @@ -22,14 +22,13 @@ #include #include #include +#include #include #include #include #include -std::unique_ptr coinJoinClientManagers; - void CCoinJoinClientQueueManager::ProcessMessage(const CNode& peer, PeerManager& peerman, std::string_view msg_type, CDataStream& vRecv) { if (fMasternodeMode) return; @@ -98,7 +97,7 @@ void CCoinJoinClientQueueManager::ProcessDSQueue(const CNode& peer, PeerManager& } // if the queue is ready, submit if we can - if (dsq.fReady && ranges::any_of(m_clientman.raw(), + if (dsq.fReady && ranges::any_of(m_walletman.raw(), [this, &dmn](const auto &pair) { return pair.second->TrySubmitDenominate(dmn->pdmnState->addr, this->connman); @@ -123,7 +122,7 @@ void CCoinJoinClientQueueManager::ProcessDSQueue(const CNode& peer, PeerManager& LogPrint(BCLog::COINJOIN, "DSQUEUE -- new CoinJoin queue (%s) from masternode %s\n", dsq.ToString(), dmn->pdmnState->addr.ToString()); - ranges::any_of(m_clientman.raw(), + ranges::any_of(m_walletman.raw(), [&dsq](const auto &pair) { return pair.second->MarkAlreadyJoinedQueueAsTried(dsq); }); WITH_LOCK(cs_vecqueue, vecCoinJoinQueue.push_back(dsq)); @@ -156,11 +155,11 @@ void CCoinJoinClientManager::ProcessMessage(CNode& peer, PeerManager& peerman, C } } -CCoinJoinClientSession::CCoinJoinClientSession(CWallet& pwallet, CJClientManager& clientman, const CMasternodeSync& mn_sync, +CCoinJoinClientSession::CCoinJoinClientSession(CWallet& wallet, CoinJoinWalletManager& walletman, const CMasternodeSync& mn_sync, const std::unique_ptr& queueman) : - m_wallet(pwallet), - m_clientman(clientman), - m_manager(*Assert(clientman.Get(pwallet))), + m_wallet(wallet), + m_walletman(walletman), + m_manager(*Assert(walletman.Get(wallet.GetName()))), m_mn_sync(mn_sync), m_queueman(queueman) {} @@ -223,7 +222,7 @@ void CCoinJoinClientSession::ProcessMessage(CNode& peer, PeerManager& peerman, C return; } - WalletCJLogPrint(m_wallet, "DSCOMPLETE -- nMsgSessionID %d nMsgMessageID %d (%s)\n", nMsgSessionID, nMsgMessageID, CCoinJoin::GetMessageByID(nMsgMessageID).translated); + WalletCJLogPrint(m_wallet, "DSCOMPLETE -- nMsgSessionID %d nMsgMessageID %d (%s)\n", nMsgSessionID, nMsgMessageID, CoinJoin::GetMessageByID(nMsgMessageID).translated); CompletedTransaction(nMsgMessageID); } @@ -354,7 +353,7 @@ std::string CCoinJoinClientManager::GetSessionDenoms() AssertLockNotHeld(cs_deqsessions); LOCK(cs_deqsessions); for (const auto& session : deqSessions) { - strSessionDenoms += CCoinJoin::DenominationToString(session.nSessionDenom); + strSessionDenoms += CoinJoin::DenominationToString(session.nSessionDenom); strSessionDenoms += "; "; } return strSessionDenoms.empty() ? "N/A" : strSessionDenoms; @@ -410,7 +409,7 @@ bool CCoinJoinClientSession::CheckTimeout() UnlockCoins(); keyHolderStorage.ReturnAll(); nTimeLastSuccessfulStep = GetTime(); - strLastMessage = CCoinJoin::GetMessageByID(ERR_SESSION); + strLastMessage = CoinJoin::GetMessageByID(ERR_SESSION); return true; } @@ -511,7 +510,7 @@ void CCoinJoinClientSession::ProcessPoolStateUpdate(CCoinJoinStatusUpdate psssup return; } - bilingual_str strMessageTmp = CCoinJoin::GetMessageByID(psssup.nMessageID); + bilingual_str strMessageTmp = CoinJoin::GetMessageByID(psssup.nMessageID); strAutoDenomResult = _("Masternode:") + Untranslated(" ") + strMessageTmp; switch (psssup.nStatusUpdate) { @@ -576,7 +575,7 @@ bool CCoinJoinClientSession::SignFinalTransaction(const CTxMemPool& mempool, con // Make sure all inputs/outputs are valid PoolMessage nMessageID{MSG_NOERR}; if (!IsValidInOuts(mempool, finalMutableTransaction.vin, finalMutableTransaction.vout, nMessageID, nullptr)) { - WalletCJLogPrint(m_wallet, "CCoinJoinClientSession::%s -- ERROR! IsValidInOuts() failed: %s\n", __func__, CCoinJoin::GetMessageByID(nMessageID).translated); + WalletCJLogPrint(m_wallet, "CCoinJoinClientSession::%s -- ERROR! IsValidInOuts() failed: %s\n", __func__, CoinJoin::GetMessageByID(nMessageID).translated); UnlockCoins(); keyHolderStorage.ReturnAll(); SetNull(); @@ -691,7 +690,7 @@ void CCoinJoinClientSession::CompletedTransaction(PoolMessage nMessageID) } UnlockCoins(); WITH_LOCK(cs_coinjoin, SetNull()); - strLastMessage = CCoinJoin::GetMessageByID(nMessageID); + strLastMessage = CoinJoin::GetMessageByID(nMessageID); } void CCoinJoinClientManager::UpdatedSuccessBlock() @@ -831,12 +830,12 @@ bool CCoinJoinClientSession::DoAutomaticDenominating(CConnman& connman, CBlockPo return false; } - CAmount nValueMin = CCoinJoin::GetSmallestDenomination(); + CAmount nValueMin = CoinJoin::GetSmallestDenomination(); // if there are no confirmed DS collateral inputs yet if (!m_wallet.HasCollateralInputs()) { // should have some additional amount for them - nValueMin += CCoinJoin::GetMaxCollateralAmount(); + nValueMin += CoinJoin::GetMaxCollateralAmount(); } // including denoms but applying some restrictions @@ -859,7 +858,7 @@ bool CCoinJoinClientSession::DoAutomaticDenominating(CConnman& connman, CBlockPo // adjust nBalanceNeedsAnonymized to consume final denom if (nBalanceDenominated - nBalanceAnonymized > nBalanceNeedsAnonymized) { - auto denoms = CCoinJoin::GetStandardDenominations(); + auto denoms = CoinJoin::GetStandardDenominations(); CAmount nAdditionalDenom{0}; for (const auto& denom : denoms) { if (nBalanceNeedsAnonymized < denom) { @@ -897,7 +896,7 @@ bool CCoinJoinClientSession::DoAutomaticDenominating(CConnman& connman, CBlockPo // Check if we have should create more denominated inputs i.e. // there are funds to denominate and denominated balance does not exceed // max amount to mix yet. - if (nBalanceAnonimizableNonDenom >= nValueMin + CCoinJoin::GetCollateralAmount() && nBalanceToDenominate > 0) { + if (nBalanceAnonimizableNonDenom >= nValueMin + CoinJoin::GetCollateralAmount() && nBalanceToDenominate > 0) { CreateDenominated(fee_estimator, nBalanceToDenominate); } @@ -932,7 +931,7 @@ bool CCoinJoinClientSession::DoAutomaticDenominating(CConnman& connman, CBlockPo return false; } } else { - if (!CCoinJoin::IsCollateralValid(mempool, CTransaction(txMyCollateral))) { + if (!CoinJoin::IsCollateralValid(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); @@ -990,7 +989,7 @@ bool CCoinJoinClientManager::DoAutomaticDenominating(CConnman& connman, CBlockPo AssertLockNotHeld(cs_deqsessions); LOCK(cs_deqsessions); if (int(deqSessions.size()) < CCoinJoinClientOptions::GetSessions()) { - deqSessions.emplace_back(m_wallet, m_clientman, m_mn_sync, m_queueman); + deqSessions.emplace_back(m_wallet, m_walletman, m_mn_sync, m_queueman); } for (auto& session : deqSessions) { if (!CheckAutomaticBackup()) return false; @@ -1091,7 +1090,7 @@ bool CCoinJoinClientSession::JoinExistingQueue(CAmount nBalanceNeedsAnonymized, // Try to match their denominations if possible, select exact number of denominations if (!m_wallet.SelectTxDSInsByDenomination(dsq.nDenom, nBalanceNeedsAnonymized, vecTxDSInTmp)) { - WalletCJLogPrint(m_wallet, "CCoinJoinClientSession::JoinExistingQueue -- Couldn't match denomination %d (%s)\n", dsq.nDenom, CCoinJoin::DenominationToString(dsq.nDenom)); + WalletCJLogPrint(m_wallet, "CCoinJoinClientSession::JoinExistingQueue -- Couldn't match denomination %d (%s)\n", dsq.nDenom, CoinJoin::DenominationToString(dsq.nDenom)); continue; } @@ -1109,7 +1108,7 @@ bool CCoinJoinClientSession::JoinExistingQueue(CAmount nBalanceNeedsAnonymized, SetState(POOL_STATE_QUEUE); nTimeLastSuccessfulStep = GetTime(); WalletCJLogPrint(m_wallet, "CCoinJoinClientSession::JoinExistingQueue -- pending connection (from queue): nSessionDenom: %d (%s), addr=%s\n", - nSessionDenom, CCoinJoin::DenominationToString(nSessionDenom), dmn->pdmnState->addr.ToString()); + nSessionDenom, CoinJoin::DenominationToString(nSessionDenom), dmn->pdmnState->addr.ToString()); strAutoDenomResult = _("Trying to connect..."); return true; } @@ -1177,7 +1176,7 @@ bool CCoinJoinClientSession::StartNewQueue(CAmount nBalanceNeedsAnonymized, CCon while (nSessionDenom == 0) { for (auto it = setAmounts.rbegin(); it != setAmounts.rend(); ++it) { if (setAmounts.size() > 1 && GetRandInt(2)) continue; - nSessionDenom = CCoinJoin::AmountToDenomination(*it); + nSessionDenom = CoinJoin::AmountToDenomination(*it); break; } } @@ -1188,7 +1187,7 @@ bool CCoinJoinClientSession::StartNewQueue(CAmount nBalanceNeedsAnonymized, CCon SetState(POOL_STATE_QUEUE); nTimeLastSuccessfulStep = GetTime(); WalletCJLogPrint(m_wallet, "CCoinJoinClientSession::StartNewQueue -- pending connection, nSessionDenom: %d (%s), addr=%s\n", - nSessionDenom, CCoinJoin::DenominationToString(nSessionDenom), dmn->pdmnState->addr.ToString()); + nSessionDenom, CoinJoin::DenominationToString(nSessionDenom), dmn->pdmnState->addr.ToString()); strAutoDenomResult = _("Trying to connect..."); return true; } @@ -1325,7 +1324,7 @@ bool CCoinJoinClientSession::SelectDenominate(std::string& strErrorRet, std::vec vecTxDSInRet.clear(); - bool fSelected = m_wallet.SelectTxDSInsByDenomination(nSessionDenom, CCoinJoin::GetMaxPoolAmount(), vecTxDSInRet); + bool fSelected = m_wallet.SelectTxDSInsByDenomination(nSessionDenom, CoinJoin::GetMaxPoolAmount(), vecTxDSInRet); if (!fSelected) { strErrorRet = "Can't select current denominated inputs"; return false; @@ -1338,11 +1337,11 @@ bool CCoinJoinClientSession::PrepareDenominate(int nMinRounds, int nMaxRounds, s { AssertLockHeld(m_wallet.cs_wallet); - if (!CCoinJoin::IsValidDenomination(nSessionDenom)) { + if (!CoinJoin::IsValidDenomination(nSessionDenom)) { strErrorRet = "Incorrect session denom"; return false; } - CAmount nDenomAmount = CCoinJoin::DenominationToAmount(nSessionDenom); + CAmount nDenomAmount = CoinJoin::DenominationToAmount(nSessionDenom); // NOTE: No need to randomize order of inputs because they were // initially shuffled in CWallet::SelectTxDSInsByDenomination already. @@ -1443,12 +1442,12 @@ bool CCoinJoinClientSession::MakeCollateralAmounts(const CBlockPolicyEstimator& if (!CCoinJoinClientOptions::IsEnabled()) return false; // Denominated input is always a single one, so we can check its amount directly and return early - if (!fTryDenominated && tallyItem.vecInputCoins.size() == 1 && CCoinJoin::IsDenominatedAmount(tallyItem.nAmount)) { + if (!fTryDenominated && tallyItem.vecInputCoins.size() == 1 && CoinJoin::IsDenominatedAmount(tallyItem.nAmount)) { return false; } // Skip single inputs that can be used as collaterals already - if (tallyItem.vecInputCoins.size() == 1 && CCoinJoin::IsCollateralAmount(tallyItem.nAmount)) { + if (tallyItem.vecInputCoins.size() == 1 && CoinJoin::IsCollateralAmount(tallyItem.nAmount)) { return false; } @@ -1464,29 +1463,29 @@ bool CCoinJoinClientSession::MakeCollateralAmounts(const CBlockPolicyEstimator& WalletCJLogPrint(m_wallet, "CCoinJoinClientSession::%s -- Start %s\n", __func__, txBuilder.ToString()); // Skip way too tiny amounts. Smallest we want is minimum collateral amount in a one output tx - if (!txBuilder.CouldAddOutput(CCoinJoin::GetCollateralAmount())) { + if (!txBuilder.CouldAddOutput(CoinJoin::GetCollateralAmount())) { return false; } int nCase{0}; // Just for debug logs - if (txBuilder.CouldAddOutputs({CCoinJoin::GetMaxCollateralAmount(), CCoinJoin::GetCollateralAmount()})) { + if (txBuilder.CouldAddOutputs({CoinJoin::GetMaxCollateralAmount(), CoinJoin::GetCollateralAmount()})) { nCase = 1; // , see TransactionRecord::decomposeTransaction - // Out1 == CCoinJoin::GetMaxCollateralAmount() - // Out2 >= CCoinJoin::GetCollateralAmount() + // Out1 == CoinJoin::GetMaxCollateralAmount() + // Out2 >= CoinJoin::GetCollateralAmount() - txBuilder.AddOutput(CCoinJoin::GetMaxCollateralAmount()); + txBuilder.AddOutput(CoinJoin::GetMaxCollateralAmount()); // Note, here we first add a zero amount output to get the remainder after all fees and then assign it CTransactionBuilderOutput* out = txBuilder.AddOutput(); CAmount nAmountLeft = txBuilder.GetAmountLeft(); // If remainder is denominated add one duff to the fee - out->UpdateAmount(CCoinJoin::IsDenominatedAmount(nAmountLeft) ? nAmountLeft - 1 : nAmountLeft); + out->UpdateAmount(CoinJoin::IsDenominatedAmount(nAmountLeft) ? nAmountLeft - 1 : nAmountLeft); - } else if (txBuilder.CouldAddOutputs({CCoinJoin::GetCollateralAmount(), CCoinJoin::GetCollateralAmount()})) { + } else if (txBuilder.CouldAddOutputs({CoinJoin::GetCollateralAmount(), CoinJoin::GetCollateralAmount()})) { nCase = 2; // , see TransactionRecord::decomposeTransaction - // Out1 CCoinJoin::IsCollateralAmount() - // Out2 CCoinJoin::IsCollateralAmount() + // Out1 CoinJoin::IsCollateralAmount() + // Out2 CoinJoin::IsCollateralAmount() // First add two outputs to get the available value after all fees CTransactionBuilderOutput* out1 = txBuilder.AddOutput(); @@ -1495,20 +1494,20 @@ bool CCoinJoinClientSession::MakeCollateralAmounts(const CBlockPolicyEstimator& // Create two equal outputs from the available value. This adds one duff to the fee if txBuilder.GetAmountLeft() is odd. CAmount nAmountOutputs = txBuilder.GetAmountLeft() / 2; - assert(CCoinJoin::IsCollateralAmount(nAmountOutputs)); + assert(CoinJoin::IsCollateralAmount(nAmountOutputs)); out1->UpdateAmount(nAmountOutputs); out2->UpdateAmount(nAmountOutputs); - } else { // still at least possible to add one CCoinJoin::GetCollateralAmount() output + } else { // still at least possible to add one CoinJoin::GetCollateralAmount() output nCase = 3; // , see TransactionRecord::decomposeTransaction - // Out1 CCoinJoin::IsCollateralAmount() + // Out1 CoinJoin::IsCollateralAmount() // Out2 Skipped CTransactionBuilderOutput* out = txBuilder.AddOutput(); out->UpdateAmount(txBuilder.GetAmountLeft()); - assert(CCoinJoin::IsCollateralAmount(out->GetAmount())); + assert(CoinJoin::IsCollateralAmount(out->GetAmount())); } WalletCJLogPrint(m_wallet, "CCoinJoinClientSession::%s -- Done with case %d: %s\n", __func__, nCase, txBuilder.ToString()); @@ -1552,8 +1551,8 @@ bool CCoinJoinClientSession::CreateCollateralTransaction(CMutableTransaction& tx // pay collateral charge in fees // NOTE: no need for protobump patch here, - // CCoinJoin::IsCollateralAmount in GetCollateralTxDSIn should already take care of this - if (txout.nValue >= CCoinJoin::GetCollateralAmount() * 2) { + // CoinJoin::IsCollateralAmount in GetCollateralTxDSIn should already take care of this + if (txout.nValue >= CoinJoin::GetCollateralAmount() * 2) { // make our change address CScript scriptChange; CTxDestination dest; @@ -1563,8 +1562,8 @@ bool CCoinJoinClientSession::CreateCollateralTransaction(CMutableTransaction& tx scriptChange = GetScriptForDestination(dest); reserveDest.KeepDestination(); // return change - txCollateral.vout.emplace_back(txout.nValue - CCoinJoin::GetCollateralAmount(), scriptChange); - } else { // txout.nValue < CCoinJoin::GetCollateralAmount() * 2 + txCollateral.vout.emplace_back(txout.nValue - CoinJoin::GetCollateralAmount(), scriptChange); + } else { // txout.nValue < CoinJoin::GetCollateralAmount() * 2 // create dummy data output only and pay everything as a fee txCollateral.vout.emplace_back(0, CScript() << OP_RETURN); } @@ -1618,7 +1617,7 @@ bool CCoinJoinClientSession::CreateDenominated(CBlockPolicyEstimator& fee_estima if (!CCoinJoinClientOptions::IsEnabled()) return false; // denominated input is always a single one, so we can check its amount directly and return early - if (tallyItem.vecInputCoins.size() == 1 && CCoinJoin::IsDenominatedAmount(tallyItem.nAmount)) { + if (tallyItem.vecInputCoins.size() == 1 && CoinJoin::IsDenominatedAmount(tallyItem.nAmount)) { return false; } @@ -1635,7 +1634,7 @@ bool CCoinJoinClientSession::CreateDenominated(CBlockPolicyEstimator& fee_estima // ****** Add an output for mixing collaterals ************ / - if (fCreateMixingCollaterals && !txBuilder.AddOutput(CCoinJoin::GetMaxCollateralAmount())) { + if (fCreateMixingCollaterals && !txBuilder.AddOutput(CoinJoin::GetMaxCollateralAmount())) { WalletCJLogPrint(m_wallet, "CCoinJoinClientSession::%s -- Failed to add collateral output\n", __func__); return false; } @@ -1643,7 +1642,7 @@ bool CCoinJoinClientSession::CreateDenominated(CBlockPolicyEstimator& fee_estima // ****** Add outputs for denoms ************ / bool fAddFinal = true; - auto denoms = CCoinJoin::GetStandardDenominations(); + auto denoms = CoinJoin::GetStandardDenominations(); std::map mapDenomCount; for (auto nDenomValue : denoms) { @@ -1659,7 +1658,7 @@ bool CCoinJoinClientSession::CreateDenominated(CBlockPolicyEstimator& fee_estima // Now, in this system, so long as we don't reach COINJOIN_DENOM_OUTPUTS_THRESHOLD outputs the process repeats in // the same transaction, creating up to nCoinJoinDenomsHardCap per denomination in a single transaction. - while (txBuilder.CouldAddOutput(CCoinJoin::GetSmallestDenomination()) && txBuilder.CountOutputs() < COINJOIN_DENOM_OUTPUTS_THRESHOLD) { + while (txBuilder.CouldAddOutput(CoinJoin::GetSmallestDenomination()) && txBuilder.CountOutputs() < COINJOIN_DENOM_OUTPUTS_THRESHOLD) { for (auto it = denoms.rbegin(); it != denoms.rend(); ++it) { CAmount nDenomValue = *it; auto currentDenomIt = mapDenomCount.find(nDenomValue); @@ -1719,7 +1718,7 @@ bool CCoinJoinClientSession::CreateDenominated(CBlockPolicyEstimator& fee_estima } // Now that nCoinJoinDenomsGoal worth of each denom have been created or the max number of denoms given the value of the input, do something with the remainder. - if (txBuilder.CouldAddOutput(CCoinJoin::GetSmallestDenomination()) && nBalanceToDenominate >= CCoinJoin::GetSmallestDenomination() && txBuilder.CountOutputs() < COINJOIN_DENOM_OUTPUTS_THRESHOLD) { + if (txBuilder.CouldAddOutput(CoinJoin::GetSmallestDenomination()) && nBalanceToDenominate >= CoinJoin::GetSmallestDenomination() && txBuilder.CountOutputs() < COINJOIN_DENOM_OUTPUTS_THRESHOLD) { CAmount nLargestDenomValue = denoms.front(); WalletCJLogPrint(m_wallet, "CCoinJoinClientSession::%s -- 2 - Process remainder: %s\n", __func__, txBuilder.ToString()); @@ -1866,7 +1865,7 @@ void CCoinJoinClientSession::GetJsonInfo(UniValue& obj) const obj.pushKV("outpoint", mixingMasternode->collateralOutpoint.ToStringShort()); obj.pushKV("service", mixingMasternode->pdmnState->addr.ToString()); } - obj.pushKV("denomination", ValueFromAmount(CCoinJoin::DenominationToAmount(nSessionDenom))); + obj.pushKV("denomination", ValueFromAmount(CoinJoin::DenominationToAmount(nSessionDenom))); obj.pushKV("state", GetStateString()); obj.pushKV("entries_count", GetEntriesCount()); } @@ -1889,15 +1888,35 @@ void CCoinJoinClientManager::GetJsonInfo(UniValue& obj) const obj.pushKV("sessions", arrSessions); } -void CJClientManager::Add(CWallet& wallet) { +void CoinJoinWalletManager::Add(CWallet& wallet) { + assert(::masternodeSync != nullptr); m_wallet_manager_map.try_emplace( wallet.GetName(), std::make_unique(wallet, *this, m_mn_sync, m_queueman) ); + g_wallet_init_interface.InitCoinJoinSettings(*this); } -void CJClientManager::DoMaintenance(CBlockPolicyEstimator& fee_estimator) { - for (auto& [wallet_str, clientman] : m_wallet_manager_map) { - clientman->DoMaintenance(m_connman, fee_estimator, m_mempool); +void CoinJoinWalletManager::DoMaintenance(CBlockPolicyEstimator& fee_estimator) { + for (auto& [wallet_str, walletman] : m_wallet_manager_map) { + walletman->DoMaintenance(m_connman, fee_estimator, m_mempool); } } +void CoinJoinWalletManager::Remove(const std::string& name) { + m_wallet_manager_map.erase(name); + g_wallet_init_interface.InitCoinJoinSettings(*this); +} + +void CoinJoinWalletManager::Flush(const std::string& name) +{ + auto clientman = Get(name); + assert(clientman != nullptr); + clientman->ResetPool(); + clientman->StopMixing(); +} + +CCoinJoinClientManager* CoinJoinWalletManager::Get(const std::string& name) const +{ + auto it = m_wallet_manager_map.find(name); + return (it != m_wallet_manager_map.end()) ? it->second.get() : nullptr; +} diff --git a/src/coinjoin/client.h b/src/coinjoin/client.h index 8d2c883091fa..1536c58af932 100644 --- a/src/coinjoin/client.h +++ b/src/coinjoin/client.h @@ -19,7 +19,7 @@ class CCoinJoinClientManager; class CCoinJoinClientQueueManager; class CConnman; class CDeterministicMN; -class CJClientManager; +class CoinJoinWalletManager; class CNode; class CMasternodeSync; class CTxMemPool; @@ -29,9 +29,6 @@ class UniValue; using CDeterministicMNCPtr = std::shared_ptr; -// The main object for accessing mixing -extern std::unique_ptr coinJoinClientManagers; - class CPendingDsaRequest { private: @@ -69,15 +66,15 @@ class CPendingDsaRequest } }; -class CJClientManager { +class CoinJoinWalletManager { public: using wallet_name_cjman_map = std::map>; public: - CJClientManager(CConnman& connman, CTxMemPool& mempool, const CMasternodeSync& mn_sync, + CoinJoinWalletManager(CConnman& connman, CTxMemPool& mempool, const CMasternodeSync& mn_sync, const std::unique_ptr& queueman) : m_connman(connman), m_mempool(mempool), m_mn_sync(mn_sync), m_queueman(queueman) {} - ~CJClientManager() { + ~CoinJoinWalletManager() { for (auto& [wallet_name, cj_man] : m_wallet_manager_map) { cj_man.reset(); } @@ -86,14 +83,10 @@ class CJClientManager { void Add(CWallet& wallet); void DoMaintenance(CBlockPolicyEstimator& fee_estimator); - void Remove(const std::string& name) { - m_wallet_manager_map.erase(name); - } + void Remove(const std::string& name); + void Flush(const std::string& name); - CCoinJoinClientManager* Get(const CWallet& wallet) const { - auto it = m_wallet_manager_map.find(wallet.GetName()); - return (it != m_wallet_manager_map.end()) ? it->second.get() : nullptr; - } + CCoinJoinClientManager* Get(const std::string& name) const; const wallet_name_cjman_map& raw() const { return m_wallet_manager_map; } @@ -111,7 +104,7 @@ class CCoinJoinClientSession : public CCoinJoinBaseSession { private: CWallet& m_wallet; - CJClientManager& m_clientman; + CoinJoinWalletManager& m_walletman; CCoinJoinClientManager& m_manager; const CMasternodeSync& m_mn_sync; @@ -163,7 +156,7 @@ class CCoinJoinClientSession : public CCoinJoinBaseSession void SetNull() EXCLUSIVE_LOCKS_REQUIRED(cs_coinjoin); public: - explicit CCoinJoinClientSession(CWallet& pwallet, CJClientManager& clientman, const CMasternodeSync& mn_sync, + explicit CCoinJoinClientSession(CWallet& wallet, CoinJoinWalletManager& walletman, const CMasternodeSync& mn_sync, const std::unique_ptr& queueman); void ProcessMessage(CNode& peer, PeerManager& peerman, CConnman& connman, const CTxMemPool& mempool, std::string_view msg_type, CDataStream& vRecv); @@ -195,13 +188,13 @@ class CCoinJoinClientQueueManager : public CCoinJoinBaseManager { private: CConnman& connman; - CJClientManager& m_clientman; + CoinJoinWalletManager& m_walletman; const CMasternodeSync& m_mn_sync; mutable Mutex cs_ProcessDSQueue; public: - explicit CCoinJoinClientQueueManager(CConnman& _connman, CJClientManager& clientman, const CMasternodeSync& mn_sync) : - connman(_connman), m_clientman(clientman), m_mn_sync(mn_sync) {}; + explicit CCoinJoinClientQueueManager(CConnman& _connman, CoinJoinWalletManager& walletman, const CMasternodeSync& mn_sync) : + connman(_connman), m_walletman(walletman), m_mn_sync(mn_sync) {}; void ProcessMessage(const CNode& peer, PeerManager& peerman, std::string_view msg_type, CDataStream& vRecv) LOCKS_EXCLUDED(cs_vecqueue); void ProcessDSQueue(const CNode& peer, PeerManager& peerman, CDataStream& vRecv); @@ -214,7 +207,7 @@ class CCoinJoinClientManager { private: CWallet& m_wallet; - CJClientManager& m_clientman; + CoinJoinWalletManager& m_walletman; const CMasternodeSync& m_mn_sync; const std::unique_ptr& m_queueman; @@ -248,9 +241,9 @@ class CCoinJoinClientManager CCoinJoinClientManager(CCoinJoinClientManager const&) = delete; CCoinJoinClientManager& operator=(CCoinJoinClientManager const&) = delete; - explicit CCoinJoinClientManager(CWallet& wallet, CJClientManager& clientman, const CMasternodeSync& mn_sync, + explicit CCoinJoinClientManager(CWallet& wallet, CoinJoinWalletManager& walletman, const CMasternodeSync& mn_sync, const std::unique_ptr& queueman) : - m_wallet(wallet), m_clientman(clientman), m_mn_sync(mn_sync), m_queueman(queueman) {} + m_wallet(wallet), m_walletman(walletman), m_mn_sync(mn_sync), m_queueman(queueman) {} void ProcessMessage(CNode& peer, PeerManager& peerman, CConnman& connman, const CTxMemPool& mempool, std::string_view msg_type, CDataStream& vRecv) LOCKS_EXCLUDED(cs_deqsessions); diff --git a/src/coinjoin/coinjoin.cpp b/src/coinjoin/coinjoin.cpp index 09072bbf8908..9bb932da05b3 100644 --- a/src/coinjoin/coinjoin.cpp +++ b/src/coinjoin/coinjoin.cpp @@ -141,14 +141,14 @@ bool CCoinJoinBroadcastTx::IsValidStructure() const if (tx->vin.size() != tx->vout.size()) { return false; } - if (tx->vin.size() < size_t(CCoinJoin::GetMinPoolParticipants())) { + if (tx->vin.size() < size_t(CoinJoin::GetMinPoolParticipants())) { return false; } - if (tx->vin.size() > CCoinJoin::GetMaxPoolParticipants() * COINJOIN_ENTRY_MAX_SIZE) { + if (tx->vin.size() > CoinJoin::GetMaxPoolParticipants() * COINJOIN_ENTRY_MAX_SIZE) { return false; } return ranges::all_of(tx->vout, [] (const auto& txOut){ - return CCoinJoin::IsDenominatedAmount(txOut.nValue) && txOut.scriptPubKey.IsPayToPublicKeyHash(); + return CoinJoin::IsDenominatedAmount(txOut.nValue) && txOut.scriptPubKey.IsPayToPublicKeyHash(); }); } @@ -236,9 +236,9 @@ bool CCoinJoinBaseSession::IsValidInOuts(const CTxMemPool& mempool, const std::v } auto checkTxOut = [&](const CTxOut& txout) { - if (int nDenom = CCoinJoin::AmountToDenomination(txout.nValue); nDenom != nSessionDenom) { + if (int nDenom = CoinJoin::AmountToDenomination(txout.nValue); nDenom != nSessionDenom) { LogPrint(BCLog::COINJOIN, "CCoinJoinBaseSession::IsValidInOuts -- ERROR: incompatible denom %d (%s) != nSessionDenom %d (%s)\n", - nDenom, CCoinJoin::DenominationToString(nDenom), nSessionDenom, CCoinJoin::DenominationToString(nSessionDenom)); + nDenom, CoinJoin::DenominationToString(nDenom), nSessionDenom, CoinJoin::DenominationToString(nSessionDenom)); nMessageIDRet = ERR_DENOM; if (fConsumeCollateralRet) *fConsumeCollateralRet = true; return false; @@ -307,12 +307,8 @@ bool CCoinJoinBaseSession::IsValidInOuts(const CTxMemPool& mempool, const std::v return true; } -// Definitions for static data members -Mutex CCoinJoin::cs_mapdstx; -std::map CCoinJoin::mapDSTX GUARDED_BY(CCoinJoin::cs_mapdstx); - // check to make sure the collateral provided by the client is valid -bool CCoinJoin::IsCollateralValid(CTxMemPool& mempool, const CTransaction& txCollateral) +bool CoinJoin::IsCollateralValid(CTxMemPool& mempool, const CTransaction& txCollateral) { if (txCollateral.vout.empty()) return false; if (txCollateral.nLockTime != 0) return false; @@ -324,7 +320,7 @@ bool CCoinJoin::IsCollateralValid(CTxMemPool& mempool, const CTransaction& txCol nValueOut += txout.nValue; if (!txout.scriptPubKey.IsPayToPublicKeyHash() && !txout.scriptPubKey.IsUnspendable()) { - LogPrint(BCLog::COINJOIN, "CCoinJoin::IsCollateralValid -- Invalid Script, txCollateral=%s", txCollateral.ToString()); /* Continued */ + LogPrint(BCLog::COINJOIN, "CoinJoin::IsCollateralValid -- Invalid Script, txCollateral=%s", txCollateral.ToString()); /* Continued */ return false; } } @@ -334,31 +330,31 @@ bool CCoinJoin::IsCollateralValid(CTxMemPool& mempool, const CTransaction& txCol auto mempoolTx = mempool.get(txin.prevout.hash); if (mempoolTx != nullptr) { if (mempool.isSpent(txin.prevout) || !llmq::quorumInstantSendManager->IsLocked(txin.prevout.hash)) { - LogPrint(BCLog::COINJOIN, "CCoinJoin::IsCollateralValid -- spent or non-locked mempool input! txin=%s\n", txin.ToString()); + LogPrint(BCLog::COINJOIN, "CoinJoin::IsCollateralValid -- spent or non-locked mempool input! txin=%s\n", txin.ToString()); return false; } nValueIn += mempoolTx->vout[txin.prevout.n].nValue; } else if (GetUTXOCoin(txin.prevout, coin)) { nValueIn += coin.out.nValue; } else { - LogPrint(BCLog::COINJOIN, "CCoinJoin::IsCollateralValid -- Unknown inputs in collateral transaction, txCollateral=%s", txCollateral.ToString()); /* Continued */ + LogPrint(BCLog::COINJOIN, "CoinJoin::IsCollateralValid -- Unknown inputs in collateral transaction, txCollateral=%s", txCollateral.ToString()); /* Continued */ return false; } } //collateral transactions are required to pay out a small fee to the miners if (nValueIn - nValueOut < GetCollateralAmount()) { - LogPrint(BCLog::COINJOIN, "CCoinJoin::IsCollateralValid -- did not include enough fees in transaction: fees: %d, txCollateral=%s", nValueOut - nValueIn, txCollateral.ToString()); /* Continued */ + LogPrint(BCLog::COINJOIN, "CoinJoin::IsCollateralValid -- did not include enough fees in transaction: fees: %d, txCollateral=%s", nValueOut - nValueIn, txCollateral.ToString()); /* Continued */ return false; } - LogPrint(BCLog::COINJOIN, "CCoinJoin::IsCollateralValid -- %s", txCollateral.ToString()); /* Continued */ + LogPrint(BCLog::COINJOIN, "CoinJoin::IsCollateralValid -- %s", txCollateral.ToString()); /* Continued */ { LOCK(cs_main); TxValidationState validationState; if (!AcceptToMemoryPool(::ChainstateActive(), mempool, validationState, MakeTransactionRef(txCollateral), /*bypass_limits=*/false, /*nAbsurdFee=*/DEFAULT_MAX_RAW_TX_FEE, /*test_accept=*/true)) { - LogPrint(BCLog::COINJOIN, "CCoinJoin::IsCollateralValid -- didn't pass AcceptToMemoryPool()\n"); + LogPrint(BCLog::COINJOIN, "CoinJoin::IsCollateralValid -- didn't pass AcceptToMemoryPool()\n"); return false; } } @@ -366,21 +362,7 @@ bool CCoinJoin::IsCollateralValid(CTxMemPool& mempool, const CTransaction& txCol return true; } -std::string CCoinJoin::DenominationToString(int nDenom) -{ - switch (CAmount nDenomAmount = DenominationToAmount(nDenom)) { - case 0: return "N/A"; - case -1: return "out-of-bounds"; - case -2: return "non-denom"; - case -3: return "to-amount-error"; - default: return ValueFromAmount(nDenomAmount).getValStr(); - } - - // shouldn't happen - return "to-string-error"; -} - -bilingual_str CCoinJoin::GetMessageByID(PoolMessage nMessageID) +bilingual_str CoinJoin::GetMessageByID(PoolMessage nMessageID) { switch (nMessageID) { case ERR_ALREADY_HAVE: @@ -432,14 +414,17 @@ bilingual_str CCoinJoin::GetMessageByID(PoolMessage nMessageID) } } -void CCoinJoin::AddDSTX(const CCoinJoinBroadcastTx& dstx) +// Definitions for static data members +std::unique_ptr dstxManager; + +void CDSTXManager::AddDSTX(const CCoinJoinBroadcastTx& dstx) { AssertLockNotHeld(cs_mapdstx); LOCK(cs_mapdstx); mapDSTX.insert(std::make_pair(dstx.tx->GetHash(), dstx)); } -CCoinJoinBroadcastTx CCoinJoin::GetDSTX(const uint256& hash) +CCoinJoinBroadcastTx CDSTXManager::GetDSTX(const uint256& hash) { AssertLockNotHeld(cs_mapdstx); LOCK(cs_mapdstx); @@ -447,7 +432,7 @@ CCoinJoinBroadcastTx CCoinJoin::GetDSTX(const uint256& hash) return (it == mapDSTX.end()) ? CCoinJoinBroadcastTx() : it->second; } -void CCoinJoin::CheckDSTXes(const CBlockIndex* pindex, const llmq::CChainLocksHandler& clhandler) +void CDSTXManager::CheckDSTXes(const CBlockIndex* pindex, const llmq::CChainLocksHandler& clhandler) { AssertLockNotHeld(cs_mapdstx); LOCK(cs_mapdstx); @@ -459,24 +444,24 @@ void CCoinJoin::CheckDSTXes(const CBlockIndex* pindex, const llmq::CChainLocksHa ++it; } } - LogPrint(BCLog::COINJOIN, "CCoinJoin::CheckDSTXes -- mapDSTX.size()=%llu\n", mapDSTX.size()); + LogPrint(BCLog::COINJOIN, "CoinJoin::CheckDSTXes -- mapDSTX.size()=%llu\n", mapDSTX.size()); } -void CCoinJoin::UpdatedBlockTip(const CBlockIndex* pindex, const llmq::CChainLocksHandler& clhandler, const CMasternodeSync& mn_sync) +void CDSTXManager::UpdatedBlockTip(const CBlockIndex* pindex, const llmq::CChainLocksHandler& clhandler, const CMasternodeSync& mn_sync) { if (pindex && mn_sync.IsBlockchainSynced()) { CheckDSTXes(pindex, clhandler); } } -void CCoinJoin::NotifyChainLock(const CBlockIndex* pindex, const llmq::CChainLocksHandler& clhandler, const CMasternodeSync& mn_sync) +void CDSTXManager::NotifyChainLock(const CBlockIndex* pindex, const llmq::CChainLocksHandler& clhandler, const CMasternodeSync& mn_sync) { if (pindex && mn_sync.IsBlockchainSynced()) { CheckDSTXes(pindex, clhandler); } } -void CCoinJoin::UpdateDSTXConfirmedHeight(const CTransactionRef& tx, std::optional nHeight) +void CDSTXManager::UpdateDSTXConfirmedHeight(const CTransactionRef& tx, std::optional nHeight) { AssertLockHeld(cs_mapdstx); @@ -486,17 +471,17 @@ void CCoinJoin::UpdateDSTXConfirmedHeight(const CTransactionRef& tx, std::option } it->second.SetConfirmedHeight(nHeight); - LogPrint(BCLog::COINJOIN, "CCoinJoin::%s -- txid=%s, nHeight=%d\n", __func__, tx->GetHash().ToString(), nHeight.value_or(-1)); + LogPrint(BCLog::COINJOIN, "CDSTXManager::%s -- txid=%s, nHeight=%d\n", __func__, tx->GetHash().ToString(), nHeight.value_or(-1)); } -void CCoinJoin::TransactionAddedToMempool(const CTransactionRef& tx) +void CDSTXManager::TransactionAddedToMempool(const CTransactionRef& tx) { AssertLockNotHeld(cs_mapdstx); LOCK(cs_mapdstx); UpdateDSTXConfirmedHeight(tx, std::nullopt); } -void CCoinJoin::BlockConnected(const std::shared_ptr& pblock, const CBlockIndex* pindex) +void CDSTXManager::BlockConnected(const std::shared_ptr& pblock, const CBlockIndex* pindex) { AssertLockNotHeld(cs_mapdstx); LOCK(cs_mapdstx); @@ -506,7 +491,7 @@ void CCoinJoin::BlockConnected(const std::shared_ptr& pblock, cons } } -void CCoinJoin::BlockDisconnected(const std::shared_ptr& pblock, const CBlockIndex*) +void CDSTXManager::BlockDisconnected(const std::shared_ptr& pblock, const CBlockIndex*) { AssertLockNotHeld(cs_mapdstx); LOCK(cs_mapdstx); @@ -515,5 +500,5 @@ void CCoinJoin::BlockDisconnected(const std::shared_ptr& pblock, c } } -int CCoinJoin::GetMinPoolParticipants() { return Params().PoolMinParticipants(); } -int CCoinJoin::GetMaxPoolParticipants() { return Params().PoolMaxParticipants(); } +int CoinJoin::GetMinPoolParticipants() { return Params().PoolMinParticipants(); } +int CoinJoin::GetMaxPoolParticipants() { return Params().PoolMaxParticipants(); } diff --git a/src/coinjoin/coinjoin.h b/src/coinjoin/coinjoin.h index 8f56aa61b696..c010fac9e690 100644 --- a/src/coinjoin/coinjoin.h +++ b/src/coinjoin/coinjoin.h @@ -5,6 +5,8 @@ #ifndef BITCOIN_COINJOIN_COINJOIN_H #define BITCOIN_COINJOIN_COINJOIN_H +#include + #include #include #include @@ -12,15 +14,14 @@ #include #include #include -#include #include #include #include +#include #include #include -class CCoinJoin; class CConnman; class CBLSPublicKey; class CBlockIndex; @@ -112,26 +113,6 @@ class CCoinJoinStatusUpdate } }; -/** Holds a mixing input - */ -class CTxDSIn : public CTxIn -{ -public: - // memory only - CScript prevPubKey; - bool fHasSig{false}; // flag to indicate if signed - int nRounds{-10}; - - CTxDSIn(const CTxIn& txin, CScript script, int nRounds) : - CTxIn(txin), - prevPubKey(std::move(script)), - nRounds(nRounds) - { - } - - CTxDSIn() = default; -}; - class CCoinJoinAccept { public: @@ -357,139 +338,46 @@ class CCoinJoinBaseManager bool GetQueueItemAndTry(CCoinJoinQueue& dsqRet) LOCKS_EXCLUDED(cs_vecqueue); }; -// helper class -class CCoinJoin +// Various helpers and dstx manager implementation +namespace CoinJoin { -private: - // make constructor, destructor and copying not available - CCoinJoin() = default; - ~CCoinJoin() = default; - CCoinJoin(CCoinJoin const&) = delete; - CCoinJoin& operator=(CCoinJoin const&) = delete; - - // static members - static constexpr std::array vecStandardDenominations{ - (10 * COIN) + 10000, - (1 * COIN) + 1000, - (COIN / 10) + 100, - (COIN / 100) + 10, - (COIN / 1000) + 1, - }; - - static Mutex cs_mapdstx; - static std::map mapDSTX GUARDED_BY(cs_mapdstx); - - static void CheckDSTXes(const CBlockIndex* pindex, const llmq::CChainLocksHandler& clhandler) LOCKS_EXCLUDED(cs_mapdstx); - -public: - static constexpr std::array GetStandardDenominations() { return vecStandardDenominations; } - static constexpr CAmount GetSmallestDenomination() { return vecStandardDenominations.back(); } - - static constexpr bool IsDenominatedAmount(CAmount nInputAmount) { return AmountToDenomination(nInputAmount) > 0; } - static constexpr bool IsValidDenomination(int nDenom) { return DenominationToAmount(nDenom) > 0; } - - /* - Return a bitshifted integer representing a denomination in vecStandardDenominations - or 0 if none was found - */ - static constexpr int AmountToDenomination(CAmount nInputAmount) - { - for (size_t i = 0; i < vecStandardDenominations.size(); ++i) { - if (nInputAmount == vecStandardDenominations[i]) { - return 1 << i; - } - } - return 0; - } - - /* - Returns: - - one of standard denominations from vecStandardDenominations based on the provided bitshifted integer - - 0 for non-initialized sessions (nDenom = 0) - - a value below 0 if an error occurred while converting from one to another - */ - static constexpr CAmount DenominationToAmount(int nDenom) - { - if (nDenom == 0) { - // not initialized - return 0; - } - - size_t nMaxDenoms = vecStandardDenominations.size(); - - if (nDenom >= (1 << nMaxDenoms) || nDenom < 0) { - // out of bounds - return -1; - } - - if ((nDenom & (nDenom - 1)) != 0) { - // non-denom - return -2; - } - - CAmount nDenomAmount{-3}; - - for (size_t i = 0; i < nMaxDenoms; ++i) { - if (nDenom & (1 << i)) { - nDenomAmount = vecStandardDenominations[i]; - break; - } - } - - return nDenomAmount; - } - - /* - Same as DenominationToAmount but returns a string representation - */ - static std::string DenominationToString(int nDenom); - - static bilingual_str GetMessageByID(PoolMessage nMessageID); + bilingual_str GetMessageByID(PoolMessage nMessageID); /// Get the minimum/maximum number of participants for the pool - static int GetMinPoolParticipants(); - static int GetMaxPoolParticipants(); + int GetMinPoolParticipants(); + int GetMaxPoolParticipants(); - static constexpr CAmount GetMaxPoolAmount() { return COINJOIN_ENTRY_MAX_SIZE * vecStandardDenominations.front(); } + constexpr CAmount GetMaxPoolAmount() { return COINJOIN_ENTRY_MAX_SIZE * vecStandardDenominations.front(); } /// If the collateral is valid given by a client - static bool IsCollateralValid(CTxMemPool& mempool, const CTransaction& txCollateral); - static constexpr CAmount GetCollateralAmount() { return GetSmallestDenomination() / 10; } - static constexpr CAmount GetMaxCollateralAmount() { return GetCollateralAmount() * 4; } - - static constexpr bool IsCollateralAmount(CAmount nInputAmount) - { - // collateral input can be anything between 1x and "max" (including both) - return (nInputAmount >= GetCollateralAmount() && nInputAmount <= GetMaxCollateralAmount()); - } + bool IsCollateralValid(CTxMemPool& mempool, const CTransaction& txCollateral); - static constexpr int CalculateAmountPriority(CAmount nInputAmount) - { - if (auto optDenom = ranges::find_if_opt(GetStandardDenominations(), [&nInputAmount](const auto& denom) { - return nInputAmount == denom; - })) { - return (float)COIN / *optDenom * 10000; - } - if (nInputAmount < COIN) { - return 20000; - } +} - //nondenom return largest first - return -1 * (nInputAmount / COIN); - } +class CDSTXManager +{ + Mutex cs_mapdstx; + std::map mapDSTX GUARDED_BY(cs_mapdstx); +public: + CDSTXManager() = default; + void AddDSTX(const CCoinJoinBroadcastTx& dstx) LOCKS_EXCLUDED(cs_mapdstx); + CCoinJoinBroadcastTx GetDSTX(const uint256& hash) LOCKS_EXCLUDED(cs_mapdstx); - static void AddDSTX(const CCoinJoinBroadcastTx& dstx) LOCKS_EXCLUDED(cs_mapdstx); - static CCoinJoinBroadcastTx GetDSTX(const uint256& hash) LOCKS_EXCLUDED(cs_mapdstx); + void UpdatedBlockTip(const CBlockIndex* pindex, const llmq::CChainLocksHandler& clhandler, const CMasternodeSync& mn_sync); + void NotifyChainLock(const CBlockIndex* pindex, const llmq::CChainLocksHandler& clhandler, const CMasternodeSync& mn_sync); - static void UpdatedBlockTip(const CBlockIndex* pindex, const llmq::CChainLocksHandler& clhandler, const CMasternodeSync& mn_sync); - static void NotifyChainLock(const CBlockIndex* pindex, const llmq::CChainLocksHandler& clhandler, const CMasternodeSync& mn_sync); + void TransactionAddedToMempool(const CTransactionRef& tx) LOCKS_EXCLUDED(cs_mapdstx); + void BlockConnected(const std::shared_ptr& pblock, const CBlockIndex* pindex) LOCKS_EXCLUDED(cs_mapdstx); + void BlockDisconnected(const std::shared_ptr& pblock, const CBlockIndex*) LOCKS_EXCLUDED(cs_mapdstx); - static void TransactionAddedToMempool(const CTransactionRef& tx) LOCKS_EXCLUDED(cs_mapdstx); - static void BlockConnected(const std::shared_ptr& pblock, const CBlockIndex* pindex) LOCKS_EXCLUDED(cs_mapdstx); - static void BlockDisconnected(const std::shared_ptr& pblock, const CBlockIndex*) LOCKS_EXCLUDED(cs_mapdstx); private: - static void UpdateDSTXConfirmedHeight(const CTransactionRef& tx, std::optional nHeight); + void CheckDSTXes(const CBlockIndex* pindex, const llmq::CChainLocksHandler& clhandler); + void UpdateDSTXConfirmedHeight(const CTransactionRef& tx, std::optional nHeight); + }; + +extern std::unique_ptr dstxManager; + #endif // BITCOIN_COINJOIN_COINJOIN_H diff --git a/src/coinjoin/common.cpp b/src/coinjoin/common.cpp new file mode 100644 index 000000000000..c772be1bef6a --- /dev/null +++ b/src/coinjoin/common.cpp @@ -0,0 +1,26 @@ +// Copyright (c) 2014-2023 The Dash Core developers +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include + +#include +#include + +namespace CoinJoin +{ +std::string DenominationToString(int nDenom) +{ + switch (CAmount nDenomAmount = DenominationToAmount(nDenom)) { + case 0: return "N/A"; + case -1: return "out-of-bounds"; + case -2: return "non-denom"; + case -3: return "to-amount-error"; + default: return ValueFromAmount(nDenomAmount).getValStr(); + } + + // shouldn't happen + return "to-string-error"; +} + +} // namespace CoinJoin diff --git a/src/coinjoin/common.h b/src/coinjoin/common.h new file mode 100644 index 000000000000..9ff0f734ae4f --- /dev/null +++ b/src/coinjoin/common.h @@ -0,0 +1,135 @@ +// Copyright (c) 2014-2023 The Dash Core developers +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef BITCOIN_COINJOIN_COMMON_H +#define BITCOIN_COINJOIN_COMMON_H + +#include +#include + +#include +#include +#include + +/** Holds a mixing input + */ +class CTxDSIn : public CTxIn +{ +public: + // memory only + CScript prevPubKey; + bool fHasSig{false}; // flag to indicate if signed + int nRounds{-10}; + + CTxDSIn(const CTxIn& txin, CScript script, int nRounds) : + CTxIn(txin), + prevPubKey(std::move(script)), + nRounds(nRounds) + { + } + + CTxDSIn() = default; +}; + +namespace CoinJoin +{ + +constexpr std::array vecStandardDenominations{ + (10 * COIN) + 10000, + (1 * COIN) + 1000, + (COIN / 10) + 100, + (COIN / 100) + 10, + (COIN / 1000) + 1, +}; + +constexpr std::array GetStandardDenominations() { return vecStandardDenominations; } +constexpr CAmount GetSmallestDenomination() { return vecStandardDenominations.back(); } + +/* + Return a bitshifted integer representing a denomination in vecStandardDenominations + or 0 if none was found +*/ +constexpr int AmountToDenomination(CAmount nInputAmount) +{ + for (size_t i = 0; i < vecStandardDenominations.size(); ++i) { + if (nInputAmount == vecStandardDenominations[i]) { + return 1 << i; + } + } + return 0; +} + +/* + Returns: + - one of standard denominations from vecStandardDenominations based on the provided bitshifted integer + - 0 for non-initialized sessions (nDenom = 0) + - a value below 0 if an error occurred while converting from one to another +*/ +constexpr CAmount DenominationToAmount(int nDenom) +{ + if (nDenom == 0) { + // not initialized + return 0; + } + + size_t nMaxDenoms = vecStandardDenominations.size(); + + if (nDenom >= (1 << nMaxDenoms) || nDenom < 0) { + // out of bounds + return -1; + } + + if ((nDenom & (nDenom - 1)) != 0) { + // non-denom + return -2; + } + + CAmount nDenomAmount{-3}; + + for (size_t i = 0; i < nMaxDenoms; ++i) { + if (nDenom & (1 << i)) { + nDenomAmount = vecStandardDenominations[i]; + break; + } + } + + return nDenomAmount; +} + + +constexpr bool IsDenominatedAmount(CAmount nInputAmount) { return AmountToDenomination(nInputAmount) > 0; } +constexpr bool IsValidDenomination(int nDenom) { return DenominationToAmount(nDenom) > 0; } + +/* +Same as DenominationToAmount but returns a string representation +*/ +std::string DenominationToString(int nDenom); + +constexpr CAmount GetCollateralAmount() { return GetSmallestDenomination() / 10; } +constexpr CAmount GetMaxCollateralAmount() { return GetCollateralAmount() * 4; } + +constexpr bool IsCollateralAmount(CAmount nInputAmount) +{ + // collateral input can be anything between 1x and "max" (including both) + return (nInputAmount >= GetCollateralAmount() && nInputAmount <= GetMaxCollateralAmount()); +} + +constexpr int CalculateAmountPriority(CAmount nInputAmount) +{ + if (auto optDenom = ranges::find_if_opt(GetStandardDenominations(), [&nInputAmount](const auto& denom) { + return nInputAmount == denom; + })) { + return (float)COIN / *optDenom * 10000; + } + if (nInputAmount < COIN) { + return 20000; + } + + //nondenom return largest first + return -1 * (nInputAmount / COIN); +} + +} // namespace CoinJoin + +#endif diff --git a/src/coinjoin/context.cpp b/src/coinjoin/context.cpp index 4e8c7253208c..b0ffe893ac78 100644 --- a/src/coinjoin/context.cpp +++ b/src/coinjoin/context.cpp @@ -5,8 +5,8 @@ #include #include -#include #include +#include #ifdef ENABLE_WALLET #include @@ -15,20 +15,10 @@ CJContext::CJContext(CChainState& chainstate, CConnman& connman, CTxMemPool& mempool, const CMasternodeSync& mn_sync, bool relay_txes) : #ifdef ENABLE_WALLET - clientman { - [&]() -> CJClientManager* const { - assert(::coinJoinClientManagers == nullptr); - ::coinJoinClientManagers = std::make_unique(connman, mempool, mn_sync, queueman); - return ::coinJoinClientManagers.get(); - }() - }, - queueman {relay_txes ? std::make_unique(connman, *clientman, mn_sync) : nullptr}, + walletman{std::make_unique(connman, mempool, mn_sync, queueman)}, + queueman {relay_txes ? std::make_unique(connman, *walletman, mn_sync) : nullptr}, #endif // ENABLE_WALLET server{std::make_unique(chainstate, connman, mempool, mn_sync)} {} -CJContext::~CJContext() { -#ifdef ENABLE_WALLET - ::coinJoinClientManagers.reset(); -#endif // ENABLE_WALLET -} +CJContext::~CJContext() {} diff --git a/src/coinjoin/context.h b/src/coinjoin/context.h index d05da33e3c7c..0a0c9d908e00 100644 --- a/src/coinjoin/context.h +++ b/src/coinjoin/context.h @@ -20,7 +20,7 @@ class CTxMemPool; #ifdef ENABLE_WALLET class CCoinJoinClientQueueManager; -class CJClientManager; +class CoinJoinWalletManager; #endif // ENABLE_WALLET struct CJContext { @@ -30,7 +30,8 @@ struct CJContext { ~CJContext(); #ifdef ENABLE_WALLET - CJClientManager* const clientman; + // The main object for accessing mixing + const std::unique_ptr walletman; const std::unique_ptr queueman; #endif // ENABLE_WALLET const std::unique_ptr server; diff --git a/src/coinjoin/interfaces.cpp b/src/coinjoin/interfaces.cpp new file mode 100644 index 000000000000..78a97194319b --- /dev/null +++ b/src/coinjoin/interfaces.cpp @@ -0,0 +1,98 @@ +// Copyright (c) 2024 The Dash Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include + +#include +#include + +#include +#include + +namespace coinjoin { +namespace { + +class CoinJoinClientImpl : public interfaces::CoinJoin::Client +{ + CCoinJoinClientManager& m_clientman; + +public: + explicit CoinJoinClientImpl(CCoinJoinClientManager& clientman) + : m_clientman(clientman) {} + + void resetCachedBlocks() override + { + m_clientman.nCachedNumBlocks = std::numeric_limits::max(); + } + void resetPool() override + { + m_clientman.ResetPool(); + } + void disableAutobackups() override + { + m_clientman.fCreateAutoBackups = false; + } + int getCachedBlocks() override + { + return m_clientman.nCachedNumBlocks; + } + std::string getSessionDenoms() override + { + return m_clientman.GetSessionDenoms(); + } + void setCachedBlocks(int nCachedBlocks) override + { + m_clientman.nCachedNumBlocks = nCachedBlocks; + } + bool isMixing() override + { + return m_clientman.IsMixing(); + } + bool startMixing() override + { + return m_clientman.StartMixing(); + } + void stopMixing() override + { + m_clientman.StopMixing(); + } +}; + +class CoinJoinLoaderImpl : public interfaces::CoinJoin::Loader +{ + CoinJoinWalletManager& m_walletman; + +public: + explicit CoinJoinLoaderImpl(CoinJoinWalletManager& walletman) + : m_walletman(walletman) {} + + void AddWallet(CWallet& wallet) override + { + m_walletman.Add(wallet); + } + void RemoveWallet(const std::string& name) override + { + m_walletman.Remove(name); + } + void FlushWallet(const std::string& name) override + { + m_walletman.Flush(name); + } + std::unique_ptr GetClient(const std::string& name) override + { + auto clientman = m_walletman.Get(name); + return clientman ? std::make_unique(*clientman) : nullptr; + } + CoinJoinWalletManager& walletman() override + { + return m_walletman; + } +}; + +} // namespace +} // namespace coinjoin + +namespace interfaces { +std::unique_ptr MakeCoinJoinLoader(CoinJoinWalletManager& walletman) { return std::make_unique(walletman); } +} // namespace interfaces diff --git a/src/coinjoin/options.h b/src/coinjoin/options.h index b0497f2c4073..124ed71dcebd 100644 --- a/src/coinjoin/options.h +++ b/src/coinjoin/options.h @@ -9,6 +9,7 @@ #include #include +// This header is used by both Wallet and Server libraries class UniValue; static constexpr int MIN_COINJOIN_SESSIONS = 1; diff --git a/src/coinjoin/server.cpp b/src/coinjoin/server.cpp index 9b4b615a57ff..c81abb5359f2 100644 --- a/src/coinjoin/server.cpp +++ b/src/coinjoin/server.cpp @@ -53,7 +53,7 @@ void CCoinJoinServer::ProcessDSACCEPT(CNode& peer, CDataStream& vRecv) CCoinJoinAccept dsa; vRecv >> dsa; - LogPrint(BCLog::COINJOIN, "DSACCEPT -- nDenom %d (%s) txCollateral %s", dsa.nDenom, CCoinJoin::DenominationToString(dsa.nDenom), dsa.txCollateral.ToString()); /* Continued */ + LogPrint(BCLog::COINJOIN, "DSACCEPT -- nDenom %d (%s) txCollateral %s", dsa.nDenom, CoinJoin::DenominationToString(dsa.nDenom), dsa.txCollateral.ToString()); /* Continued */ auto mnList = deterministicMNManager->GetListAtChainTip(); auto dmn = WITH_LOCK(activeMasternodeInfoCs, return mnList.GetValidMNByCollateral(activeMasternodeInfo.outpoint)); @@ -260,7 +260,7 @@ void CCoinJoinServer::CheckPool() // Check for Time Out // If we timed out while accepting entries, then if we have more than minimum, create final tx if (nState == POOL_STATE_ACCEPTING_ENTRIES && CCoinJoinServer::HasTimedOut() - && GetEntriesCount() >= CCoinJoin::GetMinPoolParticipants()) { + && GetEntriesCount() >= CoinJoin::GetMinPoolParticipants()) { // Punish misbehaving participants ChargeFees(); // Try to complete this session ignoring the misbehaving ones @@ -333,13 +333,13 @@ void CCoinJoinServer::CommitFinalTransaction() LogPrint(BCLog::COINJOIN, "CCoinJoinServer::CommitFinalTransaction -- CREATING DSTX\n"); // create and sign masternode dstx transaction - if (!CCoinJoin::GetDSTX(hashTx)) { + if (!::dstxManager->GetDSTX(hashTx)) { CCoinJoinBroadcastTx dstxNew(finalTransaction, WITH_LOCK(activeMasternodeInfoCs, return activeMasternodeInfo.outpoint), WITH_LOCK(activeMasternodeInfoCs, return activeMasternodeInfo.proTxHash), GetAdjustedTime()); dstxNew.Sign(); - CCoinJoin::AddDSTX(dstxNew); + ::dstxManager->AddDSTX(dstxNew); } LogPrint(BCLog::COINJOIN, "CCoinJoinServer::CommitFinalTransaction -- TRANSMITTING DSTX\n"); @@ -573,7 +573,7 @@ bool CCoinJoinServer::AddEntry(const CCoinJoinEntry& entry, PoolMessage& nMessag return false; } - if (!CCoinJoin::IsCollateralValid(mempool, *entry.txCollateral)) { + if (!CoinJoin::IsCollateralValid(mempool, *entry.txCollateral)) { LogPrint(BCLog::COINJOIN, "CCoinJoinServer::%s -- ERROR: collateral not valid!\n", __func__); nMessageIDRet = ERR_INVALID_COLLATERAL; return false; @@ -608,7 +608,7 @@ bool CCoinJoinServer::AddEntry(const CCoinJoinEntry& entry, PoolMessage& nMessag bool fConsumeCollateral{false}; if (!IsValidInOuts(mempool, vin, entry.vecTxOut, nMessageIDRet, &fConsumeCollateral)) { - LogPrint(BCLog::COINJOIN, "CCoinJoinServer::%s -- ERROR! IsValidInOuts() failed: %s\n", __func__, CCoinJoin::GetMessageByID(nMessageIDRet).translated); + LogPrint(BCLog::COINJOIN, "CCoinJoinServer::%s -- ERROR! IsValidInOuts() failed: %s\n", __func__, CoinJoin::GetMessageByID(nMessageIDRet).translated); if (fConsumeCollateral) { ConsumeCollateral(entry.txCollateral); } @@ -617,7 +617,7 @@ bool CCoinJoinServer::AddEntry(const CCoinJoinEntry& entry, PoolMessage& nMessag WITH_LOCK(cs_coinjoin, vecEntries.push_back(entry)); - LogPrint(BCLog::COINJOIN, "CCoinJoinServer::%s -- adding entry %d of %d required\n", __func__, GetEntriesCount(), CCoinJoin::GetMaxPoolParticipants()); + LogPrint(BCLog::COINJOIN, "CCoinJoinServer::%s -- adding entry %d of %d required\n", __func__, GetEntriesCount(), CoinJoin::GetMaxPoolParticipants()); nMessageIDRet = MSG_ENTRIES_ADDED; return true; @@ -677,14 +677,14 @@ bool CCoinJoinServer::IsAcceptableDSA(const CCoinJoinAccept& dsa, PoolMessage& n if (!fMasternodeMode) return false; // is denom even something legit? - if (!CCoinJoin::IsValidDenomination(dsa.nDenom)) { + if (!CoinJoin::IsValidDenomination(dsa.nDenom)) { LogPrint(BCLog::COINJOIN, "CCoinJoinServer::%s -- denom not valid!\n", __func__); nMessageIDRet = ERR_DENOM; return false; } // check collateral - if (!fUnitTest && !CCoinJoin::IsCollateralValid(mempool, CTransaction(dsa.txCollateral))) { + if (!fUnitTest && !CoinJoin::IsCollateralValid(mempool, CTransaction(dsa.txCollateral))) { LogPrint(BCLog::COINJOIN, "CCoinJoinServer::%s -- collateral not valid!\n", __func__); nMessageIDRet = ERR_INVALID_COLLATERAL; return false; @@ -729,8 +729,8 @@ bool CCoinJoinServer::CreateNewSession(const CCoinJoinAccept& dsa, PoolMessage& } vecSessionCollaterals.push_back(MakeTransactionRef(dsa.txCollateral)); - LogPrint(BCLog::COINJOIN, "CCoinJoinServer::CreateNewSession -- new session created, nSessionID: %d nSessionDenom: %d (%s) vecSessionCollaterals.size(): %d CCoinJoin::GetMaxPoolParticipants(): %d\n", - nSessionID, nSessionDenom, CCoinJoin::DenominationToString(nSessionDenom), vecSessionCollaterals.size(), CCoinJoin::GetMaxPoolParticipants()); + LogPrint(BCLog::COINJOIN, "CCoinJoinServer::CreateNewSession -- new session created, nSessionID: %d nSessionDenom: %d (%s) vecSessionCollaterals.size(): %d CoinJoin::GetMaxPoolParticipants(): %d\n", + nSessionID, nSessionDenom, CoinJoin::DenominationToString(nSessionDenom), vecSessionCollaterals.size(), CoinJoin::GetMaxPoolParticipants()); return true; } @@ -752,7 +752,7 @@ bool CCoinJoinServer::AddUserToExistingSession(const CCoinJoinAccept& dsa, PoolM if (dsa.nDenom != nSessionDenom) { LogPrint(BCLog::COINJOIN, "CCoinJoinServer::AddUserToExistingSession -- incompatible denom %d (%s) != nSessionDenom %d (%s)\n", - dsa.nDenom, CCoinJoin::DenominationToString(dsa.nDenom), nSessionDenom, CCoinJoin::DenominationToString(nSessionDenom)); + dsa.nDenom, CoinJoin::DenominationToString(dsa.nDenom), nSessionDenom, CoinJoin::DenominationToString(nSessionDenom)); nMessageIDRet = ERR_DENOM; return false; } @@ -762,8 +762,8 @@ bool CCoinJoinServer::AddUserToExistingSession(const CCoinJoinAccept& dsa, PoolM nMessageIDRet = MSG_NOERR; vecSessionCollaterals.push_back(MakeTransactionRef(dsa.txCollateral)); - LogPrint(BCLog::COINJOIN, "CCoinJoinServer::AddUserToExistingSession -- new user accepted, nSessionID: %d nSessionDenom: %d (%s) vecSessionCollaterals.size(): %d CCoinJoin::GetMaxPoolParticipants(): %d\n", - nSessionID, nSessionDenom, CCoinJoin::DenominationToString(nSessionDenom), vecSessionCollaterals.size(), CCoinJoin::GetMaxPoolParticipants()); + LogPrint(BCLog::COINJOIN, "CCoinJoinServer::AddUserToExistingSession -- new user accepted, nSessionID: %d nSessionDenom: %d (%s) vecSessionCollaterals.size(): %d CoinJoin::GetMaxPoolParticipants(): %d\n", + nSessionID, nSessionDenom, CoinJoin::DenominationToString(nSessionDenom), vecSessionCollaterals.size(), CoinJoin::GetMaxPoolParticipants()); return true; } @@ -772,10 +772,10 @@ bool CCoinJoinServer::AddUserToExistingSession(const CCoinJoinAccept& dsa, PoolM bool CCoinJoinServer::IsSessionReady() const { if (nState == POOL_STATE_QUEUE) { - if ((int)vecSessionCollaterals.size() >= CCoinJoin::GetMaxPoolParticipants()) { + if ((int)vecSessionCollaterals.size() >= CoinJoin::GetMaxPoolParticipants()) { return true; } - if (CCoinJoinServer::HasTimedOut() && (int)vecSessionCollaterals.size() >= CCoinJoin::GetMinPoolParticipants()) { + if (CCoinJoinServer::HasTimedOut() && (int)vecSessionCollaterals.size() >= CoinJoin::GetMinPoolParticipants()) { return true; } } @@ -789,7 +789,7 @@ void CCoinJoinServer::RelayFinalTransaction(const CTransaction& txFinal) { AssertLockHeld(cs_coinjoin); LogPrint(BCLog::COINJOIN, "CCoinJoinServer::%s -- nSessionID: %d nSessionDenom: %d (%s)\n", - __func__, nSessionID, nSessionDenom, CCoinJoin::DenominationToString(nSessionDenom)); + __func__, nSessionID, nSessionDenom, CoinJoin::DenominationToString(nSessionDenom)); // final mixing tx with empty signatures should be relayed to mixing participants only for (const auto& entry : vecEntries) { @@ -832,7 +832,7 @@ void CCoinJoinServer::RelayStatus(PoolStatusUpdate nStatusUpdate, PoolMessage nM // something went wrong LogPrint(BCLog::COINJOIN, "CCoinJoinServer::%s -- can't continue, %llu client(s) disconnected, nSessionID: %d nSessionDenom: %d (%s)\n", - __func__, nDisconnected, nSessionID, nSessionDenom, CCoinJoin::DenominationToString(nSessionDenom)); + __func__, nDisconnected, nSessionID, nSessionDenom, CoinJoin::DenominationToString(nSessionDenom)); // notify everyone else that this session should be terminated for (const auto& entry : vecEntries) { @@ -853,7 +853,7 @@ void CCoinJoinServer::RelayCompletedTransaction(PoolMessage nMessageID) { AssertLockNotHeld(cs_coinjoin); LogPrint(BCLog::COINJOIN, "CCoinJoinServer::%s -- nSessionID: %d nSessionDenom: %d (%s)\n", - __func__, nSessionID, nSessionDenom, CCoinJoin::DenominationToString(nSessionDenom)); + __func__, nSessionID, nSessionDenom, CoinJoin::DenominationToString(nSessionDenom)); // final mixing tx with empty signatures should be relayed to mixing participants only LOCK(cs_coinjoin); @@ -901,7 +901,7 @@ void CCoinJoinServer::GetJsonInfo(UniValue& obj) const obj.clear(); obj.setObject(); obj.pushKV("queue_size", GetQueueSize()); - obj.pushKV("denomination", ValueFromAmount(CCoinJoin::DenominationToAmount(nSessionDenom))); + obj.pushKV("denomination", ValueFromAmount(CoinJoin::DenominationToAmount(nSessionDenom))); obj.pushKV("state", GetStateString()); obj.pushKV("entries_count", GetEntriesCount()); } diff --git a/src/dsnotificationinterface.cpp b/src/dsnotificationinterface.cpp index d933ba3c157e..f821607c9af1 100644 --- a/src/dsnotificationinterface.cpp +++ b/src/dsnotificationinterface.cpp @@ -67,9 +67,9 @@ void CDSNotificationInterface::UpdatedBlockTip(const CBlockIndex *pindexNew, con if (fInitialDownload) return; - CCoinJoin::UpdatedBlockTip(pindexNew, *llmq_ctx->clhandler, m_mn_sync); + ::dstxManager->UpdatedBlockTip(pindexNew, *llmq_ctx->clhandler, m_mn_sync); #ifdef ENABLE_WALLET - for (auto& pair : cj_ctx->clientman->raw()) { + for (auto& pair : cj_ctx->walletman->raw()) { pair.second->UpdatedBlockTip(pindexNew); } #endif // ENABLE_WALLET @@ -88,7 +88,7 @@ void CDSNotificationInterface::TransactionAddedToMempool(const CTransactionRef& { llmq_ctx->isman->TransactionAddedToMempool(ptx); llmq_ctx->clhandler->TransactionAddedToMempool(ptx, nAcceptTime); - CCoinJoin::TransactionAddedToMempool(ptx); + ::dstxManager->TransactionAddedToMempool(ptx); } void CDSNotificationInterface::TransactionRemovedFromMempool(const CTransactionRef& ptx, MemPoolRemovalReason reason) @@ -100,14 +100,14 @@ void CDSNotificationInterface::BlockConnected(const std::shared_ptrisman->BlockConnected(pblock, pindex); llmq_ctx->clhandler->BlockConnected(pblock, pindex); - CCoinJoin::BlockConnected(pblock, pindex); + ::dstxManager->BlockConnected(pblock, pindex); } void CDSNotificationInterface::BlockDisconnected(const std::shared_ptr& pblock, const CBlockIndex* pindexDisconnected) { llmq_ctx->isman->BlockDisconnected(pblock, pindexDisconnected); llmq_ctx->clhandler->BlockDisconnected(pblock, pindexDisconnected); - CCoinJoin::BlockDisconnected(pblock, pindexDisconnected); + ::dstxManager->BlockDisconnected(pblock, pindexDisconnected); } void CDSNotificationInterface::NotifyMasternodeListChanged(bool undo, const CDeterministicMNList& oldMNList, const CDeterministicMNListDiff& diff) @@ -119,5 +119,5 @@ void CDSNotificationInterface::NotifyMasternodeListChanged(bool undo, const CDet void CDSNotificationInterface::NotifyChainLock(const CBlockIndex* pindex, const std::shared_ptr& clsig) { llmq_ctx->isman->NotifyChainLock(pindex); - CCoinJoin::NotifyChainLock(pindex, *llmq_ctx->clhandler, m_mn_sync); + ::dstxManager->NotifyChainLock(pindex, *llmq_ctx->clhandler, m_mn_sync); } diff --git a/src/dummywallet.cpp b/src/dummywallet.cpp index ae088b36c4a4..6bd92a5f25b7 100644 --- a/src/dummywallet.cpp +++ b/src/dummywallet.cpp @@ -24,7 +24,7 @@ class DummyWalletInit : public WalletInitInterface { // Dash Specific WalletInitInterface InitCoinJoinSettings void AutoLockMasternodeCollaterals() const override {} - void InitCoinJoinSettings(const CJClientManager& clientman) const override {} + void InitCoinJoinSettings(const CoinJoinWalletManager& cjwalletman) const override {} bool InitAutoBackup() const override {return true;} }; @@ -74,7 +74,7 @@ const WalletInitInterface& g_wallet_init_interface = DummyWalletInit(); namespace interfaces { -std::unique_ptr MakeWallet(const std::shared_ptr& wallet, const CJClientManager& clientman) +std::unique_ptr MakeWallet(const std::shared_ptr& wallet, const CoinJoinWalletManager& cjwalletman) { throw std::logic_error("Wallet function called in non-wallet build."); } diff --git a/src/evo/deterministicmns.cpp b/src/evo/deterministicmns.cpp index 73d72b2be639..184a0a888a1a 100644 --- a/src/evo/deterministicmns.cpp +++ b/src/evo/deterministicmns.cpp @@ -15,7 +15,6 @@ #include #include #include