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

refactor: handle roundid gap when do growID #311

Merged
merged 2 commits into from
Feb 21, 2025

Conversation

leonz789
Copy link
Contributor

@leonz789 leonz789 commented Feb 20, 2025

Description

use 'expected' roundID to update next round when do growID instead of increased on state ID.
Both approach should work fine for the 'GrowRoundID' case, this refactored one get rid of the 'impossible case' that increasing roundID by mistake which will lead 'incorrect' roundID forever.

supersede #295


Closes #XXX

Summary by CodeRabbit

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced the pricing update process with improved error handling and reliable round management.
  • Refactor
    • Revised internal operations for streamlined parameter handling and more robust pricing updates.
  • Tests
    • Expanded test coverage to ensure consistent behavior in price updates and round transitions.
  • Chores
    • Removed specific environment configuration in the release preparation process.
  • New Features
    • Added a new constant for better handling of default values in the pricing system.

Copy link
Contributor

coderabbitai bot commented Feb 20, 2025

Walkthrough

The changes update the GrowRoundID method across several modules. Its signature now accepts an extra parameter (nextRoundID) in the KeeperOracle interface, which is propagated to related method calls. In the feeder management module, the GrowRoundID call and error handling for the AppendPriceTR method have been revised. The keeper module refines the logic for price handling and round ID management, and a new test function for GrowRoundID has been added. Additionally, a new constant, NilDetID, is introduced in the types module.

Changes

File(s) Change Summary
x/oracle/keeper/common/expected_keepers.go
x/oracle/keeper/feedermanagement/feedermanager.go
x/oracle/keeper/prices.go
Updated GrowRoundID signature to include an extra nextRoundID parameter. Modified calls to GrowRoundID and enhanced AppendPriceTR handling and round ID logic.
x/oracle/keeper/prices_test.go Added new test function TestPriceGrowID to verify GrowRoundID behavior; removed obsolete cache and block initialization lines.
x/oracle/types/types.go Introduced constant NilDetID with an empty string value as a placeholder.
Makefile Removed line setting GOPROXY in the release-dry-run target.

Sequence Diagram(s)

sequenceDiagram
    participant F as FeederManager
    participant K as Keeper
    F->>K: AppendPriceTR(ctx, tokenID, priceCommit, finalPrice.DetID)
    alt AppendPriceTR fails
        F->>K: GrowRoundID(ctx, tokenID, roundID)
    else AppendPriceTR succeeds
        Note right of F: Proceed without additional call
    end
Loading

Poem

I'm a rabbit, hopping in the code,
New parameters guide me down a smoother road.
GrowRoundID now takes two—oh, what fun!
Error checks, tests shining like the sun.
With NilDetID as my secret snack,
I celebrate these changes, hop, and never look back!
🥕🐇 Happy coding!


📜 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 33b0706 and 5a36f29.

📒 Files selected for processing (1)
  • Makefile (0 hunks)
💤 Files with no reviewable changes (1)
  • Makefile
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: test-unit-cover
  • GitHub Check: test-unit-e2e
  • GitHub Check: goreleaser
  • GitHub Check: run-lint
  • GitHub Check: docker-build
  • GitHub Check: Analyze (go)
  • GitHub Check: docker-localnet-build

🪧 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/prices.go (1)

241-270: Address naked return and streamline clarity in GrowRoundID.
The linter flags the naked return on line 254 as a readability issue. While named returns are valid in Go, consider removing the naked return to improve clarity, especially in a 30+ line function.

-		return
+		return price, roundID
🧰 Tools
🪛 GitHub Check: Run golangci-lint

[failure] 254-254:
naked return in func GrowRoundID with 31 lines of code (nakedret)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7b27f4b and 0368bba.

📒 Files selected for processing (5)
  • x/oracle/keeper/common/expected_keepers.go (1 hunks)
  • x/oracle/keeper/feedermanagement/feedermanager.go (1 hunks)
  • x/oracle/keeper/prices.go (2 hunks)
  • x/oracle/keeper/prices_test.go (1 hunks)
  • x/oracle/types/types.go (1 hunks)
🧰 Additional context used
🪛 GitHub Check: Run golangci-lint
x/oracle/keeper/prices.go

[failure] 254-254:
naked return in func GrowRoundID with 31 lines of code (nakedret)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: test-unit-e2e
  • GitHub Check: Analyze (go)
  • GitHub Check: goreleaser
🔇 Additional comments (7)
x/oracle/keeper/prices.go (2)

213-216: Consider test coverage for early return with nil DetID.
Currently, the code skips further processing if detID is NilDetID. If this is intentional, ensure there's test coverage confirming that no additional side effects are needed.


218-222: Double-check skipping post-processing for empty price.
Similar to the NilDetID check, this early return could bypass post-processing steps if the Price field is empty. Confirm that this behavior aligns with requirements and is tested.

x/oracle/types/types.go (1)

70-71: Validate the use of an empty string for NilDetID.
Storing a nil/empty identifier as "" is simple, but confirm that it won’t introduce confusion or collisions with legitimate empty strings.

x/oracle/keeper/prices_test.go (1)

92-124: Good coverage for GrowRoundID.
This test thoroughly checks multiple scenarios of the function, including when nextRoundID is less than, equal to, or greater than the stored value.

x/oracle/keeper/common/expected_keepers.go (1)

32-32:

❓ Verification inconclusive

Breaking change: GrowRoundID method signature updated.

The addition of the nextRoundID parameter aligns with the PR objective to handle roundID gaps more effectively. However, this is a breaking change that requires all implementations of the KeeperOracle interface to be updated.

Let's verify all implementations of the interface have been updated:


🏁 Script executed:

#!/bin/bash
# Description: Find all implementations of GrowRoundID to ensure they match the new signature.

# Search for GrowRoundID implementations
ast-grep --pattern 'func $_ GrowRoundID(ctx sdk.Context, tokenID uint64) $$$'

Length of output: 79


I'll generate an additional verification script to check for both the new and any potentially outdated implementations of GrowRoundID. This will clarify whether all implementations have been updated to include the nextRoundID parameter.

Once you run this script, please review the output. If implementations with the old signature are found, they must be updated. Otherwise, if only the updated signature is present, no further changes are needed.


Action Required: Update Implementations of GrowRoundID

The updated signature for GrowRoundID(ctx sdk.Context, tokenID, nextRoundID uint64) (price string, roundID uint64) is a breaking change. Please ensure that all implementations of the KeeperOracle interface include the new nextRoundID parameter. The initial verification using the ast-grep command did not provide output, so use the above script to manually verify that no outdated implementations exist.


🏁 Script executed:

#!/bin/bash
# Description: Verify the GrowRoundID method signature across the codebase.
# This script searches for implementations with the new signature (including nextRoundID)
# and also checks for any implementations missing the parameter.

echo "Searching for GrowRoundID implementations with the new signature (with nextRoundID)..."
rg "func\s+.*GrowRoundID\(ctx sdk.Context, tokenID, nextRoundID uint64" -n .

echo "------------------------------------------"

echo "Searching for any GrowRoundID implementations that might be missing nextRoundID..."
rg "func\s+.*GrowRoundID\(ctx sdk.Context, tokenID(?!,)" -n .

Length of output: 1033


BREAKING CHANGE Verification: GrowRoundID Signature Updated

  • The implementation in x/oracle/keeper/prices.go (line 241) has been updated to the new signature:

    func (k Keeper) GrowRoundID(ctx sdk.Context, tokenID, nextRoundID uint64) (price string, roundID uint64) {
  • Our initial search confirms this updated implementation. However, our attempt to search for outdated signatures using look-around regex failed. To double-check that no implementations are still using the old signature (i.e., missing the nextRoundID parameter), please run the following script:

    #!/bin/bash
    echo "Searching for implementations of GrowRoundID that don't mention nextRoundID parameter..."
    rg "func.*GrowRoundID\\(.*tokenID" -n . | grep -v "nextRoundID"
  • If this search returns no results, it confirms that all implementations of the KeeperOracle interface have been updated as required by this breaking change.

Please verify the output of the above script to ensure that no legacy implementations remain.

x/oracle/keeper/feedermanagement/feedermanager.go (2)

278-278: LGTM: GrowRoundID call updated with roundID parameter.

The call has been correctly updated to match the new interface signature, passing the current round's ID as the expected next round ID.


285-288:

✅ Verification successful

Verify error handling for roundID gap.

The new error handling for AppendPriceTR failure looks good. It attempts to grow the roundID when price appending fails, which aligns with the PR objective to handle roundID gaps. However, we should verify if this is the only place where such gaps can occur.

Let's search for other AppendPriceTR calls that might need similar error handling:


🏁 Script executed:

#!/bin/bash
# Description: Find all AppendPriceTR calls to ensure consistent error handling.

# Search for AppendPriceTR calls
ast-grep --pattern 'AppendPriceTR($$$)'

Length of output: 41


Action Required: Double-Check AppendPriceTR Calls for Consistent Error Handling

The current implementation correctly handles an AppendPriceTR failure by attempting to grow the roundID when a gap is detected, which aligns with the PR’s objectives. However, to be certain that this is the only location requiring such error handling, please perform a comprehensive repository-wide search for "AppendPriceTR" (for example, using the above rg command) to ensure there are no additional calls that might be missing similar safeguards.


🏁 Script executed:

#!/bin/bash
# Using rg to search for any occurrences of "AppendPriceTR" in the entire repository
rg "AppendPriceTR" .

Length of output: 541


Action Required: Confirm if any additional AppendPriceTR calls need similar error handling.

The initial search confirmed three locations referencing AppendPriceTR. The error handling we reviewed in feedermanager.go appears to cover the case where the function returns false due to a roundID gap. Meanwhile, the call in prices.go simply delegates to AppendPriceTR without additional error handling, likely because it is part of the internal implementation.

Please verify the output of the GrowRoundID search to confirm no other call sites require similar error handling. Once verified, the current approach in feedermanager.go is considered appropriate within its context.


🏁 Script executed:

#!/bin/bash
# Using rg to search for any occurrences of "GrowRoundID" to understand the usage context in the repository.
rg "GrowRoundID" .

Length of output: 978


AppendPriceTR Error Handling Verification Approved

After verifying across the repository, we confirmed that the only instance where error handling is applied to an AppendPriceTR call is in x/oracle/keeper/feedermanagement/feedermanager.go. The other instances in prices.go and the interface in expected_keepers.go appear to be part of the internal implementation and do not require additional error handling. The current approach—invoking GrowRoundID upon AppendPriceTR failure—is appropriate and consistent with the intended behavior for handling roundID gaps.

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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0368bba and 33b0706.

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

213-222: LGTM! Efficient optimization of post-processing logic.

The early returns for NilDetID and empty price cases improve efficiency by avoiding unnecessary post-processing while maintaining the core functionality.


241-244: LGTM! Improved roundID handling logic.

The changes effectively prevent incorrect roundID persistence by:

  • Using expected nextRoundID instead of incrementing state ID
  • Handling cases where stored nextRoundID differs from expected

Also applies to: 249-260

@cloud8little cloud8little added this to the Testnet V8 milestone Feb 20, 2025
Copy link
Contributor

@bwhour bwhour left a comment

Choose a reason for hiding this comment

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

LGTM.

@leonz789 leonz789 added this pull request to the merge queue Feb 21, 2025
Merged via the queue into imua-xyz:develop with commit 8ed5a43 Feb 21, 2025
22 checks passed
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.

4 participants