Skip to content

Commit

Permalink
fix: solver connection errors (#427)
Browse files Browse the repository at this point in the history
* fix: use KeyByRealIP for rate limiter

* fix: relax balance check errors
  • Loading branch information
walkah committed Dec 10, 2024
1 parent 2291942 commit 164e996
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions pkg/solver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,17 +351,23 @@ func (controller *SolverController) addResourceOffer(resourceOffer data.Resource

// If the balance is less than the required balance, don't add the resource offer
if balance.Cmp(requiredBalanceWei) < 0 {
return nil, fmt.Errorf("address %s doesn't have enough ETH balance. The required balance is %s but current balance is %s", resourceOffer.ResourceProvider, requiredBalanceWei, balance)
err := fmt.Errorf("address %s doesn't have enough ETH balance. The required balance is %s but current balance is %s", resourceOffer.ResourceProvider, requiredBalanceWei, balance)
controller.log.Error("ETH balance check failed", err)
return nil, nil
}

// required LP balance
requiredBalanceLp := web3.EtherToWei(float64(resourceOffer.DefaultPricing.InstructionPrice)) // based on the required LP balance for a job
balanceLp, err := controller.web3SDK.GetLPBalance(resourceOffer.ResourceProvider)
if err != nil {
return nil, fmt.Errorf("failed to retrieve LP balance for resource provider: %v", err)
err := fmt.Errorf("failed to retrieve LP balance for resource provider: %v", err)
controller.log.Error("LP Balance error", err)
return nil, nil
}
if balanceLp.Cmp(requiredBalanceLp) < 0 {
return nil, fmt.Errorf("address %s doesn't have enough LP balance. The required balance is %s but current balance is %s", resourceOffer.ResourceProvider, requiredBalanceLp, balanceLp)
err := fmt.Errorf("address %s doesn't have enough LP balance. The required balance is %s but current balance is %s", resourceOffer.ResourceProvider, requiredBalanceLp, balanceLp)
controller.log.Error("LP balance check failed", err)
return nil, nil
}

controller.log.Info("add resource offer", resourceOffer)
Expand Down
2 changes: 1 addition & 1 deletion pkg/solver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (solverServer *solverServer) ListenAndServe(ctx context.Context, cm *system
subrouter.Use(httprate.Limit(
solverServer.options.RateLimiter.RequestLimit,
time.Duration(solverServer.options.RateLimiter.WindowLength)*time.Second,
httprate.WithKeyFuncs(httprate.KeyByIP, httprate.KeyByEndpoint),
httprate.WithKeyFuncs(httprate.KeyByRealIP, httprate.KeyByEndpoint),
))

subrouter.HandleFunc("/job_offers", http.GetHandler(solverServer.getJobOffers)).Methods("GET")
Expand Down

0 comments on commit 164e996

Please sign in to comment.