Skip to content

Commit

Permalink
Fix Last Valid Block Height Issue (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xIchigo authored Oct 2, 2024
1 parent 6fbb3e7 commit cb2db7a
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/RpcClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,12 @@ export class RpcClient {

const commitment = sendOptions?.preflightCommitment || 'confirmed';

const currentBlockHeight = await this.connection.getBlockHeight();
const lastValidBlockHeight = Math.min(
blockhash.lastValidBlockHeight,
currentBlockHeight + lastValidBlockHeightOffset
);

let error: Error;

// We will retry the transaction on TransactionExpiredBlockheightExceededError
Expand Down Expand Up @@ -767,9 +773,7 @@ export class RpcClient {
abortSignal,
signature,
blockhash: blockhash.blockhash,
lastValidBlockHeight:
blockhash.lastValidBlockHeight +
lastValidBlockHeightOffset,
lastValidBlockHeight: lastValidBlockHeight,
},
commitment
);
Expand Down Expand Up @@ -961,15 +965,20 @@ export class RpcClient {
jitoApiUrl
);

const currentBlockHeight = await this.connection.getBlockHeight();
const lastValidBlockHeight = Math.min(
blockhash.lastValidBlockHeight,
currentBlockHeight + lastValidBlockHeightOffset
);

// Poll for confirmation status
const timeout = 60000; // 60 second timeout
const interval = 5000; // 5 second interval
const startTime = Date.now();

while (
Date.now() - startTime < timeout ||
(await this.connection.getBlockHeight()) <=
blockhash.lastValidBlockHeight + lastValidBlockHeightOffset
(await this.connection.getBlockHeight()) <= lastValidBlockHeight
) {
const bundleStatuses = await this.getBundleStatuses(
[bundleId],
Expand Down

0 comments on commit cb2db7a

Please sign in to comment.