@lifi/sdk-provider-solana 4.0.6 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +116 -0
- package/dist/cjs/actions/sendAndConfirmBundle.d.ts +18 -25
- package/dist/cjs/actions/sendAndConfirmBundle.js +33 -54
- package/dist/cjs/actions/sendAndConfirmBundle.js.map +1 -1
- package/dist/cjs/actions/sendAndConfirmTransaction.d.ts +14 -22
- package/dist/cjs/actions/sendAndConfirmTransaction.js +38 -55
- package/dist/cjs/actions/sendAndConfirmTransaction.js.map +1 -1
- package/dist/cjs/confirmation/abortableSleep.d.ts +19 -0
- package/dist/cjs/confirmation/abortableSleep.js +32 -0
- package/dist/cjs/confirmation/abortableSleep.js.map +1 -0
- package/dist/cjs/confirmation/confirmBundle.d.ts +43 -0
- package/dist/cjs/confirmation/confirmBundle.js +57 -0
- package/dist/cjs/confirmation/confirmBundle.js.map +1 -0
- package/dist/cjs/confirmation/confirmSignature.d.ts +29 -0
- package/dist/cjs/confirmation/confirmSignature.js +66 -0
- package/dist/cjs/confirmation/confirmSignature.js.map +1 -0
- package/dist/cjs/confirmation/createConfirmationDeadline.d.ts +51 -0
- package/dist/cjs/confirmation/createConfirmationDeadline.js +101 -0
- package/dist/cjs/confirmation/createConfirmationDeadline.js.map +1 -0
- package/dist/cjs/confirmation/pollUntilDeadline.d.ts +58 -0
- package/dist/cjs/confirmation/pollUntilDeadline.js +97 -0
- package/dist/cjs/confirmation/pollUntilDeadline.js.map +1 -0
- package/dist/cjs/confirmation/raceRpcs.d.ts +26 -0
- package/dist/cjs/confirmation/raceRpcs.js +93 -0
- package/dist/cjs/confirmation/raceRpcs.js.map +1 -0
- package/dist/cjs/confirmation/types.d.ts +18 -0
- package/dist/cjs/confirmation/types.js +9 -0
- package/dist/cjs/confirmation/types.js.map +1 -0
- package/dist/cjs/core/tasks/SolanaJitoWaitForTransactionTask.js +30 -9
- package/dist/cjs/core/tasks/SolanaJitoWaitForTransactionTask.js.map +1 -1
- package/dist/cjs/core/tasks/SolanaSignAndExecuteTask.js +5 -1
- package/dist/cjs/core/tasks/SolanaSignAndExecuteTask.js.map +1 -1
- package/dist/cjs/core/tasks/SolanaStandardWaitForTransactionTask.js +20 -7
- package/dist/cjs/core/tasks/SolanaStandardWaitForTransactionTask.js.map +1 -1
- package/dist/cjs/core/tasks/readSignature.d.ts +17 -0
- package/dist/cjs/core/tasks/readSignature.js +26 -0
- package/dist/cjs/core/tasks/readSignature.js.map +1 -0
- package/dist/cjs/core/tasks/unwrapConfirmation.d.ts +25 -0
- package/dist/cjs/core/tasks/unwrapConfirmation.js +24 -0
- package/dist/cjs/core/tasks/unwrapConfirmation.js.map +1 -0
- package/dist/cjs/rpc/jito/api/getBundleStatuses.d.ts +4 -2
- package/dist/cjs/rpc/registry.d.ts +37 -11
- package/dist/cjs/rpc/registry.js +103 -18
- package/dist/cjs/rpc/registry.js.map +1 -1
- package/dist/cjs/rpc/utils.js +1 -1
- package/dist/cjs/rpc/utils.js.map +1 -1
- package/dist/cjs/utils/KeypairWalletAdapter.js +10 -4
- package/dist/cjs/utils/KeypairWalletAdapter.js.map +1 -1
- package/dist/cjs/utils/getTransactionLifetime.d.ts +21 -0
- package/dist/cjs/utils/getTransactionLifetime.js +28 -0
- package/dist/cjs/utils/getTransactionLifetime.js.map +1 -0
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/version.js.map +1 -1
- package/dist/esm/actions/sendAndConfirmBundle.d.ts +18 -25
- package/dist/esm/actions/sendAndConfirmBundle.d.ts.map +1 -1
- package/dist/esm/actions/sendAndConfirmBundle.js +34 -55
- package/dist/esm/actions/sendAndConfirmBundle.js.map +1 -1
- package/dist/esm/actions/sendAndConfirmTransaction.d.ts +14 -22
- package/dist/esm/actions/sendAndConfirmTransaction.d.ts.map +1 -1
- package/dist/esm/actions/sendAndConfirmTransaction.js +38 -55
- package/dist/esm/actions/sendAndConfirmTransaction.js.map +1 -1
- package/dist/esm/confirmation/abortableSleep.d.ts +19 -0
- package/dist/esm/confirmation/abortableSleep.d.ts.map +1 -0
- package/dist/esm/confirmation/abortableSleep.js +31 -0
- package/dist/esm/confirmation/abortableSleep.js.map +1 -0
- package/dist/esm/confirmation/confirmBundle.d.ts +43 -0
- package/dist/esm/confirmation/confirmBundle.d.ts.map +1 -0
- package/dist/esm/confirmation/confirmBundle.js +55 -0
- package/dist/esm/confirmation/confirmBundle.js.map +1 -0
- package/dist/esm/confirmation/confirmSignature.d.ts +29 -0
- package/dist/esm/confirmation/confirmSignature.d.ts.map +1 -0
- package/dist/esm/confirmation/confirmSignature.js +64 -0
- package/dist/esm/confirmation/confirmSignature.js.map +1 -0
- package/dist/esm/confirmation/createConfirmationDeadline.d.ts +51 -0
- package/dist/esm/confirmation/createConfirmationDeadline.d.ts.map +1 -0
- package/dist/esm/confirmation/createConfirmationDeadline.js +93 -0
- package/dist/esm/confirmation/createConfirmationDeadline.js.map +1 -0
- package/dist/esm/confirmation/pollUntilDeadline.d.ts +58 -0
- package/dist/esm/confirmation/pollUntilDeadline.d.ts.map +1 -0
- package/dist/esm/confirmation/pollUntilDeadline.js +93 -0
- package/dist/esm/confirmation/pollUntilDeadline.js.map +1 -0
- package/dist/esm/confirmation/raceRpcs.d.ts +26 -0
- package/dist/esm/confirmation/raceRpcs.d.ts.map +1 -0
- package/dist/esm/confirmation/raceRpcs.js +92 -0
- package/dist/esm/confirmation/raceRpcs.js.map +1 -0
- package/dist/esm/confirmation/types.d.ts +18 -0
- package/dist/esm/confirmation/types.d.ts.map +1 -0
- package/dist/esm/confirmation/types.js +8 -0
- package/dist/esm/confirmation/types.js.map +1 -0
- package/dist/esm/core/tasks/SolanaJitoWaitForTransactionTask.d.ts.map +1 -1
- package/dist/esm/core/tasks/SolanaJitoWaitForTransactionTask.js +30 -9
- package/dist/esm/core/tasks/SolanaJitoWaitForTransactionTask.js.map +1 -1
- package/dist/esm/core/tasks/SolanaSignAndExecuteTask.js +5 -1
- package/dist/esm/core/tasks/SolanaSignAndExecuteTask.js.map +1 -1
- package/dist/esm/core/tasks/SolanaStandardWaitForTransactionTask.d.ts.map +1 -1
- package/dist/esm/core/tasks/SolanaStandardWaitForTransactionTask.js +20 -7
- package/dist/esm/core/tasks/SolanaStandardWaitForTransactionTask.js.map +1 -1
- package/dist/esm/core/tasks/readSignature.d.ts +17 -0
- package/dist/esm/core/tasks/readSignature.d.ts.map +1 -0
- package/dist/esm/core/tasks/readSignature.js +25 -0
- package/dist/esm/core/tasks/readSignature.js.map +1 -0
- package/dist/esm/core/tasks/unwrapConfirmation.d.ts +25 -0
- package/dist/esm/core/tasks/unwrapConfirmation.d.ts.map +1 -0
- package/dist/esm/core/tasks/unwrapConfirmation.js +23 -0
- package/dist/esm/core/tasks/unwrapConfirmation.js.map +1 -0
- package/dist/esm/rpc/jito/api/getBundleStatuses.d.ts +4 -2
- package/dist/esm/rpc/jito/api/getBundleStatuses.d.ts.map +1 -1
- package/dist/esm/rpc/registry.d.ts +37 -11
- package/dist/esm/rpc/registry.d.ts.map +1 -1
- package/dist/esm/rpc/registry.js +102 -19
- package/dist/esm/rpc/registry.js.map +1 -1
- package/dist/esm/rpc/utils.js +1 -1
- package/dist/esm/rpc/utils.js.map +1 -1
- package/dist/esm/utils/KeypairWalletAdapter.d.ts.map +1 -1
- package/dist/esm/utils/KeypairWalletAdapter.js +11 -5
- package/dist/esm/utils/KeypairWalletAdapter.js.map +1 -1
- package/dist/esm/utils/getTransactionLifetime.d.ts +21 -0
- package/dist/esm/utils/getTransactionLifetime.d.ts.map +1 -0
- package/dist/esm/utils/getTransactionLifetime.js +27 -0
- package/dist/esm/utils/getTransactionLifetime.js.map +1 -0
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/package.json +4 -4
- package/src/actions/sendAndConfirmBundle.ts +82 -142
- package/src/actions/sendAndConfirmTransaction.ts +82 -134
- package/src/confirmation/abortableSleep.ts +30 -0
- package/src/confirmation/confirmBundle.ts +121 -0
- package/src/confirmation/confirmSignature.ts +113 -0
- package/src/confirmation/createConfirmationDeadline.ts +174 -0
- package/src/confirmation/pollUntilDeadline.ts +182 -0
- package/src/confirmation/raceRpcs.ts +135 -0
- package/src/confirmation/types.ts +23 -0
- package/src/core/tasks/SolanaJitoWaitForTransactionTask.ts +49 -16
- package/src/core/tasks/SolanaSignAndExecuteTask.ts +15 -0
- package/src/core/tasks/SolanaStandardWaitForTransactionTask.ts +28 -17
- package/src/core/tasks/readSignature.ts +29 -0
- package/src/core/tasks/unwrapConfirmation.ts +59 -0
- package/src/rpc/jito/api/getBundleStatuses.ts +4 -2
- package/src/rpc/registry.ts +183 -25
- package/src/rpc/utils.ts +5 -2
- package/src/utils/KeypairWalletAdapter.ts +34 -9
- package/src/utils/getTransactionLifetime.ts +38 -0
- package/src/version.ts +1 -1
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
//#region src/confirmation/createConfirmationDeadline.ts
|
|
2
|
+
/** Give-up point for a branch's polling. Read between iterations only, so a
|
|
3
|
+
* hung RPC call needs `BRANCH_TIMEOUT_MS` to close the gap. */
|
|
4
|
+
const CONFIRMATION_TIMEOUT_MS = 9e4;
|
|
5
|
+
/** Head-room for the final probe after the deadline.
|
|
6
|
+
* `STATUS_RETRY_BACKOFF_CAP_MS` must stay below it. */
|
|
7
|
+
const FINAL_PROBE_MARGIN_MS = 5e3;
|
|
8
|
+
/** Hard bound on a branch, in-flight requests included. Above the ceiling so
|
|
9
|
+
* an abort cannot pre-empt the final probe. */
|
|
10
|
+
const BRANCH_TIMEOUT_MS = 95e3;
|
|
11
|
+
/** How long a healthy-but-lagging node may need to catch up. A premise, not a
|
|
12
|
+
* knob: `isBlockhashValid` answers `false` for lag and for death alike, so no
|
|
13
|
+
* verdict may land inside this window. */
|
|
14
|
+
const NODE_LAG_WINDOW_MS = 12e3;
|
|
15
|
+
/** Gap between `isBlockhashValid` probes. Spacing them is what makes the
|
|
16
|
+
* consecutive-`false` rule meaningful: quantized to the 400 ms tick, probes
|
|
17
|
+
* land at 0.4/7.6/14.8 s, so no verdict lands inside `NODE_LAG_WINDOW_MS`. */
|
|
18
|
+
const EXPIRY_PROBE_INTERVAL_MS = 7e3;
|
|
19
|
+
/** Consecutive `false` results before a blockhash is believed dead. Derived so
|
|
20
|
+
* a change to either premise moves it automatically; `+ 2` keeps the
|
|
21
|
+
* inequality strict when the window divides exactly. */
|
|
22
|
+
const EXPIRY_CONFIRMATIONS = Math.floor(NODE_LAG_WINDOW_MS / EXPIRY_PROBE_INTERVAL_MS) + 2;
|
|
23
|
+
/** Probe failures per blockhash before that blockhash stops being probed.
|
|
24
|
+
* Prober-only; the status pollers have `MAX_STATUS_READ_SILENCE_MS`. */
|
|
25
|
+
const MAX_PROBE_ERRORS = 5;
|
|
26
|
+
/**
|
|
27
|
+
* Owns every "should I stop polling?" decision.
|
|
28
|
+
*
|
|
29
|
+
* Never reads `getBlockHeight`: at least one default LI.FI RPC answers it with
|
|
30
|
+
* the slot number, making any `lastValidBlockHeight` comparison false on its
|
|
31
|
+
* first evaluation.
|
|
32
|
+
*/
|
|
33
|
+
function createConfirmationDeadline(options) {
|
|
34
|
+
const { lifetimes, rpc } = options;
|
|
35
|
+
const now = options.now ?? Date.now;
|
|
36
|
+
const startedAt = now();
|
|
37
|
+
const blockhashLifetimes = lifetimes.filter((lifetime) => lifetime.kind === "blockhash");
|
|
38
|
+
const blockhashes = lifetimes.length > 0 && blockhashLifetimes.length === lifetimes.length ? [...new Set(blockhashLifetimes.map((lifetime) => lifetime.blockhash))] : [];
|
|
39
|
+
const expiredStreaks = /* @__PURE__ */ new Map();
|
|
40
|
+
const errorStreaks = /* @__PURE__ */ new Map();
|
|
41
|
+
const probeable = new Set(blockhashes);
|
|
42
|
+
let lastProbeAt;
|
|
43
|
+
/** Derived, not latched: a blockhash that reads valid again zeroes its
|
|
44
|
+
* streak and clears the verdict with it. */
|
|
45
|
+
const isExpired = () => {
|
|
46
|
+
for (const streak of expiredStreaks.values()) if (streak >= EXPIRY_CONFIRMATIONS) return true;
|
|
47
|
+
return false;
|
|
48
|
+
};
|
|
49
|
+
return {
|
|
50
|
+
reached() {
|
|
51
|
+
if (now() - startedAt >= 9e4) return true;
|
|
52
|
+
return isExpired();
|
|
53
|
+
},
|
|
54
|
+
async tick(signal) {
|
|
55
|
+
if (probeable.size === 0 || signal.aborted) return;
|
|
56
|
+
const probeAt = now();
|
|
57
|
+
if (lastProbeAt !== void 0 && probeAt - lastProbeAt < 7e3) return;
|
|
58
|
+
lastProbeAt = probeAt;
|
|
59
|
+
const active = [...probeable];
|
|
60
|
+
const probes = await Promise.allSettled(active.map(async (blockhash) => {
|
|
61
|
+
return (await rpc.isBlockhashValid(blockhash, { commitment: "confirmed" }).send({ abortSignal: signal })).value;
|
|
62
|
+
}));
|
|
63
|
+
const recordFailedProbe = (blockhash) => {
|
|
64
|
+
expiredStreaks.set(blockhash, 0);
|
|
65
|
+
const errors = (errorStreaks.get(blockhash) ?? 0) + 1;
|
|
66
|
+
errorStreaks.set(blockhash, errors);
|
|
67
|
+
if (errors >= 5) probeable.delete(blockhash);
|
|
68
|
+
};
|
|
69
|
+
probes.forEach((probe, index) => {
|
|
70
|
+
const blockhash = active[index];
|
|
71
|
+
if (probe.status === "rejected") {
|
|
72
|
+
recordFailedProbe(blockhash);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (probe.value === true) {
|
|
76
|
+
errorStreaks.set(blockhash, 0);
|
|
77
|
+
expiredStreaks.set(blockhash, 0);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (probe.value === false) {
|
|
81
|
+
errorStreaks.set(blockhash, 0);
|
|
82
|
+
expiredStreaks.set(blockhash, (expiredStreaks.get(blockhash) ?? 0) + 1);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
recordFailedProbe(blockhash);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
//#endregion
|
|
91
|
+
export { BRANCH_TIMEOUT_MS, CONFIRMATION_TIMEOUT_MS, EXPIRY_CONFIRMATIONS, EXPIRY_PROBE_INTERVAL_MS, FINAL_PROBE_MARGIN_MS, MAX_PROBE_ERRORS, NODE_LAG_WINDOW_MS, createConfirmationDeadline };
|
|
92
|
+
|
|
93
|
+
//# sourceMappingURL=createConfirmationDeadline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createConfirmationDeadline.js","names":[],"sources":["../../../src/confirmation/createConfirmationDeadline.ts"],"sourcesContent":["import type { Blockhash } from '@solana/kit'\nimport type { SolanaRpcType } from '../rpc/types.js'\nimport type { TransactionLifetime } from '../utils/getTransactionLifetime.js'\n\n/** Give-up point for a branch's polling. Read between iterations only, so a\n * hung RPC call needs `BRANCH_TIMEOUT_MS` to close the gap. */\nexport const CONFIRMATION_TIMEOUT_MS = 90_000\n/** Head-room for the final probe after the deadline.\n * `STATUS_RETRY_BACKOFF_CAP_MS` must stay below it. */\nexport const FINAL_PROBE_MARGIN_MS = 5_000\n/** Hard bound on a branch, in-flight requests included. Above the ceiling so\n * an abort cannot pre-empt the final probe. */\nexport const BRANCH_TIMEOUT_MS: number =\n CONFIRMATION_TIMEOUT_MS + FINAL_PROBE_MARGIN_MS\n/** How long a healthy-but-lagging node may need to catch up. A premise, not a\n * knob: `isBlockhashValid` answers `false` for lag and for death alike, so no\n * verdict may land inside this window. */\nexport const NODE_LAG_WINDOW_MS = 12_000\n/** Gap between `isBlockhashValid` probes. Spacing them is what makes the\n * consecutive-`false` rule meaningful: quantized to the 400 ms tick, probes\n * land at 0.4/7.6/14.8 s, so no verdict lands inside `NODE_LAG_WINDOW_MS`. */\nexport const EXPIRY_PROBE_INTERVAL_MS = 7_000\n/** Consecutive `false` results before a blockhash is believed dead. Derived so\n * a change to either premise moves it automatically; `+ 2` keeps the\n * inequality strict when the window divides exactly. */\nexport const EXPIRY_CONFIRMATIONS: number =\n Math.floor(NODE_LAG_WINDOW_MS / EXPIRY_PROBE_INTERVAL_MS) + 2\n/** Probe failures per blockhash before that blockhash stops being probed.\n * Prober-only; the status pollers have `MAX_STATUS_READ_SILENCE_MS`. */\nexport const MAX_PROBE_ERRORS = 5\n\n/** Structural, so one implementation serves both the Solana and Jito RPC. */\nexport type BlockhashProbeRpc = Pick<SolanaRpcType, 'isBlockhashValid'>\n\nexport interface ConfirmationDeadline {\n /** Checked at the top of every poll iteration. */\n reached(): boolean\n /** Advances the policy; never throws. Probes at most once per\n * `EXPIRY_PROBE_INTERVAL_MS`. */\n tick(signal: AbortSignal): Promise<void>\n}\n\n/**\n * Owns every \"should I stop polling?\" decision.\n *\n * Never reads `getBlockHeight`: at least one default LI.FI RPC answers it with\n * the slot number, making any `lastValidBlockHeight` comparison false on its\n * first evaluation.\n */\nexport function createConfirmationDeadline(options: {\n lifetimes: TransactionLifetime[]\n rpc: BlockhashProbeRpc\n now?: () => number\n}): ConfirmationDeadline {\n const { lifetimes, rpc } = options\n const now = options.now ?? Date.now\n const startedAt = now()\n\n const blockhashLifetimes = lifetimes.filter(\n (\n lifetime\n ): lifetime is Extract<TransactionLifetime, { kind: 'blockhash' }> =>\n lifetime.kind === 'blockhash'\n )\n // A single non-blockhash lifetime disables the early exit for the whole set:\n // we cannot know when such a transaction stops being landable.\n const allProbeable =\n lifetimes.length > 0 && blockhashLifetimes.length === lifetimes.length\n const blockhashes: Blockhash[] = allProbeable\n ? [...new Set(blockhashLifetimes.map((lifetime) => lifetime.blockhash))]\n : []\n\n // Keyed by blockhash: expiry is a property of a blockhash, not of the set.\n const expiredStreaks = new Map<Blockhash, number>()\n // Keyed for the same reason: a sibling's broken probe is not evidence about\n // this blockhash, so it must not spend this blockhash's error budget.\n const errorStreaks = new Map<Blockhash, number>()\n // The blockhashes still worth asking about. One leaves this set after\n // MAX_PROBE_ERRORS failures of its own; the others keep being probed.\n const probeable = new Set<Blockhash>(blockhashes)\n let lastProbeAt: number | undefined\n\n /** Derived, not latched: a blockhash that reads valid again zeroes its\n * streak and clears the verdict with it. */\n const isExpired = (): boolean => {\n for (const streak of expiredStreaks.values()) {\n if (streak >= EXPIRY_CONFIRMATIONS) {\n return true\n }\n }\n return false\n }\n\n return {\n reached(): boolean {\n const elapsed = now() - startedAt\n if (elapsed >= CONFIRMATION_TIMEOUT_MS) {\n return true\n }\n return isExpired()\n },\n async tick(signal: AbortSignal): Promise<void> {\n if (probeable.size === 0 || signal.aborted) {\n return\n }\n // The cadence is wall-clock, not iteration count, and it uses the\n // injected `now` so the policy stays testable without timers.\n const probeAt = now()\n if (\n lastProbeAt !== undefined &&\n probeAt - lastProbeAt < EXPIRY_PROBE_INTERVAL_MS\n ) {\n return\n }\n lastProbeAt = probeAt\n // `allSettled`, not `all`: `all` rejects on the first failure and\n // discards answers the other probes already produced. All state is keyed\n // by blockhash, so one broken probe cannot disable the early exit for\n // the rest.\n const active = [...probeable]\n const probes = await Promise.allSettled(\n active.map(async (blockhash) => {\n const result = await rpc\n .isBlockhashValid(blockhash, { commitment: 'confirmed' })\n .send({ abortSignal: signal })\n return result.value\n })\n )\n\n // A read that produced no usable answer says nothing about this\n // blockhash: it must never spend the expiry streak, only the error\n // budget. Shared by a rejected probe and by a fulfilled one whose\n // response carried no boolean.\n const recordFailedProbe = (blockhash: Blockhash): void => {\n expiredStreaks.set(blockhash, 0)\n const errors = (errorStreaks.get(blockhash) ?? 0) + 1\n errorStreaks.set(blockhash, errors)\n if (errors >= MAX_PROBE_ERRORS) {\n // Degrade to ceiling-only for this blockhash.\n probeable.delete(blockhash)\n }\n }\n\n probes.forEach((probe, index) => {\n const blockhash = active[index]\n\n if (probe.status === 'rejected') {\n recordFailedProbe(blockhash)\n return\n }\n\n // `=== true` / `=== false`, never truthiness: a response carrying no\n // `value` is not a `false`, and reading it as one is the only coercion\n // here that can invent an expiry.\n if (probe.value === true) {\n errorStreaks.set(blockhash, 0)\n expiredStreaks.set(blockhash, 0)\n return\n }\n\n if (probe.value === false) {\n errorStreaks.set(blockhash, 0)\n expiredStreaks.set(\n blockhash,\n (expiredStreaks.get(blockhash) ?? 0) + 1\n )\n return\n }\n\n recordFailedProbe(blockhash)\n })\n },\n }\n}\n"],"mappings":";;;AAMA,MAAa,0BAA0B;;;AAGvC,MAAa,wBAAwB;;;AAGrC,MAAa,oBACX;;;;AAIF,MAAa,qBAAqB;;;;AAIlC,MAAa,2BAA2B;;;;AAIxC,MAAa,uBACX,KAAK,MAAM,qBAAqB,wBAAwB,IAAI;;;AAG9D,MAAa,mBAAmB;;;;;;;;AAoBhC,SAAgB,2BAA2B,SAIlB;CACvB,MAAM,EAAE,WAAW,QAAQ;CAC3B,MAAM,MAAM,QAAQ,OAAO,KAAK;CAChC,MAAM,YAAY,IAAI;CAEtB,MAAM,qBAAqB,UAAU,QAEjC,aAEA,SAAS,SAAS,WACtB;CAKA,MAAM,cADJ,UAAU,SAAS,KAAK,mBAAmB,WAAW,UAAU,SAE9D,CAAC,GAAG,IAAI,IAAI,mBAAmB,KAAK,aAAa,SAAS,SAAS,CAAC,CAAC,IACrE,CAAC;CAGL,MAAM,iCAAiB,IAAI,IAAuB;CAGlD,MAAM,+BAAe,IAAI,IAAuB;CAGhD,MAAM,YAAY,IAAI,IAAe,WAAW;CAChD,IAAI;;;CAIJ,MAAM,kBAA2B;EAC/B,KAAK,MAAM,UAAU,eAAe,OAAO,GACzC,IAAI,UAAU,sBACZ,OAAO;EAGX,OAAO;CACT;CAEA,OAAO;EACL,UAAmB;GAEjB,IADgB,IAAI,IAAI,aAAA,KAEtB,OAAO;GAET,OAAO,UAAU;EACnB;EACA,MAAM,KAAK,QAAoC;GAC7C,IAAI,UAAU,SAAS,KAAK,OAAO,SACjC;GAIF,MAAM,UAAU,IAAI;GACpB,IACE,gBAAgB,KAAA,KAChB,UAAU,cAAA,KAEV;GAEF,cAAc;GAKd,MAAM,SAAS,CAAC,GAAG,SAAS;GAC5B,MAAM,SAAS,MAAM,QAAQ,WAC3B,OAAO,IAAI,OAAO,cAAc;IAI9B,QAAO,MAHc,IAClB,iBAAiB,WAAW,EAAE,YAAY,YAAY,CAAC,CAAC,CACxD,KAAK,EAAE,aAAa,OAAO,CAAC,EAAA,CACjB;GAChB,CAAC,CACH;GAMA,MAAM,qBAAqB,cAA+B;IACxD,eAAe,IAAI,WAAW,CAAC;IAC/B,MAAM,UAAU,aAAa,IAAI,SAAS,KAAK,KAAK;IACpD,aAAa,IAAI,WAAW,MAAM;IAClC,IAAI,UAAA,GAEF,UAAU,OAAO,SAAS;GAE9B;GAEA,OAAO,SAAS,OAAO,UAAU;IAC/B,MAAM,YAAY,OAAO;IAEzB,IAAI,MAAM,WAAW,YAAY;KAC/B,kBAAkB,SAAS;KAC3B;IACF;IAKA,IAAI,MAAM,UAAU,MAAM;KACxB,aAAa,IAAI,WAAW,CAAC;KAC7B,eAAe,IAAI,WAAW,CAAC;KAC/B;IACF;IAEA,IAAI,MAAM,UAAU,OAAO;KACzB,aAAa,IAAI,WAAW,CAAC;KAC7B,eAAe,IACb,YACC,eAAe,IAAI,SAAS,KAAK,KAAK,CACzC;KACA;IACF;IAEA,kBAAkB,SAAS;GAC7B,CAAC;EACH;CACF;AACF"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { ConfirmationOutcome } from "./types.js";
|
|
2
|
+
import { ConfirmationDeadline } from "./createConfirmationDeadline.js";
|
|
3
|
+
//#region src/confirmation/pollUntilDeadline.d.ts
|
|
4
|
+
/** Cadence of the detached deadline-advance loop. Independent of the
|
|
5
|
+
* status-poll interval, which each caller sets for its own rate limits. */
|
|
6
|
+
declare const DEADLINE_TICK_INTERVAL_MS = 400;
|
|
7
|
+
/** How long an endpoint may go without answering a status read before its
|
|
8
|
+
* branch gives up. Measured in wall-clock time, not in failures: a count is
|
|
9
|
+
* coupled to the backoff curve, and ten failures spanned only ~16.4 s, so a
|
|
10
|
+
* routine 20 s throttling window ended the branch 74 s inside the 90 s ceiling
|
|
11
|
+
* and reported an already-broadcast transaction as an outage. */
|
|
12
|
+
declare const MAX_STATUS_READ_SILENCE_MS = 3e4;
|
|
13
|
+
/** Ceiling on one backoff sleep. Squeezed between two bounds:
|
|
14
|
+
* - Above `BUNDLE_POLL_INTERVAL_MS`, the largest base interval any caller
|
|
15
|
+
* uses. At 2 s the two were equal, so `Math.max(pollIntervalMs, ...)` below
|
|
16
|
+
* returned the base interval for every failure count and the bundle path
|
|
17
|
+
* never backed off at all.
|
|
18
|
+
* - Far enough below `FINAL_PROBE_MARGIN_MS` to leave the final probe a
|
|
19
|
+
* usable window. A sleep straddling the ceiling delays that probe by up to
|
|
20
|
+
* the cap, so the window is the margin minus this value - 2 s here. `cap <
|
|
21
|
+
* margin` alone is not the constraint: 4 s satisfied it and left the probe
|
|
22
|
+
* 1 s, on the failing endpoints where the cap is reached and reads are
|
|
23
|
+
* slowest.
|
|
24
|
+
*
|
|
25
|
+
* The gap between the two bounds fits one doubling, so the bundle path's
|
|
26
|
+
* backoff is a single step rather than a curve. Widening it means raising
|
|
27
|
+
* `FINAL_PROBE_MARGIN_MS`, which lengthens the branch bound the SDK
|
|
28
|
+
* documents. */
|
|
29
|
+
declare const STATUS_RETRY_BACKOFF_CAP_MS = 3e3;
|
|
30
|
+
/**
|
|
31
|
+
* Polls one probe against one RPC until the deadline, and owns the verdict
|
|
32
|
+
* rules shared by the signature and bundle branches.
|
|
33
|
+
*
|
|
34
|
+
* `probe` resolves non-`null` for a confirmation, `null` for "answered, saw
|
|
35
|
+
* nothing", and rejects for a failed read. The deadline advances on a detached
|
|
36
|
+
* loop so a hung blockhash probe cannot stop status polling.
|
|
37
|
+
*/
|
|
38
|
+
declare function pollUntilDeadline<T>(options: {
|
|
39
|
+
deadline: ConfirmationDeadline;
|
|
40
|
+
signal: AbortSignal;
|
|
41
|
+
/** Sleep between two status reads that answered. */
|
|
42
|
+
pollIntervalMs: number;
|
|
43
|
+
/** One status read. `null` means it answered but saw no confirmation. */
|
|
44
|
+
probe: () => Promise<T | null>;
|
|
45
|
+
/** Names the read in error messages, e.g. 'signature status read'. */
|
|
46
|
+
read: string;
|
|
47
|
+
/** Names the thing being confirmed in error messages, e.g. 'transaction'. */
|
|
48
|
+
subject: string;
|
|
49
|
+
/** `true` when this RPC never accepted the broadcast. Read at verdict time,
|
|
50
|
+
* and only when the observation did not complete. */
|
|
51
|
+
neverBroadcast?: () => boolean;
|
|
52
|
+
/** Injectable clock, so the silence budget is testable without timers.
|
|
53
|
+
* Mirrors `createConfirmationDeadline`. */
|
|
54
|
+
now?: () => number;
|
|
55
|
+
}): Promise<ConfirmationOutcome<T>>;
|
|
56
|
+
//#endregion
|
|
57
|
+
export { DEADLINE_TICK_INTERVAL_MS, MAX_STATUS_READ_SILENCE_MS, STATUS_RETRY_BACKOFF_CAP_MS, pollUntilDeadline };
|
|
58
|
+
//# sourceMappingURL=pollUntilDeadline.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pollUntilDeadline.d.ts","names":[],"sources":["../../../src/confirmation/pollUntilDeadline.ts"],"mappings":";;;;;cAMa;;;;;;cAMA;;;;;;;;;;;;;;;;;cAiBA;;;;;;;;;iBAUS,kBAAkB,GAAG;EACzC,UAAU;EACV,QAAQ;;EAER;;EAEA,aAAa,QAAQ;;EAErB;;EAEA;;;EAGA;;;EAGA;IACE,QAAQ,oBAAoB"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { abortableSleep } from "./abortableSleep.js";
|
|
2
|
+
//#region src/confirmation/pollUntilDeadline.ts
|
|
3
|
+
/** Cadence of the detached deadline-advance loop. Independent of the
|
|
4
|
+
* status-poll interval, which each caller sets for its own rate limits. */
|
|
5
|
+
const DEADLINE_TICK_INTERVAL_MS = 400;
|
|
6
|
+
/** How long an endpoint may go without answering a status read before its
|
|
7
|
+
* branch gives up. Measured in wall-clock time, not in failures: a count is
|
|
8
|
+
* coupled to the backoff curve, and ten failures spanned only ~16.4 s, so a
|
|
9
|
+
* routine 20 s throttling window ended the branch 74 s inside the 90 s ceiling
|
|
10
|
+
* and reported an already-broadcast transaction as an outage. */
|
|
11
|
+
const MAX_STATUS_READ_SILENCE_MS = 3e4;
|
|
12
|
+
/** Ceiling on one backoff sleep. Squeezed between two bounds:
|
|
13
|
+
* - Above `BUNDLE_POLL_INTERVAL_MS`, the largest base interval any caller
|
|
14
|
+
* uses. At 2 s the two were equal, so `Math.max(pollIntervalMs, ...)` below
|
|
15
|
+
* returned the base interval for every failure count and the bundle path
|
|
16
|
+
* never backed off at all.
|
|
17
|
+
* - Far enough below `FINAL_PROBE_MARGIN_MS` to leave the final probe a
|
|
18
|
+
* usable window. A sleep straddling the ceiling delays that probe by up to
|
|
19
|
+
* the cap, so the window is the margin minus this value - 2 s here. `cap <
|
|
20
|
+
* margin` alone is not the constraint: 4 s satisfied it and left the probe
|
|
21
|
+
* 1 s, on the failing endpoints where the cap is reached and reads are
|
|
22
|
+
* slowest.
|
|
23
|
+
*
|
|
24
|
+
* The gap between the two bounds fits one doubling, so the bundle path's
|
|
25
|
+
* backoff is a single step rather than a curve. Widening it means raising
|
|
26
|
+
* `FINAL_PROBE_MARGIN_MS`, which lengthens the branch bound the SDK
|
|
27
|
+
* documents. */
|
|
28
|
+
const STATUS_RETRY_BACKOFF_CAP_MS = 3e3;
|
|
29
|
+
/**
|
|
30
|
+
* Polls one probe against one RPC until the deadline, and owns the verdict
|
|
31
|
+
* rules shared by the signature and bundle branches.
|
|
32
|
+
*
|
|
33
|
+
* `probe` resolves non-`null` for a confirmation, `null` for "answered, saw
|
|
34
|
+
* nothing", and rejects for a failed read. The deadline advances on a detached
|
|
35
|
+
* loop so a hung blockhash probe cannot stop status polling.
|
|
36
|
+
*/
|
|
37
|
+
async function pollUntilDeadline(options) {
|
|
38
|
+
const { deadline, signal, pollIntervalMs, probe, read, subject } = options;
|
|
39
|
+
const now = options.now ?? Date.now;
|
|
40
|
+
let settled = false;
|
|
41
|
+
(async () => {
|
|
42
|
+
while (!settled && !signal.aborted) {
|
|
43
|
+
await abortableSleep(400, signal);
|
|
44
|
+
if (settled || signal.aborted) break;
|
|
45
|
+
await deadline.tick(signal);
|
|
46
|
+
}
|
|
47
|
+
})().catch(() => {});
|
|
48
|
+
try {
|
|
49
|
+
let failures = 0;
|
|
50
|
+
let probeSucceeded = false;
|
|
51
|
+
let lastAnswerAt = now();
|
|
52
|
+
let deadlineReached = false;
|
|
53
|
+
while (!signal.aborted) {
|
|
54
|
+
if (deadline.reached()) {
|
|
55
|
+
deadlineReached = true;
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
const value = await probe();
|
|
60
|
+
failures = 0;
|
|
61
|
+
lastAnswerAt = now();
|
|
62
|
+
probeSucceeded = true;
|
|
63
|
+
if (value !== null) return {
|
|
64
|
+
kind: "confirmed",
|
|
65
|
+
value
|
|
66
|
+
};
|
|
67
|
+
} catch (error) {
|
|
68
|
+
failures += 1;
|
|
69
|
+
if (now() - lastAnswerAt >= 3e4) throw error;
|
|
70
|
+
}
|
|
71
|
+
const delay = failures === 0 ? pollIntervalMs : Math.max(pollIntervalMs, Math.min(pollIntervalMs * 2 ** failures, STATUS_RETRY_BACKOFF_CAP_MS));
|
|
72
|
+
await abortableSleep(delay, signal);
|
|
73
|
+
}
|
|
74
|
+
if (!signal.aborted) try {
|
|
75
|
+
const value = await probe();
|
|
76
|
+
probeSucceeded = true;
|
|
77
|
+
if (value !== null) return {
|
|
78
|
+
kind: "confirmed",
|
|
79
|
+
value
|
|
80
|
+
};
|
|
81
|
+
} catch (_) {}
|
|
82
|
+
if (probeSucceeded && deadlineReached) return { kind: "not-confirmed" };
|
|
83
|
+
if (options.neverBroadcast?.()) throw new Error(`Every ${subject} send to this RPC failed.`);
|
|
84
|
+
if (!probeSucceeded) throw new Error(`No ${read} against this RPC ever completed.`);
|
|
85
|
+
throw new Error(`This RPC stopped answering before a final ${read} could run.`);
|
|
86
|
+
} finally {
|
|
87
|
+
settled = true;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
//#endregion
|
|
91
|
+
export { DEADLINE_TICK_INTERVAL_MS, MAX_STATUS_READ_SILENCE_MS, STATUS_RETRY_BACKOFF_CAP_MS, pollUntilDeadline };
|
|
92
|
+
|
|
93
|
+
//# sourceMappingURL=pollUntilDeadline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pollUntilDeadline.js","names":[],"sources":["../../../src/confirmation/pollUntilDeadline.ts"],"sourcesContent":["import { abortableSleep } from './abortableSleep.js'\nimport type { ConfirmationDeadline } from './createConfirmationDeadline.js'\nimport type { ConfirmationOutcome } from './types.js'\n\n/** Cadence of the detached deadline-advance loop. Independent of the\n * status-poll interval, which each caller sets for its own rate limits. */\nexport const DEADLINE_TICK_INTERVAL_MS = 400\n/** How long an endpoint may go without answering a status read before its\n * branch gives up. Measured in wall-clock time, not in failures: a count is\n * coupled to the backoff curve, and ten failures spanned only ~16.4 s, so a\n * routine 20 s throttling window ended the branch 74 s inside the 90 s ceiling\n * and reported an already-broadcast transaction as an outage. */\nexport const MAX_STATUS_READ_SILENCE_MS = 30_000\n/** Ceiling on one backoff sleep. Squeezed between two bounds:\n * - Above `BUNDLE_POLL_INTERVAL_MS`, the largest base interval any caller\n * uses. At 2 s the two were equal, so `Math.max(pollIntervalMs, ...)` below\n * returned the base interval for every failure count and the bundle path\n * never backed off at all.\n * - Far enough below `FINAL_PROBE_MARGIN_MS` to leave the final probe a\n * usable window. A sleep straddling the ceiling delays that probe by up to\n * the cap, so the window is the margin minus this value - 2 s here. `cap <\n * margin` alone is not the constraint: 4 s satisfied it and left the probe\n * 1 s, on the failing endpoints where the cap is reached and reads are\n * slowest.\n *\n * The gap between the two bounds fits one doubling, so the bundle path's\n * backoff is a single step rather than a curve. Widening it means raising\n * `FINAL_PROBE_MARGIN_MS`, which lengthens the branch bound the SDK\n * documents. */\nexport const STATUS_RETRY_BACKOFF_CAP_MS = 3_000\n\n/**\n * Polls one probe against one RPC until the deadline, and owns the verdict\n * rules shared by the signature and bundle branches.\n *\n * `probe` resolves non-`null` for a confirmation, `null` for \"answered, saw\n * nothing\", and rejects for a failed read. The deadline advances on a detached\n * loop so a hung blockhash probe cannot stop status polling.\n */\nexport async function pollUntilDeadline<T>(options: {\n deadline: ConfirmationDeadline\n signal: AbortSignal\n /** Sleep between two status reads that answered. */\n pollIntervalMs: number\n /** One status read. `null` means it answered but saw no confirmation. */\n probe: () => Promise<T | null>\n /** Names the read in error messages, e.g. 'signature status read'. */\n read: string\n /** Names the thing being confirmed in error messages, e.g. 'transaction'. */\n subject: string\n /** `true` when this RPC never accepted the broadcast. Read at verdict time,\n * and only when the observation did not complete. */\n neverBroadcast?: () => boolean\n /** Injectable clock, so the silence budget is testable without timers.\n * Mirrors `createConfirmationDeadline`. */\n now?: () => number\n}): Promise<ConfirmationOutcome<T>> {\n const { deadline, signal, pollIntervalMs, probe, read, subject } = options\n const now = options.now ?? Date.now\n\n let settled = false\n\n // Advances the deadline independently of the status reads.\n const advancing = (async () => {\n while (!settled && !signal.aborted) {\n await abortableSleep(DEADLINE_TICK_INTERVAL_MS, signal)\n if (settled || signal.aborted) {\n break\n }\n await deadline.tick(signal)\n }\n })()\n advancing.catch(() => {})\n\n try {\n let failures = 0\n // Did this RPC ever answer? A `null` read still answered. Separates\n // \"polled and saw nothing\" from \"never got a word out of this endpoint\".\n let probeSucceeded = false\n // When a read last answered; the branch start until one does. A `null` read\n // counts as an answer - the endpoint is alive and says nothing.\n let lastAnswerAt = now()\n\n // Records WHY the loop ended, because the two reasons earn different\n // verdicts. Reaching the deadline is a complete observation; being aborted\n // mid-read is not. The final probe below is a bonus on top of a complete\n // observation, so losing it must not downgrade the verdict.\n let deadlineReached = false\n while (!signal.aborted) {\n if (deadline.reached()) {\n deadlineReached = true\n break\n }\n try {\n const value = await probe()\n failures = 0\n lastAnswerAt = now()\n probeSucceeded = true\n if (value !== null) {\n return { kind: 'confirmed', value }\n }\n } catch (error) {\n // `failures` still drives the backoff below; only the give-up rule is\n // time-based.\n failures += 1\n if (now() - lastAnswerAt >= MAX_STATUS_READ_SILENCE_MS) {\n throw error\n }\n }\n // Exponential backoff, so a throttling burst meets a falling rate. The\n // outer `max` stops the cap inverting it for a caller whose base\n // interval already exceeds the cap.\n const delay =\n failures === 0\n ? pollIntervalMs\n : Math.max(\n pollIntervalMs,\n Math.min(\n pollIntervalMs * 2 ** failures,\n STATUS_RETRY_BACKOFF_CAP_MS\n )\n )\n await abortableSleep(delay, signal)\n }\n\n // The status may have flipped between the last poll and the deadline\n // being reached.\n if (!signal.aborted) {\n try {\n const value = await probe()\n probeSucceeded = true\n if (value !== null) {\n return { kind: 'confirmed', value }\n }\n } catch (_) {\n // The loop already ran. One failed final probe is not evidence that\n // this RPC is unusable.\n }\n }\n\n // A completed observation outranks everything below: polled to its own\n // deadline and saw nothing. It stays ahead of the send-failure signal on\n // purpose - a throw here is bucketed as `rpc-unavailable` by `raceRpcs`,\n // which would discard a real observation and misreport a genuinely expired\n // transaction as an outage. The never-broadcast case is answered one level\n // up, in the actions, which know whether ANY branch accepted the send.\n //\n // Keyed on `deadlineReached`, not on `!signal.aborted`: the final probe is\n // a bonus on top of the observation, and the shared BRANCH_TIMEOUT_MS timer\n // can abort that probe in every branch at once. Reading the abort here\n // would discard every observation and report a fleet-wide expiry as an\n // outage.\n if (probeSucceeded && deadlineReached) {\n return { kind: 'not-confirmed' }\n }\n\n if (options.neverBroadcast?.()) {\n throw new Error(`Every ${subject} send to this RPC failed.`)\n }\n\n // Every read hung until the abort: an in-flight read never answers, so it\n // never renews `lastAnswerAt` and never throws either - the abort arrives\n // first. `not-confirmed` here would report a hung endpoint as an expiry.\n if (!probeSucceeded) {\n throw new Error(`No ${read} against this RPC ever completed.`)\n }\n\n // Exiting via `signal.aborted` means the final observation never\n // happened — an in-flight read held the loop until the abort cut it off.\n // An answer received early in the window must not stand in for one near\n // the deadline: a branch that answered once and then went dark has no\n // basis to call the subject of the read expired. (A branch aborted because another\n // RPC already confirmed also throws here; `raceRpcs` drops a losing\n // branch's error once its controller has aborted, so nothing is\n // misreported.)\n throw new Error(\n `This RPC stopped answering before a final ${read} could run.`\n )\n } finally {\n settled = true\n }\n}\n"],"mappings":";;;;AAMA,MAAa,4BAA4B;;;;;;AAMzC,MAAa,6BAA6B;;;;;;;;;;;;;;;;;AAiB1C,MAAa,8BAA8B;;;;;;;;;AAU3C,eAAsB,kBAAqB,SAiBP;CAClC,MAAM,EAAE,UAAU,QAAQ,gBAAgB,OAAO,MAAM,YAAY;CACnE,MAAM,MAAM,QAAQ,OAAO,KAAK;CAEhC,IAAI,UAAU;CAYd,CATmB,YAAY;EAC7B,OAAO,CAAC,WAAW,CAAC,OAAO,SAAS;GAClC,MAAM,eAAA,KAA0C,MAAM;GACtD,IAAI,WAAW,OAAO,SACpB;GAEF,MAAM,SAAS,KAAK,MAAM;EAC5B;CACF,EAAA,CACQ,CAAC,CAAC,YAAY,CAAC,CAAC;CAExB,IAAI;EACF,IAAI,WAAW;EAGf,IAAI,iBAAiB;EAGrB,IAAI,eAAe,IAAI;EAMvB,IAAI,kBAAkB;EACtB,OAAO,CAAC,OAAO,SAAS;GACtB,IAAI,SAAS,QAAQ,GAAG;IACtB,kBAAkB;IAClB;GACF;GACA,IAAI;IACF,MAAM,QAAQ,MAAM,MAAM;IAC1B,WAAW;IACX,eAAe,IAAI;IACnB,iBAAiB;IACjB,IAAI,UAAU,MACZ,OAAO;KAAE,MAAM;KAAa;IAAM;GAEtC,SAAS,OAAO;IAGd,YAAY;IACZ,IAAI,IAAI,IAAI,gBAAA,KACV,MAAM;GAEV;GAIA,MAAM,QACJ,aAAa,IACT,iBACA,KAAK,IACH,gBACA,KAAK,IACH,iBAAiB,KAAK,UACtB,2BACF,CACF;GACN,MAAM,eAAe,OAAO,MAAM;EACpC;EAIA,IAAI,CAAC,OAAO,SACV,IAAI;GACF,MAAM,QAAQ,MAAM,MAAM;GAC1B,iBAAiB;GACjB,IAAI,UAAU,MACZ,OAAO;IAAE,MAAM;IAAa;GAAM;EAEtC,SAAS,GAAG,CAGZ;EAeF,IAAI,kBAAkB,iBACpB,OAAO,EAAE,MAAM,gBAAgB;EAGjC,IAAI,QAAQ,iBAAiB,GAC3B,MAAM,IAAI,MAAM,SAAS,QAAQ,0BAA0B;EAM7D,IAAI,CAAC,gBACH,MAAM,IAAI,MAAM,MAAM,KAAK,kCAAkC;EAW/D,MAAM,IAAI,MACR,6CAA6C,KAAK,YACpD;CACF,UAAU;EACR,UAAU;CACZ;AACF"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ConfirmationOutcome } from "./types.js";
|
|
2
|
+
//#region src/confirmation/raceRpcs.d.ts
|
|
3
|
+
type RaceResult<T> = {
|
|
4
|
+
kind: "confirmed";
|
|
5
|
+
value: T;
|
|
6
|
+
} | {
|
|
7
|
+
kind: "not-confirmed";
|
|
8
|
+
errors: Error[];
|
|
9
|
+
} | {
|
|
10
|
+
kind: "rpc-unavailable";
|
|
11
|
+
errors: Error[];
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Runs `run` against every RPC in parallel and reports the first confirmation.
|
|
15
|
+
*
|
|
16
|
+
* Not `Promise.any`: it turns "polled and saw nothing" into a thrown sentinel,
|
|
17
|
+
* collapsing the difference between an expired transaction and an RPC that
|
|
18
|
+
* never answered - the defect that reported live swaps as `TransactionExpired`.
|
|
19
|
+
* `timeoutMs` is the caller's; this module holds no confirmation policy.
|
|
20
|
+
*/
|
|
21
|
+
declare function raceRpcs<Rpc, T>(rpcs: Rpc[], run: (rpc: Rpc, signal: AbortSignal) => Promise<ConfirmationOutcome<T>>, options: {
|
|
22
|
+
timeoutMs: number;
|
|
23
|
+
}): Promise<RaceResult<T>>;
|
|
24
|
+
//#endregion
|
|
25
|
+
export { RaceResult, raceRpcs };
|
|
26
|
+
//# sourceMappingURL=raceRpcs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"raceRpcs.d.ts","names":[],"sources":["../../../src/confirmation/raceRpcs.ts"],"mappings":";;KAEY,WAAW;EACjB;EAAmB,OAAO;;EAC1B;EAAuB,QAAQ;;EAC/B;EAAyB,QAAQ;;;;;;;;;;iBAmDjB,SAAS,KAAK,GAClC,MAAM,OACN,MAAM,KAAK,KAAK,QAAQ,gBAAgB,QAAQ,oBAAoB,KACpE;EAAW;IACV,QAAQ,WAAW"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
//#region src/confirmation/raceRpcs.ts
|
|
2
|
+
const toError = (reason) => reason instanceof Error ? reason : new Error(String(reason));
|
|
3
|
+
/**
|
|
4
|
+
* Aborts when `signal` aborts or `timeoutMs` elapses, whichever is first.
|
|
5
|
+
*
|
|
6
|
+
* Not `AbortSignal.any` + `AbortSignal.timeout`: both are Baseline March 2024,
|
|
7
|
+
* and a published SDK should not raise its runtime floor for a convenience one
|
|
8
|
+
* controller and one timer already cover. The caller's signal is never aborted
|
|
9
|
+
* here, so "caller aborted" and "timeout fired" stay distinguishable.
|
|
10
|
+
*/
|
|
11
|
+
function abortAfter(signal, timeoutMs) {
|
|
12
|
+
const linked = new AbortController();
|
|
13
|
+
const forward = () => linked.abort(signal.reason);
|
|
14
|
+
const timer = setTimeout(() => {
|
|
15
|
+
linked.abort(/* @__PURE__ */ new Error(`This RPC did not answer within ${timeoutMs}ms.`));
|
|
16
|
+
}, timeoutMs);
|
|
17
|
+
timer.unref?.();
|
|
18
|
+
if (signal.aborted) forward();
|
|
19
|
+
else signal.addEventListener("abort", forward, { once: true });
|
|
20
|
+
return {
|
|
21
|
+
signal: linked.signal,
|
|
22
|
+
dispose: () => {
|
|
23
|
+
clearTimeout(timer);
|
|
24
|
+
signal.removeEventListener("abort", forward);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Runs `run` against every RPC in parallel and reports the first confirmation.
|
|
30
|
+
*
|
|
31
|
+
* Not `Promise.any`: it turns "polled and saw nothing" into a thrown sentinel,
|
|
32
|
+
* collapsing the difference between an expired transaction and an RPC that
|
|
33
|
+
* never answered - the defect that reported live swaps as `TransactionExpired`.
|
|
34
|
+
* `timeoutMs` is the caller's; this module holds no confirmation policy.
|
|
35
|
+
*/
|
|
36
|
+
async function raceRpcs(rpcs, run, options) {
|
|
37
|
+
if (rpcs.length === 0) return {
|
|
38
|
+
kind: "rpc-unavailable",
|
|
39
|
+
errors: []
|
|
40
|
+
};
|
|
41
|
+
const controller = new AbortController();
|
|
42
|
+
const branch = abortAfter(controller.signal, options.timeoutMs);
|
|
43
|
+
let resolveConfirmed;
|
|
44
|
+
const firstConfirmation = new Promise((resolve) => {
|
|
45
|
+
resolveConfirmed = resolve;
|
|
46
|
+
});
|
|
47
|
+
const settled = Promise.allSettled(rpcs.map(async (rpc) => {
|
|
48
|
+
const outcome = await run(rpc, branch.signal);
|
|
49
|
+
if (outcome.kind === "confirmed") {
|
|
50
|
+
resolveConfirmed?.(outcome.value);
|
|
51
|
+
controller.abort();
|
|
52
|
+
}
|
|
53
|
+
return outcome;
|
|
54
|
+
}));
|
|
55
|
+
const classify = (results) => {
|
|
56
|
+
let sawNotConfirmed = false;
|
|
57
|
+
const errors = [];
|
|
58
|
+
for (const entry of results) {
|
|
59
|
+
if (entry.status === "fulfilled") {
|
|
60
|
+
if (entry.value.kind === "confirmed") return {
|
|
61
|
+
kind: "confirmed",
|
|
62
|
+
value: entry.value.value
|
|
63
|
+
};
|
|
64
|
+
sawNotConfirmed = true;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (controller.signal.aborted) continue;
|
|
68
|
+
errors.push(toError(entry.reason));
|
|
69
|
+
}
|
|
70
|
+
if (sawNotConfirmed) return {
|
|
71
|
+
kind: "not-confirmed",
|
|
72
|
+
errors
|
|
73
|
+
};
|
|
74
|
+
return {
|
|
75
|
+
kind: "rpc-unavailable",
|
|
76
|
+
errors
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
try {
|
|
80
|
+
return await Promise.race([firstConfirmation.then((value) => ({
|
|
81
|
+
kind: "confirmed",
|
|
82
|
+
value
|
|
83
|
+
})), settled.then(classify)]);
|
|
84
|
+
} finally {
|
|
85
|
+
controller.abort();
|
|
86
|
+
branch.dispose();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
//#endregion
|
|
90
|
+
export { raceRpcs };
|
|
91
|
+
|
|
92
|
+
//# sourceMappingURL=raceRpcs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"raceRpcs.js","names":[],"sources":["../../../src/confirmation/raceRpcs.ts"],"sourcesContent":["import type { ConfirmationOutcome } from './types.js'\n\nexport type RaceResult<T> =\n | { kind: 'confirmed'; value: T }\n | { kind: 'not-confirmed'; errors: Error[] }\n | { kind: 'rpc-unavailable'; errors: Error[] }\n\nconst toError = (reason: unknown): Error =>\n reason instanceof Error ? reason : new Error(String(reason))\n\n/**\n * Aborts when `signal` aborts or `timeoutMs` elapses, whichever is first.\n *\n * Not `AbortSignal.any` + `AbortSignal.timeout`: both are Baseline March 2024,\n * and a published SDK should not raise its runtime floor for a convenience one\n * controller and one timer already cover. The caller's signal is never aborted\n * here, so \"caller aborted\" and \"timeout fired\" stay distinguishable.\n */\nfunction abortAfter(\n signal: AbortSignal,\n timeoutMs: number\n): { signal: AbortSignal; dispose: () => void } {\n const linked = new AbortController()\n const forward = (): void => linked.abort(signal.reason)\n\n const timer = setTimeout(() => {\n linked.abort(new Error(`This RPC did not answer within ${timeoutMs}ms.`))\n }, timeoutMs)\n // A pending timer keeps Node's event loop alive. `dispose` clears it; the\n // unref only covers a path that skips `dispose`.\n const handle = timer as unknown as { unref?: () => void }\n handle.unref?.()\n\n if (signal.aborted) {\n forward()\n } else {\n signal.addEventListener('abort', forward, { once: true })\n }\n\n return {\n signal: linked.signal,\n dispose: (): void => {\n clearTimeout(timer)\n signal.removeEventListener('abort', forward)\n },\n }\n}\n\n/**\n * Runs `run` against every RPC in parallel and reports the first confirmation.\n *\n * Not `Promise.any`: it turns \"polled and saw nothing\" into a thrown sentinel,\n * collapsing the difference between an expired transaction and an RPC that\n * never answered - the defect that reported live swaps as `TransactionExpired`.\n * `timeoutMs` is the caller's; this module holds no confirmation policy.\n */\nexport async function raceRpcs<Rpc, T>(\n rpcs: Rpc[],\n run: (rpc: Rpc, signal: AbortSignal) => Promise<ConfirmationOutcome<T>>,\n options: { timeoutMs: number }\n): Promise<RaceResult<T>> {\n if (rpcs.length === 0) {\n return { kind: 'rpc-unavailable', errors: [] }\n }\n\n const controller = new AbortController()\n // Kept distinct: `controller` means \"another branch confirmed\", the timeout\n // means \"this endpoint never answered\". The timeout aborts the linked signal\n // only.\n const branch = abortAfter(controller.signal, options.timeoutMs)\n\n let resolveConfirmed: ((value: T) => void) | undefined\n const firstConfirmation = new Promise<T>((resolve) => {\n resolveConfirmed = resolve\n })\n\n const settled = Promise.allSettled(\n rpcs.map(async (rpc) => {\n const outcome = await run(rpc, branch.signal)\n if (outcome.kind === 'confirmed') {\n resolveConfirmed?.(outcome.value)\n controller.abort()\n }\n return outcome\n })\n )\n\n const classify = (\n results: PromiseSettledResult<ConfirmationOutcome<T>>[]\n ): RaceResult<T> => {\n let sawNotConfirmed = false\n const errors: Error[] = []\n\n for (const entry of results) {\n if (entry.status === 'fulfilled') {\n // Unreachable today - `firstConfirmation` always wins - but keeps\n // `classify` correct if that structure changes.\n if (entry.value.kind === 'confirmed') {\n return { kind: 'confirmed', value: entry.value.value }\n }\n sawNotConfirmed = true\n continue\n }\n // Cancelled branches are not failures. A branch the timeout killed is,\n // so its error is collected.\n if (controller.signal.aborted) {\n continue\n }\n errors.push(toError(entry.reason))\n }\n\n // A completed observation outranks a thrown error, but the collected\n // errors still travel with it as the expiry's `cause`.\n if (sawNotConfirmed) {\n return { kind: 'not-confirmed', errors }\n }\n return { kind: 'rpc-unavailable', errors }\n }\n\n try {\n const result = await Promise.race([\n firstConfirmation.then(\n (value): RaceResult<T> => ({ kind: 'confirmed', value })\n ),\n settled.then(classify),\n ])\n\n return result\n } finally {\n // Cancels every in-flight branch on every path out, rejections included.\n // Must run before `dispose`, which detaches the listener carrying it.\n controller.abort()\n branch.dispose()\n }\n}\n"],"mappings":";AAOA,MAAM,WAAW,WACf,kBAAkB,QAAQ,SAAS,IAAI,MAAM,OAAO,MAAM,CAAC;;;;;;;;;AAU7D,SAAS,WACP,QACA,WAC8C;CAC9C,MAAM,SAAS,IAAI,gBAAgB;CACnC,MAAM,gBAAsB,OAAO,MAAM,OAAO,MAAM;CAEtD,MAAM,QAAQ,iBAAiB;EAC7B,OAAO,sBAAM,IAAI,MAAM,kCAAkC,UAAU,IAAI,CAAC;CAC1E,GAAG,SAAS;CAIZ,MAAO,QAAQ;CAEf,IAAI,OAAO,SACT,QAAQ;MAER,OAAO,iBAAiB,SAAS,SAAS,EAAE,MAAM,KAAK,CAAC;CAG1D,OAAO;EACL,QAAQ,OAAO;EACf,eAAqB;GACnB,aAAa,KAAK;GAClB,OAAO,oBAAoB,SAAS,OAAO;EAC7C;CACF;AACF;;;;;;;;;AAUA,eAAsB,SACpB,MACA,KACA,SACwB;CACxB,IAAI,KAAK,WAAW,GAClB,OAAO;EAAE,MAAM;EAAmB,QAAQ,CAAC;CAAE;CAG/C,MAAM,aAAa,IAAI,gBAAgB;CAIvC,MAAM,SAAS,WAAW,WAAW,QAAQ,QAAQ,SAAS;CAE9D,IAAI;CACJ,MAAM,oBAAoB,IAAI,SAAY,YAAY;EACpD,mBAAmB;CACrB,CAAC;CAED,MAAM,UAAU,QAAQ,WACtB,KAAK,IAAI,OAAO,QAAQ;EACtB,MAAM,UAAU,MAAM,IAAI,KAAK,OAAO,MAAM;EAC5C,IAAI,QAAQ,SAAS,aAAa;GAChC,mBAAmB,QAAQ,KAAK;GAChC,WAAW,MAAM;EACnB;EACA,OAAO;CACT,CAAC,CACH;CAEA,MAAM,YACJ,YACkB;EAClB,IAAI,kBAAkB;EACtB,MAAM,SAAkB,CAAC;EAEzB,KAAK,MAAM,SAAS,SAAS;GAC3B,IAAI,MAAM,WAAW,aAAa;IAGhC,IAAI,MAAM,MAAM,SAAS,aACvB,OAAO;KAAE,MAAM;KAAa,OAAO,MAAM,MAAM;IAAM;IAEvD,kBAAkB;IAClB;GACF;GAGA,IAAI,WAAW,OAAO,SACpB;GAEF,OAAO,KAAK,QAAQ,MAAM,MAAM,CAAC;EACnC;EAIA,IAAI,iBACF,OAAO;GAAE,MAAM;GAAiB;EAAO;EAEzC,OAAO;GAAE,MAAM;GAAmB;EAAO;CAC3C;CAEA,IAAI;EAQF,OAAO,MAPc,QAAQ,KAAK,CAChC,kBAAkB,MACf,WAA0B;GAAE,MAAM;GAAa;EAAM,EACxD,GACA,QAAQ,KAAK,QAAQ,CACvB,CAAC;CAGH,UAAU;EAGR,WAAW,MAAM;EACjB,OAAO,QAAQ;CACjB;AACF"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SolanaRpcType } from "../rpc/types.js";
|
|
2
|
+
import { Commitment } from "@solana/kit";
|
|
3
|
+
//#region src/confirmation/types.d.ts
|
|
4
|
+
type SignatureStatusesResponse = Awaited<ReturnType<ReturnType<SolanaRpcType["getSignatureStatuses"]>["send"]>>;
|
|
5
|
+
/** Derived from the RPC type rather than hand-written, which removes every
|
|
6
|
+
* `as SignatureStatus` cast. A `JitoRpcType` response assigns without one. */
|
|
7
|
+
type SignatureStatus = NonNullable<SignatureStatusesResponse["value"][number]>;
|
|
8
|
+
/** What a single RPC branch is allowed to report. Failure is a throw. */
|
|
9
|
+
type ConfirmationOutcome<T> = {
|
|
10
|
+
kind: "confirmed";
|
|
11
|
+
value: T;
|
|
12
|
+
} | {
|
|
13
|
+
kind: "not-confirmed";
|
|
14
|
+
};
|
|
15
|
+
declare function isConfirmedCommitment(status: Commitment | string | null | undefined): boolean;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { ConfirmationOutcome, SignatureStatus, isConfirmedCommitment };
|
|
18
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","names":[],"sources":["../../../src/confirmation/types.ts"],"mappings":";;;KAGK,4BAA4B,QAC/B,WAAW,WAAW;;;KAKZ,kBAAkB,YAC5B;;KAIU,oBAAoB;EAC1B;EAAmB,OAAO;;EAC1B;;iBAEU,sBACd,QAAQ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../../src/confirmation/types.ts"],"sourcesContent":["import type { Commitment } from '@solana/kit'\nimport type { SolanaRpcType } from '../rpc/types.js'\n\ntype SignatureStatusesResponse = Awaited<\n ReturnType<ReturnType<SolanaRpcType['getSignatureStatuses']>['send']>\n>\n\n/** Derived from the RPC type rather than hand-written, which removes every\n * `as SignatureStatus` cast. A `JitoRpcType` response assigns without one. */\nexport type SignatureStatus = NonNullable<\n SignatureStatusesResponse['value'][number]\n>\n\n/** What a single RPC branch is allowed to report. Failure is a throw. */\nexport type ConfirmationOutcome<T> =\n | { kind: 'confirmed'; value: T }\n | { kind: 'not-confirmed' }\n\nexport function isConfirmedCommitment(\n status: Commitment | string | null | undefined\n): boolean {\n return status === 'confirmed' || status === 'finalized'\n}\n"],"mappings":";AAkBA,SAAgB,sBACd,QACS;CACT,OAAO,WAAW,eAAe,WAAW;AAC9C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SolanaJitoWaitForTransactionTask.d.ts","names":[],"sources":["../../../../src/core/tasks/SolanaJitoWaitForTransactionTask.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"SolanaJitoWaitForTransactionTask.d.ts","names":[],"sources":["../../../../src/core/tasks/SolanaJitoWaitForTransactionTask.ts"],"mappings":";;;cAqBa,yCAAyC;EACpD,IAAU,SAAS,4BAA4B,QAAQ"}
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
import { sendAndConfirmBundle } from "../../actions/sendAndConfirmBundle.js";
|
|
2
2
|
import { SolanaTransactionDetailsError } from "../../utils/solanaErrorCause.js";
|
|
3
|
+
import { readSignature } from "./readSignature.js";
|
|
4
|
+
import { unwrapConfirmation } from "./unwrapConfirmation.js";
|
|
3
5
|
import { BaseStepExecutionTask, LiFiErrorCode, TransactionError } from "@lifi/sdk";
|
|
4
6
|
//#region src/core/tasks/SolanaJitoWaitForTransactionTask.ts
|
|
7
|
+
/** Jito encodes `err` as a Rust `Result`: a landed bundle carries
|
|
8
|
+
* `{ Ok: null }`, so only an explicit `{ Err: … }` counts as a failure. */
|
|
9
|
+
function getBundleFailure(err) {
|
|
10
|
+
if (typeof err !== "object" || err === null || !("Err" in err)) return;
|
|
11
|
+
return { failure: err.Err };
|
|
12
|
+
}
|
|
5
13
|
var SolanaJitoWaitForTransactionTask = class extends BaseStepExecutionTask {
|
|
6
14
|
async run(context) {
|
|
7
15
|
const { client, step, statusManager, fromChain, isBridgeExecution, signedTransactions: contextSignedTransactions } = context;
|
|
@@ -9,20 +17,33 @@ var SolanaJitoWaitForTransactionTask = class extends BaseStepExecutionTask {
|
|
|
9
17
|
const action = statusManager.findAction(step, isBridgeExecution ? "CROSS_CHAIN" : "SWAP");
|
|
10
18
|
if (!action) throw new TransactionError(LiFiErrorCode.TransactionUnprepared, "Unable to prepare transaction. Action not found.");
|
|
11
19
|
if (!signedTransactions.length) throw new TransactionError(LiFiErrorCode.TransactionUnprepared, "Unable to prepare transaction. Signed transactions are not found.");
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
const
|
|
20
|
+
const txSignature = readSignature(signedTransactions[0]);
|
|
21
|
+
const txLink = `${fromChain.metamask.blockExplorerUrls[0]}tx/${txSignature}`;
|
|
22
|
+
const result = await sendAndConfirmBundle(client, signedTransactions, { onBroadcast: () => {
|
|
23
|
+
statusManager.updateAction(step, action.type, "PENDING", {
|
|
24
|
+
txHash: txSignature,
|
|
25
|
+
txLink
|
|
26
|
+
});
|
|
27
|
+
} });
|
|
28
|
+
const bundleResult = unwrapConfirmation(result, {
|
|
29
|
+
rpcUnavailable: "Unable to confirm bundle: every configured Jito RPC failed.",
|
|
30
|
+
notConfirmed: "Bundle was not confirmed before the SDK stopped waiting.",
|
|
31
|
+
allRpcsFailed: "All Jito RPCs failed",
|
|
32
|
+
someRpcsFailed: "Some Jito RPCs failed while the confirmation window was open"
|
|
33
|
+
});
|
|
34
|
+
const bundleFailure = getBundleFailure(bundleResult.bundleErr);
|
|
35
|
+
if (bundleFailure) {
|
|
36
|
+
const cause = new SolanaTransactionDetailsError(bundleFailure.failure);
|
|
37
|
+
throw new TransactionError(LiFiErrorCode.TransactionFailed, `Transaction failed: ${cause.message}`, cause);
|
|
38
|
+
}
|
|
39
|
+
const failedResult = bundleResult.signatureResults.find((signatureResult) => signatureResult?.err);
|
|
15
40
|
if (failedResult?.err) {
|
|
16
41
|
const cause = new SolanaTransactionDetailsError(failedResult.err);
|
|
17
42
|
throw new TransactionError(LiFiErrorCode.TransactionFailed, `Transaction failed: ${cause.message}`, cause);
|
|
18
43
|
}
|
|
19
|
-
const confirmedTransaction = {
|
|
20
|
-
txSignature: bundleResult.txSignatures[0],
|
|
21
|
-
bundleId: bundleResult.bundleId
|
|
22
|
-
};
|
|
23
44
|
statusManager.updateAction(step, action.type, "PENDING", {
|
|
24
|
-
txHash:
|
|
25
|
-
txLink
|
|
45
|
+
txHash: txSignature,
|
|
46
|
+
txLink
|
|
26
47
|
});
|
|
27
48
|
if (isBridgeExecution) statusManager.updateAction(step, action.type, "DONE");
|
|
28
49
|
return { status: "COMPLETED" };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SolanaJitoWaitForTransactionTask.js","names":[],"sources":["../../../../src/core/tasks/SolanaJitoWaitForTransactionTask.ts"],"sourcesContent":["import {\n BaseStepExecutionTask,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport { sendAndConfirmBundle } from '../../actions/sendAndConfirmBundle.js'\nimport type { SolanaStepExecutorContext } from '../../types.js'\nimport { SolanaTransactionDetailsError } from '../../utils/solanaErrorCause.js'\n\nexport class SolanaJitoWaitForTransactionTask extends BaseStepExecutionTask {\n async run(context: SolanaStepExecutorContext): Promise<TaskResult> {\n const {\n client,\n step,\n statusManager,\n fromChain,\n isBridgeExecution,\n signedTransactions: contextSignedTransactions,\n } = context\n\n const signedTransactions = contextSignedTransactions ?? []\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n if (!action) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Action not found.'\n )\n }\n\n if (!signedTransactions.length) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Signed transactions are not found.'\n )\n }\n\n // Use Jito bundle for transaction submission\n const
|
|
1
|
+
{"version":3,"file":"SolanaJitoWaitForTransactionTask.js","names":[],"sources":["../../../../src/core/tasks/SolanaJitoWaitForTransactionTask.ts"],"sourcesContent":["import {\n BaseStepExecutionTask,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport { sendAndConfirmBundle } from '../../actions/sendAndConfirmBundle.js'\nimport type { SolanaStepExecutorContext } from '../../types.js'\nimport { SolanaTransactionDetailsError } from '../../utils/solanaErrorCause.js'\nimport { readSignature } from './readSignature.js'\nimport { unwrapConfirmation } from './unwrapConfirmation.js'\n\n/** Jito encodes `err` as a Rust `Result`: a landed bundle carries\n * `{ Ok: null }`, so only an explicit `{ Err: … }` counts as a failure. */\nfunction getBundleFailure(err: unknown): { failure: unknown } | undefined {\n if (typeof err !== 'object' || err === null || !('Err' in err)) {\n return undefined\n }\n return { failure: (err as { Err: unknown }).Err }\n}\n\nexport class SolanaJitoWaitForTransactionTask extends BaseStepExecutionTask {\n async run(context: SolanaStepExecutorContext): Promise<TaskResult> {\n const {\n client,\n step,\n statusManager,\n fromChain,\n isBridgeExecution,\n signedTransactions: contextSignedTransactions,\n } = context\n\n const signedTransactions = contextSignedTransactions ?? []\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n if (!action) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Action not found.'\n )\n }\n\n if (!signedTransactions.length) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Signed transactions are not found.'\n )\n }\n\n const txSignature = readSignature(signedTransactions[0])\n const txLink = `${fromChain.metamask.blockExplorerUrls[0]}tx/${txSignature}`\n\n // Use Jito bundle for transaction submission. An empty Jito RPC list -\n // the configuration gap, as opposed to an outage - throws inside\n // `sendAndConfirmBundle` with its own message, before anything is sent.\n const result = await sendAndConfirmBundle(client, signedTransactions, {\n onBroadcast: () => {\n // The earliest honest point for both: an RPC has accepted the\n // transaction, so the signature now resolves on chain.\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash: txSignature,\n txLink,\n })\n },\n })\n\n // The `rpc-unavailable` message is distinct from the empty-list throw\n // above: RPCs were configured and every one of them failed. That is an\n // outage, and the collected branch errors say what each endpoint did.\n const bundleResult = unwrapConfirmation(result, {\n rpcUnavailable:\n 'Unable to confirm bundle: every configured Jito RPC failed.',\n notConfirmed: 'Bundle was not confirmed before the SDK stopped waiting.',\n allRpcsFailed: 'All Jito RPCs failed',\n someRpcsFailed:\n 'Some Jito RPCs failed while the confirmation window was open',\n })\n\n // A `null` in `signatureResults` is indexing lag, never failure. The\n // bundle-level `err` is checked first: it survives a failed\n // `getSignatureStatuses` read.\n const bundleFailure = getBundleFailure(bundleResult.bundleErr)\n if (bundleFailure) {\n const cause = new SolanaTransactionDetailsError(bundleFailure.failure)\n throw new TransactionError(\n LiFiErrorCode.TransactionFailed,\n `Transaction failed: ${cause.message}`,\n cause\n )\n }\n\n const failedResult = bundleResult.signatureResults.find(\n (signatureResult) => signatureResult?.err\n )\n if (failedResult?.err) {\n const cause = new SolanaTransactionDetailsError(failedResult.err)\n throw new TransactionError(\n LiFiErrorCode.TransactionFailed,\n `Transaction failed: ${cause.message}`,\n cause\n )\n }\n\n // Transaction has been confirmed and we can update the action\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash: txSignature,\n txLink,\n })\n\n if (isBridgeExecution) {\n statusManager.updateAction(step, action.type, 'DONE')\n }\n\n return { status: 'COMPLETED' }\n }\n}\n"],"mappings":";;;;;;;;AAcA,SAAS,iBAAiB,KAAgD;CACxE,IAAI,OAAO,QAAQ,YAAY,QAAQ,QAAQ,EAAE,SAAS,MACxD;CAEF,OAAO,EAAE,SAAU,IAAyB,IAAI;AAClD;AAEA,IAAa,mCAAb,cAAsD,sBAAsB;CAC1E,MAAM,IAAI,SAAyD;EACjE,MAAM,EACJ,QACA,MACA,eACA,WACA,mBACA,oBAAoB,8BAClB;EAEJ,MAAM,qBAAqB,6BAA6B,CAAC;EAEzD,MAAM,SAAS,cAAc,WAC3B,MACA,oBAAoB,gBAAgB,MACtC;EACA,IAAI,CAAC,QACH,MAAM,IAAI,iBACR,cAAc,uBACd,kDACF;EAGF,IAAI,CAAC,mBAAmB,QACtB,MAAM,IAAI,iBACR,cAAc,uBACd,mEACF;EAGF,MAAM,cAAc,cAAc,mBAAmB,EAAE;EACvD,MAAM,SAAS,GAAG,UAAU,SAAS,kBAAkB,GAAG,KAAK;EAK/D,MAAM,SAAS,MAAM,qBAAqB,QAAQ,oBAAoB,EACpE,mBAAmB;GAGjB,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW;IACvD,QAAQ;IACR;GACF,CAAC;EACH,EACF,CAAC;EAKD,MAAM,eAAe,mBAAmB,QAAQ;GAC9C,gBACE;GACF,cAAc;GACd,eAAe;GACf,gBACE;EACJ,CAAC;EAKD,MAAM,gBAAgB,iBAAiB,aAAa,SAAS;EAC7D,IAAI,eAAe;GACjB,MAAM,QAAQ,IAAI,8BAA8B,cAAc,OAAO;GACrE,MAAM,IAAI,iBACR,cAAc,mBACd,uBAAuB,MAAM,WAC7B,KACF;EACF;EAEA,MAAM,eAAe,aAAa,iBAAiB,MAChD,oBAAoB,iBAAiB,GACxC;EACA,IAAI,cAAc,KAAK;GACrB,MAAM,QAAQ,IAAI,8BAA8B,aAAa,GAAG;GAChE,MAAM,IAAI,iBACR,cAAc,mBACd,uBAAuB,MAAM,WAC7B,KACF;EACF;EAGA,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW;GACvD,QAAQ;GACR;EACF,CAAC;EAED,IAAI,mBACF,cAAc,aAAa,MAAM,OAAO,MAAM,MAAM;EAGtD,OAAO,EAAE,QAAQ,YAAY;CAC/B;AACF"}
|
|
@@ -23,7 +23,11 @@ var SolanaSignAndExecuteTask = class extends BaseStepExecutionTask {
|
|
|
23
23
|
errorInstance: new TransactionError(LiFiErrorCode.TransactionExpired, "Transaction has expired: blockhash is no longer recent enough.")
|
|
24
24
|
});
|
|
25
25
|
if (signedTransactionOutputs.length === 0) throw new TransactionError(LiFiErrorCode.TransactionUnprepared, "No signed transaction returned from signer.");
|
|
26
|
-
statusManager.updateAction(step, action.type, "PENDING", {
|
|
26
|
+
statusManager.updateAction(step, action.type, "PENDING", {
|
|
27
|
+
signedAt: Date.now(),
|
|
28
|
+
txHash: void 0,
|
|
29
|
+
txLink: void 0
|
|
30
|
+
});
|
|
27
31
|
const transactionCodec = getTransactionCodec();
|
|
28
32
|
return {
|
|
29
33
|
status: "COMPLETED",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SolanaSignAndExecuteTask.js","names":[],"sources":["../../../../src/core/tasks/SolanaSignAndExecuteTask.ts"],"sourcesContent":["import {\n BaseStepExecutionTask,\n getTransactionRequestData,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n withTimeout,\n} from '@lifi/sdk'\nimport { getTransactionCodec } from '@solana/kit'\nimport { SolanaSignTransaction } from '@solana/wallet-standard-features'\nimport type { SolanaStepExecutorContext } from '../../types.js'\nimport { base64ToUint8Array } from '../../utils/base64ToUint8Array.js'\nimport { getWalletFeature } from '../../utils/getWalletFeature.js'\n\nexport class SolanaSignAndExecuteTask extends BaseStepExecutionTask {\n async run(context: SolanaStepExecutorContext): Promise<TaskResult> {\n const {\n step,\n wallet,\n walletAccount,\n statusManager,\n executionOptions,\n isBridgeExecution,\n } = context\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n if (!action) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Action not found.'\n )\n }\n\n const transactionRequestData = (await getTransactionRequestData(\n step,\n executionOptions\n )) as string | string[]\n\n // The backend returns an array when it produced a Jito bundle and a string\n // for a single transaction. The shape determines how we submit it later:\n // array -> sendBundle, string -> sendTransaction.\n const isBundleExecution = Array.isArray(transactionRequestData)\n\n const transactionDataArray = isBundleExecution\n ? transactionRequestData\n : [transactionRequestData]\n\n const transactionBytesArray = transactionDataArray.map((data) =>\n base64ToUint8Array(data)\n )\n\n const signedTransactionOutputs = await withTimeout(\n async () => {\n const { signTransaction } = getWalletFeature(\n wallet,\n SolanaSignTransaction\n )\n // Spread the inputs to sign all transactions at once\n return signTransaction(\n ...transactionBytesArray.map((transaction) => ({\n account: walletAccount,\n transaction,\n }))\n )\n },\n {\n // https://solana.com/docs/advanced/confirmation#transaction-expiration\n // Use 2 minutes to account for fluctuations\n timeout: 120_000,\n errorInstance: new TransactionError(\n LiFiErrorCode.TransactionExpired,\n 'Transaction has expired: blockhash is no longer recent enough.'\n ),\n }\n )\n\n if (signedTransactionOutputs.length === 0) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'No signed transaction returned from signer.'\n )\n }\n\n statusManager.updateAction(step, action.type, 'PENDING', {\n signedAt: Date.now(),\n })\n\n const transactionCodec = getTransactionCodec()\n\n // Decode all signed transactions\n const signedTransactions = signedTransactionOutputs.map((output) =>\n transactionCodec.decode(output.signedTransaction)\n )\n\n return {\n status: 'COMPLETED',\n context: { signedTransactions, isBundleExecution },\n }\n }\n}\n"],"mappings":";;;;;;AAcA,IAAa,2BAAb,cAA8C,sBAAsB;CAClE,MAAM,IAAI,SAAyD;EACjE,MAAM,EACJ,MACA,QACA,eACA,eACA,kBACA,sBACE;EAEJ,MAAM,SAAS,cAAc,WAC3B,MACA,oBAAoB,gBAAgB,MACtC;EACA,IAAI,CAAC,QACH,MAAM,IAAI,iBACR,cAAc,uBACd,kDACF;EAGF,MAAM,yBAA0B,MAAM,0BACpC,MACA,gBACF;EAKA,MAAM,oBAAoB,MAAM,QAAQ,sBAAsB;EAM9D,MAAM,yBAJuB,oBACzB,yBACA,CAAC,sBAAsB,EAAA,CAEwB,KAAK,SACtD,mBAAmB,IAAI,CACzB;EAEA,MAAM,2BAA2B,MAAM,YACrC,YAAY;GACV,MAAM,EAAE,oBAAoB,iBAC1B,QACA,qBACF;GAEA,OAAO,gBACL,GAAG,sBAAsB,KAAK,iBAAiB;IAC7C,SAAS;IACT;GACF,EAAE,CACJ;EACF,GACA;GAGE,SAAS;GACT,eAAe,IAAI,iBACjB,cAAc,oBACd,gEACF;EACF,CACF;EAEA,IAAI,yBAAyB,WAAW,GACtC,MAAM,IAAI,iBACR,cAAc,uBACd,6CACF;
|
|
1
|
+
{"version":3,"file":"SolanaSignAndExecuteTask.js","names":[],"sources":["../../../../src/core/tasks/SolanaSignAndExecuteTask.ts"],"sourcesContent":["import {\n BaseStepExecutionTask,\n getTransactionRequestData,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n withTimeout,\n} from '@lifi/sdk'\nimport { getTransactionCodec } from '@solana/kit'\nimport { SolanaSignTransaction } from '@solana/wallet-standard-features'\nimport type { SolanaStepExecutorContext } from '../../types.js'\nimport { base64ToUint8Array } from '../../utils/base64ToUint8Array.js'\nimport { getWalletFeature } from '../../utils/getWalletFeature.js'\n\nexport class SolanaSignAndExecuteTask extends BaseStepExecutionTask {\n async run(context: SolanaStepExecutorContext): Promise<TaskResult> {\n const {\n step,\n wallet,\n walletAccount,\n statusManager,\n executionOptions,\n isBridgeExecution,\n } = context\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n if (!action) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Action not found.'\n )\n }\n\n const transactionRequestData = (await getTransactionRequestData(\n step,\n executionOptions\n )) as string | string[]\n\n // The backend returns an array when it produced a Jito bundle and a string\n // for a single transaction. The shape determines how we submit it later:\n // array -> sendBundle, string -> sendTransaction.\n const isBundleExecution = Array.isArray(transactionRequestData)\n\n const transactionDataArray = isBundleExecution\n ? transactionRequestData\n : [transactionRequestData]\n\n const transactionBytesArray = transactionDataArray.map((data) =>\n base64ToUint8Array(data)\n )\n\n const signedTransactionOutputs = await withTimeout(\n async () => {\n const { signTransaction } = getWalletFeature(\n wallet,\n SolanaSignTransaction\n )\n // Spread the inputs to sign all transactions at once\n return signTransaction(\n ...transactionBytesArray.map((transaction) => ({\n account: walletAccount,\n transaction,\n }))\n )\n },\n {\n // https://solana.com/docs/advanced/confirmation#transaction-expiration\n // Use 2 minutes to account for fluctuations\n timeout: 120_000,\n errorInstance: new TransactionError(\n LiFiErrorCode.TransactionExpired,\n 'Transaction has expired: blockhash is no longer recent enough.'\n ),\n }\n )\n\n if (signedTransactionOutputs.length === 0) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'No signed transaction returned from signer.'\n )\n }\n\n // Neither `txHash` nor `txLink` is written here. A signature is fixed at\n // signing, but the transaction does not exist yet: `getTransaction`\n // returns `null` for it, and simulation, the empty-Jito-RPC throw and\n // every send failure all sit between this task and the first broadcast.\n // The wait tasks write both on `onBroadcast`, when an RPC has accepted it.\n //\n // Both are still written as an explicit `undefined`, which clears what a\n // restarted `PENDING` action carried over from a previous run.\n // `prepareRestart` keeps that action *because* its `txHash` is truthy, so\n // leaving the signature in place would report the previous run's hash if\n // this run failed before its first broadcast. It therefore has to run\n // BEFORE the decode below, which can throw on a malformed wallet\n // output and would otherwise strand the previous run's signature.\n statusManager.updateAction(step, action.type, 'PENDING', {\n signedAt: Date.now(),\n txHash: undefined,\n txLink: undefined,\n })\n\n const transactionCodec = getTransactionCodec()\n\n // Decode all signed transactions\n const signedTransactions = signedTransactionOutputs.map((output) =>\n transactionCodec.decode(output.signedTransaction)\n )\n\n return {\n status: 'COMPLETED',\n context: { signedTransactions, isBundleExecution },\n }\n }\n}\n"],"mappings":";;;;;;AAcA,IAAa,2BAAb,cAA8C,sBAAsB;CAClE,MAAM,IAAI,SAAyD;EACjE,MAAM,EACJ,MACA,QACA,eACA,eACA,kBACA,sBACE;EAEJ,MAAM,SAAS,cAAc,WAC3B,MACA,oBAAoB,gBAAgB,MACtC;EACA,IAAI,CAAC,QACH,MAAM,IAAI,iBACR,cAAc,uBACd,kDACF;EAGF,MAAM,yBAA0B,MAAM,0BACpC,MACA,gBACF;EAKA,MAAM,oBAAoB,MAAM,QAAQ,sBAAsB;EAM9D,MAAM,yBAJuB,oBACzB,yBACA,CAAC,sBAAsB,EAAA,CAEwB,KAAK,SACtD,mBAAmB,IAAI,CACzB;EAEA,MAAM,2BAA2B,MAAM,YACrC,YAAY;GACV,MAAM,EAAE,oBAAoB,iBAC1B,QACA,qBACF;GAEA,OAAO,gBACL,GAAG,sBAAsB,KAAK,iBAAiB;IAC7C,SAAS;IACT;GACF,EAAE,CACJ;EACF,GACA;GAGE,SAAS;GACT,eAAe,IAAI,iBACjB,cAAc,oBACd,gEACF;EACF,CACF;EAEA,IAAI,yBAAyB,WAAW,GACtC,MAAM,IAAI,iBACR,cAAc,uBACd,6CACF;EAgBF,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW;GACvD,UAAU,KAAK,IAAI;GACnB,QAAQ,KAAA;GACR,QAAQ,KAAA;EACV,CAAC;EAED,MAAM,mBAAmB,oBAAoB;EAO7C,OAAO;GACL,QAAQ;GACR,SAAS;IAAE,oBANc,yBAAyB,KAAK,WACvD,iBAAiB,OAAO,OAAO,iBAAiB,CAKpB;IAAG;GAAkB;EACnD;CACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SolanaStandardWaitForTransactionTask.d.ts","names":[],"sources":["../../../../src/core/tasks/SolanaStandardWaitForTransactionTask.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"SolanaStandardWaitForTransactionTask.d.ts","names":[],"sources":["../../../../src/core/tasks/SolanaStandardWaitForTransactionTask.ts"],"mappings":";;;cAca,6CAA6C;EACxD,IAAU,SAAS,4BAA4B,QAAQ"}
|