From 421b37345f02562e215497fe6a8a003ea70079f4 Mon Sep 17 00:00:00 2001 From: David Date: Sat, 16 Sep 2023 03:30:18 +0800 Subject: [PATCH] feat(proposer): shuffle prover endpoints before assigning proof tasks (#390) --- proposer/prover_selector/eth_fee_eoa_selector.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/proposer/prover_selector/eth_fee_eoa_selector.go b/proposer/prover_selector/eth_fee_eoa_selector.go index 27500756f..279a5333a 100644 --- a/proposer/prover_selector/eth_fee_eoa_selector.go +++ b/proposer/prover_selector/eth_fee_eoa_selector.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "math/big" + "math/rand" "net/url" "time" @@ -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) @@ -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,