diff --git a/src/privatesend/privatesend.cpp b/src/privatesend/privatesend.cpp index 30c694eaab..c02f19385e 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 5a2872bcd0..95e22e74e3 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();