@effectstream/solana-node 0.102.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/LICENSE-APACHE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2024-2026 Midnight Foundation
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/LICENSE-MIT ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-2026 Midnight Foundation
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,111 @@
1
+ # @effectstream/solana-node
2
+
3
+ NPM wrapper around [`solana-test-validator`](https://docs.anza.xyz/cli/examples/test-validator)
4
+ from an [Agave](https://github.com/anza-xyz/agave) release - a single-node Solana
5
+ cluster for local development. Downloads a pinned build into
6
+ `vendor/bin/solana-test-validator` on first use so the orchestrator can boot it
7
+ without each developer installing the Solana CLI.
8
+
9
+ - Pinned Agave release, verified by SHA-256 before it is ever executed.
10
+ - Exposes a `solana-node` bin plus a programmatic `run()`.
11
+ - Consumed by `@effectstream/sync`'s `SolanaFetcher` via JSON-RPC on `:8899`.
12
+ - Used by the orchestrator's `launchSolana` step for end-to-end local testing.
13
+ - The same archive also provides `cargo-build-sbf`, which the `solana-starter`
14
+ template uses to compile its Rust program.
15
+
16
+ ## Install
17
+
18
+ ```bash
19
+ bun add @effectstream/solana-node
20
+ ```
21
+
22
+ The pinned archive is downloaded on first run (not at install time) for the
23
+ current OS/arch.
24
+
25
+ ## Standalone usage
26
+
27
+ ```bash
28
+ bun ./node_modules/.bin/solana-node # boot the validator
29
+ bun ./node_modules/.bin/solana-node --verbose # stream validator output
30
+ ```
31
+
32
+ Programmatically:
33
+
34
+ ```ts
35
+ import { run } from "@effectstream/solana-node";
36
+
37
+ const validator = await run({
38
+ rpcPort: 8899,
39
+ faucetPort: 9900,
40
+ reset: true,
41
+ // bindAddress: "127.0.0.1",
42
+ // dataDir: "/tmp/my-ledger",
43
+ // verbose: false,
44
+ });
45
+
46
+ // … use http://127.0.0.1:8899 …
47
+ validator.stop();
48
+ ```
49
+
50
+ On non-zero exit the wrapper prints the last 40 lines of the validator's output.
51
+ That matters because the validator reports most startup failures on **stdout**,
52
+ and deeper detail goes only to `<ledger>/validator.log`.
53
+
54
+ ## Integrity
55
+
56
+ `bin-wrapper` has no checksum support and discards the archive after extracting,
57
+ so this package hashes the **extracted binary** and refuses to run anything that
58
+ isn't one of the pinned official builds. Set `SOLANA_NODE_SKIP_CHECKSUM=1` to
59
+ bypass when deliberately testing a locally-built validator.
60
+
61
+ Regenerate the digests whenever the pinned version changes:
62
+
63
+ ```bash
64
+ shasum -a 256 packages/binaries/solana-node/vendor/bin/solana-test-validator
65
+ ```
66
+
67
+ ## Networking
68
+
69
+ RPC and gossip bind `127.0.0.1` by default — the validator has no
70
+ authentication, so exposing it broadly is a hazard on a shared network.
71
+ Override with `SOLANA_BIND_ADDRESS` (or the `bindAddress` option) for container
72
+ setups that need external reachability.
73
+
74
+ The **faucet ignores this** and always listens on all interfaces; Agave offers no
75
+ flag to restrict it, only the `--faucet-per-request-sol-cap` /
76
+ `--faucet-per-time-sol-cap` rate limits. It hands out worthless localnet SOL, but
77
+ don't run this on an untrusted network.
78
+
79
+ ## Platform support
80
+
81
+ | Platform | Supported |
82
+ | :--- | :---: |
83
+ | linux x64 | ✅ |
84
+ | darwin x64 | ✅ |
85
+ | darwin arm64 | ✅ |
86
+ | linux arm64 | ❌ |
87
+
88
+ Upstream publishes no `aarch64-unknown-linux-gnu` build, so ARM64 Linux has no
89
+ binary to download.
90
+
91
+ ## ⚠️ Version pin: do not bump past Agave 3.0.x
92
+
93
+ Pinned to **3.0.14** deliberately. Agave ≥ 3.1 hard-asserts io_uring support on
94
+ Linux and panics during init where it is unavailable:
95
+
96
+ ```
97
+ [INFO agave_io_uring] io_uring NOT supported: Function not implemented (os error 38)
98
+ thread 'main' panicked at fs/src/dirs.rs:27:9:
99
+ assertion failed: io_uring_supported()
100
+ ```
101
+
102
+ Docker's default seccomp profile blocks the io_uring syscalls, and the whole e2e
103
+ suite runs containerized — so 3.1+ cannot start in CI as configured. macOS builds
104
+ don't compile the assert in at all, which means a newer version looks fine
105
+ locally and then fails in CI.
106
+
107
+ Verified: `4.1.2` ✗ · `4.0.3` ✗ · `3.1.14` ✗ · `3.0.14` ✓ · `2.3.13` ✓
108
+
109
+ This is a CI-configuration constraint, not an upstream dead end — on a kernel
110
+ that supports io_uring the block is purely seccomp. See the note in `index.js`
111
+ for the path to running a current release.
package/index.js ADDED
@@ -0,0 +1,249 @@
1
+ import BinWrapper from '@xhmikosr/bin-wrapper';
2
+ import path from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ import { spawn } from 'node:child_process';
5
+ import crypto from 'node:crypto';
6
+ import fs from 'node:fs';
7
+ import os from 'node:os';
8
+
9
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
10
+
11
+ // Agave is the maintained continuation of solana-labs/solana; the old org
12
+ // publishes nothing past 1.18.x, which is EOL.
13
+ //
14
+ // ⚠️ DO NOT BUMP PAST 3.0.x WITHOUT READING THIS.
15
+ // Agave >= 3.1 hard-asserts io_uring support on Linux and panics during init
16
+ // where it is unavailable:
17
+ //
18
+ // [INFO agave_io_uring] io_uring NOT supported: Function not implemented (os error 38)
19
+ // thread 'main' panicked at fs/src/dirs.rs:27:9:
20
+ // assertion failed: io_uring_supported()
21
+ // 3: solana_accounts_db::utils::create_accounts_run_and_snapshot_dirs
22
+ // 4: solana_test_validator::TestValidator::start
23
+ //
24
+ // The entire e2e suite runs inside Docker (.github/Dockerfile), and Docker's
25
+ // DEFAULT SECCOMP PROFILE blocks the io_uring syscalls, so 3.1+ cannot start in
26
+ // CI as configured. macOS builds are unaffected (io_uring is Linux-only, so the
27
+ // assert isn't compiled in) — which is exactly why 4.x passes every local check
28
+ // and dies in CI.
29
+ //
30
+ // Verified: 4.1.2 ✗ 4.0.3 ✗ 3.1.14 ✗ 3.0.14 ✓ 2.3.13 ✓
31
+ //
32
+ // This pin is a CI-configuration constraint, NOT an upstream dead end. On a
33
+ // kernel that supports io_uring, the block is purely seccomp:
34
+ // default profile -> io_uring_setup errno=1 (EPERM)
35
+ // seccomp=unconfined -> io_uring_setup OK
36
+ // So 3.1+/4.x becomes viable by relaxing seccomp for the e2e container —
37
+ // preferably a minimal custom profile allowing only io_uring_setup/enter/
38
+ // register, rather than blanket `unconfined`. Docker dropped io_uring from its
39
+ // default allowlist over a run of kernel LPE bugs, so that is a deliberate
40
+ // trade-off to make explicitly, not a rubber stamp. See PR #815 discussion.
41
+ // (Docker-on-Apple-Silicon is a separate matter: emulated amd64 has no io_uring
42
+ // at all, and no seccomp setting helps there.)
43
+ const version = '3.0.14';
44
+ const base = `https://github.com/anza-xyz/agave/releases/download/v${version}`;
45
+ const dest = path.join(__dirname, 'vendor');
46
+
47
+ // NOTE: upstream ships NO aarch64-unknown-linux-gnu build — only the three
48
+ // targets below (plus Windows, which this repo doesn't support). Adding a
49
+ // linux/arm64 entry produces a 404 at download time, not a clean error.
50
+ const bin = new BinWrapper()
51
+ .src(`${base}/solana-release-x86_64-unknown-linux-gnu.tar.bz2`, 'linux', 'x64')
52
+ .src(`${base}/solana-release-x86_64-apple-darwin.tar.bz2`, 'darwin', 'x64')
53
+ .src(`${base}/solana-release-aarch64-apple-darwin.tar.bz2`, 'darwin', 'arm64')
54
+ .dest(dest)
55
+ .use('bin/solana-test-validator');
56
+
57
+ export default bin;
58
+
59
+ /**
60
+ * SHA-256 of the extracted `solana-test-validator` in each published v3.0.14
61
+ * asset. bin-wrapper has no integrity support and discards the archive after
62
+ * extracting, so this verifies the binary we are about to execute rather than
63
+ * the tarball. Regenerate on every `version` bump with:
64
+ *
65
+ * shasum -a 256 packages/binaries/solana-node/vendor/bin/solana-test-validator
66
+ *
67
+ * Deliberately matched as a SET rather than by `os.arch()`. Asset selection goes
68
+ * through bin-wrapper -> os-filter-obj -> arch, and the reported architecture
69
+ * has not always agreed with `os.arch()`: arch@2.x had no notion of arm64 at all
70
+ * (`darwin` was hardcoded to 'x64'), which is why every Mac used to download the
71
+ * x86_64 build and run it under Rosetta. The root `overrides` now force arch@3,
72
+ * so selection is correct today — but membership in the pinned set is immune to
73
+ * that class of mismatch (including deliberate emulation) while still proving
74
+ * the binary is one of the three official builds, which is the property that
75
+ * matters here.
76
+ */
77
+ const CHECKSUMS = {
78
+ 'linux-x64': '80f3bc0e3fa6a3090e69bafbfe00b249eaa655c5874ac83aebb6acdb157140ab',
79
+ 'darwin-x64': '2a4a5ad21f7cd50021fa55948710ee2f3559d9cccf95f7a31094e45c27023b52',
80
+ 'darwin-arm64': 'ab00c9a189341ef61402efce1a27713bb1b0ffb941715cea56ed5aa133992fe1',
81
+ };
82
+
83
+ /**
84
+ * Fail closed if the downloaded validator isn't one of the builds we pinned.
85
+ * Set SOLANA_NODE_SKIP_CHECKSUM=1 to bypass when intentionally testing a
86
+ * locally-built validator.
87
+ */
88
+ function verifyChecksum(binaryPath) {
89
+ if (process.env.SOLANA_NODE_SKIP_CHECKSUM === '1') {
90
+ console.warn('[solana-node] checksum verification skipped (SOLANA_NODE_SKIP_CHECKSUM=1)');
91
+ return;
92
+ }
93
+ const actual = crypto
94
+ .createHash('sha256')
95
+ .update(fs.readFileSync(binaryPath))
96
+ .digest('hex');
97
+
98
+ const match = Object.entries(CHECKSUMS).find(([, digest]) => digest === actual);
99
+ if (!match) {
100
+ throw new Error(
101
+ `[solana-node] checksum mismatch for ${binaryPath}\n` +
102
+ ` got ${actual}\n` +
103
+ ` expected one of:\n` +
104
+ Object.entries(CHECKSUMS)
105
+ .map(([platform, digest]) => ` ${digest} (${platform})`)
106
+ .join('\n') +
107
+ `\nThis is not a pinned v${version} build. Refusing to run it.`,
108
+ );
109
+ }
110
+ return match[0];
111
+ }
112
+
113
+ export async function run(options = {}) {
114
+ const {
115
+ config,
116
+ dataDir,
117
+ verbose = false,
118
+ reset = true,
119
+ rpcPort = 8899,
120
+ faucetPort = 9900,
121
+ // The test validator has no authentication, so binding 0.0.0.0 exposed the
122
+ // RPC to the whole network. Default to loopback; override for container
123
+ // setups that genuinely need to reach it from outside.
124
+ //
125
+ // CAVEAT: this only covers the RPC and gossip/TPU. The FAUCET ignores
126
+ // --bind-address and always listens on 0.0.0.0 — there is no flag to
127
+ // change that in Agave 4.1.2 (only the --faucet-per-request-sol-cap /
128
+ // --faucet-per-time-sol-cap rate limits). It hands out worthless localnet
129
+ // SOL, but anyone on the LAN can still reach it, so don't run this on an
130
+ // untrusted network.
131
+ bindAddress = process.env.SOLANA_BIND_ADDRESS ?? '127.0.0.1',
132
+ // Programs to preload into the genesis ledger, as
133
+ // `[{ address, soPath }, …]` -> `--bpf-program <address> <soPath>`. Callers
134
+ // used to spawn the binary themselves to pass this, which duplicated all the
135
+ // ledger/reset handling below AND skipped the checksum verification above.
136
+ bpfPrograms = [],
137
+ } = options;
138
+
139
+ // Download (if needed) and verify BEFORE executing anything. `bin.run()`
140
+ // would execute the binary to check its version first, which defeats the
141
+ // point of verifying it.
142
+ if (!fs.existsSync(bin.path())) {
143
+ await bin.download();
144
+ }
145
+ const flavour = verifyChecksum(bin.path());
146
+ if (verbose) {
147
+ console.log(`[solana-node] verified solana-test-validator v${version} (${flavour})`);
148
+ }
149
+
150
+ const dataDirPath = dataDir || fs.mkdtempSync(path.join(os.tmpdir(), 'solana-test-validator-'));
151
+
152
+ if (!fs.existsSync(dataDirPath)) {
153
+ fs.mkdirSync(dataDirPath, { recursive: true });
154
+ }
155
+
156
+ const ledgerDir = path.join(dataDirPath, 'ledger');
157
+ if (!fs.existsSync(ledgerDir)) {
158
+ fs.mkdirSync(ledgerDir, { recursive: true });
159
+ }
160
+
161
+ const args = [
162
+ '--ledger', ledgerDir,
163
+ '--rpc-port', String(rpcPort),
164
+ '--faucet-port', String(faucetPort),
165
+ '--bind-address', bindAddress,
166
+ ];
167
+
168
+ for (const { address, soPath } of bpfPrograms) {
169
+ if (!address || !soPath) {
170
+ throw new Error(
171
+ `[solana-node] bpfPrograms entries need both 'address' and 'soPath'; got ${JSON.stringify({ address, soPath })}`,
172
+ );
173
+ }
174
+ if (!fs.existsSync(soPath)) {
175
+ throw new Error(
176
+ `[solana-node] program binary not found at ${soPath} (for ${address}). Build it before starting the validator.`,
177
+ );
178
+ }
179
+ args.push('--bpf-program', address, soPath);
180
+ }
181
+
182
+ if (reset) {
183
+ args.push('--reset');
184
+ }
185
+
186
+ // COPYFILE_DISABLE prevents macOS from materializing AppleDouble (`._`)
187
+ // companion files when the validator archives/unarchives genesis, which
188
+ // otherwise aborts ledger creation with
189
+ // "Archive error: extra entry found: ._genesis.bin". No-op on Linux.
190
+ const child = spawn(bin.path(), args, {
191
+ env: { ...process.env, COPYFILE_DISABLE: "1" },
192
+ });
193
+
194
+ // Keep a rolling tail of output even when quiet. The validator reports most
195
+ // startup failures on STDOUT, which used to be discarded unless `verbose` —
196
+ // so a failure surfaced as a bare "exited with code 1" with nothing to
197
+ // diagnose from, in CI least of all.
198
+ const TAIL_LINES = 40;
199
+ const tail = [];
200
+ const record = (stream) => (data) => {
201
+ const text = String(data);
202
+ if (verbose) {
203
+ const log = stream === 'stderr' ? console.error : console.log;
204
+ log(`solana-test-validator ${stream}: ${text}`);
205
+ }
206
+ for (const line of text.split('\n')) {
207
+ if (line.trim() === '') continue;
208
+ tail.push(` [${stream}] ${line}`);
209
+ if (tail.length > TAIL_LINES) tail.shift();
210
+ }
211
+ };
212
+
213
+ child.stdout.on('data', record('stdout'));
214
+ child.stderr.on('data', record('stderr'));
215
+
216
+ child.on('close', (code) => {
217
+ if (code === 0) return;
218
+ console.error(
219
+ `solana-test-validator exited with code ${code}.` +
220
+ (verbose
221
+ ? ''
222
+ : ` Last output:\n${tail.length > 0 ? tail.join('\n') : ' (no output captured)'}`),
223
+ );
224
+ });
225
+
226
+ return {
227
+ child,
228
+ dataDir: dataDirPath,
229
+ ledgerDir,
230
+ rpcPort,
231
+ faucetPort,
232
+ stop: () => child.kill(),
233
+ };
234
+ }
235
+
236
+ if (import.meta.main) {
237
+ const cliArgs = process.argv.slice(2);
238
+ const verbose = cliArgs.includes("--verbose");
239
+
240
+ (async () => {
241
+ try {
242
+ console.log("Starting Solana test validator...");
243
+ await run({ verbose });
244
+ } catch (error) {
245
+ console.error("Failed to start Solana test validator:", error);
246
+ process.exit(1);
247
+ }
248
+ })();
249
+ }
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@effectstream/solana-node",
3
+ "version": "0.102.0",
4
+ "type": "module",
5
+ "main": "./index.js",
6
+ "bin": {
7
+ "solana-node": "./index.js"
8
+ },
9
+ "scripts": {
10
+ "start": "node index.js"
11
+ },
12
+ "dependencies": {
13
+ "@xhmikosr/bin-wrapper": "^5.0.0"
14
+ },
15
+ "homepage": "https://effectstream.github.io/docs/",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/effectstream/effectstream",
19
+ "directory": "packages/binaries/solana-node"
20
+ },
21
+ "bugs": {
22
+ "url": "https://github.com/effectstream/effectstream/issues"
23
+ },
24
+ "description": "Solana test validator binary wrapper for EffectStream"
25
+ }