package services import ( "time" "ripple/bug" "ripple/commands" "ripple/types" ) const cancelPaymentFailsafeInterval = 10 * time.Minute func (pm *PaymentManager) FailsafeCancelPayment() { for paymentID, payment := range pm.st.Storage.Payments { if !payment.Cancel { continue } if (payment.Incoming == (types.UserIdentifier{})) == (payment.Outgoing == (types.UserIdentifier{})) { panic(bug.BugStateViolated) } var nextHop types.UserIdentifier if payment.Incoming != (types.UserIdentifier{}) { nextHop = payment.Incoming } else { nextHop = payment.Outgoing } instr := types.Instruction{ Command: commands.LOCKSTEP_CANCEL_PAYMENT, Arguments: paymentID[:], } if pm.lockstep.InQueue(nextHop, instr) { continue } pm.lockstep.Enqueue(nextHop, instr) } } func (pm *PaymentManager) RunFailsafe() { for { pm.FailsafeCh <- struct{}{} time.Sleep(cancelPaymentFailsafeInterval) } }