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: improve error message when persistTransaction times out. Increase default timeout to 130 seconds using Exponential Backoff #1316

Merged
merged 26 commits into from
Oct 2, 2024

Conversation

MantisClone
Copy link
Member

@MantisClone MantisClone commented Jan 5, 2024

Description of the changes

  • Update the default getConfirmation timeout to use exponential backoff by default: starting at 1s, doubling after each retry, up to a maximum of 64s and max 7 retries with an initial 3s defer delay, yielding a total of 8 calls and total timeout of 130s.
  • Update timeout error message to more adequately reassure the App Builder not to call persistTransaction again, and to more fully explain what they can do instead (poll getConfirmedTransaction() and adjust their httpConfig settings so timeouts are less likely).
  • Move getConfirmedTransaction logic to a new public function in the request-client.js package.
  • Adjust retry logic to make exponentialBackoffDelay more intuitive to configure
    • Now, 1000 means retry after 1, 2, 4, 8... seconds.
    • Previously, 1000 meant retry after 2, 4, 8, 16... seconds.

TODO

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Added a "V1 packages" section in the README for clarity on deprecated packages.
    • Introduced a new method, getConfirmedTransaction, for retrieving confirmed transactions.
  • Bug Fixes

    • Enhanced error messages for transaction confirmation failures to guide app builders.
  • Documentation

    • Expanded testing instructions in the README.
    • Improved clarity and structure in the README content.
  • Tests

    • Updated tests for persistTransaction to reflect new error handling.
    • Revised tests for the retry function to align with the new exponential backoff strategy.

  * Update error message to recommend polling getConfirmedTransaction
    instead of getTransactionsByChannelId()
  * Previously, 500 meant retry after 1, 2, 4, 8... seconds.
  * Now, 1000 means retry after 1, 2, 4, 8... seconds.
@MantisClone MantisClone changed the title fix: improve error message when persistTransaction times out. Adust exponential backoff delay to be more intituive fix: improve error message when persistTransaction times out. Adjust exponential backoff delay to be more intituive. Enable exponential backoff by default. Jan 5, 2024
Copy link

coderabbitai bot commented Oct 1, 2024

Warning

Rate limit exceeded

@MantisClone has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 7 minutes and 53 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 9f81a7f and 9a8197c.

Walkthrough

The pull request introduces updates to the README.md file, adding a new section on deprecated V1 packages and expanding testing instructions. It modifies the HttpDataAccess class in http-data-access.ts by adding a new method for retrieving confirmed transactions and updating the persistTransaction method. Additionally, the test case for persistTransaction() in http-data-access.test.ts is revised to improve error handling. Changes to the retry function tests in retry.test.ts enhance the handling of retry parameters and exponential backoff. Minor formatting adjustments are included in the README.md.

Changes

File Change Summary
README.md - Added "V1 packages" section indicating deprecation and linking to archived packages.
- Expanded "Test" section with new instructions for testing a specific package using yarn workspace @requestnetwork/request-client.js test.
- Minor formatting adjustments.
packages/request-client.js/src/http-data-access.ts - Added new method getConfirmedTransaction for retrieving confirmed transactions.
- Updated persistTransaction method to use getConfirmedTransaction and improved error handling.
packages/request-client.js/test/http-data-access.test.ts - Modified test for persistTransaction() to handle error events instead of promise rejections, with updated assertions and guidance for app builders.
packages/utils/test/retry.test.ts - Updated test cases for retry function with new parameters for retry strategy, including maxRetries and maxExponentialBackoffDelay, and revised assertions to align with the new timing logic.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant HttpDataAccess
    participant Node

    User->>HttpDataAccess: Call persistTransaction()
    HttpDataAccess->>Node: Fetch transaction confirmation
    Node-->>HttpDataAccess: Return error event
    HttpDataAccess-->>User: Emit error message with guidance
Loading

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.

@MantisClone MantisClone changed the title fix: improve error message when persistTransaction times out. Adjust exponential backoff delay to be more intituive. Enable exponential backoff by default. fix: improve error message when persistTransaction times out. Increase default timeout to 2 minutes from 30 seconds, Oct 1, 2024
@MantisClone MantisClone changed the title fix: improve error message when persistTransaction times out. Increase default timeout to 2 minutes from 30 seconds, fix: improve error message when persistTransaction times out. Increase default timeout to 2 minutes from 30 seconds, Make exponentialBackoffDelay settings easier to use. Oct 1, 2024
@MantisClone MantisClone changed the title fix: improve error message when persistTransaction times out. Increase default timeout to 2 minutes from 30 seconds, Make exponentialBackoffDelay settings easier to use. fix: improve error message when persistTransaction times out. Increase default timeout to 2 minutes from 30 seconds, Make exponential backoff easier to use. Oct 1, 2024
maxExponentialBackoffDelay: this.httpConfig.getConfirmationMaxExponentialBackoffDelay,
},
);
const confirmedData = await this.getConfirmedTransaction(transactionData);
Copy link
Member Author

Choose a reason for hiding this comment

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

I moved this logic into a new getConfirmedTransaction() function

@MantisClone MantisClone self-assigned this Oct 2, 2024
@MantisClone MantisClone marked this pull request as ready for review October 2, 2024 01:29
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: 7

🧹 Outside diff range comments (2)
packages/request-client.js/test/http-data-access.test.ts (1)

Tests do not verify compatibility with the Invoicing Template timeout dialog

The current tests in packages/request-client.js/test/http-data-access.test.ts do not cover scenarios ensuring that the new error message does not interfere with the Invoicing Template's timeout dialog. Please add appropriate tests to verify this compatibility.

🔗 Analysis chain

Line range hint 1-39: Address TODO: Verify compatibility with Invoicing Template timeout dialog

The PR objectives mention a TODO item to ensure that the new error message doesn't interfere with the timeout dialog in the Invoicing Template. This test file doesn't address that concern directly.

To verify this, we need to check the Invoicing Template code. Let's run a script to find relevant files:

Please review the output of this script to identify the relevant files and code sections that need to be updated to ensure compatibility with the new error message.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find files related to the Invoicing Template and timeout dialog

# Search for files that might contain the Invoicing Template code
echo "Searching for Invoicing Template files:"
fd -e ts -e tsx -e js -e jsx invoice

# Search for files that might contain timeout dialog code
echo "\nSearching for timeout dialog files:"
fd -e ts -e tsx -e js -e jsx timeout

# Search for usage of persistTransaction in these files
echo "\nSearching for persistTransaction usage in relevant files:"
rg "persistTransaction" $(fd -e ts -e tsx -e js -e jsx "invoice|timeout")

Length of output: 24606

README.md (1)

Line range hint 92-95: Excellent addition! Consider emphasizing the deprecation.

The new "V1 packages" section provides valuable information about the versioning of the project. It clearly states that this repository hosts V2 packages and directs users to the archived V1 packages.

To make the deprecation of V1 packages more noticeable, consider using bold text for the deprecation notice:

## V1 packages

This repository hosts the packages for the second version of Request. **The v1 packages are deprecated** and can be found on [requestNetwork-v1-archive](https://github.com/RequestNetwork/requestNetwork-v1-archive).
🧰 Tools
🪛 LanguageTool

[style] ~85-~85: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...e monorepo. bash yarn run test Test a specific package. ```bash yarn works...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between 78a353d and 3b7801c.

📒 Files selected for processing (5)
  • README.md (1 hunks)
  • packages/request-client.js/src/http-data-access.ts (2 hunks)
  • packages/request-client.js/test/http-data-access.test.ts (1 hunks)
  • packages/utils/src/retry.ts (1 hunks)
  • packages/utils/test/retry.test.ts (1 hunks)
🧰 Additional context used
📓 Learnings (1)
packages/request-client.js/test/http-data-access.test.ts (1)
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1386
File: packages/request-client.js/src/api/request-network.ts:25-25
Timestamp: 2024-07-17T15:06:14.563Z
Learning: The `persistTransaction()` function in the `no-persist-http-data-access.ts` file is tested in the `in-memory-request.test.ts` file, which is separate from the typical `index.test.ts` file to avoid test interference.
🔇 Additional comments (3)
packages/utils/src/retry.ts (1)

64-64: Approve: Improved intuitive configuration for exponential backoff delay

The modification to the exponential backoff delay calculation enhances the usability of the retry function. By halving the exponentialBackoffDelay before applying the exponential factor, the function now provides a more intuitive mapping between the input value and the resulting retry intervals.

For example, with this change, setting exponentialBackoffDelay to 1000 will result in retry intervals of approximately 0.5s, 1s, 2s, 4s, which aligns better with user expectations. This improvement makes it easier for developers to configure the desired retry behavior without needing to account for an unintuitive doubling effect.

README.md (2)

91-91: Formatting improvements look good.

The addition of a blank line before the "License" section and the removal of an unnecessary line break after the "Test" section enhance the overall readability and consistency of the README.


Line range hint 1-95: Overall, the changes to the README are well-implemented and valuable.

The additions and modifications in this file align well with the PR objectives of improving clarity regarding package versions and enhancing the developer experience. The new "V1 packages" section, the additional test instructions, and the minor formatting improvements all contribute to a more informative and readable README.

🧰 Tools
🪛 LanguageTool

[style] ~85-~85: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...e monorepo. bash yarn run test Test a specific package. ```bash yarn works...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

packages/request-client.js/test/http-data-access.test.ts Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
packages/utils/test/retry.test.ts Outdated Show resolved Hide resolved
packages/utils/test/retry.test.ts Outdated Show resolved Hide resolved
packages/utils/test/retry.test.ts Outdated Show resolved Hide resolved
packages/request-client.js/src/http-data-access.ts Outdated Show resolved Hide resolved
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: 2

🧹 Outside diff range comments (1)
README.md (1)

Line range hint 92-95: LGTM! Consider adding a version compatibility note.

The addition of the "V1 packages" section is valuable for users, clearly stating that this repository hosts V2 packages and providing information about the deprecated V1 packages. This aligns well with the goal of improving clarity in the documentation.

To further enhance this section, consider adding a brief note about version compatibility or migration, if applicable. For example:

## V1 packages

This repository hosts the packages for the second version of Request. The v1 packages are deprecated and can be found on [requestNetwork-v1-archive](https://github.com/RequestNetwork/requestNetwork-v1-archive).

Note: V2 packages are not backwards compatible with V1. If you're migrating from V1 to V2, please refer to our migration guide [link to migration guide if available].

This additional information would help users understand the implications of the version change and guide them in case they need to migrate their projects.

🧰 Tools
🪛 LanguageTool

[style] ~85-~85: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...e monorepo. bash yarn run test Test a specific package. ```bash yarn works...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between 3b7801c and 497f6aa.

📒 Files selected for processing (2)
  • README.md (1 hunks)
  • packages/request-client.js/test/http-data-access.test.ts (1 hunks)
🧰 Additional context used
📓 Learnings (1)
packages/request-client.js/test/http-data-access.test.ts (1)
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1386
File: packages/request-client.js/src/api/request-network.ts:25-25
Timestamp: 2024-07-17T15:06:14.563Z
Learning: The `persistTransaction()` function in the `no-persist-http-data-access.ts` file is tested in the `in-memory-request.test.ts` file, which is separate from the typical `index.test.ts` file to avoid test interference.
🔇 Additional comments (1)
README.md (1)

Line range hint 1-95: Overall, great improvements to the README!

The changes made to the README.md file are well-aligned with the PR objectives of improving documentation and clarity. The additions provide valuable information for users, especially regarding package testing and version differences.

Here's a summary of the improvements:

  1. Added clear instructions for testing specific packages.
  2. Included a new section about V1 packages, helping users understand the repository structure and version differences.

These changes will significantly enhance the developer experience and reduce potential confusion for users of the Request Network project.

🧰 Tools
🪛 LanguageTool

[style] ~85-~85: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...e monorepo. bash yarn run test Test a specific package. ```bash yarn works...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

README.md Outdated Show resolved Hide resolved
packages/request-client.js/test/http-data-access.test.ts Outdated Show resolved Hide resolved
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: 3

🧹 Outside diff range comments (3)
README.md (1)

Line range hint 91-95: LGTM! Consider moving the V1 packages section.

The addition of the V1 packages section is valuable, providing clear information about the deprecation of v1 packages and where to find them. This aligns well with the PR objectives.

Consider moving this section higher up in the README, perhaps after the "Published Packages" section. This would make it more visible to users who might be looking for v1 packages.

🧰 Tools
🪛 LanguageTool

[style] ~85-~85: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...e monorepo. bash yarn run test Test a specific package by replacing `@reque...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

packages/request-client.js/src/http-data-access.ts (2)

Line range hint 110-122: Approve changes with a minor suggestion for the error message

The refactoring of the persistTransaction method to use the new getConfirmedTransaction method is a good improvement. The updated error message provides valuable guidance to app builders.

However, the error message is quite long and might benefit from some formatting for better readability.

Consider breaking down the error message into multiple lines for better readability:

error = new Error(
  `The Request Network SDK timed-out while polling the Request Node to confirm that the Request was persisted successfully. 
  It is likely that the persisted Request will be confirmed eventually. 
  App Builders are discouraged from calling persistTransaction() a second time, which would create a duplicate Request. 
  Instead, App Builders are recommended to catch this error and continue polling the Request Node using getConfirmedTransaction() or by calling the /getConfirmedTransaction endpoint.
  
  To avoid timeouts in the future, try adjusting the httpConfig values when instantiating the RequestNetwork object:
  - getConfirmationDeferDelay: ${this.httpConfig.getConfirmationDeferDelay}ms
  - getConfirmationMaxRetry: ${this.httpConfig.getConfirmationMaxRetry}
  - getConfirmationRetryDelay: ${this.httpConfig.getConfirmationRetryDelay}ms
  - getConfirmationExponentialBackoffDelay: ${this.httpConfig.getConfirmationExponentialBackoffDelay}ms
  - getConfirmationMaxExponentialBackoffDelay: ${this.httpConfig.getConfirmationMaxExponentialBackoffDelay}ms`
);

Line range hint 226-246: Approve changes with a suggestion for code readability

The addition of exponential backoff parameters to the fetchAndRetry method aligns well with the PR objectives. The default values are correctly set using the class's httpConfig.

To improve code readability, consider using object destructuring for the retryConfig parameter:

protected async fetchAndRetry<T = unknown>(
  path: string,
  params: Record<string, unknown>,
  {
    maxRetries = this.httpConfig.httpRequestMaxRetry,
    retryDelay = this.httpConfig.httpRequestRetryDelay,
    exponentialBackoffDelay = this.httpConfig.httpRequestExponentialBackoffDelay,
    maxExponentialBackoffDelay = this.httpConfig.httpRequestMaxExponentialBackoffDelay,
  }: {
    maxRetries?: number;
    retryDelay?: number;
    exponentialBackoffDelay?: number;
    maxExponentialBackoffDelay?: number;
  } = {},
): Promise<T> {
  return await retry(
    async () => await this.fetch<T>('GET', path, params),
    { maxRetries, retryDelay, exponentialBackoffDelay, maxExponentialBackoffDelay }
  )();
}

This approach eliminates the need for multiple reassignments and makes the default values more explicit.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between 497f6aa and e0c5e4b.

📒 Files selected for processing (4)
  • README.md (1 hunks)
  • packages/request-client.js/src/http-data-access.ts (2 hunks)
  • packages/request-client.js/test/http-data-access.test.ts (1 hunks)
  • packages/utils/test/retry.test.ts (1 hunks)
🧰 Additional context used
📓 Learnings (1)
packages/request-client.js/test/http-data-access.test.ts (1)
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1386
File: packages/request-client.js/src/api/request-network.ts:25-25
Timestamp: 2024-07-17T15:06:14.563Z
Learning: The `persistTransaction()` function in the `no-persist-http-data-access.ts` file is tested in the `in-memory-request.test.ts` file, which is separate from the typical `index.test.ts` file to avoid test interference.
🔇 Additional comments (3)
README.md (1)

86-90: LGTM! Clear instructions for package-specific testing.

The added instructions for testing specific packages are clear and helpful. The example using @requestnetwork/request-client.js is appropriate and aligns with the project structure. This addition improves the developer experience by providing explicit guidance on how to test individual packages.

packages/request-client.js/src/http-data-access.ts (1)

Line range hint 1-284: Summary of changes

The modifications to the HttpDataAccess class align well with the PR objectives:

  1. The new getConfirmedTransaction method effectively refactors the logic for retrieving confirmed transactions.
  2. The persistTransaction method has been updated to use the new getConfirmedTransaction method and provide more detailed error messages.
  3. Exponential backoff parameters have been added to the fetchAndRetry method, making it easier to use and configure.

These changes improve the overall functionality and usability of the class. The suggestions provided in the review comments are minor and focus on enhancing code readability and error handling.

packages/utils/test/retry.test.ts (1)

141-216: Implementation of the exponential backoff test is accurate

The test correctly simulates the exponential backoff delays and validates the expected call times and elapsed times. The use of fake timers and time advancements is appropriately handled.

packages/request-client.js/test/http-data-access.test.ts Outdated Show resolved Hide resolved
packages/utils/test/retry.test.ts Outdated Show resolved Hide resolved
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: 2

🧹 Outside diff range comments (2)
packages/request-client.js/test/http-data-access.test.ts (1)

Line range hint 25-30: Consider extracting httpConfig for better readability

While the test setup is good, we could improve its readability by extracting the httpConfig object. This would make it easier to understand and modify the configuration in future tests.

Consider refactoring the HttpDataAccess instantiation as follows:

const httpConfig = {
  getConfirmationDeferDelay: 0,
  getConfirmationMaxRetry: 0,
};
const httpDataAccess = new HttpDataAccess({ httpConfig });

This change would make the configuration more explicit and easier to maintain.

packages/request-client.js/src/http-data-access.ts (1)

Line range hint 118-126: Simplify and clarify the error message for better readability

The current error message is quite lengthy and may be overwhelming for users. Consider simplifying it to make it more concise and easier to understand. Focus on the essential information and actionable steps.

Apply this diff to simplify the error message:

 error = new Error(
-  `The Request Network SDK timed-out while polling the Request Node to confirm that the Request was persisted successfully. It is likely that the persisted Request will be confirmed eventually. App Builders are discouraged from calling persistTransaction() a second time, which would create a duplicate Request. Instead, App Builders are recommended to catch this error and continue polling the Request Node using getConfirmedTransaction() or by calling the /getConfirmedTransaction endpoint.  To avoid timeouts in the future, try adjusting the httpConfig values when instantiating the RequestNetwork object. The current httpConfig settings are: getConfirmationDeferDelay: ${this.httpConfig.getConfirmationDeferDelay}ms, getConfirmationMaxRetry: ${this.httpConfig.getConfirmationMaxRetry}, getConfirmationRetryDelay: ${this.httpConfig.getConfirmationRetryDelay}ms, getConfirmationExponentialBackoffDelay: ${this.httpConfig.getConfirmationExponentialBackoffDelay}ms, getConfirmationMaxExponentialBackoffDelay: ${this.httpConfig.getConfirmationMaxExponentialBackoffDelay}ms`,
+  `Timeout while confirming the transaction. It is likely that the transaction will be confirmed eventually. Please use getConfirmedTransaction() to continue polling for confirmation or adjust the httpConfig settings to avoid future timeouts.`,
 );

This revision conveys the necessary information more succinctly and directs users to the recommended actions.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between e0c5e4b and 3647631.

📒 Files selected for processing (4)
  • packages/request-client.js/src/http-config-defaults.ts (1 hunks)
  • packages/request-client.js/src/http-data-access.ts (2 hunks)
  • packages/request-client.js/test/http-data-access.test.ts (1 hunks)
  • packages/utils/test/retry.test.ts (1 hunks)
🧰 Additional context used
📓 Learnings (1)
packages/request-client.js/test/http-data-access.test.ts (1)
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1386
File: packages/request-client.js/src/api/request-network.ts:25-25
Timestamp: 2024-07-17T15:06:14.563Z
Learning: The `persistTransaction()` function in the `no-persist-http-data-access.ts` file is tested in the `in-memory-request.test.ts` file, which is separate from the typical `index.test.ts` file to avoid test interference.
🔇 Additional comments (5)
packages/request-client.js/src/http-config-defaults.ts (2)

11-14: LGTM! Configuration changes align with the new exponential backoff strategy.

The modifications to the configuration values are consistent with the exponential backoff strategy described in the comment:

  1. getConfirmationMaxRetry: 7: Reduces the maximum number of retries from 30 to 7, which is appropriate for the new strategy.
  2. getConfirmationRetryDelay: 0: Sets the initial delay to 0, as delays are now handled by the exponential backoff.
  3. getConfirmationExponentialBackoffDelay: 1000: Introduces a 1-second starting delay for the exponential backoff.
  4. getConfirmationMaxExponentialBackoffDelay: 64000: Increases the maximum delay to 64 seconds, allowing for longer waits between retries.

These changes should improve the efficiency of the retry mechanism while potentially reducing unnecessary network traffic.

Let's verify that these are the only changes made to the configuration object:

#!/bin/bash
# Description: Verify that no other changes were made to the configuration object

# Test: Check for any other changes in the configuration object
rg --type typescript -C 10 'const config: ClientTypes.IHttpDataAccessConfig = {' packages/request-client.js/src/http-config-defaults.ts

# Expected output: Only the changes we've reviewed should be present in the diff

9-10: LGTM! Clear and informative comment.

The added comment provides a comprehensive explanation of the new exponential backoff strategy. It clearly outlines the starting delay, doubling mechanism, maximum delay, number of retries, and total timeout calculation.

Let's verify the accuracy of the comment by checking the configuration values:

packages/request-client.js/test/http-data-access.test.ts (1)

32-43: Excellent refactoring of the persistTransaction() test case!

The changes in this test case are well-aligned with the PR objectives and address previous review comments. Here are the key improvements:

  1. The use of async/await simplifies the test structure and improves readability.
  2. The implementation of Promise.race() elegantly handles both the error event and a potential timeout, making the test more robust.
  3. The expanded error message now provides detailed guidance for app builders, which aligns perfectly with the PR objective of enhancing user experience when dealing with transaction timeouts.
  4. The addition of a 5-second timeout prevents the test from hanging indefinitely if the error event is never emitted, addressing a suggestion from a past review.
  5. The test now directly uses the persistTransaction() method, which provides a more realistic scenario.

These changes significantly improve the test's reliability and its alignment with the intended behavior of the persistTransaction() method.

packages/request-client.js/src/http-data-access.ts (2)

110-116: Efficient refactoring by utilizing getConfirmedTransaction

Refactoring the code to use the new getConfirmedTransaction method simplifies the logic in persistTransaction and promotes code reuse.


127-149: Add error handling to getConfirmedTransaction method

Including explicit error handling within the getConfirmedTransaction method can provide more context if the fetchAndRetry call fails. This will help users understand the reason for the failure and take appropriate action.

packages/utils/test/retry.test.ts Outdated Show resolved Hide resolved
@@ -61,7 +61,7 @@ const retry = <TParams extends unknown[], TReturn>(
setTimeout(
resolve,
retryDelay +
Math.min(maxExponentialBackoffDelay, exponentialBackoffDelay * 2 ** retry),
Math.min(maxExponentialBackoffDelay, (exponentialBackoffDelay / 2) * 2 ** retry),
Copy link
Member Author

Choose a reason for hiding this comment

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

This change adjusts the retry logic to make exponentialBackoffDelay more intuitive to configure

  • Now, 1000 means retry after 1, 2, 4, 8... seconds.
  • Previously, 1000 meant retry after 2, 4, 8, 16... seconds.

@MantisClone MantisClone changed the title fix: improve error message when persistTransaction times out. Increase default timeout to 2 minutes from 30 seconds, Make exponential backoff easier to use. fix: improve error message when persistTransaction times out. Increase default timeout to 130 seconds using Exponential Backoff Oct 2, 2024
@MantisClone MantisClone enabled auto-merge (squash) October 2, 2024 05:30
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: 4

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between 3647631 and 9f81a7f.

📒 Files selected for processing (2)
  • packages/request-client.js/src/http-data-access.ts (2 hunks)
  • packages/request-client.js/test/http-data-access.test.ts (1 hunks)
🧰 Additional context used
📓 Learnings (2)
packages/request-client.js/src/http-data-access.ts (1)
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1316
File: packages/request-client.js/src/http-data-access.ts:127-149
Timestamp: 2024-10-02T05:01:57.381Z
Learning: In the `getConfirmedTransaction` method, explicit error handling for the `fetchAndRetry` call is not necessary.
packages/request-client.js/test/http-data-access.test.ts (1)
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1386
File: packages/request-client.js/src/api/request-network.ts:25-25
Timestamp: 2024-07-17T15:06:14.563Z
Learning: The `persistTransaction()` function in the `no-persist-http-data-access.ts` file is tested in the `in-memory-request.test.ts` file, which is separate from the typical `index.test.ts` file to avoid test interference.
🔇 Additional comments (1)
packages/request-client.js/src/http-data-access.ts (1)

127-149: New getConfirmedTransaction method is well-implemented

The addition of the getConfirmedTransaction method effectively encapsulates the logic for fetching confirmed transactions. It correctly normalizes the transaction hash and utilizes fetchAndRetry with appropriate configuration parameters.

packages/request-client.js/test/http-data-access.test.ts Outdated Show resolved Hide resolved
packages/request-client.js/src/http-data-access.ts Outdated Show resolved Hide resolved
packages/request-client.js/src/http-data-access.ts Outdated Show resolved Hide resolved
// when found, emit the event 'confirmed'
result.emit('confirmed', confirmedData);
})
.catch((e) => {
let error: Error = e;
if (e.status === 404) {
if (e && 'status' in e && e.status === 404) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This was a coderabbit suggestion.

Copy link
Contributor

@rodrigopavezi rodrigopavezi left a comment

Choose a reason for hiding this comment

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

great job 💯

@MantisClone MantisClone merged commit b2019da into master Oct 2, 2024
25 checks passed
@MantisClone MantisClone deleted the update-default-http-config branch October 2, 2024 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

3 participants