diff --git a/web3.js/src/util/send-and-confirm-raw-transaction.js b/web3.js/src/util/send-and-confirm-raw-transaction.js index b4e0b6b44e..b73df5c82a 100644 --- a/web3.js/src/util/send-and-confirm-raw-transaction.js +++ b/web3.js/src/util/send-and-confirm-raw-transaction.js @@ -3,6 +3,7 @@ import {Connection} from '../connection'; import {sleep} from './sleep'; import type {TransactionSignature} from '../transaction'; +import {DEFAULT_TICKS_PER_SLOT, NUM_TICKS_PER_SECOND} from '../timing'; /** * Sign, send and confirm a raw transaction @@ -14,16 +15,18 @@ export async function sendAndConfirmRawTransaction( const start = Date.now(); let signature = await connection.sendRawTransaction(rawTransaction); - // Wait up to a couple seconds for a confirmation + // Wait up to a couple slots for a confirmation let status = ''; - let statusRetries = 4; + let statusRetries = 6; for (;;) { status = await connection.getSignatureStatus(signature); if (status !== 'SignatureNotFound') { break; } - await sleep(500); + // Sleep for approximately half a slot + await sleep((500 * DEFAULT_TICKS_PER_SLOT) / NUM_TICKS_PER_SECOND); + if (--statusRetries <= 0) { const duration = (Date.now() - start) / 1000; throw new Error( diff --git a/web3.js/src/util/send-and-confirm-transaction.js b/web3.js/src/util/send-and-confirm-transaction.js index 9a1986d011..a4a3535a92 100644 --- a/web3.js/src/util/send-and-confirm-transaction.js +++ b/web3.js/src/util/send-and-confirm-transaction.js @@ -7,6 +7,7 @@ import {Transaction} from '../transaction'; import {sleep} from './sleep'; import type {Account} from '../account'; import type {TransactionSignature} from '../transaction'; +import {DEFAULT_TICKS_PER_SLOT, NUM_TICKS_PER_SECOND} from '../timing'; /** * Sign, send and confirm a transaction @@ -22,9 +23,9 @@ export async function sendAndConfirmTransaction( const start = Date.now(); signature = await connection.sendTransaction(transaction, ...signers); - // Wait up to a couple seconds for a confirmation + // Wait up to a couple slots for a confirmation let status = 'SignatureNotFound'; - let statusRetries = 4; + let statusRetries = 6; for (;;) { status = await connection.getSignatureStatus(signature); if (status !== 'SignatureNotFound') { @@ -34,7 +35,8 @@ export async function sendAndConfirmTransaction( if (--statusRetries <= 0) { break; } - await sleep(500); + // Sleep for approximately half a slot + await sleep((500 * DEFAULT_TICKS_PER_SLOT) / NUM_TICKS_PER_SECOND); } if (status === 'Confirmed') {