From 82b81d8a5eb076189dd09920d846e3341faedadf Mon Sep 17 00:00:00 2001 From: Alexander Block Date: Mon, 30 Sep 2019 10:09:55 +0200 Subject: [PATCH] Also consider txindex for transactions in AlreadyHave() 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 39d59f358b42..aa2a83797f8c 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" @@ -1008,7 +1009,8 @@ bool static AlreadyHave(const CInv& inv) EXCLUSIVE_LOCKS_REQUIRED(cs_main) return recentRejects->contains(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 9acfea075f54..49e6dc2705b1 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);