Skip to content

Commit d85b40c

Browse files
committed
fix: remove unnecessary tx fetching in RemoveMempoolConflictsForLock
`RemoveMempoolConflictsForLock` is called in two instances * `ProcessInstantSendLock` when we *have* a valid transaction (tx != nullptr) and want to purge conflicting transactions * `TransactionAddedToMempool` when we have received a transaction and found the corresponding lock (else condition to `islock == nullptr`), and want to purge conflicting transactions Neither case calls for fetching the transaction based on the islock hash since in both cases, we already have the transaction
1 parent 8031058 commit d85b40c

File tree

3 files changed

+9
-13
lines changed

3 files changed

+9
-13
lines changed

src/dsnotificationinterface.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ void CDSNotificationInterface::TransactionAddedToMempool(const CTransactionRef&
106106
{
107107
assert(m_cj_ctx && m_llmq_ctx);
108108

109-
m_llmq_ctx->isman->TransactionAddedToMempool(m_peerman, ptx);
109+
m_llmq_ctx->isman->TransactionAddedToMempool(ptx);
110110
m_llmq_ctx->clhandler->TransactionAddedToMempool(ptx, nAcceptTime);
111111
m_cj_ctx->dstxman->TransactionAddedToMempool(ptx);
112112
}

src/instantsend/instantsend.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ void CInstantSendManager::ProcessInstantSendLock(NodeId from, PeerManager& peerm
409409
ResolveBlockConflicts(hash, *islock);
410410

411411
if (found_transaction) {
412-
RemoveMempoolConflictsForLock(peerman, hash, *islock);
412+
RemoveMempoolConflictsForLock(hash, *islock);
413413
LogPrint(BCLog::INSTANTSEND, "CInstantSendManager::%s -- notify about lock %s for tx %s\n", __func__,
414414
hash.ToString(), tx->GetHash().ToString());
415415
GetMainSignals().NotifyTransactionLock(tx, islock);
@@ -428,7 +428,7 @@ void CInstantSendManager::ProcessInstantSendLock(NodeId from, PeerManager& peerm
428428
}
429429
}
430430

431-
void CInstantSendManager::TransactionAddedToMempool(PeerManager& peerman, const CTransactionRef& tx)
431+
void CInstantSendManager::TransactionAddedToMempool(const CTransactionRef& tx)
432432
{
433433
if (!IsInstantSendEnabled() || !m_mn_sync.IsBlockchainSynced() || tx->vin.empty()) {
434434
return;
@@ -459,7 +459,7 @@ void CInstantSendManager::TransactionAddedToMempool(PeerManager& peerman, const
459459
// TX is not locked, so make sure it is tracked
460460
AddNonLockedTx(tx, nullptr);
461461
} else {
462-
RemoveMempoolConflictsForLock(peerman, ::SerializeHash(*islock), *islock);
462+
RemoveMempoolConflictsForLock(::SerializeHash(*islock), *islock);
463463
}
464464
}
465465

@@ -691,8 +691,7 @@ void CInstantSendManager::HandleFullyConfirmedBlock(const CBlockIndex* pindex)
691691
}
692692
}
693693

694-
void CInstantSendManager::RemoveMempoolConflictsForLock(PeerManager& peerman, const uint256& hash,
695-
const instantsend::InstantSendLock& islock)
694+
void CInstantSendManager::RemoveMempoolConflictsForLock(const uint256& hash, const instantsend::InstantSendLock& islock)
696695
{
697696
std::unordered_map<uint256, CTransactionRef, StaticSaltedHasher> toDelete;
698697

@@ -717,11 +716,8 @@ void CInstantSendManager::RemoveMempoolConflictsForLock(PeerManager& peerman, co
717716
}
718717
}
719718

720-
if (!toDelete.empty()) {
721-
for (const auto& p : toDelete) {
722-
RemoveConflictedTx(*p.second);
723-
}
724-
peerman.AskPeersForTransaction(islock.txid, /*is_masternode=*/m_signer != nullptr);
719+
for (const auto& p : toDelete) {
720+
RemoveConflictedTx(*p.second);
725721
}
726722
}
727723

src/instantsend/instantsend.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class CInstantSendManager final : public instantsend::InstantSendStorage
117117
EXCLUSIVE_LOCKS_REQUIRED(!cs_nonLocked, !cs_pendingRetry);
118118
void TruncateRecoveredSigsForInputs(const instantsend::InstantSendLock& islock);
119119

120-
void RemoveMempoolConflictsForLock(PeerManager& peerman, const uint256& hash, const instantsend::InstantSendLock& islock)
120+
void RemoveMempoolConflictsForLock(const uint256& hash, const instantsend::InstantSendLock& islock)
121121
EXCLUSIVE_LOCKS_REQUIRED(!cs_nonLocked, !cs_pendingRetry);
122122
void ResolveBlockConflicts(const uint256& islockHash, const instantsend::InstantSendLock& islock)
123123
EXCLUSIVE_LOCKS_REQUIRED(!cs_nonLocked, !cs_pendingLocks, !cs_pendingRetry);
@@ -135,7 +135,7 @@ class CInstantSendManager final : public instantsend::InstantSendStorage
135135

136136
PeerMsgRet ProcessMessage(const CNode& pfrom, PeerManager& peerman, std::string_view msg_type, CDataStream& vRecv);
137137

138-
void TransactionAddedToMempool(PeerManager& peerman, const CTransactionRef& tx)
138+
void TransactionAddedToMempool(const CTransactionRef& tx)
139139
EXCLUSIVE_LOCKS_REQUIRED(!cs_nonLocked, !cs_pendingLocks, !cs_pendingRetry);
140140
void TransactionRemovedFromMempool(const CTransactionRef& tx);
141141
void BlockConnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindex)

0 commit comments

Comments
 (0)