From 2d1fa42e85c9164688aa69b3f54f015fbefc06aa Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Fri, 11 Jan 2013 01:47:57 +0100 Subject: Add optional transaction index to databases By specifying -txindex when initializing the database, a txid-to-diskpos index is maintained in the blktree database. This database is used to help answering getrawtransaction() RPC queries, when enabled. Changing the -txindex value requires a -reindex; the client will abort at startup if the database and the specified -txindex mismatch. --- src/init.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/init.cpp') diff --git a/src/init.cpp b/src/init.cpp index 4f319e8cb..69ca4785c 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -305,6 +305,7 @@ std::string HelpMessage() " -salvagewallet " + _("Attempt to recover private keys from a corrupt wallet.dat") + "\n" + " -checkblocks= " + _("How many blocks to check at startup (default: 2500, 0 = all)") + "\n" + " -checklevel= " + _("How thorough the block verification is (0-4, default: 3)") + "\n" + + " -txindex " + _("Maintain a full transaction index (default: 0)") + "\n" + " -loadblock= " + _("Imports blocks from external blk000??.dat file") + "\n" + " -reindex " + _("Rebuild blockchain index from current blk000??.dat files") + "\n" + " -par=N " + _("Set the number of script verification threads (1-16, 0=auto, default: 0)") + "\n" + @@ -781,7 +782,7 @@ bool AppInit2() if (nTotalCache < (1 << 22)) nTotalCache = (1 << 22); // total cache cannot be less than 4 MiB size_t nBlockTreeDBCache = nTotalCache / 8; - if (nBlockTreeDBCache > (1 << 21)) + if (nBlockTreeDBCache > (1 << 21) && !GetBoolArg("-txindex", false)) nBlockTreeDBCache = (1 << 21); // block tree db cache shouldn't be larger than 2 MiB nTotalCache -= nBlockTreeDBCache; size_t nCoinDBCache = nTotalCache / 2; // use half of the remaining cache for coindb cache @@ -806,6 +807,9 @@ bool AppInit2() if (!VerifyDB()) return InitError(_("Corrupted block database detected. Please restart the client with -reindex.")); + if (mapArgs.count("-txindex") && fTxIndex != GetBoolArg("-txindex", false)) + return InitError(_("You need to rebuild the databases using -reindex to change -txindex")); + // as LoadBlockIndex can take several minutes, it's possible the user // requested to kill bitcoin-qt during the last operation. If so, exit. // As the program has not fully started yet, Shutdown() is possibly overkill. -- cgit v1.2.3