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

(Reporter) Update nonce error handling #2294

Merged
merged 1 commit into from
Oct 3, 2024

Conversation

nick-bisonai
Copy link
Collaborator

Description

reset nonce from block in case of nonce error

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist before requesting a review

  • I have performed a self-review of my code.
  • If it is a core feature, I have added thorough tests.

Deployment

  • Should publish npm package
  • Should publish Docker image

@nick-bisonai nick-bisonai self-assigned this Oct 3, 2024
@nick-bisonai nick-bisonai requested a review from a team as a code owner October 3, 2024 04:22
Copy link
Contributor

coderabbitai bot commented Oct 3, 2024

Warning

Rate limit exceeded

@nick-bisonai has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 13 minutes and 25 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Files that changed from the base of the PR and between 6481a0b and 9c15751.

📝 Walkthrough
📝 Walkthrough

Walkthrough

The pull request introduces modifications to several files, focusing on enhancing nonce management in transaction submissions and updating a JSON-RPC endpoint. The json-rpc-sync-check.sh script's public endpoint has been changed to a new URL. Additionally, the SubmitDelegatedFallbackDirect method in helper.go has improved error handling for nonce errors, while noncemanager.go adds new methods for resetting nonces, ensuring better management of transaction submissions.

Changes

File Change Summary
inspector/scripts/json-rpc-sync-check.sh Updated constant PUBLIC_KAIA_JSON_RPC URL from https://public-en-cypress.klaytn.net to https://public-en.node.kaia.io.
node/pkg/chain/helper/helper.go Enhanced SubmitDelegatedFallbackDirect method with improved nonce error handling and reset logic.
node/pkg/chain/noncemanager/noncemanager.go Added ResetNonce method for nonce management, including a new exported function and necessary imports.

Possibly related PRs

Suggested labels

enhancement, core

Suggested reviewers

  • Intizar-T
  • martinkersner

Poem

🐇 In the garden of code, we hop and play,
With new paths and nonce, we find our way.
The RPC's changed, a fresh breeze in sight,
With every small tweak, our future looks bright!
So let’s dance in the fields of logic and fun,
For every small change, a victory won! 🌼


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

🧹 Outside diff range and nitpick comments (2)
inspector/scripts/json-rpc-sync-check.sh (1)

PR does not implement nonce error handling changes.

The only modification in this PR is updating the PUBLIC_KAIA_JSON_RPC URL in inspector/scripts/json-rpc-sync-check.sh. This change does not address the PR objective of handling nonce errors.

Please ensure that nonce error handling changes are included in this PR or update the PR description to reflect the actual changes.

🔗 Analysis chain

Line range hint 1-105: Summary: URL change implemented, but clarification needed on PR objectives.

The change in this file is limited to updating the PUBLIC_KAIA_JSON_RPC URL. While this change appears to be correct, it doesn't seem to address the PR objective of updating nonce error handling.

Please provide more context on how this URL change contributes to the stated PR objective of resetting the nonce from the block in the event of a nonce error. Are there other files in this PR that implement the nonce error handling changes?

To ensure no unintended changes were made, you can run the following diff command:

This command should not produce any output if only the PUBLIC_KAIA_JSON_RPC line was changed.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify that only the intended line was changed
git diff HEAD^ HEAD -- inspector/scripts/json-rpc-sync-check.sh | grep -v "PUBLIC_KAIA_JSON_RPC"

Length of output: 613

node/pkg/chain/noncemanager/noncemanager.go (1)

43-53: Add unit tests for the ResetNonce method

To ensure the correctness and reliability of the new ResetNonce method, consider adding unit tests that cover:

  • Successful nonce reset scenarios.
  • Error handling when GetNonceFromPk returns an error.

Would you like assistance in generating unit tests for this method?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 4ee6f2d and 6481a0b.

📒 Files selected for processing (3)
  • inspector/scripts/json-rpc-sync-check.sh (1 hunks)
  • node/pkg/chain/helper/helper.go (2 hunks)
  • node/pkg/chain/noncemanager/noncemanager.go (3 hunks)
🔇 Additional comments (2)
inspector/scripts/json-rpc-sync-check.sh (1)

9-9: Verify the new URL and clarify its relation to PR objectives.

The change of PUBLIC_KAIA_JSON_RPC URL from "https://public-en-cypress.klaytn.net" to "https://public-en.node.kaia.io" looks good. However, please address the following points:

  1. Confirm that the new URL is correct and operational.
  2. Clarify how this URL change relates to the PR objective of updating nonce error handling. The connection between changing the JSON-RPC endpoint and nonce error handling is not immediately apparent.

To verify the new URL, you can run the following command:

This command should return a valid JSON response with a block number if the URL is operational.

✅ Verification successful

URL Verification Successful. Please Clarify Its Relation to PR Objectives.

The new PUBLIC_KAIA_JSON_RPC URL is operational and responding correctly. However, it's unclear how this change relates to the PR objective of updating nonce error handling. Could you please provide more details on the connection between the updated JSON-RPC endpoint and nonce error management?

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify that the new URL is operational
curl -H "Content-Type: application/json" \
     -d '{"jsonrpc":"2.0","method":"klay_blockNumber","params":[],"id":1}' \
     https://public-en.node.kaia.io

Length of output: 585

node/pkg/chain/noncemanager/noncemanager.go (1)

31-34: LGTM

The new ResetNonce function provides a convenient way to reset the nonce for a given address and aligns with the existing API patterns in the NonceManager.

Comment on lines +43 to +53
func (m *NonceManager) ResetNonce(ctx context.Context, address string, client utils.ClientInterface) error {
m.mu.Lock()
defer m.mu.Unlock()
nonce, err := utils.GetNonceFromPk(ctx, address, client)
if err != nil {
return err
}
m.nonces[address] = nonce
return nil
}

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

Avoid holding the lock while performing network I/O

Holding the mutex lock while calling utils.GetNonceFromPk can block other operations on NonceManager longer than necessary, especially if the network call experiences latency. To improve concurrency, consider fetching the nonce before acquiring the lock.

Apply this diff to adjust the locking:

 func (m *NonceManager) ResetNonce(ctx context.Context, address string, client utils.ClientInterface) error {
+    nonce, err := utils.GetNonceFromPk(ctx, address, client)
+    if err != nil {
+        return err
+    }

     m.mu.Lock()
     defer m.mu.Unlock()
-    nonce, err := utils.GetNonceFromPk(ctx, address, client)
-    if err != nil {
-        return err
-    }
     m.nonces[address] = nonce
     return nil
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
func (m *NonceManager) ResetNonce(ctx context.Context, address string, client utils.ClientInterface) error {
m.mu.Lock()
defer m.mu.Unlock()
nonce, err := utils.GetNonceFromPk(ctx, address, client)
if err != nil {
return err
}
m.nonces[address] = nonce
return nil
}
func (m *NonceManager) ResetNonce(ctx context.Context, address string, client utils.ClientInterface) error {
nonce, err := utils.GetNonceFromPk(ctx, address, client)
if err != nil {
return err
}
m.mu.Lock()
defer m.mu.Unlock()
m.nonces[address] = nonce
return nil
}

Comment on lines +278 to +281
err = noncemanager.ResetNonce(ctx, t.wallet, t.clients[clientIndex])
if err != nil {
return err
}
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

Refactor nonce reset logic to eliminate code duplication

The nonce reset and retrieval logic at lines 278-281 and 309-312 is duplicated. Consider extracting this repeated code into a helper method to improve maintainability and reduce redundancy.

Apply this diff to extract the duplicated code:

+func (t *ChainHelper) resetAndIncrementNonce(ctx context.Context, clientIndex int) (uint64, error) {
+    err := noncemanager.ResetNonce(ctx, t.wallet, t.clients[clientIndex])
+    if err != nil {
+        return 0, err
+    }
+    nonce, err := noncemanager.GetAndIncrementNonce(t.wallet)
+    if err != nil {
+        return 0, err
+    }
+    return nonce, nil
+}

Replace the duplicated code at lines 278-281:

 err = noncemanager.ResetNonce(ctx, t.wallet, t.clients[clientIndex])
 if err != nil {
     return err
 }
 nonce, err = noncemanager.GetAndIncrementNonce(t.wallet)
 if err != nil {
     return err
 }

With a call to the new helper method:

+nonce, err = t.resetAndIncrementNonce(ctx, clientIndex)
+if err != nil {
+    return err
+}

Similarly, replace the code at lines 309-312 with:

+nonce, err = t.resetAndIncrementNonce(ctx, clientIndex)
+if err != nil {
+    return err
+}

Also applies to: 309-312

@nick-bisonai nick-bisonai force-pushed the feat/update-nonce-error-handling branch from 6481a0b to 9c15751 Compare October 3, 2024 04:39
@nick-bisonai nick-bisonai merged commit ff77019 into master Oct 3, 2024
4 checks passed
@nick-bisonai nick-bisonai deleted the feat/update-nonce-error-handling branch October 3, 2024 04:45
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.

1 participant