Repository navigation
wallet: Enumerate walletdb keys - #16475
Conversation
fa59e42 to
fa01c0e
Compare
fa01c0e to
fa6f22b
Compare
|
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. |
|
Concept ACK. This seems like an improvement to code self-documentation. I think this would be even more helpful if the We could go further and change this to an enum, which would ensure that only known keys are read/written, and would allow us to tidy the long sequence of if-else statments in |
| ADD_SERIALIZE_METHODS; | ||
|
|
||
| template <typename Stream, typename Operation> | ||
| inline void SerializationOp(Stream& s, Operation ser_action) { |
There was a problem hiding this comment.
Could go further and just implement Unserialize?
There was a problem hiding this comment.
I kept the changes to a minimum. Happy to add a commit for this, if other think it is useful.
meshcollider
left a comment
There was a problem hiding this comment.
utACK fa6f22b
Agree with John though, the PR title says enumerate so why not use an enum?
The underlying type on an enum in cpp can only be integer, not I could switch it to an enum and then add helper methods for
I don't understand how this would prevent anyone from inlining a string literal (bypassing the enum). |
You'd still have to do the if-else statements elsewhere, so I don't see the benefit. I know a log(N) map lookup would also work, but I think the computational complexity shouldn't be a concern here. |
|
ACK fa6f22b, I'm a big fan of this kind of change as it prevents typos, which can happen with 'magic' strings in the code. |
The idea would be to change Changing this to an enum was a suggested follow-up. This PR is a useful change by itself. |
| } | ||
| } else if (strType != "bestblock" && strType != "bestblock_nomerkle" && | ||
| strType != "minversion" && strType != "acentry" && strType != "version") { | ||
| } else if (strType != DBKeys::BESTBLOCK && strType != DBKeys::BESTBLOCK_NOMERKLE && |
There was a problem hiding this comment.
(maybe for a followup) I think it would be better to define a const set of the types that are unused but kept around to avoid triggering unknown record warnings. Then we could change this if to be checking membership in that set.
| { | ||
| return (strType== "key" || strType == "wkey" || | ||
| strType == "mkey" || strType == "ckey"); | ||
| return (strType == DBKeys::KEY || strType == DBKeys::OLD_KEY || |
There was a problem hiding this comment.
(maybe for a followup) I think it would be better to define a const set of the types that are keys. Then we could change this function to be returning membership in that set.
|
Thanks for the plethora of suggestions of follow-up refactorings. To not invalidate the ACKs and to not scope creep this change, which should be minimal, but still an improvement, I will leave them for later. |
fanquake
left a comment
There was a problem hiding this comment.
ACK fa6f22b - I had a quick look over, definitely prefer this to strings floating around everywhere.
5 ACKs, including both the wallet maintainers, means I'll merge this now and all the follow ups can be done in a new PR. I like the idea of using a const set of types.
fa6f22b wallet: Rename CWalletKey to OldKey (MarcoFalke) fa6dc7f wallet: Enumerate walletdb keys (MarcoFalke) Pull request description: It is nice to see all the keys that exists in a single enum Also, rename CWalletKey to OldKey and update the outdated documentation ACKs for top commit: laanwj: ACK fa6f22b, I'm a big fan of this kind of change as it prevents typos, which can happen with 'magic' strings in the code. promag: ACK fa6f22b. @jnewbery suggestions are great followups, I think this is good enough. meshcollider: utACK fa6f22b achow101: Code review ACK fa6f22b fanquake: ACK fa6f22b - I had a quick look over, definitely prefer this to strings floating around everywhere. Tree-SHA512: 8ac3abd5a0d22dac1d77b8f97fe1e16c2608d650f3e9d6dd1df2fd5aeb35ef6643dfd4cd5c162404bb0100343c927d66df04dc695507ffc84a6c667e603acc54
|
post-merge ACK fa6f22b Potential follow-up PRs:
|
merge bitcoin#15588...bitcoin#16475: backports
It is nice to see all the keys that exists in a single enum
Also, rename CWalletKey to OldKey and update the outdated documentation