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

BE-661 | Fix: claimbot panics #597

Merged
merged 1 commit into from
Dec 6, 2024
Merged

BE-661 | Fix: claimbot panics #597

merged 1 commit into from
Dec 6, 2024

Conversation

deividaspetraitis
Copy link
Collaborator

@deividaspetraitis deividaspetraitis commented Dec 6, 2024

Fixes claimbot panics due nil routerrepo.RouterRepository in txGasCalulator

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Resolved a critical panic issue related to uninitialized router repository, enhancing application stability.
  • New Features

    • Improved the orderbookclaimbot functionality by integrating a gas calculator during initialization.
    • Enhanced transaction handling in the claimbot by incorporating transaction simulation capabilities.
  • Documentation

    • Updated the changelog to reflect recent changes and fixes.

Fixed claimbot panics due nil routerrepo.RouterRepository in txGasCalulator
@deividaspetraitis deividaspetraitis self-assigned this Dec 6, 2024
@deividaspetraitis deividaspetraitis added the A:backport/v28.x Backport to v28.x branch label Dec 6, 2024
Copy link

sonarqubecloud bot commented Dec 6, 2024

Copy link
Contributor

coderabbitai bot commented Dec 6, 2024

Walkthrough

The changes include updates to the CHANGELOG.md to document a fix for a panic issue in the txGasCalculator, along with modifications to several functions in the claimbot package. The NewSideCarQueryServer function now accepts a gasCalculator parameter, while the NewConfig function has been updated to include a msgSimulator parameter. Additionally, the New function in the plugin.go file has been altered to integrate the msgSimulator into the order processing logic, enhancing the functionality of the claimbot.

Changes

File Path Change Summary
CHANGELOG.md Added entry for a fix addressing a panic issue in txGasCalculator due to a nil reference.
app/sidecar_query_server.go Updated NewSideCarQueryServer to include gasCalculator as a parameter for orderbookclaimbot.
ingest/usecase/plugins/orderbook/claimbot/config.go Modified NewConfig to accept msgSimulator parameter, altering instantiation logic.
ingest/usecase/plugins/orderbook/claimbot/plugin.go Updated New function to include msgSimulator, affecting transaction processing in processOrderbookOrders.

Possibly related PRs

  • refactor: gas estimation APIs #546: The changes in this PR involve updates to the CHANGELOG.md that include a reference to gas estimation APIs, which relates to the gasCalculator mentioned in the main PR's changelog update.

Suggested labels

A:backport/v28.x

Poem

🐇 In the land of code where bunnies hop,
A fix for panic made our worries stop.
With gasCalculator and msgSimulator in tow,
The claimbot now dances, putting on a show!
So let’s celebrate this code delight,
Hopping through changes, everything feels right! 🌟


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

🧹 Outside diff range and nitpick comments (3)
ingest/usecase/plugins/orderbook/claimbot/config.go (1)

34-34: LGTM! Consider adding documentation.

The change to inject msgSimulator through the constructor is a good practice as it makes dependencies explicit and helps prevent nil references. Consider adding documentation to describe the expected behavior of the msgSimulator parameter.

Add a comment above the msgSimulator parameter:

 func NewConfig(
 	keyring keyring.Keyring,
 	orderbookusecase mvc.OrderBookUsecase,
 	poolsUseCase mvc.PoolsUsecase,
+	// msgSimulator is used to simulate messages before sending them to ensure they will succeed
 	msgSimulator sqstx.MsgSimulator,
 	logger log.Logger,
 	chainGRPCGatewayEndpoint string,
 	chainID string,
 )

Also applies to: 49-49

CHANGELOG.md (1)

40-40: LGTM! Consider following the changelog format consistently.

The entry accurately describes the fix. Consider following the established format with a bullet point and issue reference.

-Fixed claimbot panics due nil routerrepo.RouterRepository in txGasCalulator
+- Fixed claimbot panics due to nil routerrepo.RouterRepository in txGasCalculator
app/sidecar_query_server.go (1)

Line range hint 319-324: Good architectural design: Consistent gas calculation across components

The changes demonstrate good architectural design by reusing the same gasCalculator instance across both the quoteSimulator and claimbot. This ensures consistent gas calculations throughout the system and reduces the likelihood of discrepancies in gas estimations between different components.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 56663e8 and 7903b0f.

📒 Files selected for processing (4)
  • CHANGELOG.md (1 hunks)
  • app/sidecar_query_server.go (1 hunks)
  • ingest/usecase/plugins/orderbook/claimbot/config.go (2 hunks)
  • ingest/usecase/plugins/orderbook/claimbot/plugin.go (2 hunks)
🔇 Additional comments (3)
ingest/usecase/plugins/orderbook/claimbot/plugin.go (1)

51-51: LGTM! The changes properly address the nil reference issue.

The addition of the msgSimulator parameter and its proper initialization through the constructor chain helps prevent the nil reference panic in txGasCalculator. The error handling and logging are well implemented.

Also applies to: 56-56

app/sidecar_query_server.go (2)

Line range hint 324-327: LGTM: Proper error handling for plugin initialization

The code properly checks and handles errors from the claimbot initialization. If the initialization fails, the error is immediately returned, preventing the system from continuing with an improperly initialized plugin.


Line range hint 320-324: LGTM: Proper initialization of claimbot with gasCalculator

The changes correctly address the nil reference issue by properly initializing the claimbot with a non-nil gasCalculator. The gasCalculator is initialized earlier in the code using tx.NewMsgSimulator with all required dependencies, ensuring it's properly configured before being passed to the claimbot.

Let's verify the initialization of gasCalculator and its dependencies:

✅ Verification successful

Let me gather more information about the orderbookclaimbot.New function to ensure it properly handles the gasCalculator parameter.


Let me try a different approach to verify the claimbot implementation.


Let me try one final verification approach focusing on the plugin package structure.


Let me check the implementation of the claimbot plugin specifically.


LGTM: Proper initialization and usage of gasCalculator in claimbot

The code shows that:

  1. The gasCalculator (MsgSimulator) is properly passed through the constructor and stored in the config
  2. It's correctly used in sendBatchClaimTx for transaction simulation and building
  3. The implementation includes proper error handling and sequence number management
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the proper initialization and usage of gasCalculator

# Check if gasCalculator is used consistently across the codebase
rg -A 3 "gasCalculator.*:=.*NewMsgSimulator"

# Verify the claimbot's usage of gasCalculator
ast-grep --pattern 'orderbookclaimbot.New($$$, gasCalculator, $$$)'

Length of output: 1230


Script:

#!/bin/bash
# Check the implementation of orderbookclaimbot.New to verify gasCalculator usage
ast-grep --pattern 'func New($$$, gasCalculator tx.MsgSimulator, $$$) (*OrderbookClaimBot, error) {
  $$$
}'

# Check for any potential nil checks on gasCalculator
rg -A 3 "if.*gasCalculator.*nil"

Length of output: 145


Script:

#!/bin/bash
# Find the orderbookclaimbot package and check its implementation
fd "orderbookclaimbot" --type f

# Check for any usage of gasCalculator in the codebase
rg -A 3 "gasCalculator.*tx\.MsgSimulator"

# Look for the OrderbookClaimBot struct definition
ast-grep --pattern 'type OrderbookClaimBot struct {
  $$$
}'

Length of output: 138


Script:

#!/bin/bash
# Search for plugin-related files
fd "plugin" --type f

# Look for any references to gasCalculator in plugin-related files
rg -A 3 "gasCalculator" --type go

# Check for the orderbookclaimbot package in a potential plugins directory
fd -e go . | rg -i "claim.*bot"

Length of output: 1865


Script:

#!/bin/bash
# Check the claimbot plugin implementation
cat ingest/usecase/plugins/orderbook/claimbot/plugin.go

# Look for gasCalculator usage in tx.go
cat ingest/usecase/plugins/orderbook/claimbot/tx.go

Length of output: 10116

@deividaspetraitis deividaspetraitis merged commit 8cb0091 into v27.x Dec 6, 2024
10 of 11 checks passed
@deividaspetraitis deividaspetraitis deleted the BE-661 branch December 6, 2024 12:23
mergify bot pushed a commit that referenced this pull request Dec 6, 2024
Fixes claimbot panics due nil routerrepo.RouterRepository in txGasCalulator

(cherry picked from commit 8cb0091)
deividaspetraitis added a commit that referenced this pull request Dec 6, 2024
Fixes claimbot panics due nil routerrepo.RouterRepository in txGasCalulator

(cherry picked from commit 8cb0091)

Co-authored-by: Deividas Petraitis <hi@deividaspetraitis.lt>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:backport/v28.x Backport to v28.x branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant