5
5
#include < bitcoin-build-config.h> // IWYU pragma: keep
6
6
7
7
#include < bench/bench.h>
8
+ #include < kernel/chain.h>
8
9
#include < interfaces/chain.h>
9
10
#include < node/context.h>
10
11
#include < test/util/mining.h>
16
17
17
18
#include < optional>
18
19
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
20
21
21
22
namespace wallet {
22
23
@@ -32,41 +33,39 @@ static void WalletMigration(benchmark::Bench& bench)
32
33
int NUM_WATCH_ONLY_ADDR = 20 ;
33
34
34
35
// 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 ();
43
39
44
40
// Add watch-only addresses
45
41
std::vector<CScript> scripts_watch_only;
46
42
for (int w = 0 ; w < NUM_WATCH_ONLY_ADDR; ++w) {
47
43
CKey key = GenerateRandomKey ();
48
44
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) );
53
49
}
54
50
55
51
// 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
+
57
60
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));
60
62
mtx.vout .emplace_back (COIN, scripts_watch_only.at (j % NUM_WATCH_ONLY_ADDR));
61
63
mtx.vin .resize (2 );
62
64
wallet->AddToWallet (MakeTransactionRef (mtx), TxStateInactive{}, /* update_wtx=*/ nullptr , /* fFlushOnClose=*/ false , /* rescanning_old_block=*/ true );
63
65
}
64
66
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 );
70
69
assert (res);
71
70
assert (res->wallet );
72
71
assert (res->watchonly_wallet );
0 commit comments