Skip to content
This repository has been archived by the owner on Dec 27, 2022. It is now read-only.

Commit

Permalink
update : waitForConfirmation to double timeout if we've received 1 co…
Browse files Browse the repository at this point in the history
…nfirmation
  • Loading branch information
jakekidd committed Jun 18, 2021
1 parent 0a3e3b9 commit dde53c0
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions modules/contracts/src.ts/services/ethService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -592,8 +592,8 @@ export class EthereumChainService extends EthereumChainReader implements IVector
/**
* Will wait for any of the given TransactionResponses to return
* a receipt. Once a receipt is returned by any of the responses,
* it will wait for 10 confirmations of the given receipt against
* a timeout. If within the timeout there are *not* 10 confirmations,
* it will wait for X confirmations of the given receipt against
* a timeout. If within the timeout there are *not* X confirmations,
* the tx will be resubmitted at the same nonce.
*/
public async waitForConfirmation(chainId: number, responses: TransactionResponse[]): Promise<TransactionReceipt> {
Expand All @@ -602,6 +602,9 @@ export class EthereumChainService extends EthereumChainReader implements IVector
throw new ChainError(ChainError.reasons.ProviderNotFound);
}
const numConfirmations = getConfirmationsForChain(chainId);
// A flag for marking when we have received at least 1 confirmation. We'll extend the wait period by 2x
// if this is the case.
let receivedConfirmation: boolean = false;

// An anon fn to get the tx receipts for all responses.
// We must check for confirmation in all previous transactions. Although it's most likely
Expand All @@ -620,6 +623,8 @@ export class EthereumChainService extends EthereumChainReader implements IVector
reverted.push(r);
} else if (r.confirmations >= numConfirmations) {
return resolve(r);
} else if (r.confirmations >= 1) {
receivedConfirmation = true;
}
}
});
Expand All @@ -645,7 +650,7 @@ export class EthereumChainService extends EthereumChainReader implements IVector
// NOTE: This loop won't execute if receipt is valid (not undefined).
let timeElapsed: number = 0;
const startMark = new Date().getTime();
while (!receipt && timeElapsed < CONFIRMATION_TIMEOUT) {
while (!receipt && timeElapsed < (receivedConfirmation ? CONFIRMATION_TIMEOUT : CONFIRMATION_TIMEOUT * 2)) {
receipt = await pollForReceipt();
// Update elapsed time.
timeElapsed = new Date().getTime() - startMark;
Expand Down

0 comments on commit dde53c0

Please sign in to comment.