-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CLI: improve Solana transaction confirmations (#281)
* send and confirm tx via metaplex; retry only transient errors * do not disable retry on rate limit when sending tx * update solana web3.js * patch solana/web3.js to increase tx confirmation sleep time * remove sending tx log
- Loading branch information
Showing
8 changed files
with
213 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,5 +29,10 @@ | |
"prettier": "^2.7.1", | ||
"shx": "^0.3.4", | ||
"typescript": "^4.7.4" | ||
}, | ||
"pnpm": { | ||
"patchedDependencies": { | ||
"@solana/[email protected]": "patches/@[email protected]" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { | ||
type Metaplex, | ||
type TransactionBuilder, | ||
FailedToConfirmTransactionError, | ||
} from "@metaplex-foundation/js"; | ||
import { TransactionExpiredBlockheightExceededError } from "@solana/web3.js"; | ||
|
||
export async function sendAndConfirmTransaction( | ||
metaplex: Metaplex, | ||
builder: TransactionBuilder | ||
): ReturnType<TransactionBuilder["sendAndConfirm"]> { | ||
for (let i = 0; i < 10; i++) { | ||
try { | ||
return await builder.sendAndConfirm(metaplex); | ||
} catch (e: unknown) { | ||
if (isTransientError(e)) { | ||
continue; | ||
} | ||
|
||
throw e; | ||
} | ||
} | ||
|
||
throw new Error("Unable to send transaction. Please try later."); | ||
} | ||
|
||
function isTransientError(e: unknown): boolean { | ||
return ( | ||
e instanceof FailedToConfirmTransactionError && | ||
(e.cause instanceof TransactionExpiredBlockheightExceededError || | ||
/blockhash not found/i.test(e.cause?.message ?? "")) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
diff --git a/lib/index.cjs.js b/lib/index.cjs.js | ||
index 013925eb21352fb560e87229ae33de94ff83115a..42ca54b5023ee9731bf8f35cb3cb49276f79dfba 100644 | ||
--- a/lib/index.cjs.js | ||
+++ b/lib/index.cjs.js | ||
@@ -6587,7 +6587,7 @@ class Connection { | ||
let currentBlockHeight = await checkBlockHeight(); | ||
if (done) return; | ||
while (currentBlockHeight <= lastValidBlockHeight) { | ||
- await sleep(1000); | ||
+ await sleep(5000); | ||
if (done) return; | ||
currentBlockHeight = await checkBlockHeight(); | ||
if (done) return; |
Oops, something went wrong.