From 411f994355435a83538da57c8467361f9dc650e2 Mon Sep 17 00:00:00 2001 From: Luke Alonso Date: Sat, 6 Jan 2018 22:01:41 -0800 Subject: [PATCH] Add test for wallet password race When the wallet password is modified it currently is a non-atomic operation. While we consider how to change the design to mitigate the condition, here's a test case that reproduces the problem. --- rai/core_test/wallet.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/rai/core_test/wallet.cpp b/rai/core_test/wallet.cpp index 9c1294cc..163d97b6 100644 --- a/rai/core_test/wallet.cpp +++ b/rai/core_test/wallet.cpp @@ -882,3 +882,27 @@ TEST (wallet, send_race) ASSERT_LT (iterations, 200); } } + +TEST (wallet, password_race) +{ + rai::system system (24000, 1); + rai::thread_runner runner (system.service, system.nodes[0]->config.io_threads); + auto wallet = system.wallet (0); + system.nodes[0]->background ([&wallet]() { + for (int i = 0; i < 100; i++) { + rai::transaction transaction (wallet->store.environment, nullptr, true); + wallet->store.rekey (transaction, std::to_string(i)); + } + }); + for (int i = 0; i < 100; i++) { + rai::transaction transaction (wallet->store.environment, nullptr, false); + // Password should always be valid, the rekey operation should be atomic. + bool ok = wallet->store.valid_password (transaction); + EXPECT_TRUE (ok); + if (!ok) { + break; + } + } + system.stop (); + runner.join (); +} \ No newline at end of file