Skip to content

Commit ed12d5d

Browse files
committed
index: Fix for indexers skipping genesis block.
1 parent 0df9b0a commit ed12d5d

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

src/index/base.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ bool BaseIndex::Init()
6060
}
6161

6262
LOCK(cs_main);
63-
m_best_block_index = FindForkInGlobalIndex(chainActive, locator);
63+
if (locator.IsNull()) {
64+
m_best_block_index = nullptr;
65+
} else {
66+
m_best_block_index = FindForkInGlobalIndex(chainActive, locator);
67+
}
6468
m_synced = m_best_block_index.load() == chainActive.Tip();
6569
return true;
6670
}

src/index/txindex.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,9 @@ bool TxIndex::Init()
245245

246246
bool TxIndex::WriteBlock(const CBlock& block, const CBlockIndex* pindex)
247247
{
248+
// Exclude genesis block transaction because outputs are not spendable.
249+
if (pindex->nHeight == 0) return true;
250+
248251
CDiskTxPos pos(pindex->GetBlockPos(), GetSizeOfCompactSize(block.vtx.size()));
249252
std::vector<std::pair<uint256, CDiskTxPos>> vPos;
250253
vPos.reserve(block.vtx.size());

src/test/txindex_tests.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

5+
#include <chainparams.h>
56
#include <index/txindex.h>
67
#include <script/standard.h>
78
#include <test/test_bitcoin.h>
@@ -38,6 +39,12 @@ BOOST_FIXTURE_TEST_CASE(txindex_initial_sync, TestChain100Setup)
3839
MilliSleep(100);
3940
}
4041

42+
// Check that txindex excludes genesis block transactions.
43+
const CBlock& genesis_block = Params().GenesisBlock();
44+
for (const auto& txn : genesis_block.vtx) {
45+
BOOST_CHECK(!txindex.FindTx(txn->GetHash(), block_hash, tx_disk));
46+
}
47+
4148
// Check that txindex has all txs that were in the chain before it started.
4249
for (const auto& txn : m_coinbase_txns) {
4350
if (!txindex.FindTx(txn->GetHash(), block_hash, tx_disk)) {

0 commit comments

Comments
 (0)