Skip to content

Commit

Permalink
chore: harsher punishment for failing to relay
Browse files Browse the repository at this point in the history
  • Loading branch information
maharifu committed Sep 24, 2024
1 parent e651d89 commit 2bd1176
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
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)))
})
})
})
13 changes: 11 additions & 2 deletions x/metrix/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ const (
// cSuccessRateDecrement specifies the decrement applied to the
// message relay success rate for every failed attempt.
cSuccessRateDecrement = 0.02

// cDefaultSuccessRateScore specifies the initial score value.
cDefaultSuccessRateScore = 0.5
)

var _ valsettypes.OnSnapshotBuiltListener = &Keeper{}
Expand Down Expand Up @@ -305,15 +308,21 @@ func (k *Keeper) UpdateRelayMetrics(ctx context.Context) {
return true
}

successRateScore := 0.5
successRateScore := cDefaultSuccessRateScore
executionTimes := make([]uint64, len(history.Records))

for i, v := range history.Records {
executionTimes[i] = v.ExecutionSpeedInBlocks
if v.Success {
successRateScore += cSuccessRateIncrement
} else {
successRateScore -= cSuccessRateDecrement
// If a validator fails to relay, we bring their score back to
// the default value
if successRateScore > cDefaultSuccessRateScore {
successRateScore = cDefaultSuccessRateScore
} else {
successRateScore -= cSuccessRateDecrement
}
}
}

Expand Down

0 comments on commit 2bd1176

Please sign in to comment.