Skip to content

Commit bdec34c

Browse files
PastaPastaPastaUdjinM6
authored andcommitted
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>
1 parent 54ab204 commit bdec34c

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

src/privatesend/privatesend.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "validation.h"
1818

1919
#include "llmq/quorums_instantsend.h"
20+
#include "llmq/quorums_chainlocks.h"
2021

2122
#include <string>
2223

@@ -115,10 +116,12 @@ bool CPrivateSendBroadcastTx::CheckSignature(const CBLSPublicKey& blsPubKey) con
115116
return true;
116117
}
117118

118-
bool CPrivateSendBroadcastTx::IsExpired(int nHeight)
119+
bool CPrivateSendBroadcastTx::IsExpired(const CBlockIndex* pindex)
119120
{
120-
// expire confirmed DSTXes after ~1h since confirmation
121-
return (nConfirmedHeight != -1) && (nHeight - nConfirmedHeight > 24);
121+
// expire confirmed DSTXes after ~1h since confirmation or chainlocked confirmation
122+
if (nConfirmedHeight == -1 || pindex->nHeight < nConfirmedHeight) return false; // not mined yet
123+
if (pindex->nHeight - nConfirmedHeight > 24) return true; // mined more then an hour ago
124+
return llmq::chainLocksHandler->HasChainLock(pindex->nHeight, *pindex->phashBlock);
122125
}
123126

124127
bool CPrivateSendBroadcastTx::IsValidStructure()
@@ -487,12 +490,12 @@ CPrivateSendBroadcastTx CPrivateSend::GetDSTX(const uint256& hash)
487490
return (it == mapDSTX.end()) ? CPrivateSendBroadcastTx() : it->second;
488491
}
489492

490-
void CPrivateSend::CheckDSTXes(int nHeight)
493+
void CPrivateSend::CheckDSTXes(const CBlockIndex* pindex)
491494
{
492495
LOCK(cs_mapdstx);
493496
auto it = mapDSTX.begin();
494497
while (it != mapDSTX.end()) {
495-
if (it->second.IsExpired(nHeight)) {
498+
if (it->second.IsExpired(pindex)) {
496499
mapDSTX.erase(it++);
497500
} else {
498501
++it;
@@ -504,7 +507,7 @@ void CPrivateSend::CheckDSTXes(int nHeight)
504507
void CPrivateSend::UpdatedBlockTip(const CBlockIndex* pindex)
505508
{
506509
if (pindex && masternodeSync.IsBlockchainSynced()) {
507-
CheckDSTXes(pindex->nHeight);
510+
CheckDSTXes(pindex);
508511
}
509512
}
510513

src/privatesend/privatesend.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ class CPrivateSendBroadcastTx
351351
bool CheckSignature(const CBLSPublicKey& blsPubKey) const;
352352

353353
void SetConfirmedHeight(int nConfirmedHeightIn) { nConfirmedHeight = nConfirmedHeightIn; }
354-
bool IsExpired(int nHeight);
354+
bool IsExpired(const CBlockIndex* pindex);
355355
bool IsValidStructure();
356356
};
357357

@@ -427,7 +427,7 @@ class CPrivateSend
427427

428428
static CCriticalSection cs_mapdstx;
429429

430-
static void CheckDSTXes(int nHeight);
430+
static void CheckDSTXes(const CBlockIndex* pindex);
431431

432432
public:
433433
static void InitStandardDenominations();

0 commit comments

Comments
 (0)