remove DS mixes once they have been included in a chainlocked block (#3015)

* remove DS mixes once they have been included in a chainlocked block

Signed-off-by: Pasta <pasta@dashboost.org>

* Use multiple if checks instead of one line conditional

Signed-off-by: Pasta <pasta@dashboost.org>
This commit is contained in:
PastaPastaPasta 2019-07-06 17:07:03 -05:00 committed by UdjinM6
parent 54ab2048ca
commit bdec34c949
2 changed files with 11 additions and 8 deletions

View File

@ -17,6 +17,7 @@
#include "validation.h" #include "validation.h"
#include "llmq/quorums_instantsend.h" #include "llmq/quorums_instantsend.h"
#include "llmq/quorums_chainlocks.h"
#include <string> #include <string>
@ -115,10 +116,12 @@ bool CPrivateSendBroadcastTx::CheckSignature(const CBLSPublicKey& blsPubKey) con
return true; return true;
} }
bool CPrivateSendBroadcastTx::IsExpired(int nHeight) bool CPrivateSendBroadcastTx::IsExpired(const CBlockIndex* pindex)
{ {
// expire confirmed DSTXes after ~1h since confirmation // expire confirmed DSTXes after ~1h since confirmation or chainlocked confirmation
return (nConfirmedHeight != -1) && (nHeight - nConfirmedHeight > 24); if (nConfirmedHeight == -1 || pindex->nHeight < nConfirmedHeight) return false; // not mined yet
if (pindex->nHeight - nConfirmedHeight > 24) return true; // mined more then an hour ago
return llmq::chainLocksHandler->HasChainLock(pindex->nHeight, *pindex->phashBlock);
} }
bool CPrivateSendBroadcastTx::IsValidStructure() bool CPrivateSendBroadcastTx::IsValidStructure()
@ -487,12 +490,12 @@ CPrivateSendBroadcastTx CPrivateSend::GetDSTX(const uint256& hash)
return (it == mapDSTX.end()) ? CPrivateSendBroadcastTx() : it->second; return (it == mapDSTX.end()) ? CPrivateSendBroadcastTx() : it->second;
} }
void CPrivateSend::CheckDSTXes(int nHeight) void CPrivateSend::CheckDSTXes(const CBlockIndex* pindex)
{ {
LOCK(cs_mapdstx); LOCK(cs_mapdstx);
auto it = mapDSTX.begin(); auto it = mapDSTX.begin();
while (it != mapDSTX.end()) { while (it != mapDSTX.end()) {
if (it->second.IsExpired(nHeight)) { if (it->second.IsExpired(pindex)) {
mapDSTX.erase(it++); mapDSTX.erase(it++);
} else { } else {
++it; ++it;
@ -504,7 +507,7 @@ void CPrivateSend::CheckDSTXes(int nHeight)
void CPrivateSend::UpdatedBlockTip(const CBlockIndex* pindex) void CPrivateSend::UpdatedBlockTip(const CBlockIndex* pindex)
{ {
if (pindex && masternodeSync.IsBlockchainSynced()) { if (pindex && masternodeSync.IsBlockchainSynced()) {
CheckDSTXes(pindex->nHeight); CheckDSTXes(pindex);
} }
} }

View File

@ -351,7 +351,7 @@ public:
bool CheckSignature(const CBLSPublicKey& blsPubKey) const; bool CheckSignature(const CBLSPublicKey& blsPubKey) const;
void SetConfirmedHeight(int nConfirmedHeightIn) { nConfirmedHeight = nConfirmedHeightIn; } void SetConfirmedHeight(int nConfirmedHeightIn) { nConfirmedHeight = nConfirmedHeightIn; }
bool IsExpired(int nHeight); bool IsExpired(const CBlockIndex* pindex);
bool IsValidStructure(); bool IsValidStructure();
}; };
@ -427,7 +427,7 @@ private:
static CCriticalSection cs_mapdstx; static CCriticalSection cs_mapdstx;
static void CheckDSTXes(int nHeight); static void CheckDSTXes(const CBlockIndex* pindex);
public: public:
static void InitStandardDenominations(); static void InitStandardDenominations();