-
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
Changes from all commits
ec00fb2
c95aef6
be2e95f
29d0aaa
5027177
ae992bf
bc405b3
ca01298
077a91f
9ca0e96
3b7801c
2a4a47b
497f6aa
3d4b407
d6339e2
1fa766b
7f2a5bd
e0c5e4b
7b76550
a246c91
b699fbd
3647631
9f81a7f
4aca871
70e4a90
9a8197c
File filter
Filter by extension
Conversations
Jump to
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); | ||
|
Member
Author
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) { | ||
|
Member
Author
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.
Show resolved
Hide resolved
|
||
| /** | ||
| * Gets the transactions for a channel from the node through HTTP. | ||
| * | ||
|
|
||
| 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), | ||
|
Member
Author
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.