Skip to content

Commit

Permalink
Random db flush crash simulator
Browse files Browse the repository at this point in the history
  • Loading branch information
sipa authored and furszy committed Feb 16, 2021
1 parent 72f3b17 commit 93f2b15
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion contrib/devtools/check-doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
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', '-sendfreetransactions', '-checklevel', '-liquidityprovider', '-anonymizepivxamount'])
SET_DOC_OPTIONAL = set(['-rpcssl', '-benchmark', '-h', '-help', '-socks', '-tor', '-debugnet', '-whitelistalwaysrelay', '-prematurewitness', '-walletprematurewitness', '-promiscuousmempoolflags', '-blockminsize', '-sendfreetransactions', '-checklevel', '-liquidityprovider', '-anonymizepivxamount', '-dbcrashratio'])

def main():
used = check_output(CMD_GREP_ARGS, shell=True, universal_newlines=True)
Expand Down
10 changes: 10 additions & 0 deletions src/txdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

#include "txdb.h"

#include "random.h"
#include "pow.h"
#include "uint256.h"
#include "util.h"
#include "zpiv/zerocoin.h"

#include <stdint.h>
Expand Down Expand Up @@ -93,6 +95,7 @@ bool CCoinsViewDB::BatchWrite(CCoinsMap& mapCoins,
size_t count = 0;
size_t changed = 0;
size_t batch_size = (size_t) gArgs.GetArg("-dbbatchsize", nDefaultDbBatchSize);
int crash_simulate = gArgs.GetArg("-dbcrashratio", 0);

uint256 old_tip = GetBestBlock();
if (old_tip.IsNull()) {
Expand Down Expand Up @@ -134,6 +137,13 @@ bool CCoinsViewDB::BatchWrite(CCoinsMap& mapCoins,
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);
}
}
}
}

Expand Down

0 comments on commit 93f2b15

Please sign in to comment.