Skip to content

Commit 8f955b9

Browse files
committed
Merge pull request #6012
0421c18 Fix CheckBlockIndex for reindex. (mrbandrews)
2 parents bc8535b + 0421c18 commit 8f955b9

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

qa/rpc-tests/reindex.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env python2
2+
# Copyright (c) 2014 The Bitcoin Core developers
3+
# Distributed under the MIT software license, see the accompanying
4+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
6+
#
7+
# Test -reindex with CheckBlockIndex
8+
#
9+
from test_framework import BitcoinTestFramework
10+
from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException
11+
from util import *
12+
import os.path
13+
14+
class ReindexTest(BitcoinTestFramework):
15+
16+
def setup_chain(self):
17+
print("Initializing test directory "+self.options.tmpdir)
18+
initialize_chain_clean(self.options.tmpdir, 1)
19+
20+
def setup_network(self):
21+
self.nodes = []
22+
self.is_network_split = False
23+
self.nodes.append(start_node(0, self.options.tmpdir))
24+
25+
def run_test(self):
26+
self.nodes[0].generate(3)
27+
stop_node(self.nodes[0], 0)
28+
wait_bitcoinds()
29+
self.nodes[0]=start_node(0, self.options.tmpdir, ["-debug", "-reindex", "-checkblockindex=1"])
30+
assert_equal(self.nodes[0].getblockcount(), 3)
31+
print "Success"
32+
33+
if __name__ == '__main__':
34+
ReindexTest().main()

src/main.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3232,6 +3232,14 @@ void static CheckBlockIndex()
32323232

32333233
LOCK(cs_main);
32343234

3235+
// During a reindex, we read the genesis block and call CheckBlockIndex before ActivateBestChain,
3236+
// so we have the genesis block in mapBlockIndex but no active chain. (A few of the tests when
3237+
// iterating the block tree require that chainActive has been initialized.)
3238+
if (chainActive.Height() < 0) {
3239+
assert(mapBlockIndex.size() <= 1);
3240+
return;
3241+
}
3242+
32353243
// Build forward-pointing map of the entire block tree.
32363244
std::multimap<CBlockIndex*,CBlockIndex*> forward;
32373245
for (BlockMap::iterator it = mapBlockIndex.begin(); it != mapBlockIndex.end(); it++) {

0 commit comments

Comments
 (0)