From faf1d40bd00380dc8f8ea6c3a88f2716cd523a67 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Wed, 6 Sep 2017 13:38:01 -0700 Subject: [PATCH] lnwallet/channel: adds directionality htlc retributions This commit also adds an incoming flag to HtlcRetribution struct to allow the breach arbiter to generate the appropriate witness based on the htlc's directionality. It also ensures that the size of the htlc retribution slice is now determined by the size of the number of htlcs present in the revoked snapshot, which fixes a minor bug that could lead to nil pointer deferences. --- lnwallet/channel.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lnwallet/channel.go b/lnwallet/channel.go index d5f0ed1b..0bf4dc53 100644 --- a/lnwallet/channel.go +++ b/lnwallet/channel.go @@ -1032,6 +1032,12 @@ type HtlcRetribution struct { // OutPoint is the target outpoint of this HTLC pointing to the // breached commitment transaction. OutPoint wire.OutPoint + + // 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 + // witness type should be used to sweep the output. + IsIncoming bool } // BreachRetribution contains all the data necessary to bring a channel @@ -1162,7 +1168,7 @@ 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(chanState.Htlcs)) + htlcRetributions := make([]HtlcRetribution, len(revokedSnapshot.Htlcs)) for i, htlc := range revokedSnapshot.Htlcs { var ( htlcScript []byte @@ -1206,6 +1212,7 @@ func newBreachRetribution(chanState *channeldb.OpenChannel, stateNum uint64, Hash: commitHash, Index: uint32(htlc.OutputIndex), }, + IsIncoming: htlc.Incoming, } }