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
630 changes: 317 additions & 313 deletions src/privatesend-client.cpp

Large diffs are not rendered by default.

64 changes: 34 additions & 30 deletions src/privatesend-client.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,35 @@
#define PRIVATESENDCLIENT_H

#include "masternode.h"
#include "privatesend-util.h"
#include "privatesend.h"
#include "wallet/wallet.h"
#include "privatesend-util.h"

class CPrivateSendClientManager;
class CConnman;

static const int DENOMS_COUNT_MAX = 100;
static const int DENOMS_COUNT_MAX = 100;

static const int MIN_PRIVATESEND_SESSIONS = 1;
static const int MIN_PRIVATESEND_ROUNDS = 2;
static const int MIN_PRIVATESEND_AMOUNT = 2;
static const int MIN_PRIVATESEND_LIQUIDITY = 0;
static const int MAX_PRIVATESEND_SESSIONS = 10;
static const int MAX_PRIVATESEND_ROUNDS = 16;
static const int MAX_PRIVATESEND_AMOUNT = MAX_MONEY / COIN;
static const int MAX_PRIVATESEND_LIQUIDITY = 100;
static const int DEFAULT_PRIVATESEND_SESSIONS = 4;
static const int DEFAULT_PRIVATESEND_ROUNDS = 4;
static const int DEFAULT_PRIVATESEND_AMOUNT = 1000;
static const int DEFAULT_PRIVATESEND_LIQUIDITY = 0;
static const int MIN_PRIVATESEND_SESSIONS = 1;
static const int MIN_PRIVATESEND_ROUNDS = 2;
static const int MIN_PRIVATESEND_AMOUNT = 2;
static const int MIN_PRIVATESEND_LIQUIDITY = 0;
static const int MAX_PRIVATESEND_SESSIONS = 10;
static const int MAX_PRIVATESEND_ROUNDS = 16;
static const int MAX_PRIVATESEND_AMOUNT = MAX_MONEY / COIN;
static const int MAX_PRIVATESEND_LIQUIDITY = 100;
static const int DEFAULT_PRIVATESEND_SESSIONS = 4;
static const int DEFAULT_PRIVATESEND_ROUNDS = 4;
static const int DEFAULT_PRIVATESEND_AMOUNT = 1000;
static const int DEFAULT_PRIVATESEND_LIQUIDITY = 0;

static const bool DEFAULT_PRIVATESEND_MULTISESSION = false;
static const bool DEFAULT_PRIVATESEND_MULTISESSION = false;

// Warn user if mixing in gui or try to create backup if mixing in daemon mode
// when we have only this many keys left
static const int PRIVATESEND_KEYS_THRESHOLD_WARNING = 100;
// Stop mixing completely, it's too dangerous to continue when we have only this many keys left
static const int PRIVATESEND_KEYS_THRESHOLD_STOP = 50;
static const int PRIVATESEND_KEYS_THRESHOLD_STOP = 50;

// The main object for accessing mixing
extern CPrivateSendClientManager privateSendClient;
Expand All @@ -49,17 +49,19 @@ class CPendingDsaRequest
int64_t nTimeCreated;

public:
CPendingDsaRequest():
CPendingDsaRequest() :
addr(CService()),
dsa(CPrivateSendAccept()),
nTimeCreated(0)
{}
{
}

CPendingDsaRequest(const CService& addr_, const CPrivateSendAccept& dsa_):
CPendingDsaRequest(const CService& addr_, const CPrivateSendAccept& dsa_) :
addr(addr_),
dsa(dsa_),
nTimeCreated(GetTime())
{}
{
}

CService GetAddr() { return addr; }
CPrivateSendAccept GetDSA() { return dsa; }
Expand Down Expand Up @@ -108,14 +110,14 @@ class CPrivateSendClientSession : public CPrivateSendBaseSession
bool StartNewQueue(CAmount nValueMin, CAmount nBalanceNeedsAnonymized, CConnman& connman);

/// step 0: select denominated inputs and txouts
bool SelectDenominate(std::string& strErrorRet, std::vector< std::pair<CTxDSIn, CTxOut> >& vecPSInOutPairsRet);
bool SelectDenominate(std::string& strErrorRet, std::vector<std::pair<CTxDSIn, CTxOut> >& vecPSInOutPairsRet);
/// step 1: prepare denominated inputs and outputs
bool PrepareDenominate(int nMinRounds, int nMaxRounds, std::string& strErrorRet, const std::vector< std::pair<CTxDSIn, CTxOut> >& vecPSInOutPairsIn, std::vector< std::pair<CTxDSIn, CTxOut> >& vecPSInOutPairsRet, bool fDryRun = false);
bool PrepareDenominate(int nMinRounds, int nMaxRounds, std::string& strErrorRet, const std::vector<std::pair<CTxDSIn, CTxOut> >& vecPSInOutPairsIn, std::vector<std::pair<CTxDSIn, CTxOut> >& vecPSInOutPairsRet, bool fDryRun = false);
/// step 2: send denominated inputs and outputs prepared in step 1
bool SendDenominate(const std::vector< std::pair<CTxDSIn, CTxOut> >& vecPSInOutPairsIn, CConnman& connman);
bool SendDenominate(const std::vector<std::pair<CTxDSIn, CTxOut> >& vecPSInOutPairsIn, CConnman& connman);

/// Get Masternode updates about the progress of mixing
bool CheckPoolStateUpdate(PoolState nStateNew, int nEntriesCountNew, PoolStatusUpdate nStatusUpdate, PoolMessage nMessageID, int nSessionIDNew=0);
bool CheckPoolStateUpdate(PoolState nStateNew, int nEntriesCountNew, PoolStatusUpdate nStatusUpdate, PoolMessage nMessageID, int nSessionIDNew = 0);
// Set the 'state' value, with some logging and capturing when the state changed
void SetState(PoolState nStateNew);

Expand All @@ -141,7 +143,8 @@ class CPrivateSendClientSession : public CPrivateSendBaseSession
txMyCollateral(),
pendingDsaRequest(),
keyHolderStorage()
{}
{
}

void ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStream& vRecv, CConnman& connman);

Expand All @@ -154,7 +157,7 @@ class CPrivateSendClientSession : public CPrivateSendBaseSession
bool GetMixingMasternodeInfo(masternode_info_t& mnInfoRet) const;

/// Passively run mixing in the background according to the configuration in settings
bool DoAutomaticDenominating(CConnman& connman, bool fDryRun=false);
bool DoAutomaticDenominating(CConnman& connman, bool fDryRun = false);

/// 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 @@ -198,7 +201,7 @@ class CPrivateSendClientManager : public CPrivateSendBaseManager
bool fEnablePrivateSend;
bool fPrivateSendMultiSession;

int nCachedNumBlocks; //used for the overview screen
int nCachedNumBlocks; //used for the overview screen
bool fCreateAutoBackups; //builtin support for automatic backups

CPrivateSendClientManager() :
Expand All @@ -216,7 +219,8 @@ class CPrivateSendClientManager : public CPrivateSendBaseManager
fPrivateSendMultiSession(DEFAULT_PRIVATESEND_MULTISESSION),
nCachedNumBlocks(std::numeric_limits<int>::max()),
fCreateAutoBackups(true)
{}
{
}

void ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStream& vRecv, CConnman& connman);

Expand All @@ -234,7 +238,7 @@ class CPrivateSendClientManager : public CPrivateSendBaseManager
bool GetMixingMasternodesInfo(std::vector<masternode_info_t>& vecMnInfoRet) const;

/// Passively run mixing in the background according to the configuration in settings
bool DoAutomaticDenominating(CConnman& connman, bool fDryRun=false);
bool DoAutomaticDenominating(CConnman& connman, bool fDryRun = false);

void CheckTimeout();

Expand All @@ -245,7 +249,7 @@ class CPrivateSendClientManager : public CPrivateSendBaseManager

void UpdatedSuccessBlock();

void UpdatedBlockTip(const CBlockIndex *pindex);
void UpdatedBlockTip(const CBlockIndex* pindex);

void DoMaintenance(CConnman& connman);
};
Expand Down
Loading