Skip to content

Commit

Permalink
Make schedling more spread across validators (#903)
Browse files Browse the repository at this point in the history
* I'm seeing the same validator selected too often when trying to be
  random.  Instead, let's just round-robin through the highest scorers.
* This means a single validator will get all messages for a single
  block, and a different validator will get all messsages for the next
block
* We may want to change this in the future when we have more
  transactions per block, but for now, this should spread the load more
evenly

Co-authored-by: Tyler Ruppert <{ID}+{username}@users.noreply.github.com>
  • Loading branch information
MechanicalTyler and Tyler Ruppert authored Jul 6, 2023
1 parent a6f9f19 commit 1d5f7b7
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions x/evm/keeper/msg_assigner.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package keeper
import (
"errors"
"math"
"math/rand"
"sort"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -189,10 +188,9 @@ func pickValidator(ctx sdk.Context, validatorsInfos map[string]ValidatorInfo, we
}
}

// All else equal, grab a random of our high scorers deterministically within this block
detRand := rand.New(rand.NewSource(ctx.BlockHeight())) //nolint:gosec
// All else equal, grab one of our high scorers, but not always the same one
sort.Strings(highScorers)
return highScorers[detRand.Intn(len(highScorers))]
return highScorers[int(ctx.BlockHeight())%len(highScorers)]
}

func (ma MsgAssigner) PickValidatorForMessage(ctx sdk.Context, weights *types.RelayWeights) (string, error) {
Expand Down

0 comments on commit 1d5f7b7

Please sign in to comment.