Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve relayer picking #1301

Merged
merged 2 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion tests/integration/metrix/keeper/keeper_intergration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -592,9 +592,12 @@ var _ = Describe("update relay metrics", func() {
Expect(metrics[1].ExecutionTime).To(Equal(math.NewInt(349)))
Expect(metrics[2].ExecutionTime).To(Equal(math.NewInt(399)))

// First validator always succeeds
Expect(metrics[0].SuccessRate).To(Equal(palomath.LegacyDecFromFloat64(1)))
// Second validator always fails
Expect(metrics[1].SuccessRate).To(Equal(palomath.LegacyDecFromFloat64(0)))
Expect(metrics[2].SuccessRate).To(Equal(palomath.LegacyDecFromFloat64(.9)))
// Third validator fails the last message (j = 100)
Expect(metrics[2].SuccessRate).To(Equal(palomath.LegacyDecFromFloat64(.5)))
})
})
})
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
Loading