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: make submitAndWait fail faster with tem errors #2948

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Conversation

mvadari
Copy link
Collaborator

@mvadari mvadari commented Mar 26, 2025

High Level Overview of Change

Title says it all. tem errors will never be validated on the XRPL, so no need to wait to see if they will. This will save a lot of waiting time on any tem errors.

Context of Change

Takes inspiration from XRPLF/xrpl-py#379 and XRPLF/xrpl-py#590 (which was for some reason not implemented in JS at the time)

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

Did you update HISTORY.md?

  • Yes

Test Plan

Added a test. CI passes.

@mvadari mvadari requested review from Copilot and khancode March 26, 2025 20:35
Copy link

coderabbitai bot commented Mar 26, 2025

Walkthrough

The PR updates several key components in the XRPL package. In the HISTORY file, an entry now documents that the submitAndWait function fails faster on tem errors. The Client class in the main source now includes a new simulate method and improved error handling in submitAndWait. Additionally, a dedicated test suite and fixture updates (including a new JSON response file) have been added to simulate and verify the behavior of tem errors during transaction submissions.

Changes

Files Change Summary
packages/xrpl/HISTORY.md Added an entry noting that submitAndWait will now fail faster on tem errors.
packages/xrpl/src/client/index.ts Introduced a new simulate method and enhanced submitAndWait with improved error handling (throws XrplError on tem errors); also updated method documentation.
packages/xrpl/test/client/submitAndWait.test.ts Added a new test suite for submitAndWait to verify early exit behavior on transactions resulting in tem errors.
packages/xrpl/test/fixtures/rippled/index.ts, packages/xrpl/test/fixtures/rippled/submitTemError.json Added a new temError property to the fixture and introduced submitTemError.json to simulate a transaction submission with a tem error.

Possibly related PRs

  • feat: add support for the simulate RPC (XLS-69d) #2867: The changes in the main PR enhance the error handling of the submitAndWait function, while the retrieved PR introduces a new simulate method in the Client class, which also modifies the submitAndWait method's error handling; thus, they are related at the code level.

Suggested reviewers

  • khancode
  • achowdhry-ripple

Poem

I'm a little rabbit, hopping through code,
Finding bugs and errors wherever they showed.
Now submitAndWait is quick to paw,
With simulate in play, we marvel in awe.
Happy hops and ASCII cheers, note this fun mode!
🐰💻


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 072326b and c59b4d7.

📒 Files selected for processing (1)
  • packages/xrpl/test/client/submitAndWait.test.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/xrpl/test/client/submitAndWait.test.ts
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: snippets (22.x)
  • GitHub Check: snippets (18.x)
  • GitHub Check: snippets (20.x)
  • GitHub Check: browser (18.x)

🪧 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.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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.

@mvadari mvadari requested a review from ckeshava March 26, 2025 20:35
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR ensures that transactions resulting in tem errors fail fast in submitAndWait, reducing unnecessary wait times.

  • Introduces an early error check in submitAndWait for tem errors.
  • Adds a new test case using a tem error fixture to verify the fast failure behavior.
  • Updates HISTORY.md to document the change.

Reviewed Changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated no comments.

File Description
packages/xrpl/test/fixtures/rippled/index.ts Added tem error fixture to support the tem error test.
packages/xrpl/test/client/submitAndWait.test.ts Added test case to assert that submitAndWait fails fast with tem errors.
packages/xrpl/src/client/index.ts Introduced simulate() method and updated submitAndWait to throw on tem errors.
packages/xrpl/HISTORY.md Updated changelog with a note on failing faster for tem errors.
Files not reviewed (1)
  • packages/xrpl/test/fixtures/rippled/submitTemError.json: Language not supported
Comments suppressed due to low confidence (2)

packages/xrpl/src/client/index.ts:847

  • [nitpick] The function is named submitAndWait, so the comment might be clearer if it referenced submitAndWait rather than submit.
* This is similar to submit, which does all of the above, but also waits to see if the transaction has been validated.

packages/xrpl/src/client/index.ts:740

  • The new simulate() method does not have any test coverage. Consider adding tests to ensure its behavior is correct.
public async simulate<Binary extends boolean = false>(

@@ -720,6 +720,41 @@ class Client extends EventEmitter<EventTypes> {
return Promise.all(promises).then(() => tx)
}

/**
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is just moved, no code change

@@ -0,0 +1,44 @@
import { XrplError } from '../../src'
Copy link
Collaborator

Choose a reason for hiding this comment

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

This file (packages/xrpl/test/integration/submitAndWait.test.ts) is also relevant for adding this test case. Why did you create a new file?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's easier to test this sort of thing with a unit test where I can control the fixture as opposed to with an integration test.

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