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:
parent
81767eb8fd
commit
c9dbaa1403
@ -1736,11 +1736,11 @@ func (lc *LightningChannel) CancelHTLC(rHash [32]byte) (uint32, error) {
|
|||||||
if addEntry == nil {
|
if addEntry == nil {
|
||||||
return 0, fmt.Errorf("unable to find HTLC to cancel")
|
return 0, fmt.Errorf("unable to find HTLC to cancel")
|
||||||
}
|
}
|
||||||
|
|
||||||
pd := &PaymentDescriptor{
|
pd := &PaymentDescriptor{
|
||||||
Amount: addEntry.Amount,
|
Amount: addEntry.Amount,
|
||||||
Index: lc.ourLogCounter,
|
RHash: addEntry.RHash,
|
||||||
ParentIndex: addEntry.Index,
|
ParentIndex: addEntry.Index,
|
||||||
|
Index: lc.ourLogCounter,
|
||||||
EntryType: Cancel,
|
EntryType: Cancel,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1766,6 +1766,7 @@ func (lc *LightningChannel) ReceiveCancelHTLC(logIndex uint32) error {
|
|||||||
htlc := addEntry.Value.(*PaymentDescriptor)
|
htlc := addEntry.Value.(*PaymentDescriptor)
|
||||||
pd := &PaymentDescriptor{
|
pd := &PaymentDescriptor{
|
||||||
Amount: htlc.Amount,
|
Amount: htlc.Amount,
|
||||||
|
RHash: htlc.RHash,
|
||||||
ParentIndex: htlc.Index,
|
ParentIndex: htlc.Index,
|
||||||
Index: lc.theirLogCounter,
|
Index: lc.theirLogCounter,
|
||||||
EntryType: Cancel,
|
EntryType: Cancel,
|
||||||
|
@ -1222,10 +1222,18 @@ func TestCancelHTLC(t *testing.T) {
|
|||||||
len(aliceChannel.remoteCommitChain.tip().outgoingHTLCs) != 0 {
|
len(aliceChannel.remoteCommitChain.tip().outgoingHTLCs) != 0 {
|
||||||
t.Fatalf("htlc's still active from alice's POV")
|
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 ||
|
if len(bobChannel.localCommitChain.tip().outgoingHTLCs) != 0 ||
|
||||||
len(bobChannel.remoteCommitChain.tip().outgoingHTLCs) != 0 {
|
len(bobChannel.remoteCommitChain.tip().outgoingHTLCs) != 0 {
|
||||||
t.Fatalf("htlc's still active from bob's POV")
|
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)
|
expectedBalance := btcutil.Amount(btcutil.SatoshiPerBitcoin * 5)
|
||||||
if aliceChannel.channelState.OurBalance != expectedBalance {
|
if aliceChannel.channelState.OurBalance != expectedBalance {
|
||||||
|
Loading…
Reference in New Issue
Block a user