From b4aefb513d2aea4f7676c5f23bf8626a8822a78b Mon Sep 17 00:00:00 2001 From: Alexander Block Date: Tue, 1 Oct 2019 16:24:42 +0200 Subject: [PATCH] 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. --- src/net_processing.cpp | 4 +++- src/txdb.cpp | 4 ++++ src/txdb.h | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 9916782308..71a0ef1706 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -25,6 +25,7 @@ #include "reverse_iterator.h" #include "scheduler.h" #include "tinyformat.h" +#include "txdb.h" #include "txmempool.h" #include "ui_interface.h" #include "util.h" @@ -1019,7 +1020,8 @@ bool static AlreadyHave(const CInv& inv) EXCLUSIVE_LOCKS_REQUIRED(cs_main) return (recentRejects->contains(inv.hash) && !llmq::quorumInstantSendManager->IsLocked(inv.hash)) || mempool.exists(inv.hash) || pcoinsTip->HaveCoinInCache(COutPoint(inv.hash, 0)) || // Best effort: only try output 0 and 1 - pcoinsTip->HaveCoinInCache(COutPoint(inv.hash, 1)); + pcoinsTip->HaveCoinInCache(COutPoint(inv.hash, 1)) || + (fTxIndex && pblocktree->HasTxIndex(inv.hash)); } case MSG_BLOCK: diff --git a/src/txdb.cpp b/src/txdb.cpp index 9acfea075f..49e6dc2705 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -240,6 +240,10 @@ bool CBlockTreeDB::WriteBatchSync(const std::vector > &list); bool ReadSpentIndex(CSpentIndexKey &key, CSpentIndexValue &value);