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
19 changes: 9 additions & 10 deletions src/coinjoin/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1794,10 +1794,12 @@ bool CCoinJoinClientSession::SubmitDenominate(CConnman& connman)
WalletCJLogPrint(m_wallet, "vecInputsByRounds: rounds: %d, inputs: %d\n", pair.first, pair.second);
}

int nRounds = vecInputsByRounds.begin()->first;
if (PrepareDenominate(nRounds, nRounds, strError, vecTxDSIn, vecPSInOutPairsTmp)) {
WalletCJLogPrint(m_wallet, "CCoinJoinClientSession::SubmitDenominate -- Running CoinJoin denominate for %d rounds, success\n", nRounds);
return SendDenominate(vecPSInOutPairsTmp, connman);
if (!vecInputsByRounds.empty()) {
int nRounds = vecInputsByRounds.begin()->first;
if (PrepareDenominate(nRounds, nRounds, strError, vecTxDSIn, vecPSInOutPairsTmp)) {
WalletCJLogPrint(m_wallet, "CCoinJoinClientSession::SubmitDenominate -- Running CoinJoin denominate for %d rounds, success\n", nRounds);
return SendDenominate(vecPSInOutPairsTmp, connman);
}
}

// We failed? That's strange but let's just make final attempt and try to mix everything
Expand Down Expand Up @@ -2443,15 +2445,12 @@ void CCoinJoinClientManager::DoMaintenance(ChainstateManager& chainman, CConnman

if (!m_mn_sync.IsBlockchainSynced() || ShutdownRequested()) return;

static int nTick = 0;
static int nDoAutoNextRun = nTick + COINJOIN_AUTO_TIMEOUT_MIN;

nTick++;
m_tick++;
CheckTimeout();
ProcessPendingDsaRequest(connman);
if (nDoAutoNextRun == nTick) {
if (m_do_auto_next_run == m_tick) {
DoAutomaticDenominating(chainman, connman, mempool);
nDoAutoNextRun = nTick + COINJOIN_AUTO_TIMEOUT_MIN + GetRand<int>(/*nMax=*/COINJOIN_AUTO_TIMEOUT_MAX - COINJOIN_AUTO_TIMEOUT_MIN);
m_do_auto_next_run = m_tick + COINJOIN_AUTO_TIMEOUT_MIN + GetRand<int>(/*nMax=*/COINJOIN_AUTO_TIMEOUT_MAX - COINJOIN_AUTO_TIMEOUT_MIN);
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/coinjoin/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ class CCoinJoinClientManager : public interfaces::CoinJoin::Client
// Keep track of current block height
int nCachedBlockHeight{0};

int m_tick{0};
int m_do_auto_next_run{COINJOIN_AUTO_TIMEOUT_MIN};

bool fCreateAutoBackups{true}; // builtin support for automatic backups

bool WaitForAnotherBlock() const;
Expand Down
33 changes: 33 additions & 0 deletions src/wallet/test/coinjoin_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,39 @@ class CTransactionBuilderTestSetup : public TestChain100Setup
}
};

BOOST_FIXTURE_TEST_CASE(coinjoin_maintenance_runs_for_every_wallet, CTransactionBuilderTestSetup)
{
struct RestoreOptions {
const bool enabled{CCoinJoinClientOptions::IsEnabled()};
const int backups{nWalletBackups};
~RestoreOptions()
{
CCoinJoinClientOptions::SetEnabled(enabled);
nWalletBackups = backups;
}
} restore_options;
CCoinJoinClientOptions::SetEnabled(true);
nWalletBackups = 0;
m_node.mn_sync->SwitchToNextAsset();
BOOST_REQUIRE(m_node.mn_sync->IsBlockchainSynced());

auto other_wallet{std::make_shared<CWallet>(m_node.chain.get(), "other", CreateMockableWalletDatabase())};
other_wallet->SetupLegacyScriptPubKeyMan();
CCoinJoinClientManager first(wallet, *m_node.dmnman, *m_node.mn_metaman, *m_node.mn_sync, *m_node.isman, nullptr);
CCoinJoinClientManager second(other_wallet, *m_node.dmnman, *m_node.mn_metaman, *m_node.mn_sync, *m_node.isman, nullptr);
BOOST_REQUIRE(first.startMixing());
BOOST_REQUIRE(second.startMixing());
for (int tick{0}; tick < COINJOIN_AUTO_TIMEOUT_MIN; ++tick) {
BOOST_CHECK(first.isMixing());
BOOST_CHECK(second.isMixing());
first.DoMaintenance(*m_node.chainman, *m_node.connman, *m_node.mempool);
second.DoMaintenance(*m_node.chainman, *m_node.connman, *m_node.mempool);
}
// Each wallet's first automatic attempt stops mixing when automatic backups are disabled.
BOOST_CHECK(!first.isMixing());
BOOST_CHECK(!second.isMixing());
}

BOOST_FIXTURE_TEST_CASE(coinjoin_pending_observation_tests, CTransactionBuilderTestSetup)
{
// 0.100001 DASH, a valid CoinJoin denomination
Expand Down
Loading