fix: resend transactions a couple times before giving up

This commit is contained in:
Michael Vines
2019-01-11 16:39:09 -07:00
parent ea9b03c393
commit bc05966765

View File

@ -31,26 +31,29 @@ export async function sendAndConfirmTransaction(
break; break;
} }
await sleep(500);
if (--statusRetries <= 0) { if (--statusRetries <= 0) {
const duration = (Date.now() - start) / 1000; break;
throw new Error(
`Transaction '${signature}' was not confirmed in ${duration.toFixed(
2,
)} seconds (${status})`,
);
} }
await sleep(500);
} }
if (status === 'Confirmed') { if (status === 'Confirmed') {
break; break;
} }
if (--sendRetries <= 0) {
const duration = (Date.now() - start) / 1000;
throw new Error(
`Transaction '${signature}' was not confirmed in ${duration.toFixed(
2,
)} seconds (${status})`,
);
}
if (status !== 'AccountInUse' || --sendRetries <= 0) { if (status !== 'AccountInUse' && status !== 'SignatureNotFound') {
throw new Error(`Transaction ${signature} failed (${status})`); throw new Error(`Transaction ${signature} failed (${status})`);
} }
// Retry in 0..100ms to try to avoid another collision // Retry in 0..100ms to try to avoid another AccountInUse collision
await sleep(Math.random() * 100); await sleep(Math.random() * 100);
} }