fix: adjust status retry algorithm
This commit is contained in:
parent
2c517c1f3c
commit
cd6b48a403
|
@ -10,6 +10,13 @@ import type {Account} from '../account';
|
||||||
import type {TransactionSignature} from '../transaction';
|
import type {TransactionSignature} from '../transaction';
|
||||||
import {DEFAULT_TICKS_PER_SLOT, NUM_TICKS_PER_SECOND} from '../timing';
|
import {DEFAULT_TICKS_PER_SLOT, NUM_TICKS_PER_SECOND} from '../timing';
|
||||||
|
|
||||||
|
const MS_PER_SECOND = 1000;
|
||||||
|
const MS_PER_SLOT =
|
||||||
|
(DEFAULT_TICKS_PER_SLOT / NUM_TICKS_PER_SECOND) * MS_PER_SECOND;
|
||||||
|
|
||||||
|
const NUM_SEND_RETRIES = 10;
|
||||||
|
const NUM_STATUS_RETRIES = 10;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sign, send and confirm a transaction with recent commitment level
|
* Sign, send and confirm a transaction with recent commitment level
|
||||||
*/
|
*/
|
||||||
|
@ -45,7 +52,7 @@ async function _sendAndConfirmTransaction(
|
||||||
): Promise<TransactionSignature> {
|
): Promise<TransactionSignature> {
|
||||||
const statusCommitment = commitment || connection.commitment || 'max';
|
const statusCommitment = commitment || connection.commitment || 'max';
|
||||||
|
|
||||||
let sendRetries = 10;
|
let sendRetries = NUM_SEND_RETRIES;
|
||||||
let signature;
|
let signature;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
@ -54,13 +61,17 @@ async function _sendAndConfirmTransaction(
|
||||||
|
|
||||||
// Wait up to a couple slots for a confirmation
|
// Wait up to a couple slots for a confirmation
|
||||||
let status = null;
|
let status = null;
|
||||||
let statusRetries = 6;
|
let statusRetries = NUM_STATUS_RETRIES;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
status = (await connection.getSignatureStatus(signature)).value;
|
status = (await connection.getSignatureStatus(signature)).value;
|
||||||
if (status) {
|
if (status) {
|
||||||
if (statusCommitment === 'max' && status.confirmations === null) {
|
// Recieved a status, if not an error wait for confirmation
|
||||||
break;
|
statusRetries = NUM_STATUS_RETRIES;
|
||||||
} else if (statusCommitment === 'recent') {
|
if (
|
||||||
|
status.err ||
|
||||||
|
status.confirmations === null ||
|
||||||
|
(statusCommitment === 'recent' && status.confirmations >= 1)
|
||||||
|
) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,7 +80,7 @@ async function _sendAndConfirmTransaction(
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// Sleep for approximately half a slot
|
// Sleep for approximately half a slot
|
||||||
await sleep((500 * DEFAULT_TICKS_PER_SLOT) / NUM_TICKS_PER_SECOND);
|
await sleep(MS_PER_SLOT / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status) {
|
if (status) {
|
||||||
|
|
Loading…
Reference in New Issue