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

fix(oracle): correctly handle misscount #2192

Merged
merged 2 commits into from
Feb 4, 2025

Conversation

expertdicer
Copy link
Contributor

Purpose / Abstract

This pull request includes several changes to the way oracle counting validators who is voting outside the spread.

Currently, during tallying, if a vote is considered a miss, the missCount counter increments for each vote. However, it should only increment once per iteration over all votes.

Solution:
Introduce missedValidators as a map[string]bool to track whether a validator has already been counted as a miss.

Also added a test TestTallyMissCount to confirm the solution works.

@expertdicer expertdicer requested a review from a team as a code owner February 3, 2025 14:39
Copy link
Contributor

coderabbitai bot commented Feb 3, 2025

📝 Walkthrough

Walkthrough

The changes introduce a new mechanism in the Tally function to track missed votes for each validator using a missedValidators map. This ensures that each validator's missed vote is counted only once. Additionally, a new test function, TestTallyMissCount, has been added to verify the accuracy of this tracking mechanism. A corresponding entry has also been made in the changelog to document this fix related to oracle functionality.

Changes

File Change Summary
x/oracle/keeper/ballot.go Introduced a missedValidators map in the Tally function to ensure missed votes are counted only once per validator.
x/oracle/keeper/ballot_test.go Added the TestTallyMissCount function to test that missed votes are accurately tracked and counted once for each validator.
CHANGELOG.md Added entry for pull request #2192 documenting the fix for handling missed counts in the oracle functionality.

Sequence Diagram(s)

sequenceDiagram
    participant V as Validator
    participant T as Tally Function
    participant M as MissedValidators Map

    V->>T: Submit vote
    T->>M: Check if validator exists
    alt Validator not recorded
        M-->>T: Not found
        T->>T: Increment miss count
        T->>M: Record validator as missed
    else Validator already recorded
        M-->>T: Found
        T->>T: Do not increment miss count
    end
Loading

Poem

I'm a hop-happy rabbit with lines so neat,
Watching missed votes get tracked on their feet.
Each miss is unique, not counted twice,
Code's now more precise—oh, isn't it nice!
With tests and maps, we dance in delight,
A joyful hop under the coding light! 🐰✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b51e8d3 and c6ee9d7.

📒 Files selected for processing (1)
  • CHANGELOG.md (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: unit-tests
  • GitHub Check: integration-tests
  • GitHub Check: e2e-evm
  • GitHub Check: lint
  • GitHub Check: build
🔇 Additional comments (1)
CHANGELOG.md (1)

97-98: Changelog Entry for PR #2192 is Correct and Well-Formatted

The new entry for "#2192 - fix(oracle): correctly handle misscount" adheres to the changelog guidelines. It is concise, follows the proper format, and is placed under the "Unreleased" section. Ensure that any additional context regarding the fix is documented in the detailed release notes if needed.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
x/oracle/keeper/ballot.go (1)

162-181: LGTM! Consider using a more efficient map value type.

The implementation correctly fixes the issue by ensuring each validator is only counted once for missed votes.

Since we only use the map value as a boolean flag, we can use an empty struct to save memory:

-missedValidators := make(map[string]bool)
+missedValidators := make(map[string]struct{})

-missedValidators[v.Voter.String()] = true
+missedValidators[v.Voter.String()] = struct{}{}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 019ef64 and b51e8d3.

📒 Files selected for processing (2)
  • x/oracle/keeper/ballot.go (2 hunks)
  • x/oracle/keeper/ballot_test.go (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: integration-tests
  • GitHub Check: e2e-evm
🔇 Additional comments (1)
x/oracle/keeper/ballot_test.go (1)

205-240: LGTM! Well-structured test case.

The test effectively verifies that a validator's miss count is incremented only once, even when they have multiple votes outside the spread.

Copy link

codecov bot commented Feb 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 65.01%. Comparing base (019ef64) to head (c6ee9d7).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2192   +/-   ##
=======================================
  Coverage   65.01%   65.01%           
=======================================
  Files         277      277           
  Lines       22341    22346    +5     
=======================================
+ Hits        14524    14529    +5     
  Misses       6828     6828           
  Partials      989      989           
Files with missing lines Coverage Δ
x/oracle/keeper/ballot.go 90.47% <100.00%> (+0.47%) ⬆️

@expertdicer expertdicer merged commit f2a1a16 into main Feb 4, 2025
15 checks passed
@expertdicer expertdicer deleted the expertdicer/tally-misscount branch February 4, 2025 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants