Skip to content

contractcourt+lnwallet: ensure the chainWatcher properly plays all remote commitments#1158

Merged
Roasbeef merged 7 commits into
lightningnetwork:masterfrom
Roasbeef:play-all-commits
May 4, 2018
Merged

contractcourt+lnwallet: ensure the chainWatcher properly plays all remote commitments#1158
Roasbeef merged 7 commits into
lightningnetwork:masterfrom
Roasbeef:play-all-commits

Conversation

@Roasbeef
Copy link
Copy Markdown
Member

In this commit, we extend the chainWatcher and the lnwire.NewUnilteralCloseSummary methods to ensure that we're able to properly play all valid commitments the remote party may be holding. A bug that existed before this commit would at times cause us to not create the proper close channel summary meaning we wouldn't detect that we had a spendable output within the commitment that the remote party broadcasted.

A test of tests at the channel state machine level as well as at the chainWatcher level have been added to ensure this PR properly fixes the issue at hand.

Fixes #1141.
Fixes #927.

@Roasbeef Roasbeef force-pushed the play-all-commits branch 2 times, most recently from 7ecf105 to 0ccdfee Compare April 29, 2018 23:27
@Roasbeef Roasbeef added this to the 0.4.2-beta milestone May 2, 2018
@Roasbeef Roasbeef force-pushed the play-all-commits branch from 0ccdfee to 4debd66 Compare May 2, 2018 02:37
@Roasbeef
Copy link
Copy Markdown
Member Author

Roasbeef commented May 2, 2018

Pushed up a new version w/ some bug fixes and also the conflict addressed.

halseth
halseth previously approved these changes May 2, 2018
Copy link
Copy Markdown
Contributor

@halseth halseth left a comment

Choose a reason for hiding this comment

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

LGTM, this takes care of an important edge case within the protocol! Also been missing chainwatcher tests in my life, so nice to see that addition. 💯💯💯💯💯💯💯💯

Comment thread contractcourt/chain_watcher_test.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: remove newline

Comment thread contractcourt/chain_watcher_test.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: remove newline

Copy link
Copy Markdown
Contributor

@cfromknecht cfromknecht left a comment

Choose a reason for hiding this comment

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

Nice fixes! Great to clean up all these pending commitment cases in next release ⚡️

Comment thread contractcourt/chain_watcher.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

maybe add warning in the even that broadcastStateNum > remoteStateNum+1 now that we would take no action?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed.

Comment thread lnwallet/channel_test.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

great test 👍

@Roasbeef Roasbeef force-pushed the play-all-commits branch 3 times, most recently from d142ac7 to 2889e0b Compare May 4, 2018 03:13
Roasbeef added 7 commits May 3, 2018 21:29
…nelSummary

In this commit, we extend the CloseChannelSummary by also storing: the
current unrevoked revocation for the remote party, the next pending
unused revocation, and also the local channel config. We move to store
these as the provide an extra level of defense against bugs as we'll
always store information required to derive keys for any current and
prior states.
In this commit, we move a set of useful functions for testing channels
into a new file. The old createTestChannels has been improved as it will
now properly set the height hint on the first created commitments, and
also no longer accepts any arguments as the revocation window no longer
exists.
…ote commits

In this commit, we modify the NewUnilateralCloseSummary to be able to
distinguish between a unilateral closure using the lowest+highest
commitment the remote party possesses. Before this commit, if the remote
party broadcast their highest commitment, when they have a lower
unrevoked commitment, then this function would fail to find the proper
output, leaving funds on the chain.

To fix this, it's now the duty of the caller to pass remotePendingCommit
with the proper value. The caller should use the lowest unrevoked
commitment, and the height hint of the broadcast commitment to discern
if this is a pending commitment or not.
@Roasbeef Roasbeef force-pushed the play-all-commits branch from 2889e0b to 7af699f Compare May 4, 2018 04:29
Copy link
Copy Markdown
Contributor

@halseth halseth left a comment

Choose a reason for hiding this comment

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

LGTM

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.

Force-closed channel balance not returned to wallet self output not swept after local remote force close

3 participants