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.
This commit is contained in:
Alexander Block 2019-10-01 16:24:42 +02:00 committed by UdjinM6
parent d9e98e31ea
commit b4aefb513d
3 changed files with 8 additions and 1 deletions

View File

@ -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:

View File

@ -240,6 +240,10 @@ bool CBlockTreeDB::WriteBatchSync(const std::vector<std::pair<int, const CBlockF
return WriteBatch(batch, true);
}
bool CBlockTreeDB::HasTxIndex(const uint256& txid) {
return Exists(std::make_pair(DB_TXINDEX, txid));
}
bool CBlockTreeDB::ReadTxIndex(const uint256 &txid, CDiskTxPos &pos) {
return Read(std::make_pair(DB_TXINDEX, txid), pos);
}

View File

@ -121,6 +121,7 @@ public:
bool ReadLastBlockFile(int &nFile);
bool WriteReindexing(bool fReindex);
bool ReadReindexing(bool &fReindex);
bool HasTxIndex(const uint256 &txid);
bool ReadTxIndex(const uint256 &txid, CDiskTxPos &pos);
bool WriteTxIndex(const std::vector<std::pair<uint256, CDiskTxPos> > &list);
bool ReadSpentIndex(CSpentIndexKey &key, CSpentIndexValue &value);