diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2017-04-05 01:37:09 -0700 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2017-06-26 10:46:51 -0700 |
commit | eaca1b7b08b4911292d49efbce8471cbc9ca0e1c (patch) | |
tree | 9b6bde7479dc3a0550a0d550f914cdebcbcdd0e2 | |
parent | 0580ee08ff413f729bd34e5a5ce0fb75894f0256 (diff) |
Random db flush crash simulator
-rwxr-xr-x | contrib/devtools/check-doc.py | 2 | ||||
-rw-r--r-- | src/txdb.cpp | 11 |
2 files changed, 11 insertions, 2 deletions
diff --git a/contrib/devtools/check-doc.py b/contrib/devtools/check-doc.py index 249214e931..150f368513 100755 --- a/contrib/devtools/check-doc.py +++ b/contrib/devtools/check-doc.py @@ -21,7 +21,7 @@ CMD_GREP_DOCS = r"egrep -r -I 'HelpMessageOpt\(\"\-[^\"=]+?(=|\")' %s" % (CMD_RO REGEX_ARG = re.compile(r'(?:map(?:Multi)?Args(?:\.count\(|\[)|Get(?:Bool)?Arg\()\"(\-[^\"]+?)\"') REGEX_DOC = re.compile(r'HelpMessageOpt\(\"(\-[^\"=]+?)(?:=|\")') # list unsupported, deprecated and duplicate args as they need no documentation -SET_DOC_OPTIONAL = set(['-rpcssl', '-benchmark', '-h', '-help', '-socks', '-tor', '-debugnet', '-whitelistalwaysrelay', '-prematurewitness', '-walletprematurewitness', '-promiscuousmempoolflags', '-blockminsize']) +SET_DOC_OPTIONAL = set(['-rpcssl', '-benchmark', '-h', '-help', '-socks', '-tor', '-debugnet', '-whitelistalwaysrelay', '-prematurewitness', '-walletprematurewitness', '-promiscuousmempoolflags', '-blockminsize', '-dbcrashratio']) def main(): used = check_output(CMD_GREP_ARGS, shell=True) diff --git a/src/txdb.cpp b/src/txdb.cpp index f0e5098b11..7de11cc617 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -7,8 +7,10 @@ #include "chainparams.h" #include "hash.h" +#include "random.h" #include "pow.h" #include "uint256.h" +#include "util.h" #include <stdint.h> @@ -82,7 +84,7 @@ bool CCoinsViewDB::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) { size_t count = 0; size_t changed = 0; size_t batch_size = (size_t)GetArg("-dbbatchsize", nDefaultDbBatchSize); - + int crash_simulate = GetArg("-dbcrashratio", 0); uint256 old_tip = GetBestBlock(); if (old_tip.IsNull()) { @@ -124,6 +126,13 @@ bool CCoinsViewDB::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) { LogPrint(BCLog::COINDB, "Writing partial batch of %.2f MiB\n", batch.SizeEstimate() * (1.0 / 1048576.0)); db.WriteBatch(batch); batch.Clear(); + if (crash_simulate) { + static FastRandomContext rng; + if (rng.randrange(crash_simulate) == 0) { + LogPrintf("Simulating a crash. Goodbye.\n"); + exit(0); + } + } } } |