fix: improve retry logic on AccountInUse

This commit is contained in:
Michael Vines 2018-10-30 11:10:11 -07:00
parent 33c59b73b4
commit 0fbf024c8c
1 changed files with 4 additions and 1 deletions

View File

@ -15,7 +15,7 @@ export async function sendAndConfirmTransaction(
runtimeErrorOk: boolean = false
): Promise<void> {
let sendRetries = 3;
let sendRetries = 10;
for (;;) {
const start = Date.now();
const signature = await connection.sendTransaction(from, transaction);
@ -44,6 +44,9 @@ export async function sendAndConfirmTransaction(
if (status !== 'AccountInUse' || --sendRetries <= 0) {
throw new Error(`Transaction ${signature} failed (${status})`);
}
// Retry in 0..100ms to try to avoid another collision
await sleep(Math.random() * 100);
}
}