diff --git a/htlcswitch/packet.go b/htlcswitch/packet.go index e991858519..ed5f82588c 100644 --- a/htlcswitch/packet.go +++ b/htlcswitch/packet.go @@ -1,6 +1,8 @@ package htlcswitch import ( + "fmt" + "github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/graph/db/models" "github.com/lightningnetwork/lnd/htlcswitch/hop" @@ -136,3 +138,12 @@ func (p *htlcPacket) keystone() Keystone { OutKey: p.outKey(), } } + +// String returns a human-readable description of the packet. +func (p *htlcPacket) String() string { + return fmt.Sprintf("keystone=%v, sourceRef=%v, destRef=%v, "+ + "incomingAmount=%v, amount=%v, localFailure=%v, hasSource=%v "+ + "isResolution=%v", p.keystone(), p.sourceRef, p.destRef, + p.incomingAmount, p.amount, p.localFailure, p.hasSource, + p.isResolution) +} diff --git a/htlcswitch/switch.go b/htlcswitch/switch.go index 4c54fab0a5..704887e8e1 100644 --- a/htlcswitch/switch.go +++ b/htlcswitch/switch.go @@ -2994,6 +2994,15 @@ func (s *Switch) handlePacketSettle(packet *htlcPacket) error { // If the source of this packet has not been set, use the circuit map // to lookup the origin. circuit, err := s.closeCircuit(packet) + + // If the circuit is in the process of closing, we will return a nil as + // there's another packet handling undergoing. + if errors.Is(err, ErrCircuitClosing) { + log.Debugf("Circuit is closing for packet=%v", packet) + return nil + } + + // Exit early if there's another error. if err != nil { return err } @@ -3005,7 +3014,7 @@ func (s *Switch) handlePacketSettle(packet *htlcPacket) error { // and when `UpdateFulfillHTLC` is received. After which `RevokeAndAck` // is received, which invokes `processRemoteSettleFails` in its link. if circuit == nil { - log.Debugf("Found nil circuit: packet=%v", spew.Sdump(packet)) + log.Debugf("Circuit already closed for packet=%v", packet) return nil }