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: iterate delegations continue instead of erroring #8732

Merged
merged 2 commits into from
Sep 27, 2024

Conversation

czarcas7ic
Copy link
Member

@czarcas7ic czarcas7ic commented Sep 26, 2024

Closes: #XXX

What is the purpose of the change

Frontports fix that was in v26.x to main

@czarcas7ic czarcas7ic changed the title fix: continue instead of err fix: iterate delegations continue instead of erroring Sep 26, 2024
@czarcas7ic czarcas7ic added the V:state/breaking State machine breaking PR label Sep 26, 2024
@czarcas7ic czarcas7ic marked this pull request as ready for review September 26, 2024 23:29
Copy link
Contributor

coderabbitai bot commented Sep 26, 2024

Walkthrough

The changes involve updates to the CHANGELOG.md and modifications to the error handling logic in the IterateDelegations function of the Keeper struct within the stake.go file. The changelog now includes a section documenting a fix related to delegation iteration in the state machine. In the code, error handling has been adjusted to log errors instead of terminating the iteration process, allowing for continued processing of delegations despite encountering errors.

Changes

Files Change Summary
CHANGELOG.md Added a section titled "State Machine Breaking" documenting a fix for delegation iteration errors.
x/superfluid/keeper/stake.go Modified error handling in IterateDelegations to log errors and continue iteration instead of halting.

Warning

Review ran into problems

🔥 Problems

Error running LanguageTool: LanguageTool error: Unknown error


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

🧹 Outside diff range and nitpick comments (1)
CHANGELOG.md (1)

Old CL swap APIs are still in use:

  • x/concentrated-liquidity/incentives_test.go
  • x/concentrated-liquidity/swaps_tick_cross_test.go
  • x/concentrated-liquidity/swapstrategy/zero_for_one.go
  • x/concentrated-liquidity/swapstrategy/one_for_zero.go
  • x/concentrated-liquidity/swaps_test.go
  • x/concentrated-liquidity/position_test.go
  • x/concentrated-liquidity/model/pool_test.go
  • x/concentrated-liquidity/model/pool.go
  • x/concentrated-liquidity/math/math.go
  • x/concentrated-liquidity/math/math_test.go
  • tests/e2e/e2e_cl_test.go
  • app/apptesting/concentrated_liquidity.go
  • x/gamm/types/query.pb.gw.go
  • x/gamm/types/query.pb.go
  • x/gamm/keeper/grpc_query.go
  • x/gamm/client/cli/query.go
  • x/gamm/client/cli/cli_test.go
  • cmd/osmosisd/cmd/stargate-query.go
  • /.coderabbit_commands_1727393649383.sh
🔗 Analysis chain

Line range hint 88-95: Bug fixes and API changes noted.

Several bug fixes are mentioned, including improvements to error handling and mathematical operations. There are also API changes, particularly in the concentrated liquidity module. These changes may require updates to dependent code and should be carefully reviewed by developers using these APIs.


Please run the following corrected script to verify the usage of the old CL swap APIs:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for any uses of the old CL swap APIs
rg --type go 'CalcAmount0Delta|GetNextSqrtPriceFromAmount0InRoundingUp'

Length of output: 64899


Script:

#!/bin/bash
# Check for any uses of the old CL swap APIs
rg --type go 'CalcAmount0Delta|GetNextSqrtPriceFromAmount0InRoundingUp'

Length of output: 5807

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between edaa948 and 8896dea.

📒 Files selected for processing (2)
  • CHANGELOG.md (1 hunks)
  • x/superfluid/keeper/stake.go (1 hunks)
🔇 Additional comments (9)
CHANGELOG.md (9)

57-60: Minor improvements and bug fixes noted.

The changes in this section appear to be mostly improvements and bug fixes. The state export fix for cwpool gauges is particularly important as it addresses a potential issue with the system's state management.


Line range hint 64-69: New features and improvements added.

Several new features and improvements have been added, including new helper functions for SDK coins operations and additional queries in the concentrated liquidity module. These additions should enhance the functionality and efficiency of the system.


Line range hint 78-86: Performance improvements and new features added.

This section introduces several performance improvements, particularly in mathematical operations and concentrated liquidity operations. New features like additional queries for concentrated liquidity are also added. These changes should enhance the overall efficiency and functionality of the system.


Line range hint 99-107: Major features and module updates introduced.

This release introduces significant new features and modules, including the ProtoRev module for MEV capture, the Validator Set Preference module, and the Pool Manager module. These additions represent substantial enhancements to the system's functionality and may require careful integration and testing.


Line range hint 118-124: Dependency upgrades and configuration changes.

The release includes upgrades to key dependencies like the Cosmos SDK, IBC, and CometBFT. There are also changes to default configurations, such as consensus parameters. These updates may require adjustments to node configurations and should be carefully reviewed by node operators.


Line range hint 128-133: Critical bug fixes and performance improvements.

This release addresses important mainnet bugs related to accumulation sumtrees and concentrated liquidity handling. It also includes performance improvements for epoch computations. These changes are crucial for the stability and efficiency of the system.


Line range hint 150-5824: Historical changelog entries provide context.

The remaining sections of the changelog document the development history of Osmosis, including various features, bug fixes, and improvements introduced in previous versions. While not directly relevant to the current release, this historical information is valuable for understanding the project's evolution and may be useful for developers working with older versions or tracking long-term changes.


Line range hint 137-146: API breaks and new features introduced.

Several API breaks are mentioned, including changes to query responses and the introduction of new modules. New features like improved trade estimation and support for different chain IDs in E2E testing are also added. These changes may require updates to dependent code and should be carefully reviewed by developers.

#!/bin/bash
# Check for any uses of the old API methods
rg --type go 'EstimateSwapExactAmountIn|EstimateSwapExactAmountOut'

Line range hint 71-74: API breaks introduced.

There are some API breaks mentioned here, particularly in the PoolModuleI CalculateSpotPrice API and some changes in the incentives module. These changes may require updates to dependent code.

Comment on lines +584 to +585
ctx.Logger().Error("intermediary account not found for lock id", "lockID", lock.UnderlyingLockId)
continue
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider the implications of error logging vs. returning

The changes in the IterateDelegations function replace error returns with error logging. While this allows the function to continue processing delegations even when errors occur, it may hide important issues.

  1. Pros:

    • Increases robustness by continuing iteration despite errors.
    • Provides more comprehensive delegation information.
  2. Cons:

    • May mask critical errors that should halt execution.
    • Could lead to inconsistent state if errors are not properly handled downstream.

Consider the following:

  1. Are these errors expected to occur occasionally, or do they represent exceptional conditions?
  2. Could continuing after these errors lead to data inconsistencies?
  3. Is there a need to aggregate or report these errors for monitoring purposes?

You might want to consider a hybrid approach:

  • Log the errors as currently implemented.
  • Keep a count or collect details of the errors encountered.
  • Return an aggregated error or error summary at the end of the function.

This would allow continued processing while still surfacing error information to callers.

func (k Keeper) IterateDelegations(context context.Context, delegator sdk.AccAddress, fn func(int64, stakingtypes.DelegationI) bool) error {
    ctx := sdk.UnwrapSDKContext(context)
    var errCount int
    var errDetails []string

    // ... (existing code)

    for i, lock := range synthlocks {
        // ... (existing code)

        if !ok {
            errCount++
            errDetails = append(errDetails, fmt.Sprintf("intermediary account not found for lock id %d", lock.UnderlyingLockId))
            ctx.Logger().Error("intermediary account not found for lock id", "lockID", lock.UnderlyingLockId)
            continue
        }

        // ... (similar error handling for other error cases)

        // if valid delegation has been found, increment delegation index
        fn(index+int64(i), delegation)
    }

    if errCount > 0 {
        return fmt.Errorf("encountered %d errors during iteration: %s", errCount, strings.Join(errDetails, "; "))
    }
    return nil
}

Also applies to: 591-591, 597-597, 604-604, 611-611, 617-617, 623-623

@PaddyMc PaddyMc merged commit 343f830 into main Sep 27, 2024
1 check passed
@PaddyMc PaddyMc deleted the adam/iterate-delegations-frontport branch September 27, 2024 08:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:x/superfluid V:state/breaking State machine breaking PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants