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

View File

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