mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-05-24 18:50:02 +02:00
channeldb+htlcswitch: make sure circuit is not nil in teardownCircuit
This commit is contained in:
parent
2fc79d8946
commit
3b6e28d19b
@ -211,6 +211,11 @@ func (f *PkgFilter) Decode(r io.Reader) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// String returns a human-readable string.
|
||||||
|
func (f *PkgFilter) String() string {
|
||||||
|
return fmt.Sprintf("count=%v, filter=%v", f.count, f.filter)
|
||||||
|
}
|
||||||
|
|
||||||
// FwdPkg records all adds, settles, and fails that were locked in as a result
|
// FwdPkg records all adds, settles, and fails that were locked in as a result
|
||||||
// of the remote peer sending us a revocation. Each package is identified by
|
// of the remote peer sending us a revocation. Each package is identified by
|
||||||
// the short chanid and remote commitment height corresponding to the revocation
|
// the short chanid and remote commitment height corresponding to the revocation
|
||||||
|
@ -3297,7 +3297,7 @@ func (l *channelLink) processRemoteSettleFails(fwdPkg *channeldb.FwdPkg,
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l.log.Debugf("settle-fail-filter %v", fwdPkg.SettleFailFilter)
|
l.log.Debugf("settle-fail-filter: %v", fwdPkg.SettleFailFilter)
|
||||||
|
|
||||||
var switchPackets []*htlcPacket
|
var switchPackets []*htlcPacket
|
||||||
for i, pd := range settleFails {
|
for i, pd := range settleFails {
|
||||||
|
@ -967,7 +967,7 @@ func (s *Switch) handleLocalResponse(pkt *htlcPacket) {
|
|||||||
// This can only happen if the circuit is still open, which is why this
|
// This can only happen if the circuit is still open, which is why this
|
||||||
// ordering is chosen.
|
// ordering is chosen.
|
||||||
if err := s.teardownCircuit(pkt); err != nil {
|
if err := s.teardownCircuit(pkt); err != nil {
|
||||||
log.Warnf("Unable to teardown circuit %s: %v",
|
log.Errorf("Unable to teardown circuit %s: %v",
|
||||||
pkt.inKey(), err)
|
pkt.inKey(), err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -1359,47 +1359,34 @@ func (s *Switch) teardownCircuit(pkt *htlcPacket) error {
|
|||||||
case *lnwire.UpdateFailHTLC:
|
case *lnwire.UpdateFailHTLC:
|
||||||
pktType = "FAIL"
|
pktType = "FAIL"
|
||||||
default:
|
default:
|
||||||
err := fmt.Errorf("cannot tear down packet of type: %T", htlc)
|
return fmt.Errorf("cannot tear down packet of type: %T", htlc)
|
||||||
log.Errorf(err.Error())
|
}
|
||||||
|
|
||||||
|
var paymentHash lntypes.Hash
|
||||||
|
|
||||||
|
// Perform a defensive check to make sure we don't try to access a nil
|
||||||
|
// circuit.
|
||||||
|
circuit := pkt.circuit
|
||||||
|
if circuit != nil {
|
||||||
|
copy(paymentHash[:], circuit.PaymentHash[:])
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Debugf("Tearing down circuit with %s pkt, removing circuit=%v "+
|
||||||
|
"with keystone=%v", pktType, pkt.inKey(), pkt.outKey())
|
||||||
|
|
||||||
|
err := s.circuits.DeleteCircuits(pkt.inKey())
|
||||||
|
if err != nil {
|
||||||
|
log.Warnf("Failed to tear down circuit (%s, %d) <-> (%s, %d) "+
|
||||||
|
"with payment_hash=%v using %s pkt", pkt.incomingChanID,
|
||||||
|
pkt.incomingHTLCID, pkt.outgoingChanID,
|
||||||
|
pkt.outgoingHTLCID, pkt.circuit.PaymentHash, pktType)
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
switch {
|
log.Debugf("Closed %s circuit for %v: (%s, %d) <-> (%s, %d)", pktType,
|
||||||
case pkt.circuit.HasKeystone():
|
paymentHash, pkt.incomingChanID, pkt.incomingHTLCID,
|
||||||
log.Debugf("Tearing down open circuit with %s pkt, removing circuit=%v "+
|
pkt.outgoingChanID, pkt.outgoingHTLCID)
|
||||||
"with keystone=%v", pktType, pkt.inKey(), pkt.outKey())
|
|
||||||
|
|
||||||
err := s.circuits.DeleteCircuits(pkt.inKey())
|
|
||||||
if err != nil {
|
|
||||||
log.Warnf("Failed to tear down open circuit (%s, %d) <-> (%s, %d) "+
|
|
||||||
"with payment_hash-%v using %s pkt",
|
|
||||||
pkt.incomingChanID, pkt.incomingHTLCID,
|
|
||||||
pkt.outgoingChanID, pkt.outgoingHTLCID,
|
|
||||||
pkt.circuit.PaymentHash, pktType)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Debugf("Closed completed %s circuit for %x: "+
|
|
||||||
"(%s, %d) <-> (%s, %d)", pktType, pkt.circuit.PaymentHash,
|
|
||||||
pkt.incomingChanID, pkt.incomingHTLCID,
|
|
||||||
pkt.outgoingChanID, pkt.outgoingHTLCID)
|
|
||||||
|
|
||||||
default:
|
|
||||||
log.Debugf("Tearing down incomplete circuit with %s for inkey=%v",
|
|
||||||
pktType, pkt.inKey())
|
|
||||||
|
|
||||||
err := s.circuits.DeleteCircuits(pkt.inKey())
|
|
||||||
if err != nil {
|
|
||||||
log.Warnf("Failed to tear down pending %s circuit for %x: "+
|
|
||||||
"(%s, %d)", pktType, pkt.circuit.PaymentHash,
|
|
||||||
pkt.incomingChanID, pkt.incomingHTLCID)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Debugf("Removed pending onion circuit for %x: "+
|
|
||||||
"(%s, %d)", pkt.circuit.PaymentHash,
|
|
||||||
pkt.incomingChanID, pkt.incomingHTLCID)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user