@@ -3747,25 +3747,17 @@ DescriptorScriptPubKeyMan& CWallet::SetupDescriptorScriptPubKeyMan(WalletBatch&
3747
3747
return *out;
3748
3748
}
3749
3749
3750
- void CWallet::SetupDescriptorScriptPubKeyMans (const CExtKey& master_key)
3750
+ void CWallet::SetupDescriptorScriptPubKeyMans (WalletBatch& batch, const CExtKey& master_key)
3751
3751
{
3752
3752
AssertLockHeld (cs_wallet);
3753
-
3754
- // Create single batch txn
3755
- WalletBatch batch (GetDatabase ());
3756
- if (!batch.TxnBegin ()) throw std::runtime_error (" Error: cannot create db transaction for descriptors setup" );
3757
-
3758
3753
for (bool internal : {false , true }) {
3759
3754
for (OutputType t : OUTPUT_TYPES) {
3760
3755
SetupDescriptorScriptPubKeyMan (batch, master_key, t, internal);
3761
3756
}
3762
3757
}
3763
-
3764
- // Ensure information is committed to disk
3765
- if (!batch.TxnCommit ()) throw std::runtime_error (" Error: cannot commit db transaction for descriptors setup" );
3766
3758
}
3767
3759
3768
- void CWallet::SetupOwnDescriptorScriptPubKeyMans ()
3760
+ void CWallet::SetupOwnDescriptorScriptPubKeyMans (WalletBatch& batch )
3769
3761
{
3770
3762
AssertLockHeld (cs_wallet);
3771
3763
assert (!IsWalletFlagSet (WALLET_FLAG_EXTERNAL_SIGNER));
@@ -3778,15 +3770,18 @@ void CWallet::SetupOwnDescriptorScriptPubKeyMans()
3778
3770
CExtKey master_key;
3779
3771
master_key.SetSeed (seed_key);
3780
3772
3781
- SetupDescriptorScriptPubKeyMans (master_key);
3773
+ SetupDescriptorScriptPubKeyMans (batch, master_key);
3782
3774
}
3783
3775
3784
3776
void CWallet::SetupDescriptorScriptPubKeyMans ()
3785
3777
{
3786
3778
AssertLockHeld (cs_wallet);
3787
3779
3788
3780
if (!IsWalletFlagSet (WALLET_FLAG_EXTERNAL_SIGNER)) {
3789
- SetupOwnDescriptorScriptPubKeyMans ();
3781
+ if (!RunWithinTxn (GetDatabase (), /* process_desc=*/ " setup descriptors" , [&](WalletBatch& batch) EXCLUSIVE_LOCKS_REQUIRED (cs_wallet){
3782
+ SetupOwnDescriptorScriptPubKeyMans (batch);
3783
+ return true ;
3784
+ })) throw std::runtime_error (" Error: cannot process db transaction for descriptors setup" );
3790
3785
} else {
3791
3786
ExternalSigner signer = ExternalSignerScriptPubKeyMan::GetExternalSigner ();
3792
3787
@@ -4113,12 +4108,13 @@ util::Result<void> CWallet::ApplyMigrationData(MigrationData& data)
4113
4108
// Setup new descriptors
4114
4109
SetWalletFlag (WALLET_FLAG_DESCRIPTORS);
4115
4110
if (!IsWalletFlagSet (WALLET_FLAG_DISABLE_PRIVATE_KEYS)) {
4111
+ WalletBatch local_wallet_batch (GetDatabase ());
4116
4112
// Use the existing master key if we have it
4117
4113
if (data.master_key .key .IsValid ()) {
4118
- SetupDescriptorScriptPubKeyMans (data.master_key );
4114
+ SetupDescriptorScriptPubKeyMans (local_wallet_batch, data.master_key );
4119
4115
} else {
4120
4116
// Setup with a new seed if we don't.
4121
- SetupOwnDescriptorScriptPubKeyMans ();
4117
+ SetupOwnDescriptorScriptPubKeyMans (local_wallet_batch );
4122
4118
}
4123
4119
}
4124
4120
0 commit comments