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 committed 2017-01-07 21:22:01 -08:00
1 parent 81767eb8fd
commit c9dbaa1403
2 files changed
+11 -2

No files matched your search

+3 -2
View File
@@ -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,
+8
View File
@@ -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 {