aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonas Schnelli <[email protected]>2019-02-17 17:28:04 -1000
committerJonas Schnelli <[email protected]>2019-02-17 19:32:58 -1000
commit0bedcbafdfaa0e980ad91c0ba4b9039575017f0e (patch)
treef31090773e75bb5c046e0c229bece22bc472a4bd
parentMerge #15431: msvc: scripted-diff: Remove NDEBUG pre-define in project file (diff)
downloaddiscoin-0bedcbafdfaa0e980ad91c0ba4b9039575017f0e.tar.xz
discoin-0bedcbafdfaa0e980ad91c0ba4b9039575017f0e.zip
Use a single wallet batch for UpgradeKeyMetadata
-rw-r--r--src/wallet/wallet.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
index d174e308f..388422bec 100644
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -371,6 +371,8 @@ void CWallet::UpgradeKeyMetadata()
return;
}
+ std::unique_ptr<WalletBatch> batch = MakeUnique<WalletBatch>(*database);
+ size_t cnt = 0;
for (auto& meta_pair : mapKeyMetadata) {
CKeyMetadata& meta = meta_pair.second;
if (!meta.hd_seed_id.IsNull() && !meta.has_key_origin && meta.hdKeypath != "s") { // If the hdKeypath is "s", that's the seed and it doesn't have a key origin
@@ -392,10 +394,15 @@ void CWallet::UpgradeKeyMetadata()
// Write meta to wallet
CPubKey pubkey;
if (GetPubKey(meta_pair.first, pubkey)) {
- WriteKeyMetadata(meta, pubkey, true);
+ batch->WriteKeyMetadata(meta, pubkey, true);
+ if (++cnt % 1000 == 0) {
+ // avoid creating overlarge in-memory batches in case the wallet contains large amounts of keys
+ batch.reset(new WalletBatch(*database));
+ }
}
}
}
+ batch.reset(); //write before setting the flag
SetWalletFlag(WALLET_FLAG_KEY_ORIGIN_METADATA);
}