lnwallet: include r-hash of canceled htlc in log entry for cancel

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.
This commit is contained in:
Olaoluwa Osuntokun 2017-01-07 19:58:54 -08:00
parent 81767eb8fd
commit c9dbaa1403
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2
2 changed files with 11 additions and 2 deletions

@ -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,

@ -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 {