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

feat(proposer): shuffle prover endpoints before assigning proof tasks #390

Merged
merged 1 commit into from
Sep 15, 2023
Merged
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
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