Skip to content

Commit 0f06b15

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 928e215 commit 0f06b15

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
@@ -420,7 +420,7 @@ void CInstantSendManager::ProcessInstantSendLock(NodeId from, PeerManager& peerm
420420
ResolveBlockConflicts(hash, *islock);
421421

422422
if (tx != nullptr) {
423-
RemoveMempoolConflictsForLock(peerman, hash, *islock);
423+
RemoveMempoolConflictsForLock(hash, *islock);
424424
LogPrint(BCLog::INSTANTSEND, "CInstantSendManager::%s -- notify about lock %s for tx %s\n", __func__,
425425
hash.ToString(), tx->GetHash().ToString());
426426
GetMainSignals().NotifyTransactionLock(tx, islock);
@@ -431,7 +431,7 @@ void CInstantSendManager::ProcessInstantSendLock(NodeId from, PeerManager& peerm
431431
}
432432
}
433433

434-
void CInstantSendManager::TransactionAddedToMempool(PeerManager& peerman, const CTransactionRef& tx)
434+
void CInstantSendManager::TransactionAddedToMempool(const CTransactionRef& tx)
435435
{
436436
if (!IsInstantSendEnabled() || !m_mn_sync.IsBlockchainSynced() || tx->vin.empty()) {
437437
return;
@@ -462,7 +462,7 @@ void CInstantSendManager::TransactionAddedToMempool(PeerManager& peerman, const
462462
// TX is not locked, so make sure it is tracked
463463
AddNonLockedTx(tx, nullptr);
464464
} else {
465-
RemoveMempoolConflictsForLock(peerman, ::SerializeHash(*islock), *islock);
465+
RemoveMempoolConflictsForLock(::SerializeHash(*islock), *islock);
466466
}
467467
}
468468

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

694-
void CInstantSendManager::RemoveMempoolConflictsForLock(PeerManager& peerman, const uint256& hash,
695-
const CInstantSendLock& islock)
694+
void CInstantSendManager::RemoveMempoolConflictsForLock(const uint256& hash, const CInstantSendLock& 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_activeman != 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
@@ -116,7 +116,7 @@ class CInstantSendManager
116116
EXCLUSIVE_LOCKS_REQUIRED(!cs_nonLocked, !cs_pendingRetry);
117117
void TruncateRecoveredSigsForInputs(const CInstantSendLock& islock);
118118

119-
void RemoveMempoolConflictsForLock(PeerManager& peerman, const uint256& hash, const CInstantSendLock& islock)
119+
void RemoveMempoolConflictsForLock(const uint256& hash, const CInstantSendLock& islock)
120120
EXCLUSIVE_LOCKS_REQUIRED(!cs_nonLocked, !cs_pendingRetry);
121121
void ResolveBlockConflicts(const uint256& islockHash, const CInstantSendLock& islock)
122122
EXCLUSIVE_LOCKS_REQUIRED(!cs_nonLocked, !cs_pendingLocks, !cs_pendingRetry);
@@ -134,7 +134,7 @@ class CInstantSendManager
134134

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

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

0 commit comments

Comments
 (0)