Skip to content

Commit

Permalink
index: Fix for indexers skipping genesis block.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimpo committed Aug 28, 2018
1 parent 0df9b0a commit ed12d5d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/index/base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
3 changes: 3 additions & 0 deletions src/index/txindex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::pair<uint256, CDiskTxPos>> vPos;
vPos.reserve(block.vtx.size());
Expand Down
7 changes: 7 additions & 0 deletions src/test/txindex_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <chainparams.h>
#include <index/txindex.h>
#include <script/standard.h>
#include <test/test_bitcoin.h>
Expand Down Expand Up @@ -38,6 +39,12 @@ BOOST_FIXTURE_TEST_CASE(txindex_initial_sync, TestChain100Setup)
MilliSleep(100);
}

// Check that txindex excludes genesis block transactions.
const CBlock& genesis_block = Params().GenesisBlock();
for (const auto& txn : genesis_block.vtx) {
BOOST_CHECK(!txindex.FindTx(txn->GetHash(), block_hash, tx_disk));
}

// Check that txindex has all txs that were in the chain before it started.
for (const auto& txn : m_coinbase_txns) {
if (!txindex.FindTx(txn->GetHash(), block_hash, tx_disk)) {
Expand Down

0 comments on commit ed12d5d

Please sign in to comment.