mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 12:32:48 +01:00
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
This commit is contained in:
parent
d3ce0964b2
commit
e0781095f0
18
src/init.cpp
18
src/init.cpp
@ -1807,6 +1807,24 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check for changed -addressindex state
|
||||||
|
if (fAddressIndex != gArgs.GetBoolArg("-addressindex", DEFAULT_ADDRESSINDEX)) {
|
||||||
|
strLoadError = _("You need to rebuild the database using -reindex to change -addressindex");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for changed -timestampindex state
|
||||||
|
if (fTimestampIndex != gArgs.GetBoolArg("-timestampindex", DEFAULT_TIMESTAMPINDEX)) {
|
||||||
|
strLoadError = _("You need to rebuild the database using -reindex to change -timestampindex");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for changed -spentindex state
|
||||||
|
if (fSpentIndex != gArgs.GetBoolArg("-spentindex", DEFAULT_SPENTINDEX)) {
|
||||||
|
strLoadError = _("You need to rebuild the database using -reindex to change -spentindex");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// Check for changed -prune state. What we are concerned about is a user who has pruned blocks
|
// Check for changed -prune state. What we are concerned about is a user who has pruned blocks
|
||||||
// in the past, but is now trying to run unpruned.
|
// in the past, but is now trying to run unpruned.
|
||||||
if (fHavePruned && !fPruneMode) {
|
if (fHavePruned && !fPruneMode) {
|
||||||
|
@ -4252,6 +4252,18 @@ bool LoadBlockIndex(const CChainParams& chainparams)
|
|||||||
// Use the provided setting for -txindex in the new database
|
// Use the provided setting for -txindex in the new database
|
||||||
fTxIndex = gArgs.GetBoolArg("-txindex", DEFAULT_TXINDEX);
|
fTxIndex = gArgs.GetBoolArg("-txindex", DEFAULT_TXINDEX);
|
||||||
pblocktree->WriteFlag("txindex", fTxIndex);
|
pblocktree->WriteFlag("txindex", fTxIndex);
|
||||||
|
|
||||||
|
// Use the provided setting for -addressindex in the new database
|
||||||
|
fAddressIndex = gArgs.GetBoolArg("-addressindex", DEFAULT_ADDRESSINDEX);
|
||||||
|
pblocktree->WriteFlag("addressindex", fAddressIndex);
|
||||||
|
|
||||||
|
// Use the provided setting for -timestampindex in the new database
|
||||||
|
fTimestampIndex = gArgs.GetBoolArg("-timestampindex", DEFAULT_TIMESTAMPINDEX);
|
||||||
|
pblocktree->WriteFlag("timestampindex", fTimestampIndex);
|
||||||
|
|
||||||
|
// Use the provided setting for -spentindex in the new database
|
||||||
|
fSpentIndex = gArgs.GetBoolArg("-spentindex", DEFAULT_SPENTINDEX);
|
||||||
|
pblocktree->WriteFlag("spentindex", fSpentIndex);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -4282,17 +4294,6 @@ bool LoadGenesisBlock(const CChainParams& chainparams)
|
|||||||
if (mapBlockIndex.count(chainparams.GenesisBlock().GetHash()))
|
if (mapBlockIndex.count(chainparams.GenesisBlock().GetHash()))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// Use the provided setting for -addressindex in the new database
|
|
||||||
fAddressIndex = gArgs.GetBoolArg("-addressindex", DEFAULT_ADDRESSINDEX);
|
|
||||||
pblocktree->WriteFlag("addressindex", fAddressIndex);
|
|
||||||
|
|
||||||
// Use the provided setting for -timestampindex in the new database
|
|
||||||
fTimestampIndex = gArgs.GetBoolArg("-timestampindex", DEFAULT_TIMESTAMPINDEX);
|
|
||||||
pblocktree->WriteFlag("timestampindex", fTimestampIndex);
|
|
||||||
|
|
||||||
fSpentIndex = gArgs.GetBoolArg("-spentindex", DEFAULT_SPENTINDEX);
|
|
||||||
pblocktree->WriteFlag("spentindex", fSpentIndex);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
CValidationState state;
|
CValidationState state;
|
||||||
|
|
||||||
|
@ -171,6 +171,9 @@ extern std::atomic_bool fImporting;
|
|||||||
extern bool fReindex;
|
extern bool fReindex;
|
||||||
extern int nScriptCheckThreads;
|
extern int nScriptCheckThreads;
|
||||||
extern bool fTxIndex;
|
extern bool fTxIndex;
|
||||||
|
extern bool fAddressIndex;
|
||||||
|
extern bool fTimestampIndex;
|
||||||
|
extern bool fSpentIndex;
|
||||||
extern bool fIsBareMultisigStd;
|
extern bool fIsBareMultisigStd;
|
||||||
extern bool fRequireStandard;
|
extern bool fRequireStandard;
|
||||||
extern unsigned int nBytesPerSigOp;
|
extern unsigned int nBytesPerSigOp;
|
||||||
|
@ -35,6 +35,18 @@ class AddressIndexTest(BitcoinTestFramework):
|
|||||||
self.sync_all()
|
self.sync_all()
|
||||||
|
|
||||||
def run_test(self):
|
def run_test(self):
|
||||||
|
self.log.info("Test that settings can't be changed without -reindex...")
|
||||||
|
self.stop_node(1)
|
||||||
|
self.assert_start_raises_init_error(1, ["-addressindex=0"], 'You need to rebuild the database using -reindex to change -addressindex')
|
||||||
|
self.start_node(1, ["-addressindex=0", "-reindex"])
|
||||||
|
connect_nodes(self.nodes[0], 1)
|
||||||
|
self.sync_all()
|
||||||
|
self.stop_node(1)
|
||||||
|
self.assert_start_raises_init_error(1, ["-addressindex"], 'You need to rebuild the database using -reindex to change -addressindex')
|
||||||
|
self.start_node(1, ["-addressindex", "-reindex"])
|
||||||
|
connect_nodes(self.nodes[0], 1)
|
||||||
|
self.sync_all()
|
||||||
|
|
||||||
self.log.info("Mining blocks...")
|
self.log.info("Mining blocks...")
|
||||||
self.nodes[0].generate(105)
|
self.nodes[0].generate(105)
|
||||||
self.sync_all()
|
self.sync_all()
|
||||||
|
@ -35,6 +35,18 @@ class SpentIndexTest(BitcoinTestFramework):
|
|||||||
self.sync_all()
|
self.sync_all()
|
||||||
|
|
||||||
def run_test(self):
|
def run_test(self):
|
||||||
|
self.log.info("Test that settings can't be changed without -reindex...")
|
||||||
|
self.stop_node(1)
|
||||||
|
self.assert_start_raises_init_error(1, ["-spentindex=0"], 'You need to rebuild the database using -reindex to change -spentindex')
|
||||||
|
self.start_node(1, ["-spentindex=0", "-reindex"])
|
||||||
|
connect_nodes(self.nodes[0], 1)
|
||||||
|
self.sync_all()
|
||||||
|
self.stop_node(1)
|
||||||
|
self.assert_start_raises_init_error(1, ["-spentindex"], 'You need to rebuild the database using -reindex to change -spentindex')
|
||||||
|
self.start_node(1, ["-spentindex", "-reindex"])
|
||||||
|
connect_nodes(self.nodes[0], 1)
|
||||||
|
self.sync_all()
|
||||||
|
|
||||||
self.log.info("Mining blocks...")
|
self.log.info("Mining blocks...")
|
||||||
self.nodes[0].generate(105)
|
self.nodes[0].generate(105)
|
||||||
self.sync_all()
|
self.sync_all()
|
||||||
|
@ -33,6 +33,18 @@ class TimestampIndexTest(BitcoinTestFramework):
|
|||||||
self.sync_all()
|
self.sync_all()
|
||||||
|
|
||||||
def run_test(self):
|
def run_test(self):
|
||||||
|
self.log.info("Test that settings can't be changed without -reindex...")
|
||||||
|
self.stop_node(1)
|
||||||
|
self.assert_start_raises_init_error(1, ["-timestampindex=0"], 'You need to rebuild the database using -reindex to change -timestampindex')
|
||||||
|
self.start_node(1, ["-timestampindex=0", "-reindex"])
|
||||||
|
connect_nodes(self.nodes[0], 1)
|
||||||
|
self.sync_all()
|
||||||
|
self.stop_node(1)
|
||||||
|
self.assert_start_raises_init_error(1, ["-timestampindex"], 'You need to rebuild the database using -reindex to change -timestampindex')
|
||||||
|
self.start_node(1, ["-timestampindex", "-reindex"])
|
||||||
|
connect_nodes(self.nodes[0], 1)
|
||||||
|
self.sync_all()
|
||||||
|
|
||||||
self.log.info("Mining 5 blocks...")
|
self.log.info("Mining 5 blocks...")
|
||||||
blockhashes = self.nodes[0].generate(5)
|
blockhashes = self.nodes[0].generate(5)
|
||||||
low = self.nodes[0].getblock(blockhashes[0])["time"]
|
low = self.nodes[0].getblock(blockhashes[0])["time"]
|
||||||
|
@ -35,6 +35,18 @@ class TxIndexTest(BitcoinTestFramework):
|
|||||||
self.sync_all()
|
self.sync_all()
|
||||||
|
|
||||||
def run_test(self):
|
def run_test(self):
|
||||||
|
self.log.info("Test that settings can't be changed without -reindex...")
|
||||||
|
self.stop_node(1)
|
||||||
|
self.assert_start_raises_init_error(1, ["-txindex=0"], 'You need to rebuild the database using -reindex to change -txindex')
|
||||||
|
self.start_node(1, ["-txindex=0", "-reindex"])
|
||||||
|
connect_nodes(self.nodes[0], 1)
|
||||||
|
self.sync_all()
|
||||||
|
self.stop_node(1)
|
||||||
|
self.assert_start_raises_init_error(1, ["-txindex"], 'You need to rebuild the database using -reindex to change -txindex')
|
||||||
|
self.start_node(1, ["-txindex", "-reindex"])
|
||||||
|
connect_nodes(self.nodes[0], 1)
|
||||||
|
self.sync_all()
|
||||||
|
|
||||||
self.log.info("Mining blocks...")
|
self.log.info("Mining blocks...")
|
||||||
self.nodes[0].generate(105)
|
self.nodes[0].generate(105)
|
||||||
self.sync_all()
|
self.sync_all()
|
||||||
|
Loading…
Reference in New Issue
Block a user