aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Chow <achow101-github@achow101.com>2021-04-07 20:55:09 -0400
committerAndrew Chow <achow101-github@achow101.com>2021-04-12 19:29:03 -0400
commit41f891da508114f1fd4df30b4068073ec30abc2a (patch)
tree1b3e171dfbc7eadf4d503659e4c973dcc93c3d9d /src
parentcb79cabdd9d9a6d183cf09575dd46925f2c9cb3b (diff)
downloadbitcoin-41f891da508114f1fd4df30b4068073ec30abc2a.tar.xz
tests: Skip SQLite fsyncs while testing
Since we want tests to run quickly, and since tests do a lot more db operations than expected we expect to see in actual usage, we disable sqlite's syncing behavior to make db operations run much faster. This syncing behavior is necessary for normal operation as it helps guarantee that data won't become lost or corrupted, but in tests, we don't care about that.
Diffstat (limited to 'src')
-rw-r--r--src/dummywallet.cpp1
-rw-r--r--src/wallet/init.cpp6
-rw-r--r--src/wallet/sqlite.cpp9
-rw-r--r--src/wallet/test/wallet_tests.cpp2
4 files changed, 18 insertions, 0 deletions
diff --git a/src/dummywallet.cpp b/src/dummywallet.cpp
index bb06c95e7d..95886d3138 100644
--- a/src/dummywallet.cpp
+++ b/src/dummywallet.cpp
@@ -50,6 +50,7 @@ void DummyWalletInit::AddWalletOptions(ArgsManager& argsman) const
"-flushwallet",
"-privdb",
"-walletrejectlongchains",
+ "-unsafesqlitesync",
});
}
diff --git a/src/wallet/init.cpp b/src/wallet/init.cpp
index fdeead1fa5..0dc220b6fd 100644
--- a/src/wallet/init.cpp
+++ b/src/wallet/init.cpp
@@ -82,6 +82,12 @@ void WalletInit::AddWalletOptions(ArgsManager& argsman) const
argsman.AddHiddenArgs({"-dblogsize", "-flushwallet", "-privdb"});
#endif
+#ifdef USE_SQLITE
+ argsman.AddArg("-unsafesqlitesync", "Set SQLite synchronous=OFF to disable waiting for the database to sync to disk. This is unsafe and can cause data loss and corruption. This option is only used by tests to improve their performance (default: false)", ArgsManager::ALLOW_BOOL | ArgsManager::DEBUG_ONLY, OptionsCategory::WALLET_DEBUG_TEST);
+#else
+ argsman.AddHiddenArgs({"-unsafesqlitesync"});
+#endif
+
argsman.AddArg("-walletrejectlongchains", strprintf("Wallet will not create transactions that violate mempool chain limits (default: %u)", DEFAULT_WALLET_REJECT_LONG_CHAINS), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::WALLET_DEBUG_TEST);
argsman.AddHiddenArgs({"-zapwallettxes"});
diff --git a/src/wallet/sqlite.cpp b/src/wallet/sqlite.cpp
index 91891c5fc2..e245a277e4 100644
--- a/src/wallet/sqlite.cpp
+++ b/src/wallet/sqlite.cpp
@@ -233,6 +233,15 @@ void SQLiteDatabase::Open()
throw std::runtime_error(strprintf("SQLiteDatabase: Failed to enable fullfsync: %s\n", sqlite3_errstr(ret)));
}
+ if (gArgs.GetBoolArg("-unsafesqlitesync", false)) {
+ // Use normal synchronous mode for the journal
+ LogPrintf("WARNING SQLite is configured to not wait for data to be flushed to disk. Data loss and corruption may occur.\n");
+ ret = sqlite3_exec(m_db, "PRAGMA synchronous = OFF", nullptr, nullptr, nullptr);
+ if (ret != SQLITE_OK) {
+ throw std::runtime_error(strprintf("SQLiteDatabase: Failed to set synchronous mode to OFF: %s\n", sqlite3_errstr(ret)));
+ }
+ }
+
// Make the table for our key-value pairs
// First check that the main table exists
sqlite3_stmt* check_main_stmt{nullptr};
diff --git a/src/wallet/test/wallet_tests.cpp b/src/wallet/test/wallet_tests.cpp
index ba2e17d62a..c6bce20394 100644
--- a/src/wallet/test/wallet_tests.cpp
+++ b/src/wallet/test/wallet_tests.cpp
@@ -695,6 +695,7 @@ BOOST_FIXTURE_TEST_CASE(wallet_descriptor_test, BasicTestingSetup)
//! rescanning where new transactions in new blocks could be lost.
BOOST_FIXTURE_TEST_CASE(CreateWallet, TestChain100Setup)
{
+ gArgs.ForceSetArg("-unsafesqlitesync", "1");
// Create new wallet with known key and unload it.
auto wallet = TestLoadWallet(*m_node.chain);
CKey key;
@@ -790,6 +791,7 @@ BOOST_FIXTURE_TEST_CASE(CreateWallet, TestChain100Setup)
BOOST_FIXTURE_TEST_CASE(ZapSelectTx, TestChain100Setup)
{
+ gArgs.ForceSetArg("-unsafesqlitesync", "1");
auto wallet = TestLoadWallet(*m_node.chain);
CKey key;
key.MakeNewKey(true);