fix: consider ticks_per_slot while sleeping
This commit is contained in:
@ -3,6 +3,7 @@
|
|||||||
import {Connection} from '../connection';
|
import {Connection} from '../connection';
|
||||||
import {sleep} from './sleep';
|
import {sleep} from './sleep';
|
||||||
import type {TransactionSignature} from '../transaction';
|
import type {TransactionSignature} from '../transaction';
|
||||||
|
import {DEFAULT_TICKS_PER_SLOT, NUM_TICKS_PER_SECOND} from '../timing';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sign, send and confirm a raw transaction
|
* Sign, send and confirm a raw transaction
|
||||||
@ -14,16 +15,18 @@ export async function sendAndConfirmRawTransaction(
|
|||||||
const start = Date.now();
|
const start = Date.now();
|
||||||
let signature = await connection.sendRawTransaction(rawTransaction);
|
let signature = await connection.sendRawTransaction(rawTransaction);
|
||||||
|
|
||||||
// Wait up to a couple seconds for a confirmation
|
// Wait up to a couple slots for a confirmation
|
||||||
let status = '';
|
let status = '';
|
||||||
let statusRetries = 4;
|
let statusRetries = 6;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
status = await connection.getSignatureStatus(signature);
|
status = await connection.getSignatureStatus(signature);
|
||||||
if (status !== 'SignatureNotFound') {
|
if (status !== 'SignatureNotFound') {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
await sleep(500);
|
// Sleep for approximately half a slot
|
||||||
|
await sleep((500 * DEFAULT_TICKS_PER_SLOT) / NUM_TICKS_PER_SECOND);
|
||||||
|
|
||||||
if (--statusRetries <= 0) {
|
if (--statusRetries <= 0) {
|
||||||
const duration = (Date.now() - start) / 1000;
|
const duration = (Date.now() - start) / 1000;
|
||||||
throw new Error(
|
throw new Error(
|
||||||
|
@ -7,6 +7,7 @@ import {Transaction} from '../transaction';
|
|||||||
import {sleep} from './sleep';
|
import {sleep} from './sleep';
|
||||||
import type {Account} from '../account';
|
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';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sign, send and confirm a transaction
|
* Sign, send and confirm a transaction
|
||||||
@ -22,9 +23,9 @@ export async function sendAndConfirmTransaction(
|
|||||||
const start = Date.now();
|
const start = Date.now();
|
||||||
signature = await connection.sendTransaction(transaction, ...signers);
|
signature = await connection.sendTransaction(transaction, ...signers);
|
||||||
|
|
||||||
// Wait up to a couple seconds for a confirmation
|
// Wait up to a couple slots for a confirmation
|
||||||
let status = 'SignatureNotFound';
|
let status = 'SignatureNotFound';
|
||||||
let statusRetries = 4;
|
let statusRetries = 6;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
status = await connection.getSignatureStatus(signature);
|
status = await connection.getSignatureStatus(signature);
|
||||||
if (status !== 'SignatureNotFound') {
|
if (status !== 'SignatureNotFound') {
|
||||||
@ -34,7 +35,8 @@ export async function sendAndConfirmTransaction(
|
|||||||
if (--statusRetries <= 0) {
|
if (--statusRetries <= 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
await sleep(500);
|
// Sleep for approximately half a slot
|
||||||
|
await sleep((500 * DEFAULT_TICKS_PER_SLOT) / NUM_TICKS_PER_SECOND);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status === 'Confirmed') {
|
if (status === 'Confirmed') {
|
||||||
|
Reference in New Issue
Block a user