From f85f1f97ca2170bc65c685e086ba032724fd3260 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Sat, 20 Jan 2018 20:12:49 -0800 Subject: [PATCH] lnwallet: add the second level witness script to the HtlcRetribution MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In this commit, we add the second level witness script to the HtlcRetribution struct. We do this as it’s possible that we when attempt to sweep funds after a channel breach, then the remote party has already gone to the second layer. In this case, we’ll then need to update our SignDesc and also the witness, in order to do that we need this script that’ll get us pass the second layer P2WSH check. --- lnwallet/channel.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lnwallet/channel.go b/lnwallet/channel.go index 270b08e5..d2a76850 100644 --- a/lnwallet/channel.go +++ b/lnwallet/channel.go @@ -1640,6 +1640,13 @@ type HtlcRetribution struct { // breached commitment transaction. OutPoint wire.OutPoint + // SecondLevelWitnessScript is the witness script that will be created + // if the second level HTLC transaction for this output is + // broadcast/confirmed. We provide this as if the remote party attempts + // to to go the second level to claim the HTLC then we'll need to + // update the SignDesc above accordingly to sweep properly. + SecondLevelWitnessScript []byte + // IsIncoming is a boolean flag that indicates whether or not this // HTLC was accepted from the counterparty. A false value indicates that // this HTLC was offered by us. This flag is used determine the exact @@ -1825,6 +1832,17 @@ func NewBreachRetribution(chanState *channeldb.OpenChannel, stateNum uint64, err error ) + // 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 + // level. + secondLevelWitnessScript, err := secondLevelHtlcScript( + keyRing.RevocationKey, keyRing.DelayKey, remoteDelay, + ) + if err != nil { + return nil, err + } + // If this is an incoming HTLC, then this means that they were // the sender of the HTLC (relative to us). So we'll // re-generate the sender HTLC script. @@ -1865,7 +1883,8 @@ func NewBreachRetribution(chanState *channeldb.OpenChannel, stateNum uint64, Hash: commitHash, Index: uint32(htlc.OutputIndex), }, - IsIncoming: htlc.Incoming, + SecondLevelWitnessScript: secondLevelWitnessScript, + IsIncoming: htlc.Incoming, } }