Transaction recovery examples#
Use the authorized execution source with the Node journal. The offline tests sign fixture transactions. They do not submit transactions or establish economic results.
Durable storage#
The adapter uses an exclusive owner.lock file and serializes writes inside its process.
It writes a temporary file, synchronizes the file, renames it, and synchronizes the directory.
It supports one owner on a local filesystem with atomic rename and directory synchronization.
Do not assume network filesystems provide these guarantees.
A clean shutdown releases the lock. A crash leaves the lock in place. Before you remove a stale lock, make sure that the old process has stopped. Keep the journal files. Do not remove the lock only because its age exceeds a timeout. If JSON parsing or persistence fails, stop. Do not replace the journal with an empty document.
The browser host uses browser-journal.ts.
It requires persistent-storage permission and an IndexedDB read/write transaction for each atomic update across tabs.
The host has no in-memory or local-storage fallback. When you recover a transaction, use the same origin and browser profile.
Reviewed intent#
- Read wallet, cluster, program, market, fee policy, referral decision, and Clock.
- Call
createReviewedOrderIntentwith exact share and quote units. Put every order field in the draft, including match limit, self-trade behavior, resting age, resting expiry, post-only cross policy, and client order id. - Show the limits, expiry, fees, and referral decision to the user.
- Obtain authorization for
reviewedIntentDigest. The digest covers every byte of thePlaceOrderdata except the treasury shard index. - Build with
placeOrderParamsFromReviewedIntent. Do not add or change fields in the result. A field changed after review is signed outside the digest. - Simulate the exact transaction.
- Check fresh observations with
checkReviewedIntentAtSigning. - Sign the transaction.
- Compare the signed message with the reviewed unsigned message.
- Derive its identity with
deriveSignedTransactionIdentity. - Save the signed transaction with
TransactionAttemptJournal.recordSigned. - Send those exact bytes.
The example rejects a changed digest, journal scope, fee payer, or message.
The shared native-tutorial.ts host supplies account validation, strict preflight, and transaction construction for the Node and browser tutorials.
Do not use a TypeScript type assertion as runtime validation of an external authorization request.
Lost acknowledgement#
Before you sign a new transaction, run reconcileReplacementGate.
Use signature history and a block-height read after the status read.
If blocking contains an attempt, do not sign a new transaction.
If landed contains an attempt, display that result and refresh state.
An expired blockhash with no status remains unresolved.
A failure is not final until the transaction is finalized.
If rebroadcast is enabled, submit only the journal's identical signed bytes while valid.
If the host requires a final result, continue to check confirmed transactions until finalization.
The journal's list of blocking attempts does not include confirmed transactions.
Do not use that list as the complete list of transactions that need finalization.
The tests cover restart after a lost response, corrupt storage, persistence failure, and wrong authorization.
Run bun run --cwd packages/core vitest run src/__tests__/documentation-examples.test.ts.
Local restart drill#
Use the funded inputs from the sandbox. Replace INPUTS_JSON with the generated inputs file:
node scripts/docs_recovery_drill.mjs INPUTS_JSON --execute-local-fixture
This command submits one authorized fixture transaction to the local RPC.
After the RPC accepts the transaction, the drill sends SIGKILL to the client before it receives the acknowledgement.
Before the drill removes the lock file, it checks that the client process has stopped. It keeps the journal and restarts the Node host with that journal. The drill checks finalization, the stored signature, and the exact balance change.
The command checks the source hash and accepts only local fixture inputs. Its presence does not establish a successful run. See the release evidence for completed runs.
Measured partitions#
Call resolveNativeTransport with the real payer, version, prefix instructions, and lookup tables.
Pass that transport to partitionInstructionsByWireSize.
Each returned wireBytes includes prefix instructions and signature slots.
The returned instructions omit the prefix. Add it exactly once during construction.
Keep dependency order. Journal each signed partition separately.
Do not start the next dependent partition while the previous result is unknown.
Redemption restart#
Save the original ordered instruction identities from getRedeemInstructionIdentity.
Save the completed prefix and the pending instruction's signatures.
Keep this recovery record in the same atomic persistence document as the transaction-attempt journal.
The transaction-attempt journal must record the signature before dispatch.
If the return-data request fails, keep that signature as pending.
Call reconcilePendingRedeemProgress with the saved original context.
Supply finalized return data from the expected program.
The failure classifier must accept only authenticated finalized failures.
An RPC exception is not an authenticated finalized failure.
| Result | Next action |
|---|---|
unknown | Keep the saved progress. Stop new sends. |
completed | Before you continue, save the completed prefix. |
more | Save active progress. Reconcile the result, then continue the same instruction. |
failed | Save the failure result. Check authorization before you make another attempt. |
none | Check the stored plan before a new send. |
Pass the authenticated completed prefix to sendResumableRedeemSequence.
A suffix plan must keep the full original identities and its global index offset.
Do not send completed instructions again. Do not use changed holdings as proof of completion.
Run packages/core/src/__tests__/resumable-redeem.test.ts for partial progress, malformed metadata, and interrupted sequence fixtures.
Both tutorials use packages/core/examples/14-resumable-redemption.ts for persistent recovery.
It saves the original plan, completed prefix, active instruction, page count, and pending signature.
The plan identifies the wallet, cluster, program, and market.
Before the adapter sends a transaction, it saves the signed transaction and its pending page in one atomic update.
The shared session saves the reviewed plan before the user approves it.
redeem-approve records the exact approved digest.
After a restart, redeem loads that original plan. It does not calculate a new amount from current balances.
An approved unfinished plan blocks a new plan. Missing finalized metadata also blocks a new plan. The approved page budget limits the number of signed pages.
Each page has a deterministic memo that identifies that page. Thus, two pages have different signed messages even when they use the same blockhash.
Run bun run --cwd packages/core vitest run src/__tests__/durable-redemption-example.test.ts src/__tests__/browser-tutorial-example.test.ts for persistent partial pages, lost acknowledgements, missing metadata, identical-wire rebroadcast, failed writes, wrong authorization, finalized failure, page limits, browser persistence, and wallet boundary fixtures.