mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-19 05:12:03 +02:00
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.
This commit is contained in:
parent
075aa44ceb
commit
3eb769f150
@ -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);
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
@ -1274,19 +1275,22 @@ bool LegacyScriptPubKeyMan::TopUp(unsigned int kpSize)
|
|||||||
return false;
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
for (auto& [chain_id, chain] : m_inactive_hd_chains) {
|
for (auto& [chain_id, chain] : m_inactive_hd_chains) {
|
||||||
if (!TopUpChain(chain, kpSize)) {
|
if (!TopUpChain(batch, chain, kpSize)) {
|
||||||
return false;
|
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();
|
NotifyCanGetAddressesChanged();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LegacyScriptPubKeyMan::TopUpChain(CHDChain& chain, unsigned int kpSize)
|
bool LegacyScriptPubKeyMan::TopUpChain(WalletBatch& batch, CHDChain& chain, unsigned int kpSize)
|
||||||
{
|
{
|
||||||
LOCK(cs_KeyStore);
|
LOCK(cs_KeyStore);
|
||||||
|
|
||||||
@ -1318,7 +1322,6 @@ bool LegacyScriptPubKeyMan::TopUpChain(CHDChain& chain, unsigned int kpSize)
|
|||||||
missingInternal = 0;
|
missingInternal = 0;
|
||||||
}
|
}
|
||||||
bool internal = false;
|
bool internal = false;
|
||||||
WalletBatch batch(m_storage.GetDatabase());
|
|
||||||
for (int64_t i = missingInternal + missingExternal; i--;) {
|
for (int64_t i = missingInternal + missingExternal; i--;) {
|
||||||
if (i < missingInternal) {
|
if (i < missingInternal) {
|
||||||
internal = true;
|
internal = true;
|
||||||
|
@ -366,7 +366,7 @@ private:
|
|||||||
*/
|
*/
|
||||||
bool TopUpInactiveHDChain(const CKeyID seed_id, int64_t index, bool internal);
|
bool TopUpInactiveHDChain(const CKeyID seed_id, int64_t index, bool internal);
|
||||||
|
|
||||||
bool TopUpChain(CHDChain& chain, unsigned int size);
|
bool TopUpChain(WalletBatch& batch, CHDChain& chain, unsigned int size);
|
||||||
public:
|
public:
|
||||||
LegacyScriptPubKeyMan(WalletStorage& storage, int64_t keypool_size) : ScriptPubKeyMan(storage), m_keypool_size(keypool_size) {}
|
LegacyScriptPubKeyMan(WalletStorage& storage, int64_t keypool_size) : ScriptPubKeyMan(storage), m_keypool_size(keypool_size) {}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user