Skip to content

Commit d51fbab

Browse files
committed
wallet, test: Be able to always swap BDB endianness
1 parent 0b75315 commit d51fbab

File tree

5 files changed

+12
-1
lines changed

5 files changed

+12
-1
lines changed

src/dummywallet.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ void DummyWalletInit::AddWalletOptions(ArgsManager& argsman) const
5353
"-walletrejectlongchains",
5454
"-walletcrosschain",
5555
"-unsafesqlitesync",
56+
"-swapbdbendian",
5657
});
5758
}
5859

src/wallet/init.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ void WalletInit::AddWalletOptions(ArgsManager& argsman) const
8787
argsman.AddArg("-dblogsize=<n>", strprintf("Flush wallet database activity from memory to disk log every <n> megabytes (default: %u)", DatabaseOptions().max_log_mb), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::WALLET_DEBUG_TEST);
8888
argsman.AddArg("-flushwallet", strprintf("Run a thread to flush wallet periodically (default: %u)", DEFAULT_FLUSHWALLET), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::WALLET_DEBUG_TEST);
8989
argsman.AddArg("-privdb", strprintf("Sets the DB_PRIVATE flag in the wallet db environment (default: %u)", !DatabaseOptions().use_shared_memory), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::WALLET_DEBUG_TEST);
90+
argsman.AddArg("-swapbdbendian", "Swaps the internal endianness of BDB wallet databases (default: false)", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::WALLET_DEBUG_TEST);
9091
#else
91-
argsman.AddHiddenArgs({"-dblogsize", "-flushwallet", "-privdb"});
92+
argsman.AddHiddenArgs({"-dblogsize", "-flushwallet", "-privdb", "-swapbdbendian"});
9293
#endif
9394

9495
#ifdef USE_SQLITE

src/wallet/wallet.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,12 @@ std::shared_ptr<CWallet> CreateWallet(WalletContext& context, const std::string&
375375
uint64_t wallet_creation_flags = options.create_flags;
376376
const SecureString& passphrase = options.create_passphrase;
377377

378+
ArgsManager& args = *Assert(context.args);
379+
378380
if (wallet_creation_flags & WALLET_FLAG_DESCRIPTORS) options.require_format = DatabaseFormat::SQLITE;
381+
else if (args.GetBoolArg("-swapbdbendian", false)) {
382+
options.require_format = DatabaseFormat::BERKELEY_SWAP;
383+
}
379384

380385
// Indicate that the wallet is actually supposed to be blank and not just blank to make it encrypted
381386
bool create_blank = (wallet_creation_flags & WALLET_FLAG_BLANK_WALLET);

test/functional/test_runner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@
193193
'wallet_txn_doublespend.py --mineblock',
194194
'tool_wallet.py --legacy-wallet',
195195
'tool_wallet.py --legacy-wallet --bdbro',
196+
'tool_wallet.py --legacy-wallet --bdbro --swap-bdb-endian',
196197
'tool_wallet.py --descriptors',
197198
'tool_signet_miner.py --legacy-wallet',
198199
'tool_signet_miner.py --descriptors',

test/functional/tool_wallet.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,14 @@ class ToolWalletTest(BitcoinTestFramework):
2424
def add_options(self, parser):
2525
self.add_wallet_options(parser)
2626
parser.add_argument("--bdbro", action="store_true", help="Use the BerkeleyRO internal parser when dumping a Berkeley DB wallet file")
27+
parser.add_argument("--swap-bdb-endian", action="store_true",help="When making Legacy BDB wallets, always make then byte swapped internally")
2728

2829
def set_test_params(self):
2930
self.num_nodes = 1
3031
self.setup_clean_chain = True
3132
self.rpc_timeout = 120
33+
if self.options.swap_bdb_endian:
34+
self.extra_args = [["-swapbdbendian"]]
3235

3336
def skip_test_if_missing_module(self):
3437
self.skip_if_no_wallet()

0 commit comments

Comments
 (0)