Skip to content

Commit

Permalink
fix number of blocks to wait after successful mixing tx (#1597)
Browse files Browse the repository at this point in the history
  • Loading branch information
UdjinM6 authored Sep 3, 2017
1 parent 4f0618a commit 82595b1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1911,7 +1911,10 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)


privateSendClient.nLiquidityProvider = std::min(std::max((int)GetArg("-liquidityprovider", DEFAULT_PRIVATESEND_LIQUIDITY), 0), 100);
privateSendClient.SetMinBlockSpacing(privateSendClient.nLiquidityProvider * 15);
if(privateSendClient.nLiquidityProvider) {
// special case for liquidity providers only, normal clients should use default value
privateSendClient.SetMinBlocksToWait(privateSendClient.nLiquidityProvider * 15);
}

privateSendClient.fEnablePrivateSend = GetBoolArg("-enableprivatesend", false);
privateSendClient.fPrivateSendMultiSession = GetBoolArg("-privatesendmultisession", DEFAULT_PRIVATESEND_MULTISESSION);
Expand Down
14 changes: 12 additions & 2 deletions src/privatesend-client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ std::string CPrivateSendClient::GetStatus()
nStatusMessageProgress += 10;
std::string strSuffix = "";

if((nCachedBlockHeight - nCachedLastSuccessBlock < nMinBlockSpacing) || !masternodeSync.IsBlockchainSynced())
if(WaitForAnotherBlock() || !masternodeSync.IsBlockchainSynced())
return strAutoDenomResult;

switch(nState) {
Expand Down Expand Up @@ -587,6 +587,16 @@ void CPrivateSendClient::CompletedTransaction(PoolMessage nMessageID)
strLastMessage = CPrivateSend::GetMessageByID(nMessageID);
}

bool CPrivateSendClient::WaitForAnotherBlock()
{
if(!masternodeSync.IsMasternodeListSynced())
return true;

if(fPrivateSendMultiSession)
return false;

return nCachedBlockHeight - nCachedLastSuccessBlock < nMinBlocksToWait;
}

bool CPrivateSendClient::CheckAutomaticBackup()
{
Expand Down Expand Up @@ -687,7 +697,7 @@ bool CPrivateSendClient::DoAutomaticDenominating(CConnman& connman, bool fDryRun
return false;
}

if(!fPrivateSendMultiSession && nCachedBlockHeight - nCachedLastSuccessBlock < nMinBlockSpacing) {
if(WaitForAnotherBlock()) {
LogPrintf("CPrivateSendClient::DoAutomaticDenominating -- Last successful PrivateSend action was too recent\n");
strAutoDenomResult = _("Last successful PrivateSend action was too recent.");
return false;
Expand Down
8 changes: 5 additions & 3 deletions src/privatesend-client.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class CPrivateSendClient : public CPrivateSendBase
std::vector<COutPoint> vecOutPointLocked;

int nCachedLastSuccessBlock;
int nMinBlockSpacing; //required blocks between mixes
int nMinBlocksToWait; // how many blocks to wait after one successful mixing tx in non-multisession mode

// Keep track of current block height
int nCachedBlockHeight;
Expand All @@ -63,6 +63,8 @@ class CPrivateSendClient : public CPrivateSendBase
return std::find(vecDenominationsSkipped.begin(), vecDenominationsSkipped.end(), nDenomValue) != vecDenominationsSkipped.end();
}

bool WaitForAnotherBlock();

// Make sure we have enough keys since last backup
bool CheckAutomaticBackup();
bool JoinExistingQueue(CAmount nBalanceNeedsAnonymized);
Expand Down Expand Up @@ -108,7 +110,7 @@ class CPrivateSendClient : public CPrivateSendBase

CPrivateSendClient() :
nCachedLastSuccessBlock(0),
nMinBlockSpacing(0),
nMinBlocksToWait(1),
txMyCollateral(CMutableTransaction()),
nPrivateSendRounds(DEFAULT_PRIVATESEND_ROUNDS),
nPrivateSendAmount(DEFAULT_PRIVATESEND_AMOUNT),
Expand All @@ -122,7 +124,7 @@ class CPrivateSendClient : public CPrivateSendBase

void ClearSkippedDenominations() { vecDenominationsSkipped.clear(); }

void SetMinBlockSpacing(int nMinBlockSpacingIn) { nMinBlockSpacing = nMinBlockSpacingIn; }
void SetMinBlocksToWait(int nMinBlocksToWaitIn) { nMinBlocksToWait = nMinBlocksToWaitIn; }

void ResetPool();

Expand Down

0 comments on commit 82595b1

Please sign in to comment.