Skip to content

Commit eaca1b7

Browse files
committed
Random db flush crash simulator
1 parent 0580ee0 commit eaca1b7

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

contrib/devtools/check-doc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
REGEX_ARG = re.compile(r'(?:map(?:Multi)?Args(?:\.count\(|\[)|Get(?:Bool)?Arg\()\"(\-[^\"]+?)\"')
2222
REGEX_DOC = re.compile(r'HelpMessageOpt\(\"(\-[^\"=]+?)(?:=|\")')
2323
# list unsupported, deprecated and duplicate args as they need no documentation
24-
SET_DOC_OPTIONAL = set(['-rpcssl', '-benchmark', '-h', '-help', '-socks', '-tor', '-debugnet', '-whitelistalwaysrelay', '-prematurewitness', '-walletprematurewitness', '-promiscuousmempoolflags', '-blockminsize'])
24+
SET_DOC_OPTIONAL = set(['-rpcssl', '-benchmark', '-h', '-help', '-socks', '-tor', '-debugnet', '-whitelistalwaysrelay', '-prematurewitness', '-walletprematurewitness', '-promiscuousmempoolflags', '-blockminsize', '-dbcrashratio'])
2525

2626
def main():
2727
used = check_output(CMD_GREP_ARGS, shell=True)

src/txdb.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77

88
#include "chainparams.h"
99
#include "hash.h"
10+
#include "random.h"
1011
#include "pow.h"
1112
#include "uint256.h"
13+
#include "util.h"
1214

1315
#include <stdint.h>
1416

@@ -82,7 +84,7 @@ bool CCoinsViewDB::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) {
8284
size_t count = 0;
8385
size_t changed = 0;
8486
size_t batch_size = (size_t)GetArg("-dbbatchsize", nDefaultDbBatchSize);
85-
87+
int crash_simulate = GetArg("-dbcrashratio", 0);
8688

8789
uint256 old_tip = GetBestBlock();
8890
if (old_tip.IsNull()) {
@@ -124,6 +126,13 @@ bool CCoinsViewDB::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) {
124126
LogPrint(BCLog::COINDB, "Writing partial batch of %.2f MiB\n", batch.SizeEstimate() * (1.0 / 1048576.0));
125127
db.WriteBatch(batch);
126128
batch.Clear();
129+
if (crash_simulate) {
130+
static FastRandomContext rng;
131+
if (rng.randrange(crash_simulate) == 0) {
132+
LogPrintf("Simulating a crash. Goodbye.\n");
133+
exit(0);
134+
}
135+
}
127136
}
128137
}
129138

0 commit comments

Comments
 (0)