Commit 5e45b52
committed
fix(solana-utils): lazy-load jito-ts so non-Jito consumers don't crash
Closes #1838.
`jito.ts` previously did top-level value imports of
`jito-ts/dist/sdk/block-engine/{searcher,types}`. Pulling those modules
also pulls jito-ts's nested `@solana/web3.js@~1.77.3`, which transitively
`require`s `rpc-websockets/dist/lib/client` — a path removed in
`rpc-websockets@>=7.11`. Because `solana_utils/transaction.ts` imports
`buildJitoTipInstruction` from `./jito`, any consumer that loaded a
@pythnetwork/solana-utils export — including `PythSolanaReceiver` from
`@pythnetwork/pyth-solana-receiver` — eagerly walked the broken chain
and crashed at module load with:
Error: Cannot find module 'rpc-websockets/dist/lib/client'
This change splits the imports so that jito-ts only resolves when the
Jito send path is actually exercised:
- `SearcherClient` and `Bundle` become `import type` — these were only
used as types in function signatures.
- `sendTransactionsJito` dynamic-`import`s `Bundle` from
`jito-ts/.../types` immediately before constructing the bundle. The
function is already async, so this is zero-cost for callers.
Non-Jito consumers (the case reported in the issue) no longer trigger
the broken require. Jito users still get the same runtime path; the
underlying jito-ts/rpc-websockets clash there is a separate problem
for jito-ts to solve.
Tests
- Added `JitoLazyImport.test.ts` asserting that importing either
`../transaction` or `../jito` leaves `jito-ts/*` out of `require.cache`.
- Existing `TransactionSize.test.ts` still passes (2 cases).
- `pnpm --filter @pythnetwork/solana-utils build` succeeds (esm + cjs).
Bumped to 0.6.1 (patch — runtime contract preserved, only load order changes).1 parent 75472c0 commit 5e45b52
3 files changed
Lines changed: 44 additions & 3 deletions
File tree
- target_chains/solana/sdk/js/solana_utils
- src
- __tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
84 | | - | |
| 84 | + | |
85 | 85 | | |
Lines changed: 33 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
12 | 17 | | |
13 | | - | |
| 18 | + | |
14 | 19 | | |
15 | 20 | | |
16 | 21 | | |
| |||
85 | 90 | | |
86 | 91 | | |
87 | 92 | | |
88 | | - | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
89 | 97 | | |
90 | 98 | | |
91 | 99 | | |
| |||
0 commit comments