@@ -967,7 +967,7 @@ func (s *Switch) handleLocalResponse(pkt *htlcPacket) {
967967 // This can only happen if the circuit is still open, which is why this
968968 // ordering is chosen.
969969 if err := s .teardownCircuit (pkt ); err != nil {
970- log .Warnf ("Unable to teardown circuit %s: %v" ,
970+ log .Errorf ("Unable to teardown circuit %s: %v" ,
971971 pkt .inKey (), err )
972972 return
973973 }
@@ -1359,48 +1359,35 @@ func (s *Switch) teardownCircuit(pkt *htlcPacket) error {
13591359 case * lnwire.UpdateFailHTLC :
13601360 pktType = "FAIL"
13611361 default :
1362- err := fmt .Errorf ("cannot tear down packet of type: %T" , htlc )
1363- log .Errorf (err .Error ())
1364- return err
1362+ return fmt .Errorf ("cannot tear down packet of type: %T" , htlc )
13651363 }
13661364
1367- switch {
1368- case pkt .circuit .HasKeystone ():
1369- log .Debugf ("Tearing down open circuit with %s pkt, removing circuit=%v " +
1370- "with keystone=%v" , pktType , pkt .inKey (), pkt .outKey ())
1365+ var paymentHash lntypes.Hash
13711366
1372- err := s .circuits .DeleteCircuits (pkt .inKey ())
1373- if err != nil {
1374- log .Warnf ("Failed to tear down open circuit (%s, %d) <-> (%s, %d) " +
1375- "with payment_hash-%v using %s pkt" ,
1376- pkt .incomingChanID , pkt .incomingHTLCID ,
1377- pkt .outgoingChanID , pkt .outgoingHTLCID ,
1378- pkt .circuit .PaymentHash , pktType )
1379- return err
1380- }
1381-
1382- log .Debugf ("Closed completed %s circuit for %x: " +
1383- "(%s, %d) <-> (%s, %d)" , pktType , pkt .circuit .PaymentHash ,
1384- pkt .incomingChanID , pkt .incomingHTLCID ,
1385- pkt .outgoingChanID , pkt .outgoingHTLCID )
1367+ // Perform a defensive check to make sure we don't try to access a nil
1368+ // circuit.
1369+ circuit := pkt .circuit
1370+ if circuit != nil {
1371+ copy (paymentHash [:], circuit .PaymentHash [:])
1372+ }
13861373
1387- default :
1388- log .Debugf ("Tearing down incomplete circuit with %s for inkey=%v" ,
1389- pktType , pkt .inKey ())
1374+ log .Debugf ("Tearing down circuit with %s pkt, removing circuit=%v " +
1375+ "with keystone=%v" , pktType , pkt .inKey (), pkt .outKey ())
13901376
1391- err := s .circuits .DeleteCircuits (pkt .inKey ())
1392- if err != nil {
1393- log .Warnf ("Failed to tear down pending %s circuit for %x: " +
1394- "(%s, %d)" , pktType , pkt .circuit .PaymentHash ,
1395- pkt .incomingChanID , pkt .incomingHTLCID )
1396- return err
1397- }
1377+ err := s .circuits .DeleteCircuits (pkt .inKey ())
1378+ if err != nil {
1379+ log .Warnf ("Failed to tear down circuit (%s, %d) <-> (%s, %d) " +
1380+ "with payment_hash=%v using %s pkt" , pkt .incomingChanID ,
1381+ pkt .incomingHTLCID , pkt .outgoingChanID ,
1382+ pkt .outgoingHTLCID , pkt .circuit .PaymentHash , pktType )
13981383
1399- log .Debugf ("Removed pending onion circuit for %x: " +
1400- "(%s, %d)" , pkt .circuit .PaymentHash ,
1401- pkt .incomingChanID , pkt .incomingHTLCID )
1384+ return err
14021385 }
14031386
1387+ log .Debugf ("Closed %s circuit for %v: (%s, %d) <-> (%s, %d)" , pktType ,
1388+ paymentHash , pkt .incomingChanID , pkt .incomingHTLCID ,
1389+ pkt .outgoingChanID , pkt .outgoingHTLCID )
1390+
14041391 return nil
14051392}
14061393
0 commit comments