-
Notifications
You must be signed in to change notification settings - Fork 2.3k
lnwallet+test: properly generate the sender HTLC script in a contract breach scenario #1025
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
Merged
Roasbeef
merged 5 commits into
lightningnetwork:master
from
Roasbeef:incoming-htlc-breach-retribution
Apr 6, 2018
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e91dff4
test: extend testRevokedCloseRetributionRemoteHodl to have HTLCs in b…
Roasbeef 4e44528
lnwallet: fix ordering of keys when we generate the sender script dur…
Roasbeef c393475
lnwallet: ensure that we skip dust HTLC's in NewBreachRetribution
Roasbeef f79af46
lnwallet: in NewBreachRetribution create the htlcRetributions slice t…
Roasbeef 7da8cb2
lnwallet: add new TestNewBreachRetributionSkipsDustHtlcs test
Roasbeef File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1969,13 +1969,23 @@ func NewBreachRetribution(chanState *channeldb.OpenChannel, stateNum uint64, | |
| // With the commitment outputs located, we'll now generate all the | ||
| // retribution structs for each of the HTLC transactions active on the | ||
| // remote commitment transaction. | ||
| htlcRetributions := make([]HtlcRetribution, len(revokedSnapshot.Htlcs)) | ||
| for i, htlc := range revokedSnapshot.Htlcs { | ||
| htlcRetributions := make([]HtlcRetribution, 0, len(revokedSnapshot.Htlcs)) | ||
| for _, htlc := range revokedSnapshot.Htlcs { | ||
| var ( | ||
| htlcScript []byte | ||
| err error | ||
| ) | ||
|
|
||
| // If the HTLC is dust, then we'll skip it as it doesn't have | ||
| // an output on the commitment transaction. | ||
| if htlcIsDust( | ||
| htlc.Incoming, false, | ||
| SatPerKWeight(revokedSnapshot.FeePerKw), | ||
| htlc.Amt.ToSatoshis(), chanState.RemoteChanCfg.DustLimit, | ||
| ) { | ||
| continue | ||
| } | ||
|
|
||
| // We'll generate the original second level witness script now, | ||
| // as we'll need it if we're revoking an HTLC output on the | ||
| // remote commitment transaction, and *they* go to the second | ||
|
|
@@ -1992,7 +2002,7 @@ func NewBreachRetribution(chanState *channeldb.OpenChannel, stateNum uint64, | |
| // re-generate the sender HTLC script. | ||
| if htlc.Incoming { | ||
| htlcScript, err = senderHTLCScript( | ||
| keyRing.LocalHtlcKey, keyRing.RemoteHtlcKey, | ||
| keyRing.RemoteHtlcKey, keyRing.LocalHtlcKey, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| keyRing.RevocationKey, htlc.RHash[:], | ||
| ) | ||
| if err != nil { | ||
|
|
@@ -2013,7 +2023,7 @@ func NewBreachRetribution(chanState *channeldb.OpenChannel, stateNum uint64, | |
| } | ||
| } | ||
|
|
||
| htlcRetributions[i] = HtlcRetribution{ | ||
| htlcRetributions = append(htlcRetributions, HtlcRetribution{ | ||
| SignDesc: SignDescriptor{ | ||
| KeyDesc: chanState.LocalChanCfg.RevocationBasePoint, | ||
| DoubleTweak: commitmentSecret, | ||
|
|
@@ -2029,7 +2039,7 @@ func NewBreachRetribution(chanState *channeldb.OpenChannel, stateNum uint64, | |
| }, | ||
| SecondLevelWitnessScript: secondLevelWitnessScript, | ||
| IsIncoming: htlc.Incoming, | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| // Finally, with all the necessary data constructed, we can create the | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should add a unit test that checks that this is properly fixed.
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.
Excellent call! Just push out the tests that led to another bug fix.