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
1 changed files with 12 additions and 9 deletions

View File

@ -31,26 +31,29 @@ export async function sendAndConfirmTransaction(
break;
}
await sleep(500);
if (--statusRetries <= 0) {
const duration = (Date.now() - start) / 1000;
throw new Error(
`Transaction '${signature}' was not confirmed in ${duration.toFixed(
2,
)} seconds (${status})`,
);
break;
}
await sleep(500);
}
if (status === 'Confirmed') {
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})`);
}
// 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);
}