Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

Commit

Permalink
feat(proposer): shuffle prover endpoints before assigning proof tasks (
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha committed Sep 16, 2023
1 parent fc64531 commit 421b373
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion proposer/prover_selector/eth_fee_eoa_selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"math/big"
"math/rand"
"net/url"
"time"

Expand Down Expand Up @@ -98,7 +99,7 @@ func (s *ETHFeeEOASelector) AssignProver(
increase.Div(increase, big.NewInt(100))
fee.Add(fee, increase)
}
for _, endpoint := range s.proverEndpoints {
for _, endpoint := range s.shuffleProverEndpoints() {
encodedAssignment, proverAddress, err := assignProver(ctx, meta, endpoint, fee, expiry, s.requestTimeout)
if err != nil {
log.Warn("Failed to assign prover", "endpoint", endpoint, "error", err)
Expand Down Expand Up @@ -152,6 +153,14 @@ func (s *ETHFeeEOASelector) checkProverBalance(ctx context.Context, prover commo
return true, nil
}

// shuffleProverEndpoints shuffles the current selector's prover endpoints.
func (s *ETHFeeEOASelector) shuffleProverEndpoints() []*url.URL {
rand.Shuffle(len(s.proverEndpoints), func(i, j int) {
s.proverEndpoints[i], s.proverEndpoints[j] = s.proverEndpoints[j], s.proverEndpoints[i]
})
return s.proverEndpoints
}

// assignProver tries to assign a proof generation task to the given prover by HTTP API.
func assignProver(
ctx context.Context,
Expand Down

0 comments on commit 421b373

Please sign in to comment.