diff --git a/src/dsnotificationinterface.cpp b/src/dsnotificationinterface.cpp index 233961a469..fcaa04d724 100644 --- a/src/dsnotificationinterface.cpp +++ b/src/dsnotificationinterface.cpp @@ -75,13 +75,13 @@ void CDSNotificationInterface::UpdatedBlockTip(const CBlockIndex *pindexNew, con void CDSNotificationInterface::SyncTransaction(const CTransactionRef& tx, const CBlockIndex* pindex, int posInBlock) { instantsend.SyncTransaction(tx, pindex, posInBlock); - CPrivateSend::SyncTransaction(tx, pindex, posInBlock); } void CDSNotificationInterface::TransactionAddedToMempool(const CTransactionRef& ptx) { llmq::quorumInstantSendManager->TransactionAddedToMempool(ptx); llmq::chainLocksHandler->TransactionAddedToMempool(ptx); + CPrivateSend::TransactionAddedToMempool(ptx); SyncTransaction(ptx); } @@ -97,6 +97,7 @@ void CDSNotificationInterface::BlockConnected(const std::shared_ptrBlockConnected(pblock, pindex, vtxConflicted); llmq::chainLocksHandler->BlockConnected(pblock, pindex, vtxConflicted); + CPrivateSend::BlockConnected(pblock, pindex, vtxConflicted); for (const CTransactionRef& ptx : vtxConflicted) { SyncTransaction(ptx); @@ -110,6 +111,7 @@ void CDSNotificationInterface::BlockDisconnected(const std::shared_ptrBlockDisconnected(pblock, pindexDisconnected); llmq::chainLocksHandler->BlockDisconnected(pblock, pindexDisconnected); + CPrivateSend::BlockDisconnected(pblock, pindexDisconnected); for (const CTransactionRef& ptx : pblock->vtx) { SyncTransaction(ptx, pindexDisconnected->pprev, -1); diff --git a/src/privatesend/privatesend.cpp b/src/privatesend/privatesend.cpp index 8a7b9ffc01..ad7da69547 100644 --- a/src/privatesend/privatesend.cpp +++ b/src/privatesend/privatesend.cpp @@ -509,16 +509,39 @@ void CPrivateSend::UpdatedBlockTip(const CBlockIndex* pindex) } } -void CPrivateSend::SyncTransaction(const CTransactionRef& tx, const CBlockIndex* pindex, int posInBlock) +void CPrivateSend::UpdateDSTXConfirmedHeight(const CTransactionRef& tx, int nHeight) { - if (tx->IsCoinBase()) return; - - LOCK2(cs_main, cs_mapdstx); + AssertLockHeld(cs_mapdstx); uint256 txHash = tx->GetHash(); if (!mapDSTX.count(txHash)) return; - // When tx is 0-confirmed or conflicted, posInBlock is SYNC_TRANSACTION_NOT_IN_BLOCK and nConfirmedHeight should be set to -1 - mapDSTX[txHash].SetConfirmedHeight((posInBlock == -1 || pindex == nullptr) ? -1 : pindex->nHeight); - LogPrint(BCLog::PRIVATESEND, "CPrivateSend::SyncTransaction -- txid=%s\n", txHash.ToString()); + mapDSTX[txHash].SetConfirmedHeight(nHeight); + LogPrint(BCLog::PRIVATESEND, "CPrivateSend::%s -- txid=%s, nHeight=%d\n", __func__, txHash.ToString(), nHeight); +} + +void CPrivateSend::TransactionAddedToMempool(const CTransactionRef& tx) +{ + LOCK(cs_mapdstx); + UpdateDSTXConfirmedHeight(tx, -1); +} + +void CPrivateSend::BlockConnected(const std::shared_ptr& pblock, const CBlockIndex* pindex, const std::vector& vtxConflicted) +{ + LOCK(cs_mapdstx); + for (const auto& tx : vtxConflicted) { + UpdateDSTXConfirmedHeight(tx, -1); + } + + for (const auto& tx : pblock->vtx) { + UpdateDSTXConfirmedHeight(tx, pindex->nHeight); + } +} + +void CPrivateSend::BlockDisconnected(const std::shared_ptr& pblock, const CBlockIndex* pindexDisconnected) +{ + LOCK(cs_mapdstx); + for (const auto& tx : pblock->vtx) { + UpdateDSTXConfirmedHeight(tx, -1); + } } diff --git a/src/privatesend/privatesend.h b/src/privatesend/privatesend.h index 4ff8562779..0a0534b449 100644 --- a/src/privatesend/privatesend.h +++ b/src/privatesend/privatesend.h @@ -422,7 +422,12 @@ public: static CPrivateSendBroadcastTx GetDSTX(const uint256& hash); static void UpdatedBlockTip(const CBlockIndex* pindex); - static void SyncTransaction(const CTransactionRef& tx, const CBlockIndex* pindex = nullptr, int posInBlock = 0); + + static void UpdateDSTXConfirmedHeight(const CTransactionRef& tx, int nHeight); + static void TransactionAddedToMempool(const CTransactionRef& tx); + static void BlockConnected(const std::shared_ptr& pblock, const CBlockIndex* pindex, const std::vector& vtxConflicted); + static void BlockDisconnected(const std::shared_ptr& pblock, const CBlockIndex* pindexDisconnected); + }; #endif