index: Drop legacy -txindex check

This commit is contained in:
MarcoFalke 2023-08-01 11:01:48 +02:00
parent fa69148a0a
commit fa8685597e
No known key found for this signature in database
4 changed files with 12 additions and 40 deletions

View file

@ -1550,11 +1550,6 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
// ********************************************************* Step 8: start indexers
if (args.GetBoolArg("-txindex", DEFAULT_TXINDEX)) {
auto result{WITH_LOCK(cs_main, return CheckLegacyTxindex(*Assert(chainman.m_blockman.m_block_tree_db)))};
if (!result) {
return InitError(util::ErrorString(result));
}
g_txindex = std::make_unique<TxIndex>(interfaces::MakeChain(node), cache_sizes.tx_index, false, fReindex);
node.indexes.emplace_back(g_txindex.get());
}

View file

@ -6,15 +6,23 @@
#include <txdb.h>
#include <chain.h>
#include <coins.h>
#include <dbwrapper.h>
#include <kernel/cs_main.h>
#include <logging.h>
#include <pow.h>
#include <primitives/transaction.h>
#include <random.h>
#include <serialize.h>
#include <sync.h>
#include <uint256.h>
#include <util/signalinterrupt.h>
#include <util/translation.h>
#include <util/vector.h>
#include <stdint.h>
#include <cassert>
#include <cstdlib>
#include <iterator>
static constexpr uint8_t DB_COIN{'C'};
static constexpr uint8_t DB_BLOCK_FILES{'f'};
@ -28,26 +36,9 @@ static constexpr uint8_t DB_LAST_BLOCK{'l'};
// Keys used in previous version that might still be found in the DB:
static constexpr uint8_t DB_COINS{'c'};
static constexpr uint8_t DB_TXINDEX_BLOCK{'T'};
// uint8_t DB_TXINDEX{'t'}
util::Result<void> CheckLegacyTxindex(CBlockTreeDB& block_tree_db)
{
CBlockLocator ignored{};
if (block_tree_db.Read(DB_TXINDEX_BLOCK, ignored)) {
return util::Error{_("The -txindex upgrade started by a previous version cannot be completed. Restart with the previous version or run a full -reindex.")};
}
bool txindex_legacy_flag{false};
block_tree_db.ReadFlag("txindex", txindex_legacy_flag);
if (txindex_legacy_flag) {
// Disable legacy txindex and warn once about occupied disk space
if (!block_tree_db.WriteFlag("txindex", false)) {
return util::Error{Untranslated("Failed to write block index db flag 'txindex'='0'")};
}
return util::Error{_("The block index db contains a legacy 'txindex'. To clear the occupied disk space, run a full -reindex, otherwise ignore this error. This error message will not be displayed again.")};
}
return {};
}
// CBlockTreeDB::DB_TXINDEX_BLOCK{'T'};
// CBlockTreeDB::DB_TXINDEX{'t'}
// CBlockTreeDB::ReadFlag("txindex")
bool CCoinsViewDB::NeedsUpgrade()
{

View file

@ -11,7 +11,6 @@
#include <kernel/cs_main.h>
#include <sync.h>
#include <util/fs.h>
#include <util/result.h>
#include <cstddef>
#include <cstdint>
@ -105,6 +104,4 @@ public:
EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
};
[[nodiscard]] util::Result<void> CheckLegacyTxindex(CBlockTreeDB& block_tree_db);
#endif // BITCOIN_TXDB_H

View file

@ -7,7 +7,6 @@
Previous releases are required by this test, see test/README.md.
"""
import os
import shutil
from test_framework.test_framework import BitcoinTestFramework
@ -55,10 +54,6 @@ class TxindexCompatibilityTest(BitcoinTestFramework):
drop_index_chain_dir = self.nodes[1].chain_path
shutil.rmtree(drop_index_chain_dir)
shutil.copytree(legacy_chain_dir, drop_index_chain_dir)
self.nodes[1].assert_start_raises_init_error(
extra_args=["-txindex"],
expected_msg="Error: The block index db contains a legacy 'txindex'. To clear the occupied disk space, run a full -reindex, otherwise ignore this error. This error message will not be displayed again.",
)
# Build txindex from scratch and check there is no error this time
self.start_node(1, extra_args=["-txindex"])
self.wait_until(lambda: self.nodes[1].getindexinfo()["txindex"]["synced"] == True)
@ -66,12 +61,6 @@ class TxindexCompatibilityTest(BitcoinTestFramework):
self.stop_nodes()
self.log.info("Check migrated txindex cannot be read by legacy node")
err_msg = f": You need to rebuild the database using -reindex to change -txindex.{os.linesep}Please restart with -reindex or -reindex-chainstate to recover."
shutil.rmtree(legacy_chain_dir)
shutil.copytree(drop_index_chain_dir, legacy_chain_dir)
self.nodes[0].assert_start_raises_init_error(extra_args=["-txindex"], expected_msg=err_msg)
if __name__ == "__main__":
TxindexCompatibilityTest().main()