Skip to content

Commit c0f3f32

Browse files
committed
wallet: Remove unused db functions
SOme db functions were for BDB, these are no longer needed.
1 parent 83af1a3 commit c0f3f32

File tree

15 files changed

+19
-150
lines changed

15 files changed

+19
-150
lines changed

src/bench/wallet_migration.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ static void WalletMigration(benchmark::Bench& bench)
5757
mtx.vout.emplace_back(COIN, GetScriptForDestination(dest));
5858
mtx.vout.emplace_back(COIN, scripts_watch_only.at(j % NUM_WATCH_ONLY_ADDR));
5959
mtx.vin.resize(2);
60-
wallet->AddToWallet(MakeTransactionRef(mtx), TxStateInactive{}, /*update_wtx=*/nullptr, /*fFlushOnClose=*/false, /*rescanning_old_block=*/true);
60+
wallet->AddToWallet(MakeTransactionRef(mtx), TxStateInactive{}, /*update_wtx=*/nullptr, /*rescanning_old_block=*/true);
6161
batch.WriteKey(pubkey, key.GetPrivKey(), CKeyMetadata());
6262
}
6363

src/wallet/db.h

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ class DatabaseBatch
6262
DatabaseBatch(const DatabaseBatch&) = delete;
6363
DatabaseBatch& operator=(const DatabaseBatch&) = delete;
6464

65-
virtual void Flush() = 0;
6665
virtual void Close() = 0;
6766

6867
template <typename K, typename T>
@@ -131,18 +130,14 @@ class WalletDatabase
131130
{
132131
public:
133132
/** Create dummy DB handle */
134-
WalletDatabase() : nUpdateCounter(0) {}
133+
WalletDatabase() = default;
135134
virtual ~WalletDatabase() = default;
136135

137136
/** Open the database if it is not already opened. */
138137
virtual void Open() = 0;
139138

140139
//! Counts the number of active database users to be sure that the database is not closed while someone is using it
141140
std::atomic<int> m_refcount{0};
142-
/** Indicate the a new database user has began using the database. Increments m_refcount */
143-
virtual void AddRef() = 0;
144-
/** Indicate that database user has stopped using the database and that it could be flushed or closed. Decrement m_refcount */
145-
virtual void RemoveRef() = 0;
146141

147142
/** Rewrite the entire database on disk, with the exception of key pszSkip if non-zero
148143
*/
@@ -152,33 +147,18 @@ class WalletDatabase
152147
*/
153148
virtual bool Backup(const std::string& strDest) const = 0;
154149

155-
/** Make sure all changes are flushed to database file.
156-
*/
157-
virtual void Flush() = 0;
158150
/** Flush to the database file and close the database.
159151
* Also close the environment if no other databases are open in it.
160152
*/
161153
virtual void Close() = 0;
162-
/* flush the wallet passively (TRY_LOCK)
163-
ideal to be called periodically */
164-
virtual bool PeriodicFlush() = 0;
165-
166-
virtual void IncrementUpdateCounter() = 0;
167-
168-
virtual void ReloadDbEnv() = 0;
169154

170155
/** Return path to main database file for logs and error messages. */
171156
virtual std::string Filename() = 0;
172157

173158
virtual std::string Format() = 0;
174159

175-
std::atomic<unsigned int> nUpdateCounter;
176-
unsigned int nLastSeen{0};
177-
unsigned int nLastFlushed{0};
178-
int64_t nLastWalletUpdate{0};
179-
180160
/** Make a DatabaseBatch connected to this database */
181-
virtual std::unique_ptr<DatabaseBatch> MakeBatch(bool flush_on_close = true) = 0;
161+
virtual std::unique_ptr<DatabaseBatch> MakeBatch() = 0;
182162
};
183163

184164
enum class DatabaseFormat {

src/wallet/interfaces.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ class WalletLoaderImpl : public WalletLoader
578578
m_context.scheduler = &scheduler;
579579
return StartWallets(m_context);
580580
}
581-
void flush() override { return FlushWallets(m_context); }
581+
void flush() override {}
582582
void stop() override { return StopWallets(m_context); }
583583
void setMockTime(int64_t time) override { return SetMockTime(time); }
584584
void schedulerMockForward(std::chrono::seconds delta) override { Assert(m_context.scheduler)->MockForward(delta); }

src/wallet/load.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,6 @@ void StartWallets(WalletContext& context)
162162
context.scheduler->scheduleEvery([&context] { MaybeResendWalletTxs(context); }, 1min);
163163
}
164164

165-
void FlushWallets(WalletContext& context)
166-
{
167-
for (const std::shared_ptr<CWallet>& pwallet : GetWallets(context)) {
168-
pwallet->Flush();
169-
}
170-
}
171-
172165
void StopWallets(WalletContext& context)
173166
{
174167
for (const std::shared_ptr<CWallet>& pwallet : GetWallets(context)) {

src/wallet/load.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ bool LoadWallets(WalletContext& context);
2828
//! Complete startup of wallets.
2929
void StartWallets(WalletContext& context);
3030

31-
//! Flush all wallets in preparation for shutdown.
32-
void FlushWallets(WalletContext& context);
33-
3431
//! Stop all wallets. Wallets will be flushed first.
3532
void StopWallets(WalletContext& context);
3633

src/wallet/migrate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ void BerkeleyRODatabase::Open()
699699
}
700700
}
701701

702-
std::unique_ptr<DatabaseBatch> BerkeleyRODatabase::MakeBatch(bool flush_on_close)
702+
std::unique_ptr<DatabaseBatch> BerkeleyRODatabase::MakeBatch()
703703
{
704704
return std::make_unique<BerkeleyROBatch>(*this);
705705
}

src/wallet/migrate.h

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@ class BerkeleyRODatabase : public WalletDatabase
3535
/** Open the database if it is not already opened. */
3636
void Open() override;
3737

38-
/** Indicate the a new database user has began using the database. Increments m_refcount */
39-
void AddRef() override {}
40-
/** Indicate that database user has stopped using the database and that it could be flushed or closed. Decrement m_refcount */
41-
void RemoveRef() override {}
42-
4338
/** Rewrite the entire database on disk, with the exception of key pszSkip if non-zero
4439
*/
4540
bool Rewrite(const char* pszSkip = nullptr) override { return false; }
@@ -48,28 +43,18 @@ class BerkeleyRODatabase : public WalletDatabase
4843
*/
4944
bool Backup(const std::string& strDest) const override;
5045

51-
/** Make sure all changes are flushed to database file.
52-
*/
53-
void Flush() override {}
5446
/** Flush to the database file and close the database.
5547
* Also close the environment if no other databases are open in it.
5648
*/
5749
void Close() override {}
58-
/* flush the wallet passively (TRY_LOCK)
59-
ideal to be called periodically */
60-
bool PeriodicFlush() override { return false; }
61-
62-
void IncrementUpdateCounter() override {}
63-
64-
void ReloadDbEnv() override {}
6550

6651
/** Return path to main database file for logs and error messages. */
6752
std::string Filename() override { return fs::PathToString(m_filepath); }
6853

6954
std::string Format() override { return "bdb_ro"; }
7055

7156
/** Make a DatabaseBatch connected to this database */
72-
std::unique_ptr<DatabaseBatch> MakeBatch(bool flush_on_close = true) override;
57+
std::unique_ptr<DatabaseBatch> MakeBatch() override;
7358
};
7459

7560
class BerkeleyROCursor : public DatabaseCursor
@@ -107,7 +92,6 @@ class BerkeleyROBatch : public DatabaseBatch
10792
BerkeleyROBatch(const BerkeleyROBatch&) = delete;
10893
BerkeleyROBatch& operator=(const BerkeleyROBatch&) = delete;
10994

110-
void Flush() override {}
11195
void Close() override {}
11296

11397
std::unique_ptr<DatabaseCursor> GetNewCursor() override { return std::make_unique<BerkeleyROCursor>(m_database); }

src/wallet/sqlite.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ int SQliteExecHandler::Exec(SQLiteDatabase& database, const std::string& stateme
390390
return sqlite3_exec(database.m_db, statement.data(), nullptr, nullptr, nullptr);
391391
}
392392

393-
std::unique_ptr<DatabaseBatch> SQLiteDatabase::MakeBatch(bool flush_on_close)
393+
std::unique_ptr<DatabaseBatch> SQLiteDatabase::MakeBatch()
394394
{
395395
// We ignore flush_on_close because we don't do manual flushing for SQLite
396396
return std::make_unique<SQLiteBatch>(*this);

src/wallet/sqlite.h

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,6 @@ class SQLiteBatch : public DatabaseBatch
8585

8686
void SetExecHandler(std::unique_ptr<SQliteExecHandler>&& handler) { m_exec_handler = std::move(handler); }
8787

88-
/* No-op. See comment on SQLiteDatabase::Flush */
89-
void Flush() override {}
90-
9188
void Close() override;
9289

9390
std::unique_ptr<DatabaseCursor> GetNewCursor() override;
@@ -140,36 +137,18 @@ class SQLiteDatabase : public WalletDatabase
140137
/** Close the database */
141138
void Close() override;
142139

143-
/* These functions are unused */
144-
void AddRef() override { assert(false); }
145-
void RemoveRef() override { assert(false); }
146-
147140
/** Rewrite the entire database on disk */
148141
bool Rewrite(const char* skip = nullptr) override;
149142

150143
/** Back up the entire database to a file.
151144
*/
152145
bool Backup(const std::string& dest) const override;
153146

154-
/** No-ops
155-
*
156-
* SQLite always flushes everything to the database file after each transaction
157-
* (each Read/Write/Erase that we do is its own transaction unless we called
158-
* TxnBegin) so there is no need to have Flush or Periodic Flush.
159-
*
160-
* There is no DB env to reload, so ReloadDbEnv has nothing to do
161-
*/
162-
void Flush() override {}
163-
bool PeriodicFlush() override { return false; }
164-
void ReloadDbEnv() override {}
165-
166-
void IncrementUpdateCounter() override { ++nUpdateCounter; }
167-
168147
std::string Filename() override { return m_file_path; }
169148
std::string Format() override { return "sqlite"; }
170149

171150
/** Make a SQLiteBatch connected to this database */
172-
std::unique_ptr<DatabaseBatch> MakeBatch(bool flush_on_close = true) override;
151+
std::unique_ptr<DatabaseBatch> MakeBatch() override;
173152

174153
/** Return true if there is an on-going txn in this connection */
175154
bool HasActiveTxn();

src/wallet/test/util.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ class MockableBatch : public DatabaseBatch
7676
explicit MockableBatch(MockableData& records, bool pass) : m_records(records), m_pass(pass) {}
7777
~MockableBatch() = default;
7878

79-
void Flush() override {}
8079
void Close() override {}
8180

8281
std::unique_ptr<DatabaseCursor> GetNewCursor() override
@@ -104,20 +103,14 @@ class MockableDatabase : public WalletDatabase
104103
~MockableDatabase() = default;
105104

106105
void Open() override {}
107-
void AddRef() override {}
108-
void RemoveRef() override {}
109106

110107
bool Rewrite(const char* pszSkip=nullptr) override { return m_pass; }
111108
bool Backup(const std::string& strDest) const override { return m_pass; }
112-
void Flush() override {}
113109
void Close() override {}
114-
bool PeriodicFlush() override { return m_pass; }
115-
void IncrementUpdateCounter() override {}
116-
void ReloadDbEnv() override {}
117110

118111
std::string Filename() override { return "mockable"; }
119112
std::string Format() override { return "mock"; }
120-
std::unique_ptr<DatabaseBatch> MakeBatch(bool flush_on_close = true) override { return std::make_unique<MockableBatch>(m_records, m_pass); }
113+
std::unique_ptr<DatabaseBatch> MakeBatch() override { return std::make_unique<MockableBatch>(m_records, m_pass); }
121114
};
122115

123116
std::unique_ptr<WalletDatabase> CreateMockableWalletDatabase(MockableData records = {});

0 commit comments

Comments
 (0)