Skip to content

Commit

Permalink
Improve tx confirmation rate by spamming sendRawTransaction() (#381)
Browse files Browse the repository at this point in the history
  • Loading branch information
filipzeta authored Apr 8, 2024
1 parent c49bdf6 commit 624177a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
Version changes are pinned to SDK releases.

## [1.26.2]

- Spam sendRawTransaction() in utils.processTransaction(). ([#381](https://github.com/zetamarkets/sdk/pull/381))

## [1.26.1]

- Add new update pricing ix. ([#379](https://github.com/zetamarkets/sdk/pull/379))
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@zetamarkets/sdk",
"repository": "https://github.com/zetamarkets/sdk/",
"version": "1.26.1",
"version": "1.26.2",
"description": "Zeta SDK",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
9 changes: 8 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1036,13 +1036,20 @@ export async function processTransaction(

txSig = await provider.connection.sendRawTransaction(rawTx, {
skipPreflight: true,
preflightCommitment: provider.connection.commitment,
});

// Poll the tx confirmation for N seconds
// Polling is more reliable than websockets using confirmTransaction()
let currentBlockHeight = 0;
if (!skipConfirmation) {
while (currentBlockHeight < recentBlockhash.lastValidBlockHeight) {
// Keep resending to maximise the chance of confirmation
await provider.connection.sendRawTransaction(rawTx, {
skipPreflight: true,
preflightCommitment: provider.connection.commitment,
});

let status = await provider.connection.getSignatureStatus(txSig);
currentBlockHeight = await provider.connection.getBlockHeight(
provider.connection.commitment
Expand All @@ -1064,7 +1071,7 @@ export async function processTransaction(
return txSig;
}
}
await sleep(1500); // Don't spam the RPC
await sleep(500); // Don't spam the RPC
}
throw Error(`Transaction ${txSig} was not confirmed`);
} else {
Expand Down

0 comments on commit 624177a

Please sign in to comment.