aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/scriptpubkeyman.cpp
diff options
context:
space:
mode:
authorfurszy <matiasfurszyfer@protonmail.com>2023-07-20 18:10:41 -0300
committerfurszy <matiasfurszyfer@protonmail.com>2023-11-21 23:01:30 -0300
commit3eb769f15013873755e482707cad341bc1ce8a8c (patch)
treef015bb33f7ec10334562262ba5de124c0718cdbf /src/wallet/scriptpubkeyman.cpp
parent075aa44ceba41fa82bb3ce2295e2962e5fd0508e (diff)
downloadbitcoin-3eb769f15013873755e482707cad341bc1ce8a8c.tar.xz
wallet: batch legacy spkm TopUp
Instead of performing multiple atomic write operations per legacy spkm setup call, batch them all within a single atomic db txn.
Diffstat (limited to 'src/wallet/scriptpubkeyman.cpp')
-rw-r--r--src/wallet/scriptpubkeyman.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/wallet/scriptpubkeyman.cpp b/src/wallet/scriptpubkeyman.cpp
index 997348d371..ce757a1c6b 100644
--- a/src/wallet/scriptpubkeyman.cpp
+++ b/src/wallet/scriptpubkeyman.cpp
@@ -333,7 +333,8 @@ bool LegacyScriptPubKeyMan::TopUpInactiveHDChain(const CKeyID seed_id, int64_t i
chain.m_next_external_index = std::max(chain.m_next_external_index, index + 1);
}
- TopUpChain(chain, 0);
+ WalletBatch batch(m_storage.GetDatabase());
+ TopUpChain(batch, chain, 0);
return true;
}
@@ -1274,19 +1275,22 @@ bool LegacyScriptPubKeyMan::TopUp(unsigned int kpSize)
return false;
}
- if (!TopUpChain(m_hd_chain, kpSize)) {
+ WalletBatch batch(m_storage.GetDatabase());
+ if (!batch.TxnBegin()) return false;
+ if (!TopUpChain(batch, m_hd_chain, kpSize)) {
return false;
}
for (auto& [chain_id, chain] : m_inactive_hd_chains) {
- if (!TopUpChain(chain, kpSize)) {
+ if (!TopUpChain(batch, chain, kpSize)) {
return false;
}
}
+ if (!batch.TxnCommit()) throw std::runtime_error(strprintf("Error during keypool top up. Cannot commit changes for wallet %s", m_storage.GetDisplayName()));
NotifyCanGetAddressesChanged();
return true;
}
-bool LegacyScriptPubKeyMan::TopUpChain(CHDChain& chain, unsigned int kpSize)
+bool LegacyScriptPubKeyMan::TopUpChain(WalletBatch& batch, CHDChain& chain, unsigned int kpSize)
{
LOCK(cs_KeyStore);
@@ -1318,7 +1322,6 @@ bool LegacyScriptPubKeyMan::TopUpChain(CHDChain& chain, unsigned int kpSize)
missingInternal = 0;
}
bool internal = false;
- WalletBatch batch(m_storage.GetDatabase());
for (int64_t i = missingInternal + missingExternal; i--;) {
if (i < missingInternal) {
internal = true;