Skip to content

Commit a5d87d6

Browse files
avoid duplicated HasChainLock block
1 parent 8bdb71d commit a5d87d6

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed

src/instantsend/instantsend.cpp

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -386,36 +386,28 @@ MessageProcessingResult CInstantSendManager::ProcessInstantSendLock(NodeId from,
386386

387387
uint256 hashBlock{};
388388
const auto tx = GetTransaction(nullptr, &mempool, islock->txid, Params().GetConsensus(), hashBlock);
389-
const CBlockIndex* pindexMined{nullptr};
390389
const bool found_transaction{tx != nullptr};
391390
// we ignore failure here as we must be able to propagate the lock even if we don't have the TX locally
392391
int minedHeight{-1};
393392
if (found_transaction && !hashBlock.IsNull()) {
394393
if (auto h = GetBlockHeight(hashBlock)) {
395394
minedHeight = *h;
396-
// Let's see if the TX that was locked by this islock is already mined in a ChainLocked block. If yes,
397-
// we can simply ignore the islock, as the ChainLock implies locking of all TXs in that chain
398-
if (clhandler.HasChainLock(minedHeight, hashBlock)) {
399-
LogPrint(BCLog::INSTANTSEND, /* Continued */
400-
"CInstantSendManager::%s -- txlock=%s, islock=%s: dropping islock as it already got a " /* Continued */
401-
"ChainLock in block %s, peer=%d\n",
402-
__func__, islock->txid.ToString(), hash.ToString(), hashBlock.ToString(), from);
403-
return {};
404-
}
405395
} else {
406-
pindexMined = WITH_LOCK(::cs_main, return m_chainstate.m_blockman.LookupBlockIndex(hashBlock));
396+
const CBlockIndex* pindexMined = WITH_LOCK(::cs_main, return m_chainstate.m_blockman.LookupBlockIndex(hashBlock));
407397
if (pindexMined != nullptr) {
408398
CacheBlockHeight(pindexMined->GetBlockHash(), pindexMined->nHeight);
409399
minedHeight = pindexMined->nHeight;
410-
if (clhandler.HasChainLock(minedHeight, pindexMined->GetBlockHash())) {
411-
LogPrint(BCLog::INSTANTSEND, /* Continued */
412-
"CInstantSendManager::%s -- txlock=%s, islock=%s: dropping islock as it already got a " /* Continued */
413-
"ChainLock in block %s, peer=%d\n",
414-
__func__, islock->txid.ToString(), hash.ToString(), hashBlock.ToString(), from);
415-
return {};
416-
}
417400
}
418401
}
402+
// Let's see if the TX that was locked by this islock is already mined in a ChainLocked block. If yes,
403+
// we can simply ignore the islock, as the ChainLock implies locking of all TXs in that chain
404+
if (clhandler.HasChainLock(minedHeight, hashBlock)) {
405+
LogPrint(BCLog::INSTANTSEND, /* Continued */
406+
"CInstantSendManager::%s -- txlock=%s, islock=%s: dropping islock as it already got a " /* Continued */
407+
"ChainLock in block %s, peer=%d\n",
408+
__func__, islock->txid.ToString(), hash.ToString(), hashBlock.ToString(), from);
409+
return {};
410+
}
419411
}
420412

421413
if (found_transaction) {

0 commit comments

Comments
 (0)