-
Notifications
You must be signed in to change notification settings - Fork 38.8k
wallet: Refactor BerkeleyBatch Read, Write, Erase, and Exists functions into non-template functions #19292
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
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, 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. |
|
Needs some kind of force push to prod github |
|
Have you considered making a commit for each function? Would help with scrolling during review, but no big deal if it is too cumbersome to split up. |
ryanofsky
left a comment
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.
Code review ACK 69e56486186bbcae7c8e68d891493949ea0f2af8
In order to override these later, the specific details of how the Read, Write, Erase, and Exists functions interact with the actual database file need to go into functions that are not templated.
|
Rebased |
69e5648 to
a389ed5
Compare
ryanofsky
left a comment
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.
Code review ACK a389ed5. No changes since last review, just non-conflicting rebase
Sjors
left a comment
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.
utACK a389ed5
| }; | ||
|
|
||
| private: | ||
| bool ReadKey(CDataStream& key, CDataStream& value); |
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 could use documentation. In particular the behavior when pdb is absent is not super intuitive, e.g. it returns false for ReadKey and true for WriteKey.
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.
WriteKey returns true so that it works with dummy database. After #19102, this can (and probably should) be changed to false.
|
|
||
| // Read | ||
| SafeDbt datValue; | ||
| int ret = pdb->get(activeTxn, datKey, datValue, 0); |
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 just early return false here if ret != 0 || datValue.get_data() == 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.
Meh. Will change if another push is needed.
| SafeDbt datValue; | ||
| int ret = pdb->get(activeTxn, datKey, datValue, 0); | ||
| if (ret == 0 && datValue.get_data() != nullptr) { | ||
| value.write((char*)datValue.get_data(), datValue.get_size()); |
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 is no longer inside a try-catch block, is that safe?
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.
The try-catch block is for the deserialization operation (the >> operator), not this write.
|
|
||
| bool BerkeleyBatch::WriteKey(CDataStream& key, CDataStream& value, bool overwrite) | ||
| { | ||
| if (!pdb) |
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.
It's a non-trivial move, so might as well add brackets or make it inline.
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.
Will change if another push is needed.
maflcko
left a comment
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.
ACK a389ed5 🔳
Show signature and timestamp
Signature:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
ACK a389ed52e8f4939ab5b4adcf93dcb7783d9006f1 🔳
-----BEGIN PGP SIGNATURE-----
iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUi6RwwAo8bI3tkD2UACsJtRgQS6CUj/gTqTq0lCZ9LijSV9USsdnwawka4GUQt+
Gd9h7dvn7c3I8F9fo1SnLQS+hB0VfYSB+Vo68V2dkxMiNixTxGt+CNoLsNfD3AQb
LLSvBZxA+ul1rAzopNEIGRLFBeV5ddFr3RlspZPUKTo4b7iryovqAzDmeM5YnjaW
4J95TT48By2IxwV+Q7gnw0u0OaW2I6lFcklrS8QGU17n/7phTwYu1O9ML1NmuPp4
WSvkMwx2nkJ3FXCXg572P9eCAcaj7UPwSQcA6QFeNwapUoOknIS2Qq1hhAjhtBXH
3+QxywB6Jb24ik3h57O+wWk3NQeygt7z2qXSJOr2YjfouY43M/BwyoRdE6rB9wzq
byXTD0WLrMLgk9qMzxquS8d+Pm0FCzI0R54SnesvllhT1DgvrAny6KU934YkuZVW
2mZoPwtMTzRFuDOlvoDZVHwkFlOueuLHwpO1IFdtqERAd3V6KGHV9GCdc5F1jVBq
k130gEHT
=3CaZ
-----END PGP SIGNATURE-----
Timestamp of file with hash 6bf76cee68718cc9e56aef4002215a6e74aed5587fdc5d0275fb0e5769554ec1 -
| bool ReadKey(CDataStream& key, CDataStream& value); | ||
| bool WriteKey(CDataStream& key, CDataStream& value, bool overwrite=true); | ||
| bool EraseKey(CDataStream& key); | ||
| bool HasKey(CDataStream& key); |
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 found it really confusing that all the const& are replaced by &. Is there any reason for that? If not, it could make sense to fix this up in a follow-up commit.
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 agree. If nothing else, const is good documentation about what can potentially be modified and what not.
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.
re: #19292 (comment)
I found it really confusing that all the
const&are replaced by&. Is there any reason for that? If not, it could make sense to fix this up in a follow-up commit.
I assumed it was necessary to remove const from all the arguments because reading from CDataStream objects changes their internal real read position. This is a reason I suggested replacing all the CDataStream arguments with Spans #18971 (comment). This could be done as a later followup.
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.
Both data and size are marked const in the CDataStream class. How would this affect the read position anyway?
I think the reason is that the in-memory key data needs to be purged (in case it is a private key)?
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.
Both
dataandsizeare markedconstin theCDataStreamclass. How would this affect the read position anyway?
Guess it wouldn't. I didn't check if these were const because I just remembered CDataStream being goofy about reading. Maybe it's less goofy than I thought but I still think Spans are better.
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.
@achow101 Let us know if you want to change this to span or rather have the current version of the pr merged
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.
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'll leave it for a followup.
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.
+1 on using spans
I also thought about making BerkeleyBatch::ReadKey return an Option<CDataStream> instead of passing it in, but dunno.
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.
Done in #19320
Summary: In order to override these later, the specific details of how the Read, Write, Erase, and Exists functions interact with the actual database file need to go into functions that are not templated. This is a backport of [[bitcoin/bitcoin#19292 | core#19292]] Test Plan: `ninja all check-all` Reviewers: #bitcoin_abc, deadalnix Reviewed By: #bitcoin_abc, deadalnix Differential Revision: https://reviews.bitcoinabc.org/D9618
In order to override these later, the specific details of how the Read, Write, Erase, and Exists functions interact with the actual database file need to go into functions that are not templated.
The functions
ReadKey,WriteKey,EraseKey, andHasKeyare introduced to handle the actual interaction with the database.This is mostly a moveonly.
Based on #19290