Skip to content

Commit 0700b6f

Browse files
committed
Merge bitcoin#11851: scripted-diff: Rename wallet database classes
9b0f0c5 Add m_ prefix to WalletBatch::m_batch (Russell Yanofsky) 398c6f0 Update walletdb comment after renaming. (Russell Yanofsky) ea23945 scripted-diff: Rename wallet database classes (Russell Yanofsky) Pull request description: Scripted diff to rename some wallet classes. Motivated by discussion in bitcoin#11687 (comment) | Current | New | | ---------------- | ------------------- | | CDBEnv | BerkeleyEnvironment | | CDB | BerkeleyBatch | | CWalletDBWrapper | WalletDatabase | | CWalletDB | WalletBatch | Berkeley\* classes are intended to contain BDB specific code, while Wallet\* classes are intended to be more backend-agnostic. Also renamed associated variables: | Current | New | | ------------------- | --------------- | | dbw | database | | pwalletdb | batch | | pwalletdbEncryption | encrypted_batch | Tree-SHA512: 372f2e24b2deb59d4792b5ed578aaf0cce51b6db41c400bef5d0c2cd7833e62ae4d4afa0f6000268d52e15b20f737c5a55f1cecf7768556a782fd8cd6fe051d9
2 parents a7cbe38 + 9b0f0c5 commit 0700b6f

14 files changed

+338
-338
lines changed

src/bench/coin_selection.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static void addCoin(const CAmount& nValue, const CWallet& wallet, std::vector<CO
3333
// (https://github.com/bitcoin/bitcoin/issues/7883#issuecomment-224807484)
3434
static void CoinSelection(benchmark::State& state)
3535
{
36-
const CWallet wallet("dummy", CWalletDBWrapper::CreateDummy());
36+
const CWallet wallet("dummy", WalletDatabase::CreateDummy());
3737
std::vector<COutput> vCoins;
3838
LOCK(wallet.cs_wallet);
3939

src/qt/test/wallettests.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ void TestGUI()
158158
for (int i = 0; i < 5; ++i) {
159159
test.CreateAndProcessBlock({}, GetScriptForRawPubKey(test.coinbaseKey.GetPubKey()));
160160
}
161-
CWallet wallet("mock", CWalletDBWrapper::CreateMock());
161+
CWallet wallet("mock", WalletDatabase::CreateMock());
162162
bool firstRun;
163163
wallet.LoadWallet(firstRun);
164164
{

src/test/util_tests.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ BOOST_AUTO_TEST_CASE(util_ParseHex)
6262
result = ParseHex("12 34 56 78");
6363
BOOST_CHECK(result.size() == 4 && result[0] == 0x12 && result[1] == 0x34 && result[2] == 0x56 && result[3] == 0x78);
6464

65-
// Leading space must be supported (used in CDBEnv::Salvage)
65+
// Leading space must be supported (used in BerkeleyEnvironment::Salvage)
6666
result = ParseHex(" 89 34 56 78");
6767
BOOST_CHECK(result.size() == 4 && result[0] == 0x89 && result[1] == 0x34 && result[2] == 0x56 && result[3] == 0x78);
6868

src/wallet/db.cpp

+72-72
Large diffs are not rendered by default.

src/wallet/db.h

+25-25
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
static const unsigned int DEFAULT_WALLET_DBLOGSIZE = 100;
2626
static const bool DEFAULT_WALLET_PRIVDB = true;
2727

28-
class CDBEnv
28+
class BerkeleyEnvironment
2929
{
3030
private:
3131
bool fDbEnvInit;
@@ -39,8 +39,8 @@ class CDBEnv
3939
std::map<std::string, int> mapFileUseCount;
4040
std::map<std::string, Db*> mapDb;
4141

42-
CDBEnv(const fs::path& env_directory);
43-
~CDBEnv();
42+
BerkeleyEnvironment(const fs::path& env_directory);
43+
~BerkeleyEnvironment();
4444
void Reset();
4545

4646
void MakeMock();
@@ -86,23 +86,23 @@ class CDBEnv
8686
}
8787
};
8888

89-
/** Get CDBEnv and database filename given a wallet path. */
90-
CDBEnv* GetWalletEnv(const fs::path& wallet_path, std::string& database_filename);
89+
/** Get BerkeleyEnvironment and database filename given a wallet path. */
90+
BerkeleyEnvironment* GetWalletEnv(const fs::path& wallet_path, std::string& database_filename);
9191

9292
/** An instance of this class represents one database.
9393
* For BerkeleyDB this is just a (env, strFile) tuple.
9494
**/
95-
class CWalletDBWrapper
95+
class BerkeleyDatabase
9696
{
97-
friend class CDB;
97+
friend class BerkeleyBatch;
9898
public:
9999
/** Create dummy DB handle */
100-
CWalletDBWrapper() : nUpdateCounter(0), nLastSeen(0), nLastFlushed(0), nLastWalletUpdate(0), env(nullptr)
100+
BerkeleyDatabase() : nUpdateCounter(0), nLastSeen(0), nLastFlushed(0), nLastWalletUpdate(0), env(nullptr)
101101
{
102102
}
103103

104104
/** Create DB handle to real database */
105-
CWalletDBWrapper(const fs::path& wallet_path, bool mock = false) :
105+
BerkeleyDatabase(const fs::path& wallet_path, bool mock = false) :
106106
nUpdateCounter(0), nLastSeen(0), nLastFlushed(0), nLastWalletUpdate(0)
107107
{
108108
env = GetWalletEnv(wallet_path, strFile);
@@ -114,21 +114,21 @@ class CWalletDBWrapper
114114
}
115115

116116
/** Return object for accessing database at specified path. */
117-
static std::unique_ptr<CWalletDBWrapper> Create(const fs::path& path)
117+
static std::unique_ptr<BerkeleyDatabase> Create(const fs::path& path)
118118
{
119-
return MakeUnique<CWalletDBWrapper>(path);
119+
return MakeUnique<BerkeleyDatabase>(path);
120120
}
121121

122122
/** Return object for accessing dummy database with no read/write capabilities. */
123-
static std::unique_ptr<CWalletDBWrapper> CreateDummy()
123+
static std::unique_ptr<BerkeleyDatabase> CreateDummy()
124124
{
125-
return MakeUnique<CWalletDBWrapper>();
125+
return MakeUnique<BerkeleyDatabase>();
126126
}
127127

128128
/** Return object for accessing temporary in-memory database. */
129-
static std::unique_ptr<CWalletDBWrapper> CreateMock()
129+
static std::unique_ptr<BerkeleyDatabase> CreateMock()
130130
{
131-
return MakeUnique<CWalletDBWrapper>("", true /* mock */);
131+
return MakeUnique<BerkeleyDatabase>("", true /* mock */);
132132
}
133133

134134
/** Rewrite the entire database on disk, with the exception of key pszSkip if non-zero
@@ -152,7 +152,7 @@ class CWalletDBWrapper
152152

153153
private:
154154
/** BerkeleyDB specific */
155-
CDBEnv *env;
155+
BerkeleyEnvironment *env;
156156
std::string strFile;
157157

158158
/** Return whether this database handle is a dummy for testing.
@@ -164,34 +164,34 @@ class CWalletDBWrapper
164164

165165

166166
/** RAII class that provides access to a Berkeley database */
167-
class CDB
167+
class BerkeleyBatch
168168
{
169169
protected:
170170
Db* pdb;
171171
std::string strFile;
172172
DbTxn* activeTxn;
173173
bool fReadOnly;
174174
bool fFlushOnClose;
175-
CDBEnv *env;
175+
BerkeleyEnvironment *env;
176176

177177
public:
178-
explicit CDB(CWalletDBWrapper& dbw, const char* pszMode = "r+", bool fFlushOnCloseIn=true);
179-
~CDB() { Close(); }
178+
explicit BerkeleyBatch(BerkeleyDatabase& database, const char* pszMode = "r+", bool fFlushOnCloseIn=true);
179+
~BerkeleyBatch() { Close(); }
180180

181-
CDB(const CDB&) = delete;
182-
CDB& operator=(const CDB&) = delete;
181+
BerkeleyBatch(const BerkeleyBatch&) = delete;
182+
BerkeleyBatch& operator=(const BerkeleyBatch&) = delete;
183183

184184
void Flush();
185185
void Close();
186186
static bool Recover(const fs::path& file_path, void *callbackDataIn, bool (*recoverKVcallback)(void* callbackData, CDataStream ssKey, CDataStream ssValue), std::string& out_backup_filename);
187187

188188
/* flush the wallet passively (TRY_LOCK)
189189
ideal to be called periodically */
190-
static bool PeriodicFlush(CWalletDBWrapper& dbw);
190+
static bool PeriodicFlush(BerkeleyDatabase& database);
191191
/* verifies the database environment */
192192
static bool VerifyEnvironment(const fs::path& file_path, std::string& errorStr);
193193
/* verifies the database file */
194-
static bool VerifyDatabaseFile(const fs::path& file_path, std::string& warningStr, std::string& errorStr, CDBEnv::recoverFunc_type recoverFunc);
194+
static bool VerifyDatabaseFile(const fs::path& file_path, std::string& warningStr, std::string& errorStr, BerkeleyEnvironment::recoverFunc_type recoverFunc);
195195

196196
public:
197197
template <typename K, typename T>
@@ -387,7 +387,7 @@ class CDB
387387
return Write(std::string("version"), nVersion);
388388
}
389389

390-
bool static Rewrite(CWalletDBWrapper& dbw, const char* pszSkip = nullptr);
390+
bool static Rewrite(BerkeleyDatabase& database, const char* pszSkip = nullptr);
391391
};
392392

393393
#endif // BITCOIN_WALLET_DB_H

src/wallet/init.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -277,21 +277,21 @@ bool WalletInit::Verify()
277277
}
278278

279279
std::string strError;
280-
if (!CWalletDB::VerifyEnvironment(wallet_path, strError)) {
280+
if (!WalletBatch::VerifyEnvironment(wallet_path, strError)) {
281281
return InitError(strError);
282282
}
283283

284284
if (gArgs.GetBoolArg("-salvagewallet", false)) {
285285
// Recover readable keypairs:
286-
CWallet dummyWallet("dummy", CWalletDBWrapper::CreateDummy());
286+
CWallet dummyWallet("dummy", WalletDatabase::CreateDummy());
287287
std::string backup_filename;
288-
if (!CWalletDB::Recover(wallet_path, (void *)&dummyWallet, CWalletDB::RecoverKeysOnlyFilter, backup_filename)) {
288+
if (!WalletBatch::Recover(wallet_path, (void *)&dummyWallet, WalletBatch::RecoverKeysOnlyFilter, backup_filename)) {
289289
return false;
290290
}
291291
}
292292

293293
std::string strWarning;
294-
bool dbV = CWalletDB::VerifyDatabaseFile(wallet_path, strWarning, strError);
294+
bool dbV = WalletBatch::VerifyDatabaseFile(wallet_path, strWarning, strError);
295295
if (!strWarning.empty()) {
296296
InitWarning(strWarning);
297297
}

src/wallet/test/coinselector_tests.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ std::vector<std::unique_ptr<CWalletTx>> wtxn;
2828
typedef std::set<CInputCoin> CoinSet;
2929

3030
static std::vector<COutput> vCoins;
31-
static CWallet testWallet("dummy", CWalletDBWrapper::CreateDummy());
31+
static CWallet testWallet("dummy", WalletDatabase::CreateDummy());
3232
static CAmount balance = 0;
3333

3434
CoinEligibilityFilter filter_standard(1, 6, 0);

src/wallet/test/wallet_test_fixture.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <wallet/db.h>
99

1010
WalletTestingSetup::WalletTestingSetup(const std::string& chainName):
11-
TestingSetup(chainName), m_wallet("mock", CWalletDBWrapper::CreateMock())
11+
TestingSetup(chainName), m_wallet("mock", WalletDatabase::CreateMock())
1212
{
1313
bool fFirstRun;
1414
m_wallet.LoadWallet(fFirstRun);

src/wallet/test/wallet_tests.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ BOOST_FIXTURE_TEST_CASE(rescan, TestChain100Setup)
4646
// Verify ScanForWalletTransactions picks up transactions in both the old
4747
// and new block files.
4848
{
49-
CWallet wallet("dummy", CWalletDBWrapper::CreateDummy());
49+
CWallet wallet("dummy", WalletDatabase::CreateDummy());
5050
AddKey(wallet, coinbaseKey);
5151
WalletRescanReserver reserver(&wallet);
5252
reserver.reserve();
@@ -61,7 +61,7 @@ BOOST_FIXTURE_TEST_CASE(rescan, TestChain100Setup)
6161
// Verify ScanForWalletTransactions only picks transactions in the new block
6262
// file.
6363
{
64-
CWallet wallet("dummy", CWalletDBWrapper::CreateDummy());
64+
CWallet wallet("dummy", WalletDatabase::CreateDummy());
6565
AddKey(wallet, coinbaseKey);
6666
WalletRescanReserver reserver(&wallet);
6767
reserver.reserve();
@@ -73,7 +73,7 @@ BOOST_FIXTURE_TEST_CASE(rescan, TestChain100Setup)
7373
// before the missing block, and success for a key whose creation time is
7474
// after.
7575
{
76-
CWallet wallet("dummy", CWalletDBWrapper::CreateDummy());
76+
CWallet wallet("dummy", WalletDatabase::CreateDummy());
7777
vpwallets.insert(vpwallets.begin(), &wallet);
7878
UniValue keys;
7979
keys.setArray();
@@ -132,7 +132,7 @@ BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup)
132132

133133
// Import key into wallet and call dumpwallet to create backup file.
134134
{
135-
CWallet wallet("dummy", CWalletDBWrapper::CreateDummy());
135+
CWallet wallet("dummy", WalletDatabase::CreateDummy());
136136
LOCK(wallet.cs_wallet);
137137
wallet.mapKeyMetadata[coinbaseKey.GetPubKey().GetID()].nCreateTime = KEY_TIME;
138138
wallet.AddKeyPubKey(coinbaseKey, coinbaseKey.GetPubKey());
@@ -147,7 +147,7 @@ BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup)
147147
// Call importwallet RPC and verify all blocks with timestamps >= BLOCK_TIME
148148
// were scanned, and no prior blocks were scanned.
149149
{
150-
CWallet wallet("dummy", CWalletDBWrapper::CreateDummy());
150+
CWallet wallet("dummy", WalletDatabase::CreateDummy());
151151

152152
JSONRPCRequest request;
153153
request.params.setArray();
@@ -177,7 +177,7 @@ BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup)
177177
// debit functions.
178178
BOOST_FIXTURE_TEST_CASE(coin_mark_dirty_immature_credit, TestChain100Setup)
179179
{
180-
CWallet wallet("dummy", CWalletDBWrapper::CreateDummy());
180+
CWallet wallet("dummy", WalletDatabase::CreateDummy());
181181
CWalletTx wtx(&wallet, MakeTransactionRef(coinbaseTxns.back()));
182182
LOCK2(cs_main, wallet.cs_wallet);
183183
wtx.hashBlock = chainActive.Tip()->GetBlockHash();
@@ -270,7 +270,7 @@ class ListCoinsTestingSetup : public TestChain100Setup
270270
ListCoinsTestingSetup()
271271
{
272272
CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey()));
273-
wallet = MakeUnique<CWallet>("mock", CWalletDBWrapper::CreateMock());
273+
wallet = MakeUnique<CWallet>("mock", WalletDatabase::CreateMock());
274274
bool firstRun;
275275
wallet->LoadWallet(firstRun);
276276
AddKey(*wallet, coinbaseKey);

0 commit comments

Comments
 (0)