From ed12d5df1ba52b5ef3dd3799de26bb5e1d3fc654 Mon Sep 17 00:00:00 2001 From: Jim Posen Date: Mon, 27 Aug 2018 12:28:35 -0700 Subject: [PATCH] index: Fix for indexers skipping genesis block. --- src/index/base.cpp | 6 +++++- src/index/txindex.cpp | 3 +++ src/test/txindex_tests.cpp | 7 +++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/index/base.cpp b/src/index/base.cpp index 788f7adcc..3cf2a89a2 100644 --- a/src/index/base.cpp +++ b/src/index/base.cpp @@ -60,7 +60,11 @@ bool BaseIndex::Init() } LOCK(cs_main); - m_best_block_index = FindForkInGlobalIndex(chainActive, locator); + if (locator.IsNull()) { + m_best_block_index = nullptr; + } else { + m_best_block_index = FindForkInGlobalIndex(chainActive, locator); + } m_synced = m_best_block_index.load() == chainActive.Tip(); return true; } diff --git a/src/index/txindex.cpp b/src/index/txindex.cpp index c85030e18..224004ce1 100644 --- a/src/index/txindex.cpp +++ b/src/index/txindex.cpp @@ -245,6 +245,9 @@ bool TxIndex::Init() bool TxIndex::WriteBlock(const CBlock& block, const CBlockIndex* pindex) { + // Exclude genesis block transaction because outputs are not spendable. + if (pindex->nHeight == 0) return true; + CDiskTxPos pos(pindex->GetBlockPos(), GetSizeOfCompactSize(block.vtx.size())); std::vector> vPos; vPos.reserve(block.vtx.size()); diff --git a/src/test/txindex_tests.cpp b/src/test/txindex_tests.cpp index 2a160b998..b5aa8160e 100644 --- a/src/test/txindex_tests.cpp +++ b/src/test/txindex_tests.cpp @@ -2,6 +2,7 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +#include #include #include