package services import ( "time" "ripple/bug" "ripple/helpers" "ripple/types" ) const cancelPaymentFailsafeInterval = 10 * time.Minute func (pm *PaymentManager) CancelPaymentFailsafe() { for paymentID, payment := range pm.st.Storage.Payments { if !payment.Cancelled() { continue } if (payment.Incoming == (types.UserIdentifier{})) == (payment.Outgoing == (types.UserIdentifier{})) { panic(bug.BugStateViolated) } ok, nextHop, instr := helpers.BuildCancelAuto(paymentID, payment) if !ok || pm.lockstep.InQueue(nextHop, instr) { continue } pm.lockstep.Enqueue(nextHop, instr) } } func (pm *PaymentManager) RunCancelPaymentFailsafe() { for { pm.CancelFailsafeCh <- struct{}{} time.Sleep(cancelPaymentFailsafeInterval) } }