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/sync dev after v1 52 2 #250

Merged
merged 1 commit into from
Oct 3, 2024
Merged

Conversation

PavelInjective
Copy link
Contributor

@PavelInjective PavelInjective commented Oct 3, 2024

Summary by CodeRabbit

  • Bug Fixes

    • Improved error handling during transaction broadcasting to ensure failures are captured and reported accurately.
  • New Features

    • Enhanced robustness of the transaction broadcasting process by incorporating additional checks for transaction response codes.

@PavelInjective PavelInjective requested a review from aarmoa October 3, 2024 16:08
Copy link

coderabbitai bot commented Oct 3, 2024

Walkthrough

The changes in this pull request focus on enhancing error handling in the SyncBroadcastSignedTx and broadcastTx methods of the chainClient struct located in client/chain/chain.go. The modifications ensure that errors are returned not only when an error occurs during execution but also when the transaction response code indicates a failure, thereby improving the robustness of the transaction broadcasting process.

Changes

File Change Summary
client/chain/chain.go Updated SyncBroadcastSignedTx to check if res.TxResponse.Code is not zero when returning an error.
client/chain/chain.go Modified broadcastTx to include res.TxResponse.Code check in the error handling condition.

Possibly related PRs

  • fix/check_tx_result_in_sync_broadcast_before_await #249: The changes in this PR directly modify the same methods (SyncBroadcastSignedTx and broadcastTx) in client/chain/chain.go, focusing on enhancing error handling logic during transaction broadcasting, which aligns closely with the changes made in the main PR.

Poem

In the chain where transactions flow,
Errors now catch what we need to know.
With checks in place, we’ll never miss,
A failed broadcast, a critical bliss.
Hops of joy for code so bright,
A robust chain, our future's light! 🐇✨


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 94c4b2c and d2c8a23.

📒 Files selected for processing (1)
  • client/chain/chain.go (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • client/chain/chain.go

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.

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
Collaborator

@aarmoa aarmoa left a comment

Choose a reason for hiding this comment

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

Sync looks good

Copy link

@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

🧹 Outside diff range and nitpick comments (3)
client/chain/chain.go (3)

Line range hint 836-852: Improved error handling in SyncBroadcastSignedTx method

The changes in this method enhance the error handling by checking both for errors and non-zero response codes. This is a good improvement as it ensures that transactions that fail during execution (but not during broadcast) are also caught and reported as errors.

However, there's a potential issue to consider:

The error returned on line 839 might not accurately reflect the nature of the failure when res.TxResponse.Code != 0. Consider creating a custom error that includes both the response code and any error message from the response.

Example implementation:

if err != nil || res.TxResponse.Code != 0 {
    if res.TxResponse.Code != 0 {
        return res, fmt.Errorf("transaction failed with code %d: %s", res.TxResponse.Code, res.TxResponse.RawLog)
    }
    return res, err
}

This change would provide more detailed error information to the caller.


Line range hint 907-923: Enhanced error handling in broadcastTx method

Similar to the SyncBroadcastSignedTx method, the broadcastTx method now checks for both errors and non-zero response codes. This is a consistent improvement across both methods.

However, there's a similar issue to consider:

The error handling on line 910 could be improved to provide more detailed information about the failure when res.TxResponse.Code != 0.

Suggested improvement:

if err != nil || res.TxResponse.Code != 0 {
    if res.TxResponse.Code != 0 {
        return res, fmt.Errorf("transaction failed with code %d: %s", res.TxResponse.Code, res.TxResponse.RawLog)
    }
    return res, err
}

This change would make the error handling consistent with the suggested improvement for SyncBroadcastSignedTx.

Consider extracting the error handling logic into a separate function to avoid code duplication between SyncBroadcastSignedTx and broadcastTx. This would improve maintainability and ensure consistent error handling across both methods.

Example:

func handleBroadcastResponse(res *txtypes.BroadcastTxResponse, err error) error {
    if err != nil || res.TxResponse.Code != 0 {
        if res.TxResponse.Code != 0 {
            return fmt.Errorf("transaction failed with code %d: %s", res.TxResponse.Code, res.TxResponse.RawLog)
        }
        return err
    }
    return nil
}

Then use this function in both methods:

if err := handleBroadcastResponse(res, err); err != nil {
    return res, err
}

Line range hint 1-2500: Overall assessment of changes

The modifications to SyncBroadcastSignedTx and broadcastTx methods improve the error handling by checking both for errors and non-zero response codes. This enhancement ensures that transactions failing during execution are properly caught and reported.

However, there are opportunities for further improvement:

  1. More detailed error reporting when transactions fail with non-zero response codes.
  2. Potential code duplication in error handling between the two methods.

Consider implementing the suggested improvements to provide more informative error messages and reduce code duplication. These changes would enhance the overall robustness and maintainability of the codebase.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between bb9ef54 and 94c4b2c.

📒 Files selected for processing (1)
  • client/chain/chain.go (2 hunks)

…the TX in the mainpool if it has been rejected by the node during broadcast
@PavelInjective PavelInjective force-pushed the fix/sync_dev_after_v1_52_2 branch from 94c4b2c to d2c8a23 Compare October 3, 2024 16:17
@PavelInjective PavelInjective merged commit 5ac7140 into dev Oct 3, 2024
4 checks passed
@PavelInjective PavelInjective deleted the fix/sync_dev_after_v1_52_2 branch October 3, 2024 16:22
@coderabbitai coderabbitai bot mentioned this pull request Oct 9, 2024
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