-
Notifications
You must be signed in to change notification settings - Fork 421
Clean up persistence constants #4105
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
base: main
Are you sure you want to change the base?
Clean up persistence constants #4105
Conversation
|
I've assigned @valentinewallace as a reviewer! |
lightning/src/util/persist.rs
Outdated
| CHANNEL_MONITOR_PERSISTENCE_SECONDARY_NAMESPACE, | ||
| )?; | ||
| async fn cleanup_stale_updates(&self, lazy: bool) -> Result<(), io::Error> { | ||
| let monitor_keys = self.kv_store.list(pCHANNEL_MONITOR_NAMESPACE, "").await?; |
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's a typo in the constant name on line 994: pCHANNEL_MONITOR_NAMESPACE should be CHANNEL_MONITOR_NAMESPACE. This will cause a compilation error when building.
| let monitor_keys = self.kv_store.list(pCHANNEL_MONITOR_NAMESPACE, "").await?; | |
| let monitor_keys = self.kv_store.list(CHANNEL_MONITOR_NAMESPACE, "").await?; |
Spotted by Diamond
Is this helpful? React 👍 or 👎 to let us know.
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.
nACK from my side, they were intentionally kept expressive and consistent.
|
Okay, but "they were intentionally done this way" isn't really a strong argument for keeping them that way. My point here is that, in writing some persistence logic, I almost screwed it up at least three times, with one missed by reviewers and only caught (luckily) by graphite. That tells me the way we have it is totally the wrong tradeoff. If you prefer some other way of rejiggering them to make it more clear I'm all ears, of course. |
I really don't see how a more distinct expressive constant is harder to misuse? Why did you screw up exactly? It looked like a copy/paste mistake?
Glad Graphite caught it, but I doubt there was a review round between the mistake and Graphite discovering it?
The way I see it: they are very expressive, clearly spelling out what they are for and can never be misunderstood across LDK and LDK Node codebases (where we have quite a few more of these, following exactly the same pattern). We also made sure to explicitly always including the corresponding secondary namespace constants for unformity, exactly so that you can't mess up writing "" in the wrong place etc. FWIW, the only way how to make these more foolproof would be to introduce distinct types for primary namespace / secondary namespace / key instead of having them be generic |
8fb35e4 to
2124dd2
Compare
|
Finally got around to rebasing this.
The biggest difference here is that its incredibly easy to swap
IIRC there was one in one instance. Ignoring that, though, I regularly missed it while looking back at code while I was committing it.
Just including every possible word in a constant isn't always the right answer :). Yes, it makes it more clear if you stop and read the full mouthful, but when reading code you rarely do, that would be a waste of time. If there's ambiguity in what the
Yea, fair, there's definitely a valid concern there, though given the secondary namespaces are only used for monitor updates I'm not entirely sure its worth having a second constant. Its a bunch of additional overhead and potential for confusion in accidentally swapping the namespace constants which seemed worth just removing. Does the secondary namespace get used much in ldk-node? |
The constants in `lightning::util::persist` are sufficiently long that its often difficult eyeball their correctness which nearly led to several bugs when adding async support. Here we take the first step towards condensing them by making them somewhat more concise, dropping words which are obvious from context.
The constants in `lightning::util::persist` are sufficiently long that its often difficult eyeball their correctness which nearly led to several bugs when adding async support. Here we take a further step towards condensing them by making them somewhat more concise, dropping words which are obvious from context. Importantly, this changes the prefix for monitor *update* persistence namespaces from monitor persistence namespaces so that they are visually distinct. This runs the following replacements: * s/_PERSISTENCE_/_/g * s/CHANNEL_MONITOR_UPDATE/MONITOR_UPDATE/g * s/ARCHIVED_CHANNEL_MONITOR/ARCHIVED_MONITOR/g
The constants in `lightning::util::persist` are sufficiently long that its often difficult eyeball their correctness which nearly led to several bugs when adding async support. As it turns out, all of the `*_SECONDARY_NAMESPACE` constants were simply "", so having a huge pile of them everywhere is quite verbose and makes scanning the `*_NAMESPACE` constants more difficult. Here, we simply drop the `*_SECONDARY_NAMESPACE` constants entirely.
2124dd2 to
d23181f
Compare
d23181f to
5ffee02
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4105 +/- ##
==========================================
- Coverage 89.33% 89.33% -0.01%
==========================================
Files 180 180
Lines 138055 137929 -126
Branches 138055 137929 -126
==========================================
- Hits 123326 123213 -113
+ Misses 12122 12117 -5
+ Partials 2607 2599 -8
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Here we clean up the constants, removing words from them that are clear from context and dropping constants that aren't adding anything.
Based on #4063