Skip to content

Channel restoration of old format fee update#2558

Merged
Roasbeef merged 3 commits into
lightningnetwork:masterfrom
halseth:channel-restoration-old-format-fee-update
Jan 31, 2019
Merged

Channel restoration of old format fee update#2558
Roasbeef merged 3 commits into
lightningnetwork:masterfrom
halseth:channel-restoration-old-format-fee-update

Conversation

@halseth
Copy link
Copy Markdown
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
Comment thread lnwallet/channel.go Outdated
Comment thread lnwallet/channel_test.go Outdated
Comment thread lnwallet/channel_test.go Outdated
@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
Copy Markdown
Contributor Author

halseth commented Jan 31, 2019

Comments addressed, and rebased. PTAL @Roasbeef @cfromknecht

Copy link
Copy Markdown
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