Skip to content

Commit

Permalink
feat: pick random top relayer from block timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
maharifu committed Sep 24, 2024
1 parent 3e01ede commit e651d89
Show file tree
Hide file tree
Showing 2 changed files with 1,092 additions and 932 deletions.
10 changes: 9 additions & 1 deletion x/evm/keeper/msg_assigner.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import (
valsettypes "github.com/palomachain/paloma/x/valset/types"
)

// topValidatorPoolSize is the number of validators considered when picking
const topValidatorPoolSize = 5

type msgAssigner struct {
ValsetKeeper types.ValsetKeeper
metrixKeeper types.MetrixKeeper
Expand Down Expand Up @@ -73,7 +76,12 @@ func (ma msgAssigner) PickValidatorForMessage(ctx context.Context, weights *type
return "", errors.New("no assignable validators for message")
}

winner := assignableValidators[0].address
ts := sdk.UnwrapSDKContext(ctx).BlockTime().Unix()

// Use block timestamp to pick a random validator from the top validators
winnerIdx := ts % int64(min(len(assignableValidators), topValidatorPoolSize))

winner := assignableValidators[winnerIdx].address
ma.scores = removeWinnerFromSnapshot(ma.scores, winner)
return winner, nil
}
Expand Down
Loading

0 comments on commit e651d89

Please sign in to comment.