Skip to content

Commit e078109

Browse files
authored
A couple of fixes for additional indexes (#3181)
* It should not be possible to change settings for additional indexes without reindex * Should write db flags for additional indexes on reindex * Add tests to make sure index settings can't be changed without reindex
1 parent d3ce096 commit e078109

File tree

7 files changed

+81
-11
lines changed

7 files changed

+81
-11
lines changed

src/init.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1807,6 +1807,24 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
18071807
break;
18081808
}
18091809

1810+
// Check for changed -addressindex state
1811+
if (fAddressIndex != gArgs.GetBoolArg("-addressindex", DEFAULT_ADDRESSINDEX)) {
1812+
strLoadError = _("You need to rebuild the database using -reindex to change -addressindex");
1813+
break;
1814+
}
1815+
1816+
// Check for changed -timestampindex state
1817+
if (fTimestampIndex != gArgs.GetBoolArg("-timestampindex", DEFAULT_TIMESTAMPINDEX)) {
1818+
strLoadError = _("You need to rebuild the database using -reindex to change -timestampindex");
1819+
break;
1820+
}
1821+
1822+
// Check for changed -spentindex state
1823+
if (fSpentIndex != gArgs.GetBoolArg("-spentindex", DEFAULT_SPENTINDEX)) {
1824+
strLoadError = _("You need to rebuild the database using -reindex to change -spentindex");
1825+
break;
1826+
}
1827+
18101828
// Check for changed -prune state. What we are concerned about is a user who has pruned blocks
18111829
// in the past, but is now trying to run unpruned.
18121830
if (fHavePruned && !fPruneMode) {

src/validation.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4252,6 +4252,18 @@ bool LoadBlockIndex(const CChainParams& chainparams)
42524252
// Use the provided setting for -txindex in the new database
42534253
fTxIndex = gArgs.GetBoolArg("-txindex", DEFAULT_TXINDEX);
42544254
pblocktree->WriteFlag("txindex", fTxIndex);
4255+
4256+
// Use the provided setting for -addressindex in the new database
4257+
fAddressIndex = gArgs.GetBoolArg("-addressindex", DEFAULT_ADDRESSINDEX);
4258+
pblocktree->WriteFlag("addressindex", fAddressIndex);
4259+
4260+
// Use the provided setting for -timestampindex in the new database
4261+
fTimestampIndex = gArgs.GetBoolArg("-timestampindex", DEFAULT_TIMESTAMPINDEX);
4262+
pblocktree->WriteFlag("timestampindex", fTimestampIndex);
4263+
4264+
// Use the provided setting for -spentindex in the new database
4265+
fSpentIndex = gArgs.GetBoolArg("-spentindex", DEFAULT_SPENTINDEX);
4266+
pblocktree->WriteFlag("spentindex", fSpentIndex);
42554267
}
42564268
return true;
42574269
}
@@ -4282,17 +4294,6 @@ bool LoadGenesisBlock(const CChainParams& chainparams)
42824294
if (mapBlockIndex.count(chainparams.GenesisBlock().GetHash()))
42834295
return true;
42844296

4285-
// Use the provided setting for -addressindex in the new database
4286-
fAddressIndex = gArgs.GetBoolArg("-addressindex", DEFAULT_ADDRESSINDEX);
4287-
pblocktree->WriteFlag("addressindex", fAddressIndex);
4288-
4289-
// Use the provided setting for -timestampindex in the new database
4290-
fTimestampIndex = gArgs.GetBoolArg("-timestampindex", DEFAULT_TIMESTAMPINDEX);
4291-
pblocktree->WriteFlag("timestampindex", fTimestampIndex);
4292-
4293-
fSpentIndex = gArgs.GetBoolArg("-spentindex", DEFAULT_SPENTINDEX);
4294-
pblocktree->WriteFlag("spentindex", fSpentIndex);
4295-
42964297
try {
42974298
CValidationState state;
42984299

src/validation.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ extern std::atomic_bool fImporting;
171171
extern bool fReindex;
172172
extern int nScriptCheckThreads;
173173
extern bool fTxIndex;
174+
extern bool fAddressIndex;
175+
extern bool fTimestampIndex;
176+
extern bool fSpentIndex;
174177
extern bool fIsBareMultisigStd;
175178
extern bool fRequireStandard;
176179
extern unsigned int nBytesPerSigOp;

test/functional/addressindex.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ def setup_network(self):
3535
self.sync_all()
3636

3737
def run_test(self):
38+
self.log.info("Test that settings can't be changed without -reindex...")
39+
self.stop_node(1)
40+
self.assert_start_raises_init_error(1, ["-addressindex=0"], 'You need to rebuild the database using -reindex to change -addressindex')
41+
self.start_node(1, ["-addressindex=0", "-reindex"])
42+
connect_nodes(self.nodes[0], 1)
43+
self.sync_all()
44+
self.stop_node(1)
45+
self.assert_start_raises_init_error(1, ["-addressindex"], 'You need to rebuild the database using -reindex to change -addressindex')
46+
self.start_node(1, ["-addressindex", "-reindex"])
47+
connect_nodes(self.nodes[0], 1)
48+
self.sync_all()
49+
3850
self.log.info("Mining blocks...")
3951
self.nodes[0].generate(105)
4052
self.sync_all()

test/functional/spentindex.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ def setup_network(self):
3535
self.sync_all()
3636

3737
def run_test(self):
38+
self.log.info("Test that settings can't be changed without -reindex...")
39+
self.stop_node(1)
40+
self.assert_start_raises_init_error(1, ["-spentindex=0"], 'You need to rebuild the database using -reindex to change -spentindex')
41+
self.start_node(1, ["-spentindex=0", "-reindex"])
42+
connect_nodes(self.nodes[0], 1)
43+
self.sync_all()
44+
self.stop_node(1)
45+
self.assert_start_raises_init_error(1, ["-spentindex"], 'You need to rebuild the database using -reindex to change -spentindex')
46+
self.start_node(1, ["-spentindex", "-reindex"])
47+
connect_nodes(self.nodes[0], 1)
48+
self.sync_all()
49+
3850
self.log.info("Mining blocks...")
3951
self.nodes[0].generate(105)
4052
self.sync_all()

test/functional/timestampindex.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@ def setup_network(self):
3333
self.sync_all()
3434

3535
def run_test(self):
36+
self.log.info("Test that settings can't be changed without -reindex...")
37+
self.stop_node(1)
38+
self.assert_start_raises_init_error(1, ["-timestampindex=0"], 'You need to rebuild the database using -reindex to change -timestampindex')
39+
self.start_node(1, ["-timestampindex=0", "-reindex"])
40+
connect_nodes(self.nodes[0], 1)
41+
self.sync_all()
42+
self.stop_node(1)
43+
self.assert_start_raises_init_error(1, ["-timestampindex"], 'You need to rebuild the database using -reindex to change -timestampindex')
44+
self.start_node(1, ["-timestampindex", "-reindex"])
45+
connect_nodes(self.nodes[0], 1)
46+
self.sync_all()
47+
3648
self.log.info("Mining 5 blocks...")
3749
blockhashes = self.nodes[0].generate(5)
3850
low = self.nodes[0].getblock(blockhashes[0])["time"]

test/functional/txindex.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ def setup_network(self):
3535
self.sync_all()
3636

3737
def run_test(self):
38+
self.log.info("Test that settings can't be changed without -reindex...")
39+
self.stop_node(1)
40+
self.assert_start_raises_init_error(1, ["-txindex=0"], 'You need to rebuild the database using -reindex to change -txindex')
41+
self.start_node(1, ["-txindex=0", "-reindex"])
42+
connect_nodes(self.nodes[0], 1)
43+
self.sync_all()
44+
self.stop_node(1)
45+
self.assert_start_raises_init_error(1, ["-txindex"], 'You need to rebuild the database using -reindex to change -txindex')
46+
self.start_node(1, ["-txindex", "-reindex"])
47+
connect_nodes(self.nodes[0], 1)
48+
self.sync_all()
49+
3850
self.log.info("Mining blocks...")
3951
self.nodes[0].generate(105)
4052
self.sync_all()

0 commit comments

Comments
 (0)