From c9dbaa14036bd27cf1339cfbf5e3a2b62c1162d1 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Sat, 7 Jan 2017 19:58:54 -0800 Subject: [PATCH] lnwallet: include r-hash of canceled htlc in log entry for cancel MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit modifies the logic around adding cancel entries to the update log for the commitment state machine slightly by also including the r-hash of the HTLC that’s been cancelled in the entry for the cancellation. With this change, we can accurately track which HTLC is being cancelled within outer sub-systems. --- lnwallet/channel.go | 5 +++-- lnwallet/channel_test.go | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lnwallet/channel.go b/lnwallet/channel.go index 96b38b11..9aba9d13 100644 --- a/lnwallet/channel.go +++ b/lnwallet/channel.go @@ -1736,11 +1736,11 @@ func (lc *LightningChannel) CancelHTLC(rHash [32]byte) (uint32, error) { if addEntry == nil { return 0, fmt.Errorf("unable to find HTLC to cancel") } - pd := &PaymentDescriptor{ Amount: addEntry.Amount, - Index: lc.ourLogCounter, + RHash: addEntry.RHash, ParentIndex: addEntry.Index, + Index: lc.ourLogCounter, EntryType: Cancel, } @@ -1766,6 +1766,7 @@ func (lc *LightningChannel) ReceiveCancelHTLC(logIndex uint32) error { htlc := addEntry.Value.(*PaymentDescriptor) pd := &PaymentDescriptor{ Amount: htlc.Amount, + RHash: htlc.RHash, ParentIndex: htlc.Index, Index: lc.theirLogCounter, EntryType: Cancel, diff --git a/lnwallet/channel_test.go b/lnwallet/channel_test.go index b21d81ed..f04f32a3 100644 --- a/lnwallet/channel_test.go +++ b/lnwallet/channel_test.go @@ -1222,10 +1222,18 @@ func TestCancelHTLC(t *testing.T) { len(aliceChannel.remoteCommitChain.tip().outgoingHTLCs) != 0 { t.Fatalf("htlc's still active from alice's POV") } + if len(aliceChannel.localCommitChain.tip().incomingHTLCs) != 0 || + len(aliceChannel.remoteCommitChain.tip().incomingHTLCs) != 0 { + t.Fatalf("htlc's still active from alice's POV") + } if len(bobChannel.localCommitChain.tip().outgoingHTLCs) != 0 || len(bobChannel.remoteCommitChain.tip().outgoingHTLCs) != 0 { t.Fatalf("htlc's still active from bob's POV") } + if len(bobChannel.localCommitChain.tip().incomingHTLCs) != 0 || + len(bobChannel.remoteCommitChain.tip().incomingHTLCs) != 0 { + t.Fatalf("htlc's still active from bob's POV") + } expectedBalance := btcutil.Amount(btcutil.SatoshiPerBitcoin * 5) if aliceChannel.channelState.OurBalance != expectedBalance {