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

Channel restoration of old format fee update #2558

Conversation

halseth
Copy link
Contributor

@halseth halseth commented Jan 29, 2019

This PR fixes a bug that was introduced in #2397, where we started restoring FeeUpdates from disk as other HTLC updates. The problem arose if the prior version of lnd wrote the updates to disk, and the new version attempted to restore. Since the old version did not write the logIndex for FeeUpdates, this would be 0, causing it to be out of sync with the log update index, causing problems.

We fix this by setting the logIndex to the current log update index in case it is unset. A test that would previously cause this desync and following crash during compactLogs is included.

The last commit contains a sanity check that ensures all updates have their log index properly set, to catch these bugs in the future. It is not strictly necessary, but I thought it could be nice to catch it already here, and not in some obscure situation down the road.

Fixes #2546

@halseth halseth added the P1 MUST be fixed or reviewed label Jan 29, 2019
@halseth halseth added this to the 0.5.2 milestone Jan 29, 2019
@halseth halseth force-pushed the channel-restoration-old-format-fee-update branch from 3b6d7f9 to 93fc204 Compare January 31, 2019 08:23
Earlier versions did not write the log index to disk for fee updates, so
they will be unset. To account for this we set them to to current update
log index.
TestFeeUpdateOldDiskFormat tests that we properly recover FeeUpdates
written to disk using the old format, where the logIndex was not
written.
To avoid more bugs slipping through where the logIndex is not set, we
panic to catch this. This was earlier done for Adds and the htlcCounter,
which did lead us to find the resulting retoration bug.
@halseth halseth force-pushed the channel-restoration-old-format-fee-update branch from 93fc204 to 47918bd Compare January 31, 2019 08:25
@halseth
Copy link
Contributor Author

halseth commented Jan 31, 2019

Comments addressed, and rebased. PTAL @Roasbeef @cfromknecht

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 💥

@Roasbeef Roasbeef merged commit fc869d4 into lightningnetwork:master Jan 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P1 MUST be fixed or reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

segfault in lnwallet.removeUpdate()
3 participants