Skip to content

Commit b4aefb5

Browse files
codablockUdjinM6
authored andcommitted
Also consider txindex for transactions in AlreadyHave() (#3126)
This avoids many false negatives where TXs are announced to us which are already mined and then were spent later.
1 parent d9e98e3 commit b4aefb5

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

src/net_processing.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "reverse_iterator.h"
2626
#include "scheduler.h"
2727
#include "tinyformat.h"
28+
#include "txdb.h"
2829
#include "txmempool.h"
2930
#include "ui_interface.h"
3031
#include "util.h"
@@ -1019,7 +1020,8 @@ bool static AlreadyHave(const CInv& inv) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
10191020
return (recentRejects->contains(inv.hash) && !llmq::quorumInstantSendManager->IsLocked(inv.hash)) ||
10201021
mempool.exists(inv.hash) ||
10211022
pcoinsTip->HaveCoinInCache(COutPoint(inv.hash, 0)) || // Best effort: only try output 0 and 1
1022-
pcoinsTip->HaveCoinInCache(COutPoint(inv.hash, 1));
1023+
pcoinsTip->HaveCoinInCache(COutPoint(inv.hash, 1)) ||
1024+
(fTxIndex && pblocktree->HasTxIndex(inv.hash));
10231025
}
10241026

10251027
case MSG_BLOCK:

src/txdb.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,10 @@ bool CBlockTreeDB::WriteBatchSync(const std::vector<std::pair<int, const CBlockF
240240
return WriteBatch(batch, true);
241241
}
242242

243+
bool CBlockTreeDB::HasTxIndex(const uint256& txid) {
244+
return Exists(std::make_pair(DB_TXINDEX, txid));
245+
}
246+
243247
bool CBlockTreeDB::ReadTxIndex(const uint256 &txid, CDiskTxPos &pos) {
244248
return Read(std::make_pair(DB_TXINDEX, txid), pos);
245249
}

src/txdb.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ class CBlockTreeDB : public CDBWrapper
121121
bool ReadLastBlockFile(int &nFile);
122122
bool WriteReindexing(bool fReindex);
123123
bool ReadReindexing(bool &fReindex);
124+
bool HasTxIndex(const uint256 &txid);
124125
bool ReadTxIndex(const uint256 &txid, CDiskTxPos &pos);
125126
bool WriteTxIndex(const std::vector<std::pair<uint256, CDiskTxPos> > &list);
126127
bool ReadSpentIndex(CSpentIndexKey &key, CSpentIndexValue &value);

0 commit comments

Comments
 (0)