From bdec34c949bf564d1ff0e53d4b44da5a5ebfa204 Mon Sep 17 00:00:00 2001 From: PastaPastaPasta Date: Sat, 6 Jul 2019 17:07:03 -0500 Subject: [PATCH] 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 * Use multiple if checks instead of one line conditional Signed-off-by: Pasta --- src/privatesend/privatesend.cpp | 15 +++++++++------ src/privatesend/privatesend.h | 4 ++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/privatesend/privatesend.cpp b/src/privatesend/privatesend.cpp index 30c694eaa..c02f19385 100644 --- a/src/privatesend/privatesend.cpp +++ b/src/privatesend/privatesend.cpp @@ -17,6 +17,7 @@ #include "validation.h" #include "llmq/quorums_instantsend.h" +#include "llmq/quorums_chainlocks.h" #include @@ -115,10 +116,12 @@ bool CPrivateSendBroadcastTx::CheckSignature(const CBLSPublicKey& blsPubKey) con return true; } -bool CPrivateSendBroadcastTx::IsExpired(int nHeight) +bool CPrivateSendBroadcastTx::IsExpired(const CBlockIndex* pindex) { - // expire confirmed DSTXes after ~1h since confirmation - return (nConfirmedHeight != -1) && (nHeight - nConfirmedHeight > 24); + // expire confirmed DSTXes after ~1h since confirmation or chainlocked confirmation + 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() @@ -487,12 +490,12 @@ CPrivateSendBroadcastTx CPrivateSend::GetDSTX(const uint256& hash) return (it == mapDSTX.end()) ? CPrivateSendBroadcastTx() : it->second; } -void CPrivateSend::CheckDSTXes(int nHeight) +void CPrivateSend::CheckDSTXes(const CBlockIndex* pindex) { LOCK(cs_mapdstx); auto it = mapDSTX.begin(); while (it != mapDSTX.end()) { - if (it->second.IsExpired(nHeight)) { + if (it->second.IsExpired(pindex)) { mapDSTX.erase(it++); } else { ++it; @@ -504,7 +507,7 @@ void CPrivateSend::CheckDSTXes(int nHeight) void CPrivateSend::UpdatedBlockTip(const CBlockIndex* pindex) { if (pindex && masternodeSync.IsBlockchainSynced()) { - CheckDSTXes(pindex->nHeight); + CheckDSTXes(pindex); } } diff --git a/src/privatesend/privatesend.h b/src/privatesend/privatesend.h index 5a2872bcd..95e22e74e 100644 --- a/src/privatesend/privatesend.h +++ b/src/privatesend/privatesend.h @@ -351,7 +351,7 @@ public: bool CheckSignature(const CBLSPublicKey& blsPubKey) const; void SetConfirmedHeight(int nConfirmedHeightIn) { nConfirmedHeight = nConfirmedHeightIn; } - bool IsExpired(int nHeight); + bool IsExpired(const CBlockIndex* pindex); bool IsValidStructure(); }; @@ -427,7 +427,7 @@ private: static CCriticalSection cs_mapdstx; - static void CheckDSTXes(int nHeight); + static void CheckDSTXes(const CBlockIndex* pindex); public: static void InitStandardDenominations();