feat: re-enable jailing on oracle module#279
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughAdds telemetry and validator penalty metrics to the oracle module and changes EndBlocker vote processing to build an exclusion list of denoms (including below-threshold denoms and voteTargets with no votes), remove non-voted voteTargets from active sets, and emit per-denom excluded gauges. Introduces an unexported helper Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (5)
x/oracle/abci_test.go (3)
323-325: Redundant error check.The
require.NoError(t, err)on line 324 checks anerrvariable that was already checked on line 317. This is harmless but adds noise.🧹 Suggested cleanup
// Validator should now be jailed - require.NoError(t, err) require.True(t, validator.IsJailed())🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@x/oracle/abci_test.go` around lines 323 - 325, The test contains a redundant require.NoError(t, err) immediately before asserting validator.IsJailed(); remove the duplicate error check (the earlier require.NoError already validated err) so the test only asserts require.True(t, validator.IsJailed()) and avoids the noisy duplicate require.NoError call referencing err.
422-451: Test may not fully verify the expected behavior.The test checks that
MissCountandAbstainCountremain 0, but doesn't explicitly verify thatSuccessCountincreased. When no votes are submitted andvoteTargetsbecomes empty, validators should receive a success (sinceWinCount >= len(voteTargets)where both are 0).Consider adding an explicit assertion for
SuccessCount:✅ Suggested enhancement
// Check if all three are not getting miss counts for i := 0; i < 3; i++ { counter, err := oracleKeeper.VotePenaltyCounter.Get(ctx, keeper.ValAddrs[i]) require.NoError(t, err) + require.EqualValues(t, uint64(1), counter.SuccessCount) require.EqualValues(t, uint64(0), counter.AbstainCount) require.EqualValues(t, uint64(0), counter.MissCount) }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@x/oracle/abci_test.go` around lines 422 - 451, The test "No votes submitted..." currently asserts MissCount and AbstainCount remain 0 but omits verifying SuccessCount; update the test after calling EndBlocker(ctx, oracleKeeper) to fetch each validator's VotePenaltyCounter via oracleKeeper.VotePenaltyCounter.Get(ctx, keeper.ValAddrs[i]) and add an assertion that counter.SuccessCount has incremented as expected (e.g., equals uint64(1) or the expected value given WinCount and voteTargets being empty). Ensure you reference the same loop and variables (ctx, oracleKeeper, keeper.ValAddrs) and place the SuccessCount assertion alongside the existing AbstainCount and MissCount checks.
571-577: Comment is slightly misleading.The comment states "validator 0 gets WinCount=4", but with the discardable map change in
abci.go, theWinCountinvalidatorClaimMaponly includes above-threshold wins. Validator 0's actualWinCountwould be 3 (from atom, eth, kii), which still satisfiesWinCount >= len(voteTargets)(3 >= 3).📝 Suggested comment fix
- // Validator 0 voted for all 4 denoms. Usdc went to belowThresholdVoteMap - // and still runs through Tally, so validator 0 gets WinCount=4 and - // should also get a success + // Validator 0 voted for all 4 denoms. Usdc went to belowThresholdVoteMap + // and uses a discardable claim map, so validator 0 gets WinCount=3 from + // above-threshold denoms, which matches len(voteTargets)=3, so they get success🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@x/oracle/abci_test.go` around lines 571 - 577, The test comment is inaccurate: due to the discardable map change in abci.go the validatorClaimMap.WinCount only counts above-threshold wins, so validator 0's WinCount is 3 (atom, eth, kii) not 4; update the comment above the VotePenaltyCounter assertion to state that WinCount=3 (and that 3 >= len(voteTargets) so the validator still succeeds), and keep the existing assertions using oracleKeeper.VotePenaltyCounter.Get(ctx, keeper.ValAddrs[0]) unchanged.x/oracle/abci.go (2)
238-238: Comment is misleading.The comment "Add jail back in repeated offence" suggests jail is being added at this location, but the actual jail implementation is in
slash.gowithinSlashAndResetCounters. Consider clarifying that jailing happens insideSlashAndResetCountersor removing this comment.📝 Suggested fix
- // Add jail back in repeated offence + // Slash and jail validators who failed to meet the minimum valid vote threshold err = k.SlashAndResetCounters(ctx) // slash validator and reset voting counter🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@x/oracle/abci.go` at line 238, The comment "Add jail back in repeated offence" in abci.go is misleading because the actual jailing logic lives in SlashAndResetCounters (slash.go); update the comment at that location to either remove the misleading line or replace it with a clear note such as "Jailing handled in SlashAndResetCounters (see slash.go)" and include the function name SlashAndResetCounters to guide readers to the implementation.
159-159: Consider if>=is intentional given the discardable map change.With the discardable map for below-threshold tallies (lines 141-147),
validatorClaimMapshould only accumulateWinCountfrom above-threshold denoms. This meansWinCountshould at most equallen(voteTargets)for validators who voted correctly on all above-threshold denoms.The
>=operator makes this check more permissive, which is safer but may mask unexpected behavior. IfWinCountever exceedslen(voteTargets), it could indicate a logic error elsewhere. Consider whether==would be more appropriate to catch such cases, or add a debug log whenWinCount > len(voteTargets).🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@x/oracle/abci.go` at line 159, The condition if int(claim.WinCount) >= len(voteTargets) on validatorClaimMap should not silently allow WinCount to exceed the number of voteTargets; change the comparison to == to ensure a validator is counted only when their WinCount exactly matches the number of voteTargets, and add a debug log (or warn/error) that emits the validator ID and the unexpected values when claim.WinCount > len(voteTargets) to catch logic errors elsewhere; update the check around validatorClaimMap/WinCount (the if using int(claim.WinCount) >= len(voteTargets)) and add the logging branch for the > case.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@CHANGELOG.md`:
- Line 7: Update the typo in the changelog entry by replacing the phrase "Re
enabled jailing on oracle module" with the hyphenated form "Re-enabled jailing
on oracle module" so it uses standard hyphenation; locate the exact line
containing that phrase in CHANGELOG.md and make the single-word replacement.
---
Nitpick comments:
In `@x/oracle/abci_test.go`:
- Around line 323-325: The test contains a redundant require.NoError(t, err)
immediately before asserting validator.IsJailed(); remove the duplicate error
check (the earlier require.NoError already validated err) so the test only
asserts require.True(t, validator.IsJailed()) and avoids the noisy duplicate
require.NoError call referencing err.
- Around line 422-451: The test "No votes submitted..." currently asserts
MissCount and AbstainCount remain 0 but omits verifying SuccessCount; update the
test after calling EndBlocker(ctx, oracleKeeper) to fetch each validator's
VotePenaltyCounter via oracleKeeper.VotePenaltyCounter.Get(ctx,
keeper.ValAddrs[i]) and add an assertion that counter.SuccessCount has
incremented as expected (e.g., equals uint64(1) or the expected value given
WinCount and voteTargets being empty). Ensure you reference the same loop and
variables (ctx, oracleKeeper, keeper.ValAddrs) and place the SuccessCount
assertion alongside the existing AbstainCount and MissCount checks.
- Around line 571-577: The test comment is inaccurate: due to the discardable
map change in abci.go the validatorClaimMap.WinCount only counts above-threshold
wins, so validator 0's WinCount is 3 (atom, eth, kii) not 4; update the comment
above the VotePenaltyCounter assertion to state that WinCount=3 (and that 3 >=
len(voteTargets) so the validator still succeeds), and keep the existing
assertions using oracleKeeper.VotePenaltyCounter.Get(ctx, keeper.ValAddrs[0])
unchanged.
In `@x/oracle/abci.go`:
- Line 238: The comment "Add jail back in repeated offence" in abci.go is
misleading because the actual jailing logic lives in SlashAndResetCounters
(slash.go); update the comment at that location to either remove the misleading
line or replace it with a clear note such as "Jailing handled in
SlashAndResetCounters (see slash.go)" and include the function name
SlashAndResetCounters to guide readers to the implementation.
- Line 159: The condition if int(claim.WinCount) >= len(voteTargets) on
validatorClaimMap should not silently allow WinCount to exceed the number of
voteTargets; change the comparison to == to ensure a validator is counted only
when their WinCount exactly matches the number of voteTargets, and add a debug
log (or warn/error) that emits the validator ID and the unexpected values when
claim.WinCount > len(voteTargets) to catch logic errors elsewhere; update the
check around validatorClaimMap/WinCount (the if using int(claim.WinCount) >=
len(voteTargets)) and add the logging branch for the > case.
ℹ️ Review info
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
CHANGELOG.mdx/oracle/abci.gox/oracle/abci_test.gox/oracle/keeper/slash.gox/oracle/test_helpers.gox/oracle/types/expected_keepers.go
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@tests/e2e/e2e_oracle_test.go`:
- Around line 137-138: Update the misleading comment and assertion message
around the Abstain check: change the comment that currently reads "Abstain
should be zero since there is no voting" to be clearer (e.g., "Abstain should be
zero since there is no voting activity in this test"), and update the assertion
message on the check of queryPenaltyCounter.VotePenaltyCounter.AbstainCount to
state it should be zero (e.g., "abstain penalty counter should be zero") so the
message matches the condition; ensure you modify the code around the check of
queryPenaltyCounter.VotePenaltyCounter.AbstainCount and any adjacent
success-count comment to avoid conflicting wording.
ℹ️ Review info
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
tests/e2e/e2e_oracle_test.gox/oracle/abci.go
🚧 Files skipped from review as they are similar to previous changes (1)
- x/oracle/abci.go
There was a problem hiding this comment.
🧹 Nitpick comments (1)
x/oracle/abci.go (1)
225-235: Minor:float32precision loss for very large counts.Converting
uint64counters tofloat32loses precision for values above ~16.7 million. While unlikely for vote counts in a slash window, consider usingfloat64for consistency with other telemetry patterns if high precision is desired.♻️ Optional: Use float64 for higher precision
- telemetry.SetGaugeWithLabels([]string{types.ModuleName, "miss_count"}, float32(counter.MissCount), labels) - telemetry.SetGaugeWithLabels([]string{types.ModuleName, "abstain_count"}, float32(counter.AbstainCount), labels) - telemetry.SetGaugeWithLabels([]string{types.ModuleName, "success_count"}, float32(counter.SuccessCount), labels) + telemetry.SetGaugeWithLabels([]string{types.ModuleName, "miss_count"}, float32(float64(counter.MissCount)), labels) + telemetry.SetGaugeWithLabels([]string{types.ModuleName, "abstain_count"}, float32(float64(counter.AbstainCount)), labels) + telemetry.SetGaugeWithLabels([]string{types.ModuleName, "success_count"}, float32(float64(counter.SuccessCount)), labels)Note: The Cosmos SDK telemetry API uses
float32, so this is mostly academic unless counts regularly exceed millions.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@x/oracle/abci.go` around lines 225 - 235, The telemetry gauges in writeValidatorPenaltyMetrics cast uint64 counters to float32 causing precision loss; change the casts so counter.MissCount, counter.AbstainCount and counter.SuccessCount are converted to float64 (e.g. assign to a float64 var) and pass that to the telemetry call (or use the telemetry float64 variant) instead of float32; update the calls around VotePenaltyCounter.Walk and telemetry.SetGaugeWithLabels to accept the float64 values so the counts retain precision.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@x/oracle/abci.go`:
- Around line 225-235: The telemetry gauges in writeValidatorPenaltyMetrics cast
uint64 counters to float32 causing precision loss; change the casts so
counter.MissCount, counter.AbstainCount and counter.SuccessCount are converted
to float64 (e.g. assign to a float64 var) and pass that to the telemetry call
(or use the telemetry float64 variant) instead of float32; update the calls
around VotePenaltyCounter.Walk and telemetry.SetGaugeWithLabels to accept the
float64 values so the counts retain precision.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: a6c25c4e-55f1-4dca-85d3-a8282bb5d8b3
📒 Files selected for processing (2)
x/oracle/abci.gox/oracle/keeper/slash.go
Description
Re-enable jailing on oracle module after fixing the following behaviors
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
With added tests and pipelines
PR Checklist:
Make sure each step was done:
make lint-fix