Skip to content

Conversation

S3RK
Copy link
Contributor

@S3RK S3RK commented Oct 12, 2020

This is a follow-up for #19077

This PR simplifies DB interface by removing mode string from WalletDatabase and WalletBatch.

The mode string was used to determine two flags for the instantiation of db connection:

  1. read-only flag. Never used on connection level. And on batch level Is only used within BerkeleyDatabase::Rewrite where it's replaced with bool flag.
  2. create flag. Is not required as we always check require_existing & require_create flags in MakeDatabase() before creating actual database instance. So we can safely default to always creating database if it doesn't exist yet.

@@ -305,20 +305,20 @@ BerkeleyDatabase::~BerkeleyDatabase()
}
}

BerkeleyBatch::BerkeleyBatch(BerkeleyDatabase& database, const char* pszMode, bool fFlushOnCloseIn) : pdb(nullptr), activeTxn(nullptr), m_cursor(nullptr), m_database(database)
BerkeleyBatch::BerkeleyBatch(BerkeleyDatabase& database, const bool fReadOnly, bool fFlushOnCloseIn) : pdb(nullptr), activeTxn(nullptr), m_cursor(nullptr), m_database(database)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: for new variables the naming convention is snake_case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

334eade

👍 and drop this-> below.

BTW, why not just drop member fReadOnly since it's always false?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed the name and dropped this->

BTW, why not just drop member fReadOnly since it's always false?

I kept it, because it's set to true in BerkeleyDatabase::Rewrite.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@achow101
Copy link
Member

Concept ACK

@laanwj
Copy link
Member

laanwj commented Oct 12, 2020

read-only flag. Never used on connection level.

Should we have a way to open databases read-only? It seems this would be useful in some cases, e.g. in the past I remember discussion about the bitcoin-wallet tool for purely informational commands, which should be able to leave a database unmodified otherwise (or be able to act on a read-only file system).

@achow101
Copy link
Member

Should we have a way to open databases read-only? It seems this would be useful in some cases, e.g. in the past I remember discussion about the bitcoin-wallet tool for purely informational commands, which should be able to leave a database unmodified otherwise (or be able to act on a read-only file system).

I think that it would be useful to have a read-only mode in the future, but it should be implemented differently from this mode string that we currently have. So this PR is at least a first step towards that, and we can add read-only mode for when we need it.

@DrahtBot
Copy link
Contributor

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

Copy link
Contributor

@promag promag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested ACK 53718b2, small commits that could be squashed but no big deal.

@@ -305,20 +305,20 @@ BerkeleyDatabase::~BerkeleyDatabase()
}
}

BerkeleyBatch::BerkeleyBatch(BerkeleyDatabase& database, const char* pszMode, bool fFlushOnCloseIn) : pdb(nullptr), activeTxn(nullptr), m_cursor(nullptr), m_database(database)
BerkeleyBatch::BerkeleyBatch(BerkeleyDatabase& database, const bool fReadOnly, bool fFlushOnCloseIn) : pdb(nullptr), activeTxn(nullptr), m_cursor(nullptr), m_database(database)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

334eade

👍 and drop this-> below.

BTW, why not just drop member fReadOnly since it's always false?

We never need to open database in read-only mode as it's controlled
separately for every batch.

Also we can safely create database if it doesn't exist already
because require_existing option is verified in MakeDatabase
before creating a new WalletDatabase instance.
@S3RK S3RK force-pushed the wallet_remove_mode_3 branch from 53718b2 to 135afa7 Compare October 13, 2020 11:44
@S3RK
Copy link
Contributor Author

S3RK commented Oct 13, 2020

read-only flag. Never used on connection level.

Should we have a way to open databases read-only? It seems this would be useful in some cases, e.g. in the past I remember discussion about the bitcoin-wallet tool for purely informational commands, which should be able to leave a database unmodified otherwise (or be able to act on a read-only file system).

Though I agree we might want to have it I think it's better not to keep unused functionality in the code. Also, current implementation is pretty limited. We use one connection per wallet and this prevents us from opening a true read-only connection, because it will break some wallet functionality. I guess this is why read-only mode was never used in practice.

If we want to introduce proper read-only mode we need to discuss different design trade-offs. One option would be to look at the possibility to bring it to a wallet level (for example load wallet in read-only mode). Alternatively for a command-level read-only mode we need to: a) either manage it on a batch level b) create separate read-write and read-only connections c) reconnect when needed d) other ideas..

I'll be happy to continue the work if there is strong demand for the feature.

@S3RK
Copy link
Contributor Author

S3RK commented Oct 13, 2020

@promag thanks for the quick review! I fixed the comment and squashed the commits.

Side node: I don't know what is the accepted practice here, but I usually do small commits as it's easier to squash than split. I also believe it sometimes can be useful as it provides more information on implementation.

@achow101
Copy link
Member

ACK 135afa7

@laanwj
Copy link
Member

laanwj commented Oct 14, 2020

I think that it would be useful to have a read-only mode in the future, but it should be implemented differently from this mode string that we currently have. So this PR is at least a first step towards that, and we can add read-only mode for when we need it.

Fair enough, concept ACK then.

Code review ACK 135afa7

@laanwj laanwj merged commit 9efa55c into bitcoin:master Oct 14, 2020
@S3RK S3RK deleted the wallet_remove_mode_3 branch October 15, 2020 04:52
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Oct 16, 2020
135afa7 wallet: remove db mode string (Ivan Metlushko)

Pull request description:

  This is a [follow-up](bitcoin#19077 (comment)) for bitcoin#19077

  This PR simplifies DB interface by removing mode string from `WalletDatabase` and `WalletBatch`.

  The mode string was used to determine two flags for the instantiation of db connection:
  1) read-only flag. Never used on connection level. And on batch level Is only used within `BerkeleyDatabase::Rewrite` where it's replaced with bool flag.
  2) create flag. Is not required as we always check `require_existing` & `require_create` flags in `MakeDatabase()` before creating actual database instance. So we can safely default to always creating database if it doesn't exist yet.

ACKs for top commit:
  achow101:
    ACK 135afa7
  laanwj:
    Code review ACK 135afa7

Tree-SHA512: f49c07c7387c02e517a58199620a678a918f8dfc20d1347d29fd6adea0bc89698c26cb8eef42b0977961c11c207c4bbe109bc31059f47c126cc600b01fd987eb
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Nov 17, 2021
Summary:
We never need to open database in read-only mode as it's controlled
separately for every batch.

Also we can safely create database if it doesn't exist already
because require_existing option is verified in MakeDatabase
before creating a new WalletDatabase instance.

This is a backport of [[bitcoin/bitcoin#20130 | core#20130]]

Notes:
 - walletdb_tests.cpp is an addtional ABC test suite introduced in D745
 - ABC does not have a `CWallet::MarkReplaced` method

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D10468
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants