Skip to content
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

Remove publishing last sweep tx logic during startup. #7879

Merged
merged 3 commits into from
Aug 15, 2023

Conversation

ziggie1984
Copy link
Collaborator

@ziggie1984 ziggie1984 commented Aug 9, 2023

This PR fixes #7708.

We remove the logic where we would publish the last sweep transaction during the startup of the sweeper sub-system. The main problem relates to neutrino backends which did not recognize invalid (e.g. double spends) transactions leading to used up default wallet funds almost indefinitely.
Detailed reason why we decided to remove this logic can be found in the issue and will be provided here shortly after doing some tests. The reason for publishing the last sweep tx was that we want to avoid a situation where we create a lot of empty addresses in our wallet.db when the sweeper crashes in specific situations.

Why we decided to remove this logic:

First of all no funds are at risk here, our wallet will always create addresses we can sign for.
Remains the case where we fail(crash) during the creation of the sweep. We are explicitly taking about a crash we are not anticipating here (after we created the sweep address, during the publishing of the transaction). We handle all errors we currently know of, so an error in this stage is very unlikely. If that would happen nonetheless, the sweeper only fires in special circumstances (sweep input available && finding a new block && expiration of the sweeper timeout) so the noderunner will very likely be aware of the continuous crashing and fix the problem until a lot of address space is occupied.

Therefore we decided to remove this logic.

Currently this implementation makes the migration via a mandatory path, happy to change this if we find consensus how to move forward. Opening this PR for review now.

Moreover this fix will give noderunners currently experiencing stuck funds to resolve this issue, however a wallet-rescan might be need as well.

Steps to Test

added a unit test for migration:

make unit-debug  pkg=channeldb/migration31

@ziggie1984 ziggie1984 force-pushed the remove-last-sweep-logic branch 2 times, most recently from 2041135 to a1a2515 Compare August 9, 2023 17:57
@Roasbeef
Copy link
Member

Roasbeef commented Aug 9, 2023

We might want to consider making the migration optional, so using the optionalVersions variable. We did this in the past when the migration was created to reclaim space, eg the revocation log.

@ziggie1984 ziggie1984 mentioned this pull request Aug 9, 2023
7 tasks
Copy link
Member

@yyforyongyu yyforyongyu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to consider making the migration optional

What's the reason? I think we should clean the disk for every node since this bucket will not be used after this PR. Plus I think there's some work left in the design of optional migration.

channeldb/db.go Show resolved Hide resolved
@ziggie1984
Copy link
Collaborator Author

I also find the optional path maybe not that fitting because we will remove the complete logic of broadcasting logic. Maybe roasbeef was thinking of a return path here I guess. Meaning that making this change mandatory would not allow users to run a prior version of lnd when this migration lockes in (thinking of the big taproot channel change which will come with 17?).

I think finishing the OptionalMigration code part seems also doable as well in a short enough time frame. So waiting for you final thoughts before going down this way.

@ziggie1984 ziggie1984 force-pushed the remove-last-sweep-logic branch 2 times, most recently from 5ca0220 to 4b326f5 Compare August 10, 2023 18:31
@ziggie1984 ziggie1984 marked this pull request as ready for review August 10, 2023 18:32
@Roasbeef
Copy link
Member

What's the reason? I

Mainly just trying to cut down on the number of migrations that need to be run for major updates if we're able to to do. Do we have a handle on how many keys we'd be deleting here for very large nodes? Given how active the sweeper can be at times, I think it's worth it to see what a dry run instance would look like, just so we can properly communicate to nodes how long a migration might take in practice.

@saubyk saubyk added this to the v0.18.0 milestone Aug 10, 2023
Copy link
Member

@yyforyongyu yyforyongyu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mainly just trying to cut down on the number of migrations that need to be run for major updates if we're able to to do. Do we have a handle on how many keys we'd be deleting here for very large nodes?

Yeah luckily it's just the sweeper-last-tx bucket, which is a root bucket that has one or zero item, thus performance-wise it'd be safe to migrate.

channeldb/migration31/migration.go Outdated Show resolved Hide resolved
channeldb/migration31/migration_test.go Show resolved Hide resolved
channeldb/migration31/migration_test.go Outdated Show resolved Hide resolved
docs/release-notes/release-notes-0.17.0.md Outdated Show resolved Hide resolved
@ziggie1984 ziggie1984 force-pushed the remove-last-sweep-logic branch 2 times, most recently from e9efab4 to ffcb82c Compare August 11, 2023 07:39
@ziggie1984 ziggie1984 requested a review from yyforyongyu August 11, 2023 07:41
Copy link
Member

@yyforyongyu yyforyongyu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do a final analysis of the address inflation thing, otherwise LGTM🎉

@ProofOfKeags ProofOfKeags self-requested a review August 14, 2023 22:14
Copy link
Collaborator

@ProofOfKeags ProofOfKeags left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Send it 🚀

Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🏜️

Noted one simplification in the code, otherwise I think it looks good to me.

sweep/store.go Show resolved Hide resolved
channeldb/migration31/migration.go Outdated Show resolved Hide resolved
We remove the publishing of the last published sweep tx during the
startup of the sweeper. This republishing can lead to situations
where funds of the default wallet might be locked for neutrino
backend clients.
Moreover all related tests are removed as well.
The new migration removes the sweeper-last-tx top level bucket
from the channel.db database.
@ziggie1984 ziggie1984 force-pushed the remove-last-sweep-logic branch 2 times, most recently from 654488a to e705899 Compare August 15, 2023 08:24
Copy link
Collaborator

@guggero guggero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one issue with the release notes, otherwise we're good to go.

docs/release-notes/release-notes-0.17.0.md Outdated Show resolved Hide resolved
@ziggie1984 ziggie1984 force-pushed the remove-last-sweep-logic branch from e705899 to 160eab2 Compare August 15, 2023 09:23
@guggero guggero merged commit 4ab2454 into lightningnetwork:master Aug 15, 2023
@saubyk saubyk removed this from the v0.18.0 milestone Aug 15, 2023
@saubyk saubyk added this to the v0.17.0 milestone Aug 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Last sweep tx is constantly rebroadcasted on startup
6 participants