diff options
author | Andrew Chow <achow101-github@achow101.com> | 2019-04-03 18:57:33 -0400 |
---|---|---|
committer | Andrew Chow <achow101-github@achow101.com> | 2019-05-18 12:59:17 -0400 |
commit | ccb26cf347a6fcc861768bbfbbd652e683ffd5bb (patch) | |
tree | ba68494d972c3a4441bd2268f8a3cf798a2f08e0 | |
parent | d6576e349e8a18289b0b1caa409c4de509250c3b (diff) | |
download | bitcoin-ccb26cf347a6fcc861768bbfbbd652e683ffd5bb.tar.xz |
Batch writes for importmulti
When writing all of the imported data to the wallet, use a common
WalletBatch object so that batch writes are done and the writes
finish more quickly.
AddKeypoolPubkey is no longer needed so it is also removed
-rw-r--r-- | src/wallet/rpcdump.cpp | 13 | ||||
-rw-r--r-- | src/wallet/wallet.cpp | 7 | ||||
-rw-r--r-- | src/wallet/wallet.h | 1 |
3 files changed, 7 insertions, 14 deletions
diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index c339e111ba..18e58fac7a 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -1261,8 +1261,9 @@ static UniValue ProcessImport(CWallet * const pwallet, const UniValue& data, con // All good, time to import pwallet->MarkDirty(); + WalletBatch batch(pwallet->GetDBHandle()); for (const auto& entry : import_data.import_scripts) { - if (!pwallet->HaveCScript(CScriptID(entry)) && !pwallet->AddCScript(entry)) { + if (!pwallet->HaveCScript(CScriptID(entry)) && !pwallet->AddCScriptWithDB(batch, entry)) { throw JSONRPCError(RPC_WALLET_ERROR, "Error adding script to wallet"); } } @@ -1273,13 +1274,13 @@ static UniValue ProcessImport(CWallet * const pwallet, const UniValue& data, con assert(key.VerifyPubKey(pubkey)); pwallet->mapKeyMetadata[id].nCreateTime = timestamp; // If the private key is not present in the wallet, insert it. - if (!pwallet->HaveKey(id) && !pwallet->AddKeyPubKey(key, pubkey)) { + if (!pwallet->HaveKey(id) && !pwallet->AddKeyPubKeyWithDB(batch, key, pubkey)) { throw JSONRPCError(RPC_WALLET_ERROR, "Error adding key to wallet"); } pwallet->UpdateTimeFirstKey(timestamp); } for (const auto& entry : import_data.key_origins) { - pwallet->AddKeyOrigin(entry.second.first, entry.second.second); + pwallet->AddKeyOriginWithDB(batch, entry.second.first, entry.second.second); } for (const CKeyID& id : ordered_pubkeys) { auto entry = pubkey_map.find(id); @@ -1288,20 +1289,20 @@ static UniValue ProcessImport(CWallet * const pwallet, const UniValue& data, con } const CPubKey& pubkey = entry->second; CPubKey temp; - if (!pwallet->GetPubKey(id, temp) && !pwallet->AddWatchOnly(GetScriptForRawPubKey(pubkey), timestamp)) { + if (!pwallet->GetPubKey(id, temp) && !pwallet->AddWatchOnlyWithDB(batch, GetScriptForRawPubKey(pubkey), timestamp)) { throw JSONRPCError(RPC_WALLET_ERROR, "Error adding address to wallet"); } pwallet->mapKeyMetadata[id].nCreateTime = timestamp; // Add to keypool only works with pubkeys if (add_keypool) { - pwallet->AddKeypoolPubkey(pubkey, internal); + pwallet->AddKeypoolPubkeyWithDB(pubkey, internal, batch); } } for (const CScript& script : script_pub_keys) { if (!have_solving_data || !::IsMine(*pwallet, script)) { // Always call AddWatchOnly for non-solvable watch-only, so that watch timestamp gets updated - if (!pwallet->AddWatchOnly(script, timestamp)) { + if (!pwallet->AddWatchOnlyWithDB(batch, script, timestamp)) { throw JSONRPCError(RPC_WALLET_ERROR, "Error adding address to wallet"); } } diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 26f48fccdc..dfe84238ff 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3372,13 +3372,6 @@ bool CWallet::TopUpKeyPool(unsigned int kpSize) return true; } -void CWallet::AddKeypoolPubkey(const CPubKey& pubkey, const bool internal) -{ - WalletBatch batch(*database); - AddKeypoolPubkeyWithDB(pubkey, internal, batch); - NotifyCanGetAddressesChanged(); -} - void CWallet::AddKeypoolPubkeyWithDB(const CPubKey& pubkey, const bool internal, WalletBatch& batch) { LOCK(cs_wallet); diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 487fc31e0d..f826f9a137 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -994,7 +994,6 @@ public: bool NewKeyPool(); size_t KeypoolCountExternalKeys() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); bool TopUpKeyPool(unsigned int kpSize = 0); - void AddKeypoolPubkey(const CPubKey& pubkey, const bool internal); void AddKeypoolPubkeyWithDB(const CPubKey& pubkey, const bool internal, WalletBatch& batch); /** |