Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 91
fix: improve error message when persistTransaction times out. Increase default timeout to 130 seconds using Exponential Backoff#1316
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
ec00fb2c95aef6be2e95f29d0aaa5027177ae992bfbc405b3ca01298077a91f9ca0e963b7801c2a4a47b497f6aa3d4b407d6339e21fa766b7f2a5bde0c5e4b7b76550a246c91b699fbd36476319f81a7f4aca87170e4a909a8197cFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -98,8 +98,6 @@ export default class HttpDataAccess implements DataAccessTypes.IDataAccess { | ||
| { channelId, topics, transactionData }, | ||
| ); | ||
| const transactionHash: string = normalizeKeccak256Hash(transactionData).value; | ||
| // Create the return result with EventEmitter | ||
| const result: DataAccessTypes.IReturnPersistTransaction = Object.assign( | ||
| new EventEmitter() as DataAccessTypes.PersistTransactionEmitter, | ||
| @@ -109,33 +107,15 @@ export default class HttpDataAccess implements DataAccessTypes.IDataAccess { | ||
| // Try to get the confirmation | ||
| new Promise((r) => setTimeout(r, this.httpConfig.getConfirmationDeferDelay)) | ||
| .then(async () => { | ||
| const confirmedData = | ||
| await this.fetchAndRetry<DataAccessTypes.IReturnPersistTransactionRaw>( | ||
| '/getConfirmedTransaction', | ||
| { | ||
| transactionHash, | ||
| }, | ||
| { | ||
| maxRetries: this.httpConfig.getConfirmationMaxRetry, | ||
| retryDelay: this.httpConfig.getConfirmationRetryDelay, | ||
| exponentialBackoffDelay: this.httpConfig.getConfirmationExponentialBackoffDelay, | ||
| maxExponentialBackoffDelay: this.httpConfig.getConfirmationMaxExponentialBackoffDelay, | ||
| }, | ||
| ); | ||
| const confirmedData = await this.getConfirmedTransaction(transactionData); | ||
ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I moved this logic into a new | ||
| // 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) { | ||
ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was a coderabbit suggestion. | ||
| error = new Error( | ||
| `Transaction confirmation not received. Try polling | ||
| getTransactionsByChannelId() until the transaction is confirmed. | ||
| deferDelay: ${this.httpConfig.getConfirmationDeferDelay}ms, | ||
| maxRetries: ${this.httpConfig.getConfirmationMaxRetry}, | ||
| retryDelay: ${this.httpConfig.getConfirmationRetryDelay}ms, | ||
| exponentialBackoffDelay: ${this.httpConfig.getConfirmationExponentialBackoffDelay}ms, | ||
| maxExponentialBackoffDelay: ${this.httpConfig.getConfirmationMaxExponentialBackoffDelay}ms`, | ||
| `Timeout while confirming the Request was persisted. It is likely that the Request will be confirmed eventually. Catch this error and use getConfirmedTransaction() to continue polling for confirmation. Adjusting the httpConfig settings on the RequestNetwork object to avoid future timeouts. Avoid calling persistTransaction() again to prevent creating a duplicate Request.`, | ||
| ); | ||
| } | ||
| result.emit('error', error); | ||
| @@ -144,6 +124,29 @@ export default class HttpDataAccess implements DataAccessTypes.IDataAccess { | ||
| return result; | ||
| } | ||
| /** | ||
| * Gets a transaction from the node through HTTP. | ||
| * @param transactionData The transaction data | ||
| */ | ||
| public async getConfirmedTransaction( | ||
| transactionData: DataAccessTypes.ITransaction, | ||
| ): Promise<DataAccessTypes.IReturnPersistTransaction> { | ||
| const transactionHash: string = normalizeKeccak256Hash(transactionData).value; | ||
| return await this.fetchAndRetry( | ||
| '/getConfirmedTransaction', | ||
| { | ||
| transactionHash, | ||
| }, | ||
| { | ||
| maxRetries: this.httpConfig.getConfirmationMaxRetry, | ||
| retryDelay: this.httpConfig.getConfirmationRetryDelay, | ||
| exponentialBackoffDelay: this.httpConfig.getConfirmationExponentialBackoffDelay, | ||
| maxExponentialBackoffDelay: this.httpConfig.getConfirmationMaxExponentialBackoffDelay, | ||
| }, | ||
| ); | ||
| } | ||
MantisClone marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| /** | ||
| * Gets the transactions for a channel from the node through HTTP. | ||
| * | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -29,22 +29,18 @@ describe('HttpDataAccess', () => { | ||
| getConfirmationMaxRetry: 0, | ||
| }, | ||
| }); | ||
| await expect( | ||
| new Promise((resolve, reject) => | ||
| httpDataAccess.persistTransaction({}, '', []).then((returnPersistTransaction) => { | ||
| returnPersistTransaction.on('confirmed', resolve); | ||
| returnPersistTransaction.on('error', reject); | ||
| }), | ||
| ), | ||
| ).rejects.toThrow( | ||
| new Error(`Transaction confirmation not received. Try polling | ||
| getTransactionsByChannelId() until the transaction is confirmed. | ||
| deferDelay: 0ms, | ||
| maxRetries: 0, | ||
| retryDelay: 1000ms, | ||
| exponentialBackoffDelay: 0ms, | ||
| maxExponentialBackoffDelay: 30000ms`), | ||
| ); | ||
| const returnPersistTransaction = await httpDataAccess.persistTransaction({}, '', []); | ||
| await Promise.race([ | ||
| new Promise<void>((resolve) => { | ||
| returnPersistTransaction.on('error', (e: any) => { | ||
MantisClone marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| expect(e.message).toBe( | ||
| 'Timeout while confirming the Request was persisted. It is likely that the Request will be confirmed eventually. Catch this error and use getConfirmedTransaction() to continue polling for confirmation. Adjusting the httpConfig settings on the RequestNetwork object to avoid future timeouts. Avoid calling persistTransaction() again to prevent creating a duplicate Request.', | ||
| ); | ||
| resolve(); | ||
| }); | ||
| }), | ||
| new Promise((_, reject) => setTimeout(() => reject(new Error('Test timed out')), 5000)), | ||
| ]); | ||
| }); | ||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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), | ||
ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change adjusts the retry logic to make
| ||
| ), | ||
| ); | ||
Uh oh!
There was an error while loading. Please reload this page.