Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: solver connection errors #427

Merged
merged 4 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.Default#.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
Loading