Skip to content

Conversation

@ryanofsky
Copy link
Contributor

@ryanofsky ryanofsky commented Dec 8, 2017

Scripted diff to rename some wallet classes. Motivated by discussion in #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

@jnewbery
Copy link
Contributor

jnewbery commented Dec 8, 2017

Concept ACK. The current naming is very confusing. There's even a comment in walletdb.h to say so:

/**
 * Overview of wallet database classes:
 *
 * - CDBEnv is an environment in which the database exists (has no analog in dbwrapper.h)
 * - CWalletDBWrapper represents a wallet database (similar to CDBWrapper in dbwrapper.h)
 * - CDB is a low-level database transaction (similar to CDBBatch in dbwrapper.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 in
 *   dbwrapper.h)
 *
 * The latter two are named confusingly, in contrast to what the names CDB
 * and CWalletDB suggest they are transient transaction objects and don't
 * represent the database itself.
 */

This should probably go in just before branching v0.16, since rebasing on top of this will be a pain.

Other changes you could consider:

  • manually update that overview comment (and perhaps move to wallet.h?)
  • rename the wallet/db and wallet/walletdb files to be more descriptive. Perhaps wallet/berkeley_db and wallet/db_checkpoint, but I'm sure we could do better than that.

I think your suggested class names are good ('checkpoint' is certainly better than 'transaction'!). I can't currently think of anything better.

@ryanofsky
Copy link
Contributor Author

manually update that overview comment (and perhaps move to wallet.h?)

Added commit to fix the overview comment: 51eaec4. I didn't move it into wallet.h for now because it sounds from #11687 (comment) like a goal is to pull database reading and writing code out of main wallet class, which would make wallet.h not the right place for it.

rename the wallet/db and wallet/walletdb files to be more descriptive. Perhaps wallet/berkeley_db and wallet/db_checkpoint, but I'm sure we could do better than that.

I'd be inclined to rename wallet/db.h to wallet/db-berkeley.h, leaving room for other implementations like wallet/db-dummy.h, wallet/db-sqlite.h, wallet/db-log.h (#5686), etc.

I'd be inclined to rename wallet/walletdb.h something like wallet/serialize.h, wallet/schema.h, wallet/kvschema.h, wallet/db.h, or wallet/db-keyvalue.h since it's mainly responsible for key value serialization and mostly not tied to the berkeleydb backend. This would make more sense with the CWalletDB -> CDB dependency removed or reversed, though.


Added 1 commits 003b619 -> 51eaec4 (pr/wren.1 -> pr/wren.2, compare)

@TheBlueMatt
Copy link
Contributor

Nice! I find the "WalletCheckpoint" name kinda confusing, it is a DB batch/transaction, so I'd kinda prefer we stick with "normal" nomenclature there. I'm really not sure that "BerkeleyCheckpoint" makes all that much sense for CDB, either. I kinda wish we'd split it out into an interface and implementation, though not sure if its required for this PR, but its already essentially a pretty clean interface towards a wallet DB backend.

@ryanofsky
Copy link
Contributor Author

ryanofsky commented Dec 8, 2017

I find the "WalletCheckpoint" name kinda confusing

Yeah, actually checkpoint is a bad name. I just chose it because I saw a txn_checkpoint call in CDB::Flush and assumed "checkpoint" was some kind of BDB synonym for transaction. But it's really not. It would be good to avoid the word transaction so maybe the best thing to call this is something like Batch or Update or Commit.

@jnewbery
Copy link
Contributor

jnewbery commented Dec 8, 2017

Can you push your latest branch onto pr/wren so it shows up here?

ACK changing Checkpoint to Batch or Commit. Please just not transaction!

ACK your suggested filename changes. My preferences would be:

  • wallet/db.h -> wallet/db-berkeley.h
  • wallet/walletdb.h -> wallet/schema.h

I've reviewed your commit changing the overview comment. I think it could be improved further by removing the 'analogous to x in dbwrapper.h' parts, and perhaps changing the ordering and wording, eg:

/**
 * Overview of wallet database classes:
 *
 * - WalletBatch is an abstract modifier object for the wallet database, and encapsulates a database
 *   batch update as well as methods to act on the database. It should be agnostic to the database implementation.
 *
 * The following classes are implementation specific:
 * - BerkeleyEnvironment is an environment in which the database exists.
 * - BerkeleyDatabase represents a wallet database.
 * - BerkeleyBatch is a low-level database batch update.
 */

@TheBlueMatt
Copy link
Contributor

It would be good to avoid the word transaction so maybe the best thing to call this is something like Batch or Update or Commit.

Good point. We use the term "Batch" in the context of LevelDB/CCoin stuff, so I'd vote for that.

ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Dec 8, 2017
Text from bitcoin#11851 (comment)
by John Newbery <john@johnnewbery.com>.
@ryanofsky
Copy link
Contributor Author

Updated 51eaec4 -> 4299018 (pr/wren.2 -> pr/wren.3), switching from checkpoint to batch, dropping the CWallet->Wallet rename (because it isn't really related and makes the change bigger), adding some variable renames for consistency, and adding John's comment.

The only thing I didn't do yet is rename files. There might be other suggestions for names, and file renames could also happen in a separate PR.

@jnewbery
Copy link
Contributor

jnewbery commented Dec 8, 2017

I'm going to hold off reviewing until we're closer to a major release (since I think this only makes sense going in right before branching). Russ - let me know if you disagree and think we should be reviewing/merging sooner. If this does get merged just before a branch, then I think there's no issue with doing s/CWallet/Wallet at the same time.

@ryanofsky
Copy link
Contributor Author

ryanofsky commented Dec 8, 2017

Sounds good to me. It would also make things slightly easier for me if this were merged after #11687, rather than before.

@TheBlueMatt
Copy link
Contributor

I'm not sure I'd call BerkeleyBatch so low-level or recommend it be BDB-specific. Its public interface is pretty DB-agnostic - Read/Write/Verify/PeriodicFlush.

@ryanofsky
Copy link
Contributor Author

I'm not sure I'd call BerkeleyBatch so low-level or recommend it be BDB-specific. Its public interface is pretty DB-agnostic - Read/Write/Verify/PeriodicFlush.

Yeah, that code could be pulled out into WalletBatch or a new key-value store generic class. But I think John's comment is basically right. WalletBatch code should be agnostic to berkeley db details and potentially able to work with another key-value backend, while BerkeleyBatch should contain more berkeley specific stuff. This is mostly true right now, and could be made more true with some refactoring, which I can follow up with. You should talk to John though about whether you prefer this comment or the previous comment, or want to combine them somehow.

@practicalswift
Copy link
Contributor

Concept ACK

@laanwj
Copy link
Member

laanwj commented Dec 11, 2017

Agree on the naming and using Batch.

However I agree with this as well:

I'm not sure I'd call BerkeleyBatch so low-level or recommend it be BDB-specific. Its public interface is pretty DB-agnostic - Read/Write/Verify/PeriodicFlush.

I tend to agree. I have a local patch set that ports the wallet functions to LevelDB. I don't think the interface should hardcode the database implementation name.

If you do want to do this, add a typedef so the non-database-specific code can stay without explicit Berkeley* references. e.g.:

typedef BerkeleyEnvironment WalletDBEnvironment; 
typedef BerkeleyDatabase WalletDatabase;
typedef BerkeleyBatch WalletDatabaseBatch;

(this keeps it contained; after all we don't want to have to do another batch rename every time the database changes)

@ryanofsky
Copy link
Contributor Author

@laanwj, is there a link to your leveldb patch? I'm surprised there's much code in these classes that's reusable for leveldb. BerkeleyEnvironment and BerkeleyDatabase in particular seem pretty tied to Berkeley, though BerkeleyBatch is more independent.

I'm thinking perhaps I should move the independent parts of BerkeleyBatch out into WalletBatch along with this renaming to avoid creating new confusion.

after all we don't want to have to do another batch rename every time the database changes

I can clean this up more too, but after #11687 this might not be as much of as problem as you would think. #11687 eliminates most references to the BerkeleyEnvironment, BerkeleyBatch, and BerkeleyDatabase outside of the db files.

Anyway, I think I will mark this WIP for now because there are other improvements I can make to go along with the renaming, and I think reviewer time would be better spent on #11687 anyway.

@ryanofsky ryanofsky changed the title scripted-diff: Rename wallet database classes WIP: scripted-diff: Rename wallet database classes Dec 11, 2017
@ryanofsky
Copy link
Contributor Author

I think I found the leveldb wallet branch, it is https://github.com/laanwj/bitcoin/commits/20170310_experiment_leveldb_wallet and #9951. #5686 is also similar.

@laanwj
Copy link
Member

laanwj commented Dec 12, 2017

@laanwj, is there a link to your leveldb patch? I'm surprised there's much code in these classes that's reusable for leveldb.

Right - the patch replaces pretty much all the code inside the classes.
My only comment is about the exterior. So wallet.cpp etc should not be referring to Berkeley anything as class name, it doesn't have to leak through in the class naming used by the client code what database is used.

@ryanofsky
Copy link
Contributor Author

ryanofsky commented Dec 12, 2017

My only comment is about the exterior. So wallet.cpp etc should not be referring to Berkeley anything as class name

Ah, I see. Your concern was narrower than I thought and can be addressed by a typedef like you suggested. Will fix and have the PR ready again soon. I still might want to merge this after #11687, though since #11687 touches a lot of the same code and this being a scripted-diff is easier to rebase

@PierreRochard
Copy link
Contributor

Concept ACK. Was changing dbw to database in the src/test/dbwrapper_tests.cpp file intentional? That would seem to increase the scope of this PR beyond the wallet code

@ryanofsky
Copy link
Contributor Author

ryanofsky commented Dec 12, 2017

PSA: Everybody commenting here please stop reviewing this work in progress PR and look at #11687 instead :)

Was changing dbw to database in the src/test/dbwrapper_tests.cpp file intentional? That would seem to increase the scope of this PR beyond the wallet code

This was unintentional but seemed harmless so I just left it in. I can try to tweak the scripted-diff to prevent it.

@laanwj
Copy link
Member

laanwj commented Dec 13, 2017

Will fix and have the PR ready again soon.

Thanks. Sorry for being unclear at first.

ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Dec 15, 2017
Text from bitcoin#11851 (comment)
by John Newbery <john@johnnewbery.com>.
@ryanofsky ryanofsky changed the title WIP: scripted-diff: Rename wallet database classes scripted-diff: Rename wallet database classes Dec 15, 2017
@sipa
Copy link
Member

sipa commented Dec 15, 2017

Pieter was here.

PastaPastaPasta added a commit to PastaPastaPasta/dash that referenced this pull request May 10, 2020
-BEGIN VERIFY SCRIPT-

sed -i 's/\<CWalletDBWrapper\>/BerkeleyDatabase/g' src/wallet/db.h src/wallet/db.cpp
sed -i '/statuses/i/** Backend-agnostic database type. */\nusing WalletDatabase = BerkeleyDatabase\;\n' src/wallet/walletdb.h
ren() { git grep -l "\<$1\>" 'src/*.cpp' 'src/*.h' ':(exclude)*dbwrapper*' test | xargs sed -i "s:\<$1\>:$2:g"; }
ren CDBEnv           BerkeleyEnvironment
ren CDB              BerkeleyBatch
ren CWalletDBWrapper WalletDatabase
ren CWalletDB        WalletBatch
ren dbw              database
ren m_dbw            m_database
ren walletdb         batch
ren pwalletdb        batch
ren pwalletdbIn      batch_in
ren wallet/batch.h   wallet/walletdb.h
ren pwalletdbEncryption encrypted_batch

-END VERIFY SCRIPT-

Signed-off-by: Pasta <pasta@dashboost.org>
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request May 10, 2020
Text from bitcoin#11851 (comment)
by John Newbery <john@johnnewbery.com>.
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request May 10, 2020
furszy pushed a commit to furszy/bitcoin-core that referenced this pull request Aug 28, 2021
Text from bitcoin#11851 (comment)
by John Newbery <john@johnnewbery.com>.
furszy added a commit to PIVX-Project/PIVX that referenced this pull request Sep 1, 2021
9519fc3 Backport latest commit-script-check.sh from upstream (furszy)
3b25450 Add m_ prefix to WalletBatch::m_batch (Russell Yanofsky)
4d0fe84 Update walletdb comment after renaming. (Russell Yanofsky)
5c94ffe scripted-diff: Rename wallet database classes (furszy)

Pull request description:

  Scripted diff to rename "some" wallet classes.

  Backports bitcoin#11851

  Pushing it now because this is one of those annoying text-only rename backports that touch many files that we should try to avoid during the development/review period and only merge right after the release gets packed (aka now).

ACKs for top commit:
  random-zebra:
    utACK 9519fc3
  Fuzzbawls:
    ACK 9519fc3

Tree-SHA512: 95c9f028c0836e7ddd2100eb8e5a9635d02a011994209e0bda0af98f97e788c1b047378cd95722b8b454a22cd295ff1befc201480d0359abe1c4ebd807858da6
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.