LCOV - code coverage report
Current view: top level - src/coinjoin - options.h (source / functions) Hit Total Coverage
Test: test_dash_coverage.info Lines: 8 8 100.0 %
Date: 2026-06-25 07:23:51 Functions: 8 8 100.0 %

          Line data    Source code
       1             : // Copyright (c) 2021-2025 The Dash Core developers
       2             : // Distributed under the MIT/X11 software license, see the accompanying
       3             : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
       4             : 
       5             : #ifndef BITCOIN_COINJOIN_OPTIONS_H
       6             : #define BITCOIN_COINJOIN_OPTIONS_H
       7             : 
       8             : #include <consensus/amount.h>
       9             : 
      10             : #include <atomic>
      11             : #include <mutex>
      12             : 
      13             : // This header is used by both Wallet and Server libraries
      14             : class UniValue;
      15             : 
      16             : static constexpr int MIN_COINJOIN_SESSIONS = 1;
      17             : static constexpr int MIN_COINJOIN_ROUNDS = 2;
      18             : static constexpr int MIN_COINJOIN_AMOUNT = 2;
      19             : static constexpr int MIN_COINJOIN_DENOMS_GOAL = 10;
      20             : static constexpr int MIN_COINJOIN_DENOMS_HARDCAP = 10;
      21             : static constexpr int MAX_COINJOIN_SESSIONS = 10;
      22             : static constexpr int MAX_COINJOIN_ROUNDS = 16;
      23             : static constexpr int MAX_COINJOIN_DENOMS_GOAL = 100000;
      24             : static constexpr int MAX_COINJOIN_DENOMS_HARDCAP = 100000;
      25             : static constexpr int MAX_COINJOIN_AMOUNT = MAX_MONEY / COIN;
      26             : static constexpr int DEFAULT_COINJOIN_SESSIONS = 4;
      27             : static constexpr int DEFAULT_COINJOIN_ROUNDS = 4;
      28             : static constexpr int DEFAULT_COINJOIN_AMOUNT = 1000;
      29             : static constexpr int DEFAULT_COINJOIN_DENOMS_GOAL = 50;
      30             : static constexpr int DEFAULT_COINJOIN_DENOMS_HARDCAP = 300;
      31             : 
      32             : static constexpr bool DEFAULT_COINJOIN_AUTOSTART = false;
      33             : static constexpr bool DEFAULT_COINJOIN_MULTISESSION = false;
      34             : 
      35             : // How many new denom outputs to create before we consider the "goal" loop in CreateDenominated
      36             : // a final one and start creating an actual tx. Same limit applies for the "hard cap" part of the algo.
      37             : // NOTE: We do not allow txes larger than 100kB, so we have to limit the number of outputs here.
      38             : // We still want to create a lot of outputs though.
      39             : // Knowing that each CTxOut is ~35b big, 400 outputs should take 400 x ~35b = ~17.5kb.
      40             : // More than 500 outputs starts to make qt quite laggy.
      41             : // Additionally to need all 500 outputs (assuming a max per denom of 50) you'd need to be trying to
      42             : // create denominations for over 3000 dash!
      43             : static const int COINJOIN_DENOM_OUTPUTS_THRESHOLD = 500;
      44             : 
      45             : // Warn user if mixing in gui or try to create backup if mixing in daemon mode
      46             : // when we have only this many keys left
      47             : static constexpr int COINJOIN_KEYS_THRESHOLD_WARNING = 100;
      48             : // Stop mixing completely, it's too dangerous to continue when we have only this many keys left
      49             : static constexpr int COINJOIN_KEYS_THRESHOLD_STOP = 50;
      50             : // Pseudorandomly mix up to this many times in addition to base round count
      51             : static constexpr int COINJOIN_RANDOM_ROUNDS = 3;
      52             : 
      53             : /* Application wide mixing options */
      54             : class CCoinJoinClientOptions
      55             : {
      56             : public:
      57           1 :     static int GetSessions() { return CCoinJoinClientOptions::Get().nCoinJoinSessions; }
      58           2 :     static int GetRounds() { return CCoinJoinClientOptions::Get().nCoinJoinRounds; }
      59           1 :     static int GetRandomRounds() { return CCoinJoinClientOptions::Get().nCoinJoinRandomRounds; }
      60           2 :     static int GetAmount() { return CCoinJoinClientOptions::Get().nCoinJoinAmount; }
      61           1 :     static int GetDenomsGoal() { return CCoinJoinClientOptions::Get().nCoinJoinDenomsGoal; }
      62           1 :     static int GetDenomsHardCap() { return CCoinJoinClientOptions::Get().nCoinJoinDenomsHardCap; }
      63             : 
      64             :     static void SetEnabled(bool fEnabled);
      65             :     static void SetMultiSessionEnabled(bool fEnabled);
      66             :     static void SetSessions(int sessions);
      67             :     static void SetRounds(int nRounds);
      68             :     static void SetAmount(CAmount amount);
      69             :     static void SetDenomsGoal(int denoms_goal);
      70             :     static void SetDenomsHardCap(int denoms_hardcap);
      71             : 
      72          33 :     static bool IsEnabled() { return CCoinJoinClientOptions::Get().fEnableCoinJoin; }
      73           3 :     static bool IsMultiSessionEnabled() { return CCoinJoinClientOptions::Get().fCoinJoinMultiSession; }
      74             : 
      75             :     static void GetJsonInfo(UniValue& obj);
      76             : 
      77             : private:
      78             :     static CCoinJoinClientOptions* _instance;
      79             :     static std::once_flag onceFlag;
      80             : 
      81             :     std::atomic<int> nCoinJoinSessions{DEFAULT_COINJOIN_SESSIONS};
      82             :     std::atomic<int> nCoinJoinRounds{DEFAULT_COINJOIN_ROUNDS};
      83             :     std::atomic<int> nCoinJoinRandomRounds{COINJOIN_RANDOM_ROUNDS};
      84             :     std::atomic<int> nCoinJoinAmount{DEFAULT_COINJOIN_AMOUNT};
      85             :     std::atomic<int> nCoinJoinDenomsGoal{DEFAULT_COINJOIN_DENOMS_GOAL};
      86             :     std::atomic<int> nCoinJoinDenomsHardCap{DEFAULT_COINJOIN_DENOMS_HARDCAP};
      87             :     std::atomic<bool> fEnableCoinJoin{false};
      88             :     std::atomic<bool> fCoinJoinMultiSession{DEFAULT_COINJOIN_MULTISESSION};
      89             : 
      90             :     CCoinJoinClientOptions() = default;
      91             : 
      92             :     CCoinJoinClientOptions(const CCoinJoinClientOptions& other) = delete;
      93             :     CCoinJoinClientOptions& operator=(const CCoinJoinClientOptions&) = delete;
      94             : 
      95             :     static CCoinJoinClientOptions& Get();
      96             :     static void Init();
      97             : };
      98             : 
      99             : #endif // BITCOIN_COINJOIN_OPTIONS_H

Generated by: LCOV version 1.16