55#include < bitcoin-build-config.h> // IWYU pragma: keep
66
77#include < bench/bench.h>
8+ #include < kernel/chain.h>
89#include < interfaces/chain.h>
910#include < node/context.h>
1011#include < test/util/mining.h>
1617
1718#include < optional>
1819
19- #if defined(USE_BDB) && defined( USE_SQLITE) // only enable benchmark when bdb and sqlite are enabled
20+ #if defined(USE_SQLITE) // only enable benchmark when sqlite is enabled
2021
2122namespace wallet {
2223
@@ -32,41 +33,39 @@ static void WalletMigration(benchmark::Bench& bench)
3233 int NUM_WATCH_ONLY_ADDR = 20 ;
3334
3435 // Setup legacy wallet
35- DatabaseOptions options;
36- options.use_unsafe_sync = true ;
37- options.verify = false ;
38- DatabaseStatus status;
39- bilingual_str error;
40- auto database = MakeWalletDatabase (fs::PathToString (test_setup->m_path_root / " legacy" ), options, status, error);
41- uint64_t create_flags = 0 ;
42- auto wallet = TestLoadWallet (std::move (database), context, create_flags);
36+ std::unique_ptr<CWallet> wallet = std::make_unique<CWallet>(test_setup->m_node .chain .get (), " " , CreateMockableWalletDatabase ());
37+ wallet->chainStateFlushed (ChainstateRole::NORMAL, CBlockLocator{});
38+ LegacyDataSPKM* legacy_spkm = wallet->GetOrCreateLegacyDataSPKM ();
4339
4440 // Add watch-only addresses
4541 std::vector<CScript> scripts_watch_only;
4642 for (int w = 0 ; w < NUM_WATCH_ONLY_ADDR; ++w) {
4743 CKey key = GenerateRandomKey ();
4844 LOCK (wallet->cs_wallet );
49- const CScript& script = scripts_watch_only. emplace_back ( GetScriptForDestination ( GetDestinationForKey (key.GetPubKey (), OutputType::LEGACY)) );
50- bool res = wallet-> ImportScriptPubKeys ( strprintf ( " watch_%d " , w), {script},
51- /* have_solving_data= */ false , /* apply_label= */ true , /* timestamp= */ 1 );
52- assert (res );
45+ const auto & dest = GetDestinationForKey (key.GetPubKey (), OutputType::LEGACY);
46+ const CScript& script = scripts_watch_only. emplace_back ( GetScriptForDestination (dest));
47+ assert (legacy_spkm-> LoadWatchOnly (script) );
48+ assert (wallet-> SetAddressBook (dest, strprintf ( " watch_%d " , w), /* purpose= */ std:: nullopt ) );
5349 }
5450
5551 // Generate transactions and local addresses
56- for (int j = 0 ; j < 400 ; ++j) {
52+ for (int j = 0 ; j < 500 ; ++j) {
53+ CKey key = GenerateRandomKey ();
54+ CPubKey pubkey = key.GetPubKey ();
55+ // Load key, scripts and create address book record
56+ Assert (legacy_spkm->LoadKey (key, pubkey));
57+ CTxDestination dest{PKHash (pubkey)};
58+ Assert (wallet->SetAddressBook (dest, strprintf (" legacy_%d" , j), /* purpose=*/ std::nullopt ));
59+
5760 CMutableTransaction mtx;
58- mtx.vout .emplace_back (COIN, GetScriptForDestination (*Assert (wallet->GetNewDestination (OutputType::BECH32, strprintf (" bench_%d" , j)))));
59- mtx.vout .emplace_back (COIN, GetScriptForDestination (*Assert (wallet->GetNewDestination (OutputType::LEGACY, strprintf (" legacy_%d" , j)))));
61+ mtx.vout .emplace_back (COIN, GetScriptForDestination (dest));
6062 mtx.vout .emplace_back (COIN, scripts_watch_only.at (j % NUM_WATCH_ONLY_ADDR));
6163 mtx.vin .resize (2 );
6264 wallet->AddToWallet (MakeTransactionRef (mtx), TxStateInactive{}, /* update_wtx=*/ nullptr , /* fFlushOnClose=*/ false , /* rescanning_old_block=*/ true );
6365 }
6466
65- // Unload so the migration process loads it
66- TestUnloadWallet (std::move (wallet));
67-
68- bench.epochs (/* numEpochs=*/ 1 ).run ([&] {
69- util::Result<MigrationResult> res = MigrateLegacyToDescriptor (fs::PathToString (test_setup->m_path_root / " legacy" ), " " , context);
67+ bench.epochs (/* numEpochs=*/ 1 ).run ([&context, &wallet] {
68+ util::Result<MigrationResult> res = MigrateLegacyToDescriptor (std::move (wallet), /* passphrase=*/ " " , context, /* was_loaded=*/ false );
7069 assert (res);
7170 assert (res->wallet );
7271 assert (res->watchonly_wallet );
0 commit comments