Merge #14085: index: Fix for indexers skipping genesis block.

ed12d5df1b index: Fix for indexers skipping genesis block. (Jim Posen)

Pull request description:

  This fixes a bug where indexers would skip processing of the genesis block. Preserves the current behavior of omitting genesis block transaction from the index.

Tree-SHA512: 092fd3d629bf1ef279566217c668cc913a8b8e012d811d0e544231894c49a0c0c179537ac4727c39b9bf407479541745d79c4e118db6f0795a2b848d0fe62cbf
This commit is contained in:
Wladimir J. van der Laan 2019-01-09 14:47:40 +01:00
commit e12a480e40
No known key found for this signature in database
GPG key ID: 1E4AED62986CD25D
3 changed files with 15 additions and 1 deletions

View file

@ -60,7 +60,11 @@ bool BaseIndex::Init()
} }
LOCK(cs_main); 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(); m_synced = m_best_block_index.load() == chainActive.Tip();
return true; return true;
} }

View file

@ -245,6 +245,9 @@ bool TxIndex::Init()
bool TxIndex::WriteBlock(const CBlock& block, const CBlockIndex* pindex) 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())); CDiskTxPos pos(pindex->GetBlockPos(), GetSizeOfCompactSize(block.vtx.size()));
std::vector<std::pair<uint256, CDiskTxPos>> vPos; std::vector<std::pair<uint256, CDiskTxPos>> vPos;
vPos.reserve(block.vtx.size()); vPos.reserve(block.vtx.size());

View file

@ -2,6 +2,7 @@
// Distributed under the MIT software license, see the accompanying // Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <chainparams.h>
#include <index/txindex.h> #include <index/txindex.h>
#include <script/standard.h> #include <script/standard.h>
#include <test/test_bitcoin.h> #include <test/test_bitcoin.h>
@ -38,6 +39,12 @@ BOOST_FIXTURE_TEST_CASE(txindex_initial_sync, TestChain100Setup)
MilliSleep(100); 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. // Check that txindex has all txs that were in the chain before it started.
for (const auto& txn : m_coinbase_txns) { for (const auto& txn : m_coinbase_txns) {
if (!txindex.FindTx(txn->GetHash(), block_hash, tx_disk)) { if (!txindex.FindTx(txn->GetHash(), block_hash, tx_disk)) {