Skip to content

Conversation

laanwj
Copy link
Member

@laanwj laanwj commented Apr 23, 2016

During my experiment with using LMDB as database I came across these database-agnostic changes to dbwrapper which make it easier to support other databases, or are small common-sense (I think) cleanups at most:

  • Pass parent CDBWrapper into CDBBatch and CDBIterator instead of obfuscation key (in the case of lmdb the batch needs to know about the database, to create a write transaction). This also looks cleaner.
  • Incrase privacy of methods that are implementation specific by moving them to a namespace: HandleError, GetObfuscateKey.
  • Make constructor of CDBIterator private - they rely on implementation details, others have no business instantiating these.
  • Remove GetObfuscateKeyHex - It is an unnecessary method as it is used only two times and only internally, and the whole implementation is HexStr(obfuscate_key).
  • Remove throw keywords in function signatures - Using throw() specifications in function signatures is not only not required in C++, it is considered deprecated for various reasons. It is not implemented by any of the common C++ compilers. Their usage is also inconsistent with the rest of the source code.

laanwj added 4 commits April 23, 2016 09:32
Using throw() specifications in function signatures is not only
not required in C++, it is considered deprecated for
[various reasons](https://stackoverflow.com/questions/1055387/throw-keyword-in-functions-signature).
It is not implemented by any of the common C++ compilers. The usage is
also inconsistent with the rest of the source code.
It is an unnecessary method as it is used only two times
and only internally, and the whole implementation is
HexStr(obfuscate_key).
Pass parent wrapper directly instead of obfuscation key. This
makes it possible for other databases which re-use this code
to use other properties from the database.

Add a namespace dbwrapper_private for private functions to be used
only in dbwrapper.h/cpp and dbwrapper_tests.
HandleError is implementation-specific.
@sipa
Copy link
Member

sipa commented Apr 23, 2016

utACK 869cf12

@maflcko
Copy link
Member

maflcko commented Apr 23, 2016

utACK 869cf12

@btcdrak
Copy link
Contributor

btcdrak commented Apr 23, 2016

Tested ACK 869cf12

@paveljanik
Copy link
Contributor

ACK 869cf12

throw() is still used in two other files on master:

src/support/allocators/secure.h
src/support/allocators/zeroafterfree.h

but it is not for this PR.

@jonasschnelli
Copy link
Contributor

utACK 869cf12

@jamesob
Copy link
Contributor

jamesob commented Apr 23, 2016

utACK

@laanwj
Copy link
Member Author

laanwj commented Apr 25, 2016

throw() is still used in two other files on master:

src/support/allocators/secure.h
src/support/allocators/zeroafterfree.h

Thanks for mentioning, although I think these are of a different class. They use throw() in the more conventional way to signify that a method or function doesn't ever throw. These could be replaced by the noexcept keyword in c++11.

@laanwj laanwj merged commit 869cf12 into bitcoin:master Apr 25, 2016
laanwj added a commit that referenced this pull request Apr 25, 2016
… databases

869cf12 dbwrapper: Move `HandleError` to `dbwrapper_private` (Wladimir J. van der Laan)
b69836d dbwrapper: Pass parent CDBWrapper into CDBBatch and CDBIterator (Wladimir J. van der Laan)
878bf48 dbwrapper: Remove CDBWrapper::GetObfuscateKeyHex (Wladimir J. van der Laan)
74f7b12 dbwrapper: Remove throw keywords in function signatures (Wladimir J. van der Laan)
@str4d str4d mentioned this pull request Aug 1, 2017
codablock pushed a commit to codablock/dash that referenced this pull request Oct 19, 2017
…r other databases

869cf12 dbwrapper: Move `HandleError` to `dbwrapper_private` (Wladimir J. van der Laan)
b69836d dbwrapper: Pass parent CDBWrapper into CDBBatch and CDBIterator (Wladimir J. van der Laan)
878bf48 dbwrapper: Remove CDBWrapper::GetObfuscateKeyHex (Wladimir J. van der Laan)
74f7b12 dbwrapper: Remove throw keywords in function signatures (Wladimir J. van der Laan)
zkbot added a commit to zcash/zcash that referenced this pull request Jan 15, 2018
Bitcoin 0.12+ dbwrapper improvements

Cherry-picked from the following upstream PRs:

- bitcoin/bitcoin#6650
  - Only refactor - excludes obfuscation
- bitcoin/bitcoin#6777
  - Excluding obfuscation-related changes
- bitcoin/bitcoin#6865
- bitcoin/bitcoin#6823
- bitcoin/bitcoin#6873
- bitcoin/bitcoin#7927
  - Excluding first commit (already included) and second commit (obfuscation-related)
- bitcoin/bitcoin#8467

Part of #2074.
zkbot added a commit to zcash/zcash that referenced this pull request Apr 3, 2018
Bitcoin 0.12+ dbwrapper improvements

Cherry-picked from the following upstream PRs:

- bitcoin/bitcoin#6650
  - Only refactor - excludes obfuscation
- bitcoin/bitcoin#6777
  - Excluding obfuscation-related changes
- bitcoin/bitcoin#6865
- bitcoin/bitcoin#6823
- bitcoin/bitcoin#6873
- bitcoin/bitcoin#7927
  - Excluding first commit (already included) and second commit (obfuscation-related)
- bitcoin/bitcoin#8467

Part of #2074.
random-zebra added a commit to PIVX-Project/PIVX that referenced this pull request May 27, 2020
82f9088 Refactor: Remove using namespace <xxx> from /dbwrapper_tests (random-zebra)
6db0b37 rpc: make `gettxoutsettinfo` run lock-free (random-zebra)
f009cf4 Do not shadow members in dbwrapper (random-zebra)
b7e540c dbwrapper: Move `HandleError` to `dbwrapper_private` (random-zebra)
43004d0 leveldbwrapper file rename to dbwrapper.* (random-zebra)
c882dd9 leveldbwrapper symbol rename: Remove "Level" from class, etc. names (random-zebra)
f6496da leveldbwrapper: Remove unused .Prev(), .SeekToLast() methods (random-zebra)
cacf3c2 Fix chainstate serialized_size computation (random-zebra)
a2a3d33 Add tests for CLevelDBBatch, CLevelDBIterator (random-zebra)
94150ac Encapsulate CLevelDB iterators cleanly (random-zebra)
21df7cc [DB] Refactor leveldbwrapper (random-zebra)
2251db3 change hardcoded character constants to a set of descriptive named co… (random-zebra)

Pull request description:

  This backports a series of updates and cleanups to the LevelDB wrapper from:

  - bitcoin#5707
  - bitcoin#6650 [`*`]
  - bitcoin#6777 [`*`]
  - bitcoin#6865
  - bitcoin#6873
  - bitcoin#7927 [`*`]
  - bitcoin#8467
  - bitcoin#6290
  - bitcoin#9281

  PIVX-specific edits were required to keep the sporks and zerocoin databases in line.

  [`*`] NOTE: excluding the obfuscation of databases by xoring data, as we might not want this feature (e.g. as zcash/zcash#2598). Otherwise it can be discussed, and added, with a separate PR.

ACKs for top commit:
  furszy:
    Re ACK 82f9088 .
  Fuzzbawls:
    ACK 82f9088

Tree-SHA512: 1e4a75621d2ec2eb68e01523d15321d1d2176b81aac0525617852899ab38c9b4980daecb9056d054e7961fc758a22143edf914c40d1819144a394f2869a8ad57
@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.

7 participants