diff --git a/p2p/pkg/rpc/bidder/service.go b/p2p/pkg/rpc/bidder/service.go index 76221200c..9e924f976 100644 --- a/p2p/pkg/rpc/bidder/service.go +++ b/p2p/pkg/rpc/bidder/service.go @@ -380,42 +380,39 @@ func (s *Service) CancelAutoDeposit( go func() { ticker := time.NewTicker(5 * time.Second) defer ticker.Stop() - for { - select { - case <-ticker.C: - currentWindow, err := s.blockTrackerContract.GetCurrentWindow() + for range ticker.C { + currentWindow, err := s.blockTrackerContract.GetCurrentWindow() + if err != nil { + s.logger.Error("getting current window", "error", err) + continue + } + doWithdraw := true + for _, w := range windows { + if w.Uint64() >= currentWindow.Uint64() { + doWithdraw = false + break + } + } + if doWithdraw { + opts, err := s.optsGetter(ctx) if err != nil { - s.logger.Error("getting current window", "error", err) + s.logger.Error("getting transact opts", "error", err) continue } - doWithdraw := true - for _, w := range windows { - if w.Uint64() >= currentWindow.Uint64() { - doWithdraw = false - break - } + txn, err := s.registryContract.WithdrawFromWindows(opts, windows) + if err != nil { + s.logger.Error("withdraw from windows", "error", err) + return } - if doWithdraw { - opts, err := s.optsGetter(ctx) - if err != nil { - s.logger.Error("getting transact opts", "error", err) - continue - } - txn, err := s.registryContract.WithdrawFromWindows(opts, windows) - if err != nil { - s.logger.Error("withdraw from windows", "error", err) - return - } - receipt, err := s.watcher.WaitForReceipt(ctx, txn) - if err != nil { - s.logger.Error("waiting for receipt", "error", err) - return - } - if receipt.Status != types.ReceiptStatusSuccessful { - s.logger.Error("receipt status", "status", receipt.Status) - } + receipt, err := s.watcher.WaitForReceipt(ctx, txn) + if err != nil { + s.logger.Error("waiting for receipt", "error", err) return } + if receipt.Status != types.ReceiptStatusSuccessful { + s.logger.Error("receipt status", "status", receipt.Status) + } + return } } }() diff --git a/p2p/pkg/rpc/bidder/service_test.go b/p2p/pkg/rpc/bidder/service_test.go index b18011b35..cfd46e80c 100644 --- a/p2p/pkg/rpc/bidder/service_test.go +++ b/p2p/pkg/rpc/bidder/service_test.go @@ -407,9 +407,8 @@ func TestAutoDepositHandling(t *testing.T) { } windows := make([]*wrapperspb.UInt64Value, 2) - for i, v := range resp.WindowNumbers { - windows[i] = v - } + copy(windows, resp.WindowNumbers) + _, err = client.WithdrawFromWindows(context.Background(), &bidderapiv1.WithdrawFromWindowsRequest{ WindowNumbers: windows, })