Skip to content

Commit

Permalink
fix: autobackup influences an exclusive locks made by SQLite
Browse files Browse the repository at this point in the history
It happens if dash is build with support of both SQLite and BDB
  • Loading branch information
knst committed Mar 6, 2024
1 parent e542cd2 commit 45fc8a4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/wallet/bdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ class BerkeleyDatabase : public WalletDatabase

/** Make a BerkeleyBatch connected to this database */
std::unique_ptr<DatabaseBatch> MakeBatch(bool flush_on_close = true) override;

virtual bool SupportsAutoBackup() override { return true; }
};

/** RAII class that provides access to a Berkeley database */
Expand Down
2 changes: 2 additions & 0 deletions src/wallet/db.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ class WalletDatabase

/** Make a DatabaseBatch connected to this database */
virtual std::unique_ptr<DatabaseBatch> MakeBatch(bool flush_on_close = true) = 0;

virtual bool SupportsAutoBackup() { return false; }
};

/** RAII class that provides access to a DummyDatabase. Never fails. */
Expand Down
8 changes: 7 additions & 1 deletion src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4502,6 +4502,7 @@ std::shared_ptr<CWallet> CWallet::Create(interfaces::Chain& chain, interfaces::C
// TODO: Can't use std::make_shared because we need a custom deleter but
// should be possible to use std::allocate_shared.
std::shared_ptr<CWallet> walletInstance(new CWallet(&chain, &coinjoin_loader, name, std::move(database)), ReleaseWallet);
// TODO: refactor this condition: validation of error looks like workaround
if (!walletInstance->AutoBackupWallet(walletFile, error, warnings) && !error.original.empty()) {
return nullptr;
}
Expand Down Expand Up @@ -4942,7 +4943,12 @@ bool CWallet::AutoBackupWallet(const fs::path& wallet_path, bilingual_str& error
if (strWalletName.empty()) {
strWalletName = "wallet.dat";
}

// This condition is required to be sure that wallet.dat won't be re-opened by IsBDBFile
// Re-opening of database file brokes an exclusive inter-process lock for SQLite
if (m_database && !m_database->SupportsAutoBackup()) {
WalletLogPrintf("Automatic wallet backups are not supported!\n");
return false;
}
if (!wallet_path.empty() && !IsBDBFile(BDBDataFile(wallet_path))) {
WalletLogPrintf("Automatic wallet backups are currently only supported with Berkeley DB!\n");
return false;
Expand Down

0 comments on commit 45fc8a4

Please sign in to comment.