-
Notifications
You must be signed in to change notification settings - Fork 37.8k
Wallet database handling abstractions/simplifications #9951
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Great! |
c78561e
to
4ab3a72
Compare
Yep needed trivial rebase for #9643. |
src/wallet/walletdb.h
Outdated
{ | ||
public: | ||
CWalletDB(const std::string& strFilename, const char* pszMode = "r+", bool _fFlushOnClose = true) : CDB(strFilename, pszMode, _fFlushOnClose) | ||
/** Takes a std::unique_ptr reference to avoid having to use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This unique_ptr here bothers me. The interface shouldn't care what kind of pointer is used. I think I'm going to change this to take a CWalletDBWrapper&
, then replace the call sites with CWalletDB(*dbw)
. That's better than CWalletDB(dbw.get())
at least.
Edit: done
6608924
to
a2bf727
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some comments on the first commit.
Since this is my first review, please let me know if it is overboard/too pedantic.
src/wallet/db.cpp
Outdated
{ | ||
int ret; | ||
fReadOnly = (!strchr(pszMode, '+') && !strchr(pszMode, 'w')); | ||
fFlushOnClose = fFlushOnCloseIn; | ||
if (strFilename.empty()) | ||
return; | ||
std::string strFilename = dbw.strWalletFile; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to use const std::string& strFileName
, no copying and it's clear it won't be modified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed.
src/wallet/db.cpp
Outdated
{ | ||
if (!dbw.env) | ||
return true; | ||
std::string strFile = dbw.strWalletFile; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
src/wallet/db.cpp
Outdated
if (!dbw) { | ||
return true; | ||
} | ||
std::string strFile = dbw->strWalletFile; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
src/wallet/db.cpp
Outdated
{ | ||
bool ret = false; | ||
if (!dbw) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to move the check to the top, above bool ret
.
src/wallet/db.cpp
Outdated
|
||
bool CWalletDBWrapper::Backup(const std::string& strDest) | ||
{ | ||
if (!env) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent style with using/skipping braces (above, you used braces, here, you don't). I'd add them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes the brace should be after
src/wallet/db.h
Outdated
std::string GetName() { return strWalletFile; } | ||
|
||
CDBEnv *env; | ||
std::string strWalletFile; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const std::string
src/wallet/db.h
Outdated
|
||
/** Get a name for this database, for debugging etc. | ||
*/ | ||
std::string GetName() { return strWalletFile; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::string GetName() const
You have this function, and the public strWalletFile
, which you access directly in other places. Maybe strWalletFile
should be made private, or alternatively, this function removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are subtly different, only happen to be the same for BerkeleyDB:
GetName
is an an abstract name to refer to the database object for logging or troubleshooting. It should exist for any version of CDBWrapper.strWalletFile
is an implementation detail that only exists for BerkeleyDB. Other databases may have completely different connection descriptions, which do not involve simply a string. So this is private to the low-level implementation (CDB, CWalletDBWrapper), the higher-level stuff (such as CWallet) should not refer to it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could make this clearer using "friend" I guess.
src/wallet/wallet.h
Outdated
|
||
/** Get a name for this wallet for logging/debugging purposes. | ||
*/ | ||
std::string GetName() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GetName() const
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes good catch.
src/wallet/wallet.h
Outdated
{ | ||
if (dbw) { | ||
return dbw->GetName(); | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it is a matter of personal preference, but I always find it odd to put an else
when the if
returns.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer to keep it this way. We have no guideline on this in doc/developer-notes.md
, and I personally find it easier to follow the control flow this way.
a2bf727
to
2850ed3
Compare
Fixed @benma's nits. |
2850ed3
to
e3e51fd
Compare
private: | ||
/** BerkeleyDB specific */ | ||
CDBEnv *env; | ||
std::string strFile; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const std::string strFile;
?
For my understanding: the refactor to support a different db backend than BerkeleyDB is not finished with this PR, right? It is a bit hard to see through Also, berkeley-specific fields are in
In the end, is there even a need for the class |
To be clear: CDB and CWalletDBWrapper and CDBEnv are database specific. You need to replace those if you want to change the backend (though you should keep the interface of the first two the same). In many cases you can do without CDBEnv (for LevelDB I could just delete it). So On top of this I have a patch that switches the backend to LevelDB, mostly changing only It's not quite as easy as switching the
Yes, it is a database transaction / batch. It's simlar to |
@benma FYI not for review but if you're interested https://github.com/laanwj/bitcoin/tree/20170310_experiment_leveldb_wallet is a leveldb wallet on top of this (edit: rebased, is on top of this version now). It passes the unit and QA tests apart from |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dear god this stuffs a mess, good thing you're cleaing it up :P.
utACK e3e51fd
@@ -118,7 +165,7 @@ class CDB | |||
CDB(const CDB&); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you go ahead and =delete these, since we have C++11?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea
Concept ACK |
Tested ACK e3e51fd Though needs a "trivial" rebase. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple nits, overall utack.
src/wallet/db.h
Outdated
@@ -94,6 +94,12 @@ class CWalletDBWrapper | |||
{ | |||
friend class CDB; | |||
public: | |||
/** Create dummy DB handle */ | |||
CWalletDBWrapper(): env(nullptr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there's a small benefit to not making a CWalletDBWrapper the default constructor. Maybe delete the default, and have struct MockTag{}; CWalletDBWrapper(MockTag);
to make a dummy explicitly constructed.
src/wallet/db.cpp
Outdated
{ | ||
int ret; | ||
fReadOnly = (!strchr(pszMode, '+') && !strchr(pszMode, 'w')); | ||
fFlushOnClose = fFlushOnCloseIn; | ||
if (strFilename.empty()) | ||
return; | ||
const std::string& strFilename = dbw.strFile; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously, an empty strFilename would return immediately. Also, given that we initialize strFile to copy strFileName, we may as well just toss this into the constructor's initialize list. If it's empty, it's free. If it's not empty, we were going to copy it anyways.
@@ -359,13 +359,12 @@ void CDBEnv::CheckpointLSN(const std::string& strFile) | |||
} | |||
|
|||
|
|||
CDB::CDB(const std::string& strFilename, const char* pszMode, bool fFlushOnCloseIn) : pdb(NULL), activeTxn(NULL) | |||
CDB::CDB(CWalletDBWrapper& dbw, const char* pszMode, bool fFlushOnCloseIn) : pdb(NULL), activeTxn(NULL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a little confused on the API here.
I feel like the unwrapped version of CDB shouldn't be compatible with the wrapped version of CWalletDB?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CWalletDBWrapper is not a wrapper around CWalletDB. We kind of have a naming problem with the wallet:
CDBEnv
is an environment in which the database exists (has no analog indbwrapper.h
)CWalletDBWrapper
represents a wallet database (similar toCDBWrapper
indbwrapper.h
)CDB
is a low-level database transaction (similar toCDBBatch
indbwrapper.h
)CWalletDB
is a modifier object for the wallet, and encapsulates a database transaction as well as methods to act on the database (no analog indbwrapper.h
)
The latter two are named badly, should be renamed at some point but didn't want to do it here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a commit that adds this as a comment, as it will be something that confuses everyone reading this code.
* Only to be used at a low level, application should ideally not care | ||
* about this. | ||
*/ | ||
bool IsDummy() { return env == nullptr; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's only to be used by low level stuff, maybe friend the function specifically to those classes...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, good point. CDB is already a friend and should be the only user of this, moving it to private.
src/wallet/walletdb.cpp
Outdated
@@ -33,46 +33,46 @@ static std::atomic<unsigned int> nWalletDBUpdateCounter; | |||
bool CWalletDB::WriteName(const std::string& strAddress, const std::string& strName) | |||
{ | |||
nWalletDBUpdateCounter++; | |||
return Write(make_pair(std::string("name"), strAddress), strName); | |||
return batch.Write(make_pair(std::string("name"), strAddress), strName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing std::
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why this doesn't cause a compile error. We've removed all the "using namespace std".
Needs rebase (Imo this is ready for merge). |
Yes, will rebase this soon(TM) and fix the nits. |
Abstract database handle from explicit strFilename into CWalletDBWrapper. Also move CWallet::Backup to db.cpp - as it deals with representation details this is a database specific operation.
Instead, CWalletDB() with a dummy handle will just give you a no-op database in which writes always succeeds and reads always fail. CDB already had functionality for this, so just use that.
CWalletDB now contains a CDB instead of inheriting from it. This makes it easier to replace the internal transaction with a different database, without leaking through internals.
This is only for use in the low-level functions, and CDB is already a friend class.
e3e51fd
to
69d2e9b
Compare
911a480 wallet: Add comment describing the various classes in walletdb.h (Wladimir J. van der Laan) 69d2e9b wallet: Make IsDummy private in CWalletDBWrapper (Wladimir J. van der Laan) 3323281 wallet: CWalletDB CDB composition not inheritance (Wladimir J. van der Laan) be9e1a9 wallet: Reduce references to global bitdb environment (Wladimir J. van der Laan) 071c955 wallet: Get rid of fFileBacked (Wladimir J. van der Laan) 71afe3c wallet: Introduce database handle wrapper (Wladimir J. van der Laan) Tree-SHA512: e4e72953c61a2f6995d609a32f8ed8e18cab9a92bc9e193d46a1d1f06d9daa5c6da6fce2867d4e3ba4fc0439141901a3d35f246486f0fa8f59587786379dfcbd
…ions 911a480 wallet: Add comment describing the various classes in walletdb.h (Wladimir J. van der Laan) 69d2e9b wallet: Make IsDummy private in CWalletDBWrapper (Wladimir J. van der Laan) 3323281 wallet: CWalletDB CDB composition not inheritance (Wladimir J. van der Laan) be9e1a9 wallet: Reduce references to global bitdb environment (Wladimir J. van der Laan) 071c955 wallet: Get rid of fFileBacked (Wladimir J. van der Laan) 71afe3c wallet: Introduce database handle wrapper (Wladimir J. van der Laan) Tree-SHA512: e4e72953c61a2f6995d609a32f8ed8e18cab9a92bc9e193d46a1d1f06d9daa5c6da6fce2867d4e3ba4fc0439141901a3d35f246486f0fa8f59587786379dfcbd
…ions 911a480 wallet: Add comment describing the various classes in walletdb.h (Wladimir J. van der Laan) 69d2e9b wallet: Make IsDummy private in CWalletDBWrapper (Wladimir J. van der Laan) 3323281 wallet: CWalletDB CDB composition not inheritance (Wladimir J. van der Laan) be9e1a9 wallet: Reduce references to global bitdb environment (Wladimir J. van der Laan) 071c955 wallet: Get rid of fFileBacked (Wladimir J. van der Laan) 71afe3c wallet: Introduce database handle wrapper (Wladimir J. van der Laan) Tree-SHA512: e4e72953c61a2f6995d609a32f8ed8e18cab9a92bc9e193d46a1d1f06d9daa5c6da6fce2867d4e3ba4fc0439141901a3d35f246486f0fa8f59587786379dfcbd
…ions 911a480 wallet: Add comment describing the various classes in walletdb.h (Wladimir J. van der Laan) 69d2e9b wallet: Make IsDummy private in CWalletDBWrapper (Wladimir J. van der Laan) 3323281 wallet: CWalletDB CDB composition not inheritance (Wladimir J. van der Laan) be9e1a9 wallet: Reduce references to global bitdb environment (Wladimir J. van der Laan) 071c955 wallet: Get rid of fFileBacked (Wladimir J. van der Laan) 71afe3c wallet: Introduce database handle wrapper (Wladimir J. van der Laan) Tree-SHA512: e4e72953c61a2f6995d609a32f8ed8e18cab9a92bc9e193d46a1d1f06d9daa5c6da6fce2867d4e3ba4fc0439141901a3d35f246486f0fa8f59587786379dfcbd
…ions 911a480 wallet: Add comment describing the various classes in walletdb.h (Wladimir J. van der Laan) 69d2e9b wallet: Make IsDummy private in CWalletDBWrapper (Wladimir J. van der Laan) 3323281 wallet: CWalletDB CDB composition not inheritance (Wladimir J. van der Laan) be9e1a9 wallet: Reduce references to global bitdb environment (Wladimir J. van der Laan) 071c955 wallet: Get rid of fFileBacked (Wladimir J. van der Laan) 71afe3c wallet: Introduce database handle wrapper (Wladimir J. van der Laan) Tree-SHA512: e4e72953c61a2f6995d609a32f8ed8e18cab9a92bc9e193d46a1d1f06d9daa5c6da6fce2867d4e3ba4fc0439141901a3d35f246486f0fa8f59587786379dfcbd
…ions 911a480 wallet: Add comment describing the various classes in walletdb.h (Wladimir J. van der Laan) 69d2e9b wallet: Make IsDummy private in CWalletDBWrapper (Wladimir J. van der Laan) 3323281 wallet: CWalletDB CDB composition not inheritance (Wladimir J. van der Laan) be9e1a9 wallet: Reduce references to global bitdb environment (Wladimir J. van der Laan) 071c955 wallet: Get rid of fFileBacked (Wladimir J. van der Laan) 71afe3c wallet: Introduce database handle wrapper (Wladimir J. van der Laan) Tree-SHA512: e4e72953c61a2f6995d609a32f8ed8e18cab9a92bc9e193d46a1d1f06d9daa5c6da6fce2867d4e3ba4fc0439141901a3d35f246486f0fa8f59587786379dfcbd
…ions 911a480 wallet: Add comment describing the various classes in walletdb.h (Wladimir J. van der Laan) 69d2e9b wallet: Make IsDummy private in CWalletDBWrapper (Wladimir J. van der Laan) 3323281 wallet: CWalletDB CDB composition not inheritance (Wladimir J. van der Laan) be9e1a9 wallet: Reduce references to global bitdb environment (Wladimir J. van der Laan) 071c955 wallet: Get rid of fFileBacked (Wladimir J. van der Laan) 71afe3c wallet: Introduce database handle wrapper (Wladimir J. van der Laan) Tree-SHA512: e4e72953c61a2f6995d609a32f8ed8e18cab9a92bc9e193d46a1d1f06d9daa5c6da6fce2867d4e3ba4fc0439141901a3d35f246486f0fa8f59587786379dfcbd
…ions 911a480 wallet: Add comment describing the various classes in walletdb.h (Wladimir J. van der Laan) 69d2e9b wallet: Make IsDummy private in CWalletDBWrapper (Wladimir J. van der Laan) 3323281 wallet: CWalletDB CDB composition not inheritance (Wladimir J. van der Laan) be9e1a9 wallet: Reduce references to global bitdb environment (Wladimir J. van der Laan) 071c955 wallet: Get rid of fFileBacked (Wladimir J. van der Laan) 71afe3c wallet: Introduce database handle wrapper (Wladimir J. van der Laan) Tree-SHA512: e4e72953c61a2f6995d609a32f8ed8e18cab9a92bc9e193d46a1d1f06d9daa5c6da6fce2867d4e3ba4fc0439141901a3d35f246486f0fa8f59587786379dfcbd
…ions 911a480 wallet: Add comment describing the various classes in walletdb.h (Wladimir J. van der Laan) 69d2e9b wallet: Make IsDummy private in CWalletDBWrapper (Wladimir J. van der Laan) 3323281 wallet: CWalletDB CDB composition not inheritance (Wladimir J. van der Laan) be9e1a9 wallet: Reduce references to global bitdb environment (Wladimir J. van der Laan) 071c955 wallet: Get rid of fFileBacked (Wladimir J. van der Laan) 71afe3c wallet: Introduce database handle wrapper (Wladimir J. van der Laan) Tree-SHA512: e4e72953c61a2f6995d609a32f8ed8e18cab9a92bc9e193d46a1d1f06d9daa5c6da6fce2867d4e3ba4fc0439141901a3d35f246486f0fa8f59587786379dfcbd
…ions 911a480 wallet: Add comment describing the various classes in walletdb.h (Wladimir J. van der Laan) 69d2e9b wallet: Make IsDummy private in CWalletDBWrapper (Wladimir J. van der Laan) 3323281 wallet: CWalletDB CDB composition not inheritance (Wladimir J. van der Laan) be9e1a9 wallet: Reduce references to global bitdb environment (Wladimir J. van der Laan) 071c955 wallet: Get rid of fFileBacked (Wladimir J. van der Laan) 71afe3c wallet: Introduce database handle wrapper (Wladimir J. van der Laan) Tree-SHA512: e4e72953c61a2f6995d609a32f8ed8e18cab9a92bc9e193d46a1d1f06d9daa5c6da6fce2867d4e3ba4fc0439141901a3d35f246486f0fa8f59587786379dfcbd
…ions 911a480 wallet: Add comment describing the various classes in walletdb.h (Wladimir J. van der Laan) 69d2e9b wallet: Make IsDummy private in CWalletDBWrapper (Wladimir J. van der Laan) 3323281 wallet: CWalletDB CDB composition not inheritance (Wladimir J. van der Laan) be9e1a9 wallet: Reduce references to global bitdb environment (Wladimir J. van der Laan) 071c955 wallet: Get rid of fFileBacked (Wladimir J. van der Laan) 71afe3c wallet: Introduce database handle wrapper (Wladimir J. van der Laan) Tree-SHA512: e4e72953c61a2f6995d609a32f8ed8e18cab9a92bc9e193d46a1d1f06d9daa5c6da6fce2867d4e3ba4fc0439141901a3d35f246486f0fa8f59587786379dfcbd
…ions 911a480 wallet: Add comment describing the various classes in walletdb.h (Wladimir J. van der Laan) 69d2e9b wallet: Make IsDummy private in CWalletDBWrapper (Wladimir J. van der Laan) 3323281 wallet: CWalletDB CDB composition not inheritance (Wladimir J. van der Laan) be9e1a9 wallet: Reduce references to global bitdb environment (Wladimir J. van der Laan) 071c955 wallet: Get rid of fFileBacked (Wladimir J. van der Laan) 71afe3c wallet: Introduce database handle wrapper (Wladimir J. van der Laan) Tree-SHA512: e4e72953c61a2f6995d609a32f8ed8e18cab9a92bc9e193d46a1d1f06d9daa5c6da6fce2867d4e3ba4fc0439141901a3d35f246486f0fa8f59587786379dfcbd
…ions 911a480 wallet: Add comment describing the various classes in walletdb.h (Wladimir J. van der Laan) 69d2e9b wallet: Make IsDummy private in CWalletDBWrapper (Wladimir J. van der Laan) 3323281 wallet: CWalletDB CDB composition not inheritance (Wladimir J. van der Laan) be9e1a9 wallet: Reduce references to global bitdb environment (Wladimir J. van der Laan) 071c955 wallet: Get rid of fFileBacked (Wladimir J. van der Laan) 71afe3c wallet: Introduce database handle wrapper (Wladimir J. van der Laan) Tree-SHA512: e4e72953c61a2f6995d609a32f8ed8e18cab9a92bc9e193d46a1d1f06d9daa5c6da6fce2867d4e3ba4fc0439141901a3d35f246486f0fa8f59587786379dfcbd
…ions 911a480 wallet: Add comment describing the various classes in walletdb.h (Wladimir J. van der Laan) 69d2e9b wallet: Make IsDummy private in CWalletDBWrapper (Wladimir J. van der Laan) 3323281 wallet: CWalletDB CDB composition not inheritance (Wladimir J. van der Laan) be9e1a9 wallet: Reduce references to global bitdb environment (Wladimir J. van der Laan) 071c955 wallet: Get rid of fFileBacked (Wladimir J. van der Laan) 71afe3c wallet: Introduce database handle wrapper (Wladimir J. van der Laan) Tree-SHA512: e4e72953c61a2f6995d609a32f8ed8e18cab9a92bc9e193d46a1d1f06d9daa5c6da6fce2867d4e3ba4fc0439141901a3d35f246486f0fa8f59587786379dfcbd
…ions 911a480 wallet: Add comment describing the various classes in walletdb.h (Wladimir J. van der Laan) 69d2e9b wallet: Make IsDummy private in CWalletDBWrapper (Wladimir J. van der Laan) 3323281 wallet: CWalletDB CDB composition not inheritance (Wladimir J. van der Laan) be9e1a9 wallet: Reduce references to global bitdb environment (Wladimir J. van der Laan) 071c955 wallet: Get rid of fFileBacked (Wladimir J. van der Laan) 71afe3c wallet: Introduce database handle wrapper (Wladimir J. van der Laan) Tree-SHA512: e4e72953c61a2f6995d609a32f8ed8e18cab9a92bc9e193d46a1d1f06d9daa5c6da6fce2867d4e3ba4fc0439141901a3d35f246486f0fa8f59587786379dfcbd add 'batch.' Signed-off-by: Pasta <Pasta@dash.org> remove `if (fFileBacked)` Signed-off-by: Pasta <pasta@dashboost.org> remove fFileBacked and strWalletFile Signed-off-by: Pasta <Pasta@dash.org>
…ions 911a480 wallet: Add comment describing the various classes in walletdb.h (Wladimir J. van der Laan) 69d2e9b wallet: Make IsDummy private in CWalletDBWrapper (Wladimir J. van der Laan) 3323281 wallet: CWalletDB CDB composition not inheritance (Wladimir J. van der Laan) be9e1a9 wallet: Reduce references to global bitdb environment (Wladimir J. van der Laan) 071c955 wallet: Get rid of fFileBacked (Wladimir J. van der Laan) 71afe3c wallet: Introduce database handle wrapper (Wladimir J. van der Laan) Tree-SHA512: e4e72953c61a2f6995d609a32f8ed8e18cab9a92bc9e193d46a1d1f06d9daa5c6da6fce2867d4e3ba4fc0439141901a3d35f246486f0fa8f59587786379dfcbd add 'batch.' Signed-off-by: Pasta <Pasta@dash.org> remove `if (fFileBacked)` Signed-off-by: Pasta <pasta@dashboost.org> remove fFileBacked and strWalletFile Signed-off-by: Pasta <Pasta@dash.org>
…ions 911a480 wallet: Add comment describing the various classes in walletdb.h (Wladimir J. van der Laan) 69d2e9b wallet: Make IsDummy private in CWalletDBWrapper (Wladimir J. van der Laan) 3323281 wallet: CWalletDB CDB composition not inheritance (Wladimir J. van der Laan) be9e1a9 wallet: Reduce references to global bitdb environment (Wladimir J. van der Laan) 071c955 wallet: Get rid of fFileBacked (Wladimir J. van der Laan) 71afe3c wallet: Introduce database handle wrapper (Wladimir J. van der Laan) Tree-SHA512: e4e72953c61a2f6995d609a32f8ed8e18cab9a92bc9e193d46a1d1f06d9daa5c6da6fce2867d4e3ba4fc0439141901a3d35f246486f0fa8f59587786379dfcbd add 'batch.' Signed-off-by: Pasta <Pasta@dash.org> remove `if (fFileBacked)` Signed-off-by: Pasta <pasta@dashboost.org> remove fFileBacked and strWalletFile Signed-off-by: Pasta <Pasta@dash.org>
…ications e5fd215 [WalletDb] Decouple backups history from the main BackupWallet function. (furszy) 1ec4b84 [WalletDb] Decouple custom backup path parsing from BackupWallet function. (furszy) 78c8679 [Cleanup] walletdb: removing all of the zerocoin related not used methods. (furszy) 53ad1f6 wallet: Add comment describing the various classes in walletdb.h (Wladimir J. van der Laan) 08d2310 wallet: Make IsDummy private in CWalletDBWrapper (Wladimir J. van der Laan) 2132f42 wallet: CWalletDB CDB composition not inheritance (Wladimir J. van der Laan) f40006a wallet: Reduce references to global bitdb environment (Wladimir J. van der Laan) e420d3d wallet: Get rid of fFileBacked (Wladimir J. van der Laan) 3f3a289 wallet: Introduce database handle wrapper (Wladimir J. van der Laan) Pull request description: Back ported bitcoin#9951 + cleaned all of the zerocoin related, not used, methods inside the walletdb class. Built on top of #2082. ACKs for top commit: random-zebra: re-utACK e5fd215 Fuzzbawls: utACK e5fd215 Tree-SHA512: 0447f6454f0ddea71e5046783d4e57d7f9774cc3a87bf454975f5a9d5e03ce371e58402ec527203f0a7373372a1a5d8260771295f5ed941067220a92560d21b1
My immediate goal with this is to make it easier to use a different key/value store instead of BerkeleyDB, for a sandboxing project. However, it is an improvement also for BerkeleyDB.
Steps:
Abstract database handle from explicit strFilename into CWalletDBWrapper. For many databases, a usable handle involves more than just a filename. Also make the field private.
Get rid of fFileBacked - it is only used by the tests, and used inconsistly - for example CWallet::AddToWallet doesn't check it at all, and that's not quite the only place (see AbandonWallet). Fixing would be a lot of work and lead to disjointed code.
But it is not necessary. Instead move the concern to ignoring operations with a dummy database to CDB. There were very few changes necessary for this.
Reduce references to global bitdb. CWalletDBWrapper carries this environment information around so there is less need to refer to global scope. Besides being cleaner, this could allow use of multiple database environments at some point.
CWalletDB now contains a CDB instead of inheriting from it. This makes it easier to replace the internal transaction with a different database, without leaking through internals.
Future:
The eventual goal of "CWalletDBWrapper" is like "CDBWrapper", to move further database functionality there from "CDB" (which is really a "CDBBatch", a database transaction object). Not renaming it nor CWalletDB here to not interfere unduly much with other open wallet pulls.
Two maps inside bitdb that refer to wallet files by name could be removed,
and converted to fields on CWalletDBWrapper:
std::map<std::string, int> mapFileUseCount;
std::map<std::string, Db*> mapDb;