diff --git a/htlcswitch/circuit_map.go b/htlcswitch/circuit_map.go index 3b605bbd0..6fdf36bb1 100644 --- a/htlcswitch/circuit_map.go +++ b/htlcswitch/circuit_map.go @@ -770,10 +770,12 @@ func (cm *circuitMap) CloseCircuit(outKey CircuitKey) (*PaymentCircuit, error) { return circuit, nil } -// DeleteCircuits destroys the target circuit by removing it from the circuit map, -// additionally removing the circuit's keystone if the HTLC was forwarded -// through an outgoing link. The circuit should be identified by its incoming -// circuit key. +// DeleteCircuits destroys the target circuits by removing them from the circuit +// map, additionally removing the circuits' keystones if any HTLCs were +// forwarded through an outgoing link. The circuits should be identified by its +// incoming circuit key. If a given circuit is not found in the circuit map, it +// will be ignored from the query. This would typically indicate that the +// circuit was already cleaned up at a different point in time. func (cm *circuitMap) DeleteCircuits(inKeys ...CircuitKey) error { log.Tracef("Deleting resolved circuits: %v", newLogClosure(func() string { @@ -786,22 +788,15 @@ func (cm *circuitMap) DeleteCircuits(inKeys ...CircuitKey) error { ) cm.mtx.Lock() - // First check that all provided keys are still known to the circuit - // map. + // Remove any references to the circuits from memory, keeping track of + // which circuits were removed, and which ones had been marked closed. + // This can be used to restore these entries later if the persistent + // removal fails. for _, inKey := range inKeys { - if _, ok := cm.pending[inKey]; !ok { - cm.mtx.Unlock() - return ErrUnknownCircuit + circuit, ok := cm.pending[inKey] + if !ok { + continue } - } - - // If no offenders were found, remove any references to the circuit from - // memory, keeping track of which circuits were removed, and which ones - // had been marked closed. This can be used to restore these entries - // later if the persistent removal fails. - for _, inKey := range inKeys { - circuit := cm.pending[inKey] - delete(cm.pending, inKey) if _, ok := cm.closed[inKey]; ok {