-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Decayed log optional migration #9945
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
Decayed log optional migration #9945
Conversation
Important Review skippedAuto reviews are limited to specific labels. 🏷️ Labels to auto review (1)
Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
233b756
to
fae32e9
Compare
fae32e9
to
c9c0e45
Compare
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.
Pull Request Overview
This PR introduces an optional migration for garbage collecting the decayed log while refactoring related configuration and migration handling in the codebase. Key changes include adding new configuration flags in sample-lnd.conf and lncfg/db.go; modifying htlcswitch components to incorporate a “reforward” flag along with updated logging; and integrating a new migration (migration34) into channeldb with accompanying tests and documentation updates.
Reviewed Changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
sample-lnd.conf | Adds new configuration comments and flags for decayed log GC |
lncfg/db.go | Replaces the old PruneRevocation flag with NoGcDecayedLog and NoPruneDecayedLog options |
htlcswitch/mock.go | Updates the DecodeHopIterator signature with an added bool parameter |
htlcswitch/link.go | Introduces early logging for completed fwdPkgs and refactors the decoding flow |
htlcswitch/hop/iterator.go | Modifies the iterator decoding to account for reforwarding condition |
htlcswitch/decayedlog.go | Removes legacy bucket operations and returns nil instead |
channeldb/options.go | Updates the optional migration configuration and adds decayed log options |
channeldb/migration34/* | Adds a new migration module for decayed log garbage collection |
channeldb/meta_test.go | Adjusts migration testing to verify that all optional migrations run correctly |
channeldb/db.go | Integrates the new migration logic and updates the meta information accordingly |
docs/release-notes/release-notes-0.19.2.md | Updates release notes to include the new optional migration |
Comments suppressed due to low confidence (1)
channeldb/options.go:26
- The term 'OptionalMiragtionConfig' appears to be misspelled; it should be 'OptionalMigrationConfig' for clarity and consistency.
type OptionalMiragtionConfig struct {
99987d2
to
e78253c
Compare
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 on the approach.
e78253c
to
5226a67
Compare
If it's an optional migration, shouldn't it be false by default? |
Good point, I decided to make it true by default because there is absolutely no reason to keep it (the data which is deleted in the migration). I choose the optional migration over the mandatory one overall because it is the less intrusive way into the code base, and because it is a minor release people can easy downgrade back to 19.1/19.0 if something is wrong with the migration. So I think it is totally fine having this default set to true. |
- The replay protection is | ||
[optimized](https://github.com/lightningnetwork/lnd/pull/9929) to use less disk | ||
space such that the `sphinxreplay.db` or the `decayedlogdb_kv` table will grow | ||
much slower. |
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.
much slower. | |
much more slowly. |
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 Change belongs to #9929
5226a67
to
b292569
Compare
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.
Looking good - my main comment is to split the commit a bit so we can focus on the details.
7f30276
to
2ee3115
Compare
Ok this PR still has one Question to resolve: This PR introduces a protection mechanism so that people upgrade to a newer version with a new Optional Migration applied cannot just downgrade their software because then we have to way to way to apply the optional migration again because we map it in the Optional Metadata. But we still need to solve the problem when people startup 19.2 and then for whatever reason downgrade to 19.1 again. This is not covered yet, probably we need to add a mandatory migration to prevent this ? Or we make every Optional Migration idempotent and every migration makes sure it is idempotent when called more than once and therefore we can remove the Optional Metadata bucket. |
2ee3115
to
53042bb
Compare
Solved this by counting up the migration number for migration 34. So this change will disallow LND users to revert back to previous versions. |
f69a36b
to
873ed94
Compare
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.
One question and I think it's good to go!
channeldb/db.go
Outdated
// downgrading to a prior version, otherwise the | ||
// decayed log db will not be properly cleaned up if | ||
// a users has downgraded and then upgrades again. | ||
number: 34, |
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 think it's fine to leave it uncleaned if the user decides to downgrade then upgrade - the optional migration mechanism should be removed once we are fully SQLized, it was created as the difficulty involved in the revocation log was huge, and we wanted to leave it to the users to decide to migrate or not based on their data size and machines. For this new migration tho, it's different as it's a shortcut for us to implement the migration, not that the migration itself is difficult.
I'm also not sure how this helps with the case when a user downgrades then upgrades, I think the optional meta has already been saved so it won't be applied again, and here the ver num is for mandatory migrations, which has no effect on optional ones? Essentially these are two independent migration mechanisms.
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'm also not sure how this helps with the case when a user downgrades then upgrades, I think the optional meta has already been saved so it won't be applied again, and here the ver num is for mandatory migrations, which has no effect on optional ones? Essentially these are two independent migration mechanisms.
So if you run 19.2 we increase the db version which means we cannot revert back to LND 19.1 (even if the user does not apply the optional migration). However if he applies (and it is default to true) we can be sure that he is not reverting back.
I think it's fine to leave it uncleaned if the user decides to downgrade then upgrade - the optional migration mechanism should be removed once we are fully SQLized, it was created as the difficulty involved in the revocation log was huge, and we wanted to leave it to the users to decide to migrate or not based on their data size and machines. For this new migration tho, it's different as it's a shortcut for us to implement the migration, not that the migration itself is difficult.
Let's see what the second review thinks and then we decide (open for both approaches).
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.
So if you run 19.2 we increase the db version which means we cannot revert back to LND 19.1 (even if the user does not apply the optional migration). However if he applies (and it is default to true) we can be sure that he is not reverting back.
Ok I just realized this is a powerful yet dangerous mechanism to stop people from downgrading nodes, something we didn't have before. In theory we could have this mechanism every time we create a release, tho I'm unsure atm if that's what the users want. If we have this, it means not only can they not downgrade from 19.2 to 19.1, but also that it is not possible to downgrade from 20 to 19.x.
In reality tho, we already stopped users from downgrading anyway whenever there's a mandatory migration, so by adding this just makes the optional migration a bit more mandatory, in the sense that the user cannot go back to a previous version where we still save the old data, which now we no longer use.
23f9148
to
511cc46
Compare
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.
LGTM🦾
Some context for other reviewers on why we chose the optional migration route,
- the mandatory migration is built for
channel.db
only, while here we need to work on thesphinxreplay.db
. So there's a gap already. - to make it work in mandatory migration is pretty straightforward - we can just add a new field to
mandatoryVersion
to instruct which db it should work on, without touching any of the previous migration methods. - the core issue is, again, the mandatory migration is made for
channel.db
only, which means the meta is saved there. In addition, we use a single tx to perform the migration and save its version num to the meta (putMeta
), and this tx is derived from the db we are working on, which ischannel.db
. Unless we want to break the atomicity there, there's no way to make this a mandatory migration.
So I think it's fine to emulate a mandatory migration using this optional approach, otherwise we will need to expand the scope to redesign the mandatory migration to allow multiple DBs. The only risk I'm seeing here is, if a new unrelated bug pops up in 19.2, and the user wants to downgrade to a previous version, it would now be impossible. So a second opinion here is appreciated.
511cc46
to
e0d95ca
Compare
Talked also to @guggero and the way forward here. We decided to make this migration truly optional, because nothing will get broke if the user for whatever reason downgrades from 19.2 back to 19.1 or earlier. And because everything will be SQLized in the near term we will eventually clean "garbage data". |
so, optional as in opt-in or opt-out? discussed with @Roasbeef yesterday and we think this should be an opt-in migration. |
Currently it's opt-out, but we can change that if we feel most users won't want to run it. |
I would say we are ok with selecting the |
Can be rebased now that the dep PR was merged! |
I think compared to other migrations the actually read/write a large amount of keys, this migration should be much faster (at least on |
Migration34 garbage collects the decayed log database. This commit only adds the migration code and does not use it.
This commit adds the migration code for the decayedlog db which is optional and will default to true.
e0d95ca
to
8208eb6
Compare
Builds on top of #9929.
This PR adds an Optional Migration which is by default set to true.
Looking for ACK or NACK.