Skip to content

Commit ccb26cf

Browse files
committed
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
1 parent d6576e3 commit ccb26cf

File tree

3 files changed

+7
-14
lines changed

3 files changed

+7
-14
lines changed

src/wallet/rpcdump.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,8 +1261,9 @@ static UniValue ProcessImport(CWallet * const pwallet, const UniValue& data, con
12611261

12621262
// All good, time to import
12631263
pwallet->MarkDirty();
1264+
WalletBatch batch(pwallet->GetDBHandle());
12641265
for (const auto& entry : import_data.import_scripts) {
1265-
if (!pwallet->HaveCScript(CScriptID(entry)) && !pwallet->AddCScript(entry)) {
1266+
if (!pwallet->HaveCScript(CScriptID(entry)) && !pwallet->AddCScriptWithDB(batch, entry)) {
12661267
throw JSONRPCError(RPC_WALLET_ERROR, "Error adding script to wallet");
12671268
}
12681269
}
@@ -1273,13 +1274,13 @@ static UniValue ProcessImport(CWallet * const pwallet, const UniValue& data, con
12731274
assert(key.VerifyPubKey(pubkey));
12741275
pwallet->mapKeyMetadata[id].nCreateTime = timestamp;
12751276
// If the private key is not present in the wallet, insert it.
1276-
if (!pwallet->HaveKey(id) && !pwallet->AddKeyPubKey(key, pubkey)) {
1277+
if (!pwallet->HaveKey(id) && !pwallet->AddKeyPubKeyWithDB(batch, key, pubkey)) {
12771278
throw JSONRPCError(RPC_WALLET_ERROR, "Error adding key to wallet");
12781279
}
12791280
pwallet->UpdateTimeFirstKey(timestamp);
12801281
}
12811282
for (const auto& entry : import_data.key_origins) {
1282-
pwallet->AddKeyOrigin(entry.second.first, entry.second.second);
1283+
pwallet->AddKeyOriginWithDB(batch, entry.second.first, entry.second.second);
12831284
}
12841285
for (const CKeyID& id : ordered_pubkeys) {
12851286
auto entry = pubkey_map.find(id);
@@ -1288,20 +1289,20 @@ static UniValue ProcessImport(CWallet * const pwallet, const UniValue& data, con
12881289
}
12891290
const CPubKey& pubkey = entry->second;
12901291
CPubKey temp;
1291-
if (!pwallet->GetPubKey(id, temp) && !pwallet->AddWatchOnly(GetScriptForRawPubKey(pubkey), timestamp)) {
1292+
if (!pwallet->GetPubKey(id, temp) && !pwallet->AddWatchOnlyWithDB(batch, GetScriptForRawPubKey(pubkey), timestamp)) {
12921293
throw JSONRPCError(RPC_WALLET_ERROR, "Error adding address to wallet");
12931294
}
12941295
pwallet->mapKeyMetadata[id].nCreateTime = timestamp;
12951296

12961297
// Add to keypool only works with pubkeys
12971298
if (add_keypool) {
1298-
pwallet->AddKeypoolPubkey(pubkey, internal);
1299+
pwallet->AddKeypoolPubkeyWithDB(pubkey, internal, batch);
12991300
}
13001301
}
13011302

13021303
for (const CScript& script : script_pub_keys) {
13031304
if (!have_solving_data || !::IsMine(*pwallet, script)) { // Always call AddWatchOnly for non-solvable watch-only, so that watch timestamp gets updated
1304-
if (!pwallet->AddWatchOnly(script, timestamp)) {
1305+
if (!pwallet->AddWatchOnlyWithDB(batch, script, timestamp)) {
13051306
throw JSONRPCError(RPC_WALLET_ERROR, "Error adding address to wallet");
13061307
}
13071308
}

src/wallet/wallet.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3372,13 +3372,6 @@ bool CWallet::TopUpKeyPool(unsigned int kpSize)
33723372
return true;
33733373
}
33743374

3375-
void CWallet::AddKeypoolPubkey(const CPubKey& pubkey, const bool internal)
3376-
{
3377-
WalletBatch batch(*database);
3378-
AddKeypoolPubkeyWithDB(pubkey, internal, batch);
3379-
NotifyCanGetAddressesChanged();
3380-
}
3381-
33823375
void CWallet::AddKeypoolPubkeyWithDB(const CPubKey& pubkey, const bool internal, WalletBatch& batch)
33833376
{
33843377
LOCK(cs_wallet);

src/wallet/wallet.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -994,7 +994,6 @@ class CWallet final : public CCryptoKeyStore, private interfaces::Chain::Notific
994994
bool NewKeyPool();
995995
size_t KeypoolCountExternalKeys() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
996996
bool TopUpKeyPool(unsigned int kpSize = 0);
997-
void AddKeypoolPubkey(const CPubKey& pubkey, const bool internal);
998997
void AddKeypoolPubkeyWithDB(const CPubKey& pubkey, const bool internal, WalletBatch& batch);
999998

1000999
/**

0 commit comments

Comments
 (0)