purgatory 0.0.9 → 0.1.1
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/README.md +127 -130
- package/bin/packages.json +7 -0
- package/bin/purgatory.js +72 -0
- package/package.json +18 -28
- package/.env.default +0 -3
- package/dist/cli.d.ts +0 -3
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js +0 -91
- package/dist/cli.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,180 +1,177 @@
|
|
|
1
1
|
# Purgatory
|
|
2
2
|
|
|
3
|
-
A local mempool proxy for Ethereum
|
|
3
|
+
A local mempool proxy for Ethereum development: it sits between your dApp (or wallet, or scripts) and your dev node, holds the transactions sent with `eth_sendRawTransaction`, and lets you inspect, include, drop, hide or replace them before they reach the node.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
Purgatory acts as an RPC proxy between your application and an Ethereum node. It intercepts `eth_sendRawTransaction` calls, stores transactions in a local mempool, and gives you full control over when and how they're forwarded to the actual network.
|
|
8
|
-
|
|
9
|
-
### Key Features
|
|
10
|
-
|
|
11
|
-
- **Transaction Interception**: Captures all `eth_sendRawTransaction` calls
|
|
12
|
-
- **Gas Price Filtering**: Set minimum gas price thresholds
|
|
13
|
-
- **Auto-Forward Control**: Toggle automatic forwarding to upstream node
|
|
14
|
-
- **Transaction Replacement**: Configurable replacement bump requirements (like EIP-1559 pools)
|
|
15
|
-
- **Batch Operations**: Include or drop multiple transactions at once
|
|
16
|
-
- **REST API**: Full mempool management via REST endpoints
|
|
17
|
-
- **Web Dashboard**: Visual UI for monitoring and managing transactions
|
|
18
|
-
- **Multi-Platform**: Deploy on Node.js or Cloudflare Workers
|
|
19
|
-
|
|
20
|
-
## Quick Start
|
|
21
|
-
|
|
22
|
-
### Prerequisites
|
|
23
|
-
|
|
24
|
-
- Node.js 18+
|
|
25
|
-
- pnpm
|
|
26
|
-
|
|
27
|
-
### Installation
|
|
28
|
-
|
|
29
|
-
```bash
|
|
30
|
-
npm i purgatory
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
### Using it
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
```
|
|
37
|
-
purgatory [options]
|
|
38
|
-
|
|
39
|
-
Options:
|
|
40
|
-
-p, --port <port> Port to listen on (default: 8545)
|
|
41
|
-
--db <sqlite.db> Path to SQLite database file (default: in-memory)
|
|
42
|
-
--rpc-url <url> RPC URL for the upstream Ethereum node
|
|
43
|
-
--reset-db Reset the database on startup
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
### Chain identity
|
|
47
|
-
|
|
48
|
-
The database belongs to one chain. Purgatory reads the upstream's identity (`eth_chainId` and block 0's hash) before handling RPC requests and before forwarding held transactions (the nodejs CLI also does it on start), and stores it in `MempoolState` under `chain_identity`. The answer is cached for 2 seconds and asked again after any upstream error, so a node replaced while purgatory runs is followed without restarting purgatory. Forwarding held transactions (`include`, `include-batch`, `flush`) always asks the node first, uncached.
|
|
49
|
-
|
|
50
|
-
When the node turns out to serve another chain (another chain id, or the same id with a new genesis, as every hardhat restart is), purgatory wipes its database exactly as `--reset-db` does: held transactions, history and the mempool settings (auto-forward, minimum gas price, replacement mode) go back to their defaults. It logs `chain identity changed (<old> to <new>): db reset` and stores the new identity. A database with no stored identity (new, or written by an older purgatory) adopts the node's identity as is. The check is always on: a held transaction for another chain can never be valid. Transactions signed for another chain id than the node's are refused, and are never forwarded.
|
|
51
|
-
|
|
52
|
-
When the node's identity cannot be read, `eth_sendRawTransaction` and forwarding held transactions fail (JSON-RPC error `Upstream unavailable`, HTTP 502) and held transactions stay held; other requests go to the node as before.
|
|
53
|
-
|
|
54
|
-
With a persistent `--db`, `--reset-db` is therefore only needed to wipe a database on purpose.
|
|
55
|
-
|
|
56
|
-
## Architecture
|
|
5
|
+
Purgatory is a single native binary (Rust) with a web dashboard built in. It uses about 9 MB of memory, so running one per project is cheap.
|
|
57
6
|
|
|
58
7
|
```
|
|
59
8
|
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
|
|
60
|
-
│ Your
|
|
61
|
-
│ │ │ (port
|
|
9
|
+
│ Your dApp │────▶│ purgatory │────▶│ Ethereum node │
|
|
10
|
+
│ │ │ (port 2000) │ │ (port 8545) │
|
|
62
11
|
└─────────────────┘ └─────────────────┘ └─────────────────┘
|
|
63
12
|
│
|
|
64
13
|
▼
|
|
65
14
|
┌───────────┐
|
|
66
15
|
│ SQLite │
|
|
67
|
-
│ Storage │
|
|
68
16
|
└───────────┘
|
|
69
17
|
```
|
|
70
18
|
|
|
71
|
-
##
|
|
19
|
+
## Install
|
|
72
20
|
|
|
73
|
-
|
|
21
|
+
```sh
|
|
22
|
+
npm i -g purgatory # installs the native binary for your platform
|
|
23
|
+
purgatory --help
|
|
24
|
+
```
|
|
74
25
|
|
|
75
|
-
|
|
26
|
+
The npm package installs only the binary for your platform (a `purgatory-<os>-<cpu>` package). Its `purgatory` command replaces itself with that binary on Linux and macOS, so no Node process stays around: a running purgatory is just the native process (about 9 MB). `npx purgatory` works too, but `npx` (like `npm run`) keeps npm itself running as the parent, about 95 MB more; for something that stays up, install it (globally, or as a dev dependency and call `node_modules/.bin/purgatory`).
|
|
76
27
|
|
|
77
|
-
|
|
28
|
+
Prebuilt binaries (Linux x86_64/arm64, macOS x86_64/arm64, Windows x86_64) are also attached to each [GitHub release](https://github.com/wighawag/purgatory/releases). To build from source: see [Development](#development).
|
|
78
29
|
|
|
79
|
-
|
|
30
|
+
## Usage
|
|
80
31
|
|
|
81
|
-
|
|
32
|
+
```
|
|
33
|
+
purgatory [--port 2000] [--rpc-url <url>] [--db <sqlite.db>]
|
|
82
34
|
|
|
83
|
-
|
|
35
|
+
Options:
|
|
36
|
+
-p, --port <port> port to listen on [default: 2000]
|
|
37
|
+
--db <sqlite.db> path to sqlite db file (default: $DB, else in memory)
|
|
38
|
+
--rpc-url <url> RPC URL for the Ethereum node to proxy to (default: $RPC_URL, else http://localhost:8545)
|
|
39
|
+
--reset-db whether to reset the db
|
|
40
|
+
-h, --help Print help
|
|
41
|
+
-V, --version Print version
|
|
42
|
+
```
|
|
84
43
|
|
|
85
|
-
|
|
44
|
+
Then point your dApp at `http://localhost:2000` instead of the node, and open the dashboard at `http://localhost:2000/ui/`.
|
|
86
45
|
|
|
87
|
-
|
|
46
|
+
Purgatory listens on all interfaces. `--db` accepts a plain path or a `file:` URL; an existing database written by the TypeScript version of purgatory keeps working (same schema).
|
|
88
47
|
|
|
89
|
-
|
|
48
|
+
### Environment variables
|
|
90
49
|
|
|
91
|
-
|
|
92
|
-
|--------|----------|-------------|
|
|
93
|
-
| GET | `/api/mempool/state` | Get current mempool state |
|
|
94
|
-
| POST | `/api/mempool/gas-price` | Set minimum gas price |
|
|
95
|
-
| POST | `/api/mempool/auto-forward` | Enable/disable auto-forwarding |
|
|
96
|
-
| POST | `/api/mempool/replacement-mode` | Enable/disable transaction replacement |
|
|
97
|
-
| POST | `/api/mempool/replacement-bump` | Set minimum replacement bump percentage |
|
|
50
|
+
Read from the environment, then from `.env.local` and `.env` in the working directory (the real environment wins, command line flags win over all):
|
|
98
51
|
|
|
99
|
-
|
|
52
|
+
| Variable | Meaning |
|
|
53
|
+
| --------- | ----------------------------------------------------------------------------------------------------------- |
|
|
54
|
+
| `RPC_URL` | the upstream node, when `--rpc-url` is not given |
|
|
55
|
+
| `DB` | the database (path, `file:` URL, or `:memory:`), when `--db` is not given |
|
|
56
|
+
| `DEV` | `POST /api/admin/reset-db` is refused when `DEV` is `""`, `0` or `false`; allowed otherwise (including unset) |
|
|
100
57
|
|
|
101
|
-
|
|
102
|
-
|--------|----------|-------------|
|
|
103
|
-
| GET | `/api/mempool/stats` | Get mempool statistics |
|
|
104
|
-
| GET | `/api/mempool/pending` | List all pending transactions |
|
|
105
|
-
| GET | `/api/mempool/history` | Get transaction history |
|
|
106
|
-
| GET | `/api/mempool/tx/:hash` | Get specific transaction |
|
|
107
|
-
| GET | `/api/mempool/sender/:address` | Get transactions by sender |
|
|
58
|
+
## JSON-RPC
|
|
108
59
|
|
|
109
|
-
|
|
60
|
+
`POST /` and `POST /rpc` take standard Ethereum JSON-RPC requests (one request per call; batches are refused with `-32600 Invalid Request`). Every method is forwarded to the upstream node and its answer returned as is, except:
|
|
110
61
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
| POST | `/api/mempool/drop/:hash` | Drop a pending transaction |
|
|
115
|
-
| POST | `/api/mempool/include-batch` | Forward multiple transactions |
|
|
116
|
-
| POST | `/api/mempool/drop-batch` | Drop multiple transactions |
|
|
117
|
-
| POST | `/api/mempool/flush` | Forward all pending transactions |
|
|
118
|
-
| DELETE | `/api/mempool/clear` | Clear all pending transactions |
|
|
62
|
+
- **`eth_sendRawTransaction`**: the transaction is decoded (legacy, EIP-2930, EIP-1559, and 4844/7702 envelopes), its sender recovered, validated, checked against the minimum gas price and, in replacement mode, against the replacement bump. It is then held in the local mempool; with auto-forward on (the default) it is forwarded at once and marked `forwarded`. The answer is the transaction hash (or the node's answer when forwarded).
|
|
63
|
+
- **`eth_getTransactionByHash`**: a transaction held locally (pending, not hidden) is answered in the node's format, with null block fields; anything else is asked to the node.
|
|
64
|
+
- **`eth_getTransactionCount`** with `pending`: the node's count, extended by the nonces held locally that follow it without a gap.
|
|
119
65
|
|
|
120
|
-
|
|
66
|
+
When the upstream cannot be reached, a forwarded request answers a JSON-RPC error `-32603 Upstream unavailable: ...` with HTTP 502. An upstream HTTP error answers `-32603 Upstream error: <status> <text>`.
|
|
121
67
|
|
|
122
|
-
|
|
123
|
-
|--------|----------|-------------|
|
|
124
|
-
| GET | `/health` | Health check |
|
|
125
|
-
| GET | `/health/upstream` | Upstream node health check |
|
|
68
|
+
### Chain identity
|
|
126
69
|
|
|
127
|
-
|
|
70
|
+
The database belongs to one chain. Purgatory reads the upstream's identity (`eth_chainId` and block 0's hash) on start, before handling RPC requests and before forwarding held transactions, and stores it in `MempoolState` under `chain_identity`. The answer is cached for 2 seconds and asked again after any upstream error, so a node replaced while purgatory runs is followed without restarting purgatory. Forwarding held transactions (`include`, `include-batch`, `flush`) always asks the node first, uncached.
|
|
128
71
|
|
|
129
|
-
|
|
130
|
-
|--------|----------|-------------|
|
|
131
|
-
| POST | `/api/admin/check-chain-identity` | Check the upstream's chain identity now (wipes the db on a change) |
|
|
72
|
+
When the node turns out to serve another chain (another chain id, or the same id with a new genesis, as every anvil or hardhat restart is), purgatory wipes its database exactly as `--reset-db` does: held transactions, history and the mempool settings (auto-forward, minimum gas price, replacement mode) go back to their defaults. It prints `chain identity changed (<old> to <new>): db reset` and stores the new identity. A database with no stored identity (new, or written by an older purgatory) adopts the node's identity as is. Transactions signed for another chain id than the node's are refused, and never forwarded.
|
|
132
73
|
|
|
133
|
-
|
|
74
|
+
When the node's identity cannot be read, `eth_sendRawTransaction` and forwarding held transactions fail (`Upstream unavailable`, HTTP 502) and held transactions stay held; other requests go to the node as before.
|
|
134
75
|
|
|
135
|
-
|
|
136
|
-
- View pending, forwarded, and dropped transactions
|
|
137
|
-
- Monitor mempool statistics
|
|
138
|
-
- Control auto-forward and gas price settings
|
|
139
|
-
- Manually include or drop transactions
|
|
76
|
+
With a persistent `--db`, `--reset-db` is therefore only needed to wipe a database on purpose.
|
|
140
77
|
|
|
78
|
+
## REST API
|
|
79
|
+
|
|
80
|
+
Responses are `{"success": true, "data": ...}` or `{"success": false, "error": "..."}`. Wei amounts are `0x` hex strings, timestamps unix seconds.
|
|
81
|
+
|
|
82
|
+
| Method | Endpoint | Description |
|
|
83
|
+
| ------ | --------------------------------- | ----------------------------------------------------------------------------------- |
|
|
84
|
+
| GET | `/api/mempool/state` | settings: `minGasPrice`, `autoForward`, `replacementEnabled`, `minReplacementBump` |
|
|
85
|
+
| POST | `/api/mempool/gas-price` | `{minGasPrice}` (decimal or `0x` wei) |
|
|
86
|
+
| POST | `/api/mempool/auto-forward` | `{enabled}` |
|
|
87
|
+
| POST | `/api/mempool/replacement-mode` | `{enabled}`: node-like replacement (off: several transactions may share a nonce) |
|
|
88
|
+
| POST | `/api/mempool/replacement-bump` | `{percent}` (0 to 1000) |
|
|
89
|
+
| GET | `/api/mempool/stats` | counts by status, unique senders, oldest pending age |
|
|
90
|
+
| GET | `/api/mempool/pending` | pending transactions (`?from=`, `?limit=`, `?offset=`) |
|
|
91
|
+
| GET | `/api/mempool/history` | every status (`?status=`, `?limit=` default 50, `?offset=`) |
|
|
92
|
+
| GET | `/api/mempool/tx/:hash` | one transaction (404 when unknown) |
|
|
93
|
+
| GET | `/api/mempool/sender/:address` | pending transactions of a sender, by nonce |
|
|
94
|
+
| POST | `/api/mempool/include/:hash` | forward a held transaction now |
|
|
95
|
+
| POST | `/api/mempool/drop/:hash` | drop a pending transaction (`{reason}` optional); it stays in the history |
|
|
96
|
+
| POST | `/api/mempool/include-batch` | `{hashes}` |
|
|
97
|
+
| POST | `/api/mempool/drop-batch` | `{hashes, reason?}` |
|
|
98
|
+
| POST | `/api/mempool/flush` | forward every pending transaction, sender by sender in nonce order |
|
|
99
|
+
| DELETE | `/api/mempool/clear` | delete every pending transaction (the history stays) |
|
|
100
|
+
| POST | `/api/mempool/hide/:hash` | hide a transaction (kept in the db, left out of lists and of JSON-RPC answers) |
|
|
101
|
+
| POST | `/api/mempool/restore/:hash` | show a hidden transaction again |
|
|
102
|
+
| GET | `/api/mempool/hidden` | hidden transactions (`?address=`) |
|
|
103
|
+
| POST | `/api/admin/check-chain-identity` | check the upstream's chain identity now (wipes the db on a change) |
|
|
104
|
+
| POST | `/api/admin/reset-db` | wipe the db (see `DEV`) |
|
|
105
|
+
| POST | `/api/admin/setup-db` | create missing tables (idempotent) |
|
|
106
|
+
| POST | `/api/admin/tx/hide` | `{hash}` |
|
|
107
|
+
| POST | `/api/admin/tx/restore` | `{hash}` |
|
|
108
|
+
| GET | `/api/admin/tx/hidden` | `{transactions}` (`?address=`) |
|
|
109
|
+
| GET | `/health` | `{status, timestamp, version}` |
|
|
110
|
+
| GET | `/health/upstream` | the upstream's chain id, or 503 |
|
|
111
|
+
|
|
112
|
+
## Dashboard
|
|
113
|
+
|
|
114
|
+
`GET /ui/` (and `GET /`, which redirects there) serves the dashboard, built into the binary: stats, mempool settings, the pending and history lists with include, drop and hide, nonce-conflict highlighting, hidden transactions with restore, flush all and clear pending. It refreshes itself (transactions every 2 s, stats and settings every 5 s).
|
|
115
|
+
|
|
116
|
+
## Footprint
|
|
117
|
+
|
|
118
|
+
Measured on Linux x86_64 with `pnpm footprint` (`scripts/footprint.sh`: release binary, in-memory db, 10,000 requests to `/ui/` and `/api/mempool/pending`):
|
|
119
|
+
|
|
120
|
+
| | Rust binary | TypeScript version (Node 24, `purgatory@0.0.8`) |
|
|
121
|
+
| ---------------------------- | ----------- | ----------------------------------------------- |
|
|
122
|
+
| RSS at idle | 8.4 to 8.9 MB | about 108 MB |
|
|
123
|
+
| RSS after 10,000 requests | 10.7 to 10.8 MB | about 165 MB |
|
|
124
|
+
| install size | 6.8 MB | about 113 MB of `node_modules` |
|
|
125
|
+
|
|
126
|
+
## Changes from the TypeScript version
|
|
127
|
+
|
|
128
|
+
The Rust binary keeps the CLI, the JSON-RPC behaviour, the REST API and the SQLite schema. What differs:
|
|
129
|
+
|
|
130
|
+
- An unreachable upstream on a forwarded JSON-RPC method answers a JSON-RPC error (`-32603 Upstream unavailable: ...`) with HTTP 502, not a generic 500. The same holds when forwarding a held transaction (`include` answers 502; a batch or a flush counts it as failed and goes on).
|
|
131
|
+
- `GET /` redirects to `/ui/` (it answered `hello world`); the `/setup` route and the htmx dashboard's `/ui/partials/*` and `/ui/actions/*` routes are gone.
|
|
132
|
+
- `POST /api/admin/reset-db` is allowed unless `DEV` is `""`, `0` or `false`; `--reset-db` always resets.
|
|
133
|
+
- The default upstream is `http://localhost:8545` (the npm package of the TypeScript version effectively defaulted to `http://localhost:8546` through its bundled `.env.default`).
|
|
134
|
+
- `GET /api/admin/tx/hidden` answers `TransactionInfo` objects (the TypeScript version failed with a 500 as soon as a transaction was hidden).
|
|
135
|
+
- A negative minimum gas price is refused (400).
|
|
136
|
+
- File databases are switched to SQLite's WAL journal mode.
|
|
137
|
+
- The Cloudflare Worker version and the typed Hono client are gone.
|
|
141
138
|
|
|
142
139
|
## Development
|
|
143
140
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
```bash
|
|
147
|
-
# Run all tests
|
|
148
|
-
pnpm test
|
|
141
|
+
Requirements: Rust (the toolchain is pinned by `rust-toolchain.toml`), Node.js 22+ with pnpm, and [`anvil`](https://getfoundry.sh) for the tests.
|
|
149
142
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
pnpm
|
|
143
|
+
```sh
|
|
144
|
+
pnpm install
|
|
145
|
+
pnpm build # dashboard (web/) then cargo build --release
|
|
146
|
+
pnpm verify # format check, lint (clippy, svelte-check), build, tests
|
|
153
147
|
```
|
|
154
148
|
|
|
155
|
-
|
|
149
|
+
- `crates/purgatory`: the server (axum, rusqlite, alloy). `cargo test` runs its unit tests.
|
|
150
|
+
- `web/`: the dashboard (SvelteKit, shadcn-svelte, Tailwind), see [web/README.md](web/README.md) for its dev loop (`pnpm web:dev` with hot reload against a running purgatory, or `pnpm web:build:watch` + `cargo run`).
|
|
151
|
+
- `test/`: the acceptance suite, which drives a purgatory process over HTTP; see [test/README.md](test/README.md). `pnpm test:acceptance` runs it against `target/release/purgatory` (set `PURGATORY_CMD` for another binary). It starts anvil on port 5051, and on 5052 for the tests that restart a node behind purgatory (`PURGATORY_TEST_RPC_PORT` / `PURGATORY_TEST_NODE_PORT` move them).
|
|
152
|
+
- `pnpm start` opens a zellij session with anvil, the dashboard build in watch mode and `cargo run`.
|
|
153
|
+
- `pnpm format` / `pnpm format:check`: prettier for `web/` and `test/`, `cargo fmt`.
|
|
156
154
|
|
|
157
|
-
|
|
155
|
+
## Release
|
|
158
156
|
|
|
159
|
-
|
|
160
|
-
# Start with hot reload
|
|
161
|
-
pnpm nodejs:dev
|
|
157
|
+
Releases are built by [cargo-dist](https://opensource.axo.dev/cargo-dist/) (config in `dist-workspace.toml`, workflow in `.github/workflows/release.yml`, generated by `dist generate`). Pushing a version tag builds the binaries for every target (each build runner first builds `web/`, see `.github/build-setup.yml`) and creates the GitHub release with the archives and checksums. Then `.github/workflows/publish-npm.yml` assembles the npm packages from those archives (`scripts/npm-packages.mjs`: one `purgatory-<os>-<cpu>` package per platform with the binary, and `purgatory`, which depends on them as optional dependencies) and publishes them, platform packages first.
|
|
162
158
|
|
|
163
|
-
|
|
164
|
-
pnpm start:nodejs
|
|
165
|
-
```
|
|
159
|
+
Publishing uses npm Trusted Publishing (OIDC): there is no `NPM_TOKEN` secret.
|
|
166
160
|
|
|
167
|
-
|
|
161
|
+
One-time setup:
|
|
168
162
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
pnpm format:check # Check formatting
|
|
172
|
-
```
|
|
163
|
+
1. Create the platform packages as placeholders so they can get a trusted publisher: `npm login`, then `scripts/npm-bootstrap.sh` (publishes `0.0.0` of `purgatory-linux-x64`, `purgatory-linux-arm64`, `purgatory-darwin-x64`, `purgatory-darwin-arm64`, `purgatory-windows-x64`; skips existing ones). If npm refuses a name, set `"npm": false` on that platform in `npm/platforms.json` (its users then download the binary from the GitHub release; the `purgatory` command tells them so) or pick another name there.
|
|
164
|
+
2. On npmjs.com, for each of those five packages and for `purgatory`, add a GitHub Actions trusted publisher: repository `wighawag/purgatory`, workflow `release.yml` (the workflow the tag runs). The publish happens in `publish-npm.yml`, which `release.yml` calls; if npm refuses the publish, add a second trusted publisher with workflow `publish-npm.yml`.
|
|
173
165
|
|
|
174
|
-
|
|
166
|
+
To publish a version (a human step):
|
|
175
167
|
|
|
176
|
-
|
|
168
|
+
1. Bump `version` in `crates/purgatory/Cargo.toml` (it continues the npm line: `0.1.1` is the first native release after the TypeScript `0.0.x`; `0.1.0` and `1.0.0` were used by an older package of the same name in 2017 and can never be published again), run `cargo build` so `Cargo.lock` follows, and commit.
|
|
169
|
+
2. Optionally check what will be built: `dist plan` (install `dist` from the [cargo-dist releases](https://github.com/axodotdev/cargo-dist/releases)).
|
|
170
|
+
3. Tag and push the tag: `git tag v0.1.1 && git push origin v0.1.1`.
|
|
171
|
+
4. Watch the `Release` workflow; when it is green the GitHub release and `npm i purgatory@0.1.1` are live.
|
|
172
|
+
|
|
173
|
+
After changing `dist-workspace.toml` or upgrading cargo-dist, run `dist generate` and commit the regenerated workflow (`dist plan` fails while it is out of date). CI (`.github/workflows/ci.yml`) runs `pnpm verify` on every push and pull request.
|
|
177
174
|
|
|
178
|
-
##
|
|
175
|
+
## License
|
|
179
176
|
|
|
180
|
-
|
|
177
|
+
MIT
|
package/bin/purgatory.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
// The `purgatory` command of the npm package: find the native binary that
|
|
4
|
+
// npm installed for this platform (an optional dependency such as
|
|
5
|
+
// `purgatory-linux-x64`) and run it.
|
|
6
|
+
//
|
|
7
|
+
// On Linux and macOS the binary REPLACES this Node process (`process.execve`,
|
|
8
|
+
// Node >= 22.15 / 23.11): nothing of Node stays in memory and signals go
|
|
9
|
+
// straight to purgatory. Elsewhere (Windows, older Node) it runs as a child
|
|
10
|
+
// process, with signals forwarded and its exit status passed on.
|
|
11
|
+
|
|
12
|
+
const path = require('node:path');
|
|
13
|
+
|
|
14
|
+
// `<platform> <arch>` -> package name, written by scripts/npm-packages.mjs
|
|
15
|
+
// from npm/platforms.json (only the platforms published to npm)
|
|
16
|
+
const PACKAGES = require('./packages.json');
|
|
17
|
+
|
|
18
|
+
function fail(message) {
|
|
19
|
+
console.error(`purgatory: ${message}`);
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function binaryPath() {
|
|
24
|
+
if (process.env.PURGATORY_BINARY) return process.env.PURGATORY_BINARY;
|
|
25
|
+
const key = `${process.platform} ${process.arch}`;
|
|
26
|
+
const pkg = PACKAGES[key];
|
|
27
|
+
if (!pkg) {
|
|
28
|
+
fail(
|
|
29
|
+
`no prebuilt binary for ${key}. Download one from https://github.com/wighawag/purgatory/releases or build it with cargo.`,
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
let dir;
|
|
33
|
+
try {
|
|
34
|
+
dir = path.dirname(require.resolve(`${pkg}/package.json`));
|
|
35
|
+
} catch {
|
|
36
|
+
fail(
|
|
37
|
+
`the package ${pkg} (the binary for ${key}) is not installed. Reinstall purgatory without --omit=optional / --no-optional.`,
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
return path.join(
|
|
41
|
+
dir,
|
|
42
|
+
'bin',
|
|
43
|
+
process.platform === 'win32' ? 'purgatory.exe' : 'purgatory',
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const binary = binaryPath();
|
|
48
|
+
const args = process.argv.slice(2);
|
|
49
|
+
|
|
50
|
+
if (process.platform !== 'win32' && typeof process.execve === 'function') {
|
|
51
|
+
process.execve(binary, [binary, ...args], process.env);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const {spawn} = require('node:child_process');
|
|
55
|
+
const child = spawn(binary, args, {stdio: 'inherit'});
|
|
56
|
+
const forwarded = ['SIGINT', 'SIGTERM', 'SIGHUP', 'SIGBREAK'];
|
|
57
|
+
for (const signal of forwarded) {
|
|
58
|
+
try {
|
|
59
|
+
process.on(signal, () => child.kill(signal));
|
|
60
|
+
} catch {
|
|
61
|
+
// not a signal on this platform
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
child.on('error', (error) => fail(error.message));
|
|
65
|
+
child.on('exit', (code, signal) => {
|
|
66
|
+
if (signal) {
|
|
67
|
+
for (const s of forwarded) process.removeAllListeners(s);
|
|
68
|
+
process.kill(process.pid, signal);
|
|
69
|
+
} else {
|
|
70
|
+
process.exit(code ?? 1);
|
|
71
|
+
}
|
|
72
|
+
});
|
package/package.json
CHANGED
|
@@ -1,37 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "purgatory",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Ethereum JSON-RPC proxy that holds transactions in a local mempool (native binary)",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/wighawag/purgatory.git"
|
|
6
9
|
},
|
|
7
|
-
"
|
|
10
|
+
"homepage": "https://github.com/wighawag/purgatory#readme",
|
|
8
11
|
"bin": {
|
|
9
|
-
"purgatory": "
|
|
12
|
+
"purgatory": "bin/purgatory.js"
|
|
10
13
|
},
|
|
11
14
|
"files": [
|
|
12
|
-
"
|
|
13
|
-
"stc",
|
|
14
|
-
".env.default"
|
|
15
|
+
"bin"
|
|
15
16
|
],
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"@libsql/client": "^0.17.2",
|
|
19
|
-
"commander": "^14.0.3",
|
|
20
|
-
"ldenv": "^0.3.16",
|
|
21
|
-
"named-logs-context": "^0.1.1",
|
|
22
|
-
"purgatory-core": "0.0.8",
|
|
23
|
-
"remote-sql-libsql": "^0.0.7"
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">=18"
|
|
24
19
|
},
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
},
|
|
32
|
-
"scripts": {
|
|
33
|
-
"dev": "tsx watch src/cli.ts --port 8545 --db sqlite.db",
|
|
34
|
-
"build": "tsc",
|
|
35
|
-
"build:watch": "as-soon -w src tsc"
|
|
20
|
+
"optionalDependencies": {
|
|
21
|
+
"purgatory-linux-x64": "0.1.1",
|
|
22
|
+
"purgatory-linux-arm64": "0.1.1",
|
|
23
|
+
"purgatory-darwin-x64": "0.1.1",
|
|
24
|
+
"purgatory-darwin-arm64": "0.1.1",
|
|
25
|
+
"purgatory-windows-x64": "0.1.1"
|
|
36
26
|
}
|
|
37
|
-
}
|
|
27
|
+
}
|
package/.env.default
DELETED
package/dist/cli.d.ts
DELETED
package/dist/cli.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,oBAAoB,CAAC"}
|
package/dist/cli.js
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import "named-logs-context";
|
|
3
|
-
import { createServer } from "purgatory-core";
|
|
4
|
-
import { serve } from "@hono/node-server";
|
|
5
|
-
import { RemoteLibSQL } from "remote-sql-libsql";
|
|
6
|
-
import { createClient } from "@libsql/client";
|
|
7
|
-
import fs from "node:fs";
|
|
8
|
-
import path from "node:path";
|
|
9
|
-
import { Command } from "commander";
|
|
10
|
-
import { loadEnv } from "ldenv";
|
|
11
|
-
const __dirname = import.meta.dirname;
|
|
12
|
-
loadEnv({
|
|
13
|
-
defaultEnvFile: path.join(__dirname, "../.env.default"),
|
|
14
|
-
});
|
|
15
|
-
async function main() {
|
|
16
|
-
const pkg = JSON.parse(fs.readFileSync(path.join(__dirname, "../package.json"), "utf-8"));
|
|
17
|
-
const program = new Command();
|
|
18
|
-
program
|
|
19
|
-
.name("purgatory-nodejs")
|
|
20
|
-
.version(pkg.version)
|
|
21
|
-
.usage(`purgatory-nodejs [--port 2000] [--rpc-url <url>]`)
|
|
22
|
-
.description("run purgatory-nodejs as a node process")
|
|
23
|
-
.option("-p, --port <port>", "port to listen on", "2000")
|
|
24
|
-
.option("--db <sqlite.db>", "path to sqlite db file")
|
|
25
|
-
.option("--rpc-url <url>", "RPC URL for the Ethereum node to proxy to")
|
|
26
|
-
.option("--reset-db", "whether to reset the db");
|
|
27
|
-
program.parse(process.argv);
|
|
28
|
-
const options = program.opts();
|
|
29
|
-
const port = options.port ? parseInt(options.port) : 2000;
|
|
30
|
-
// CLI arguments override environment variables
|
|
31
|
-
const env = {
|
|
32
|
-
...process.env,
|
|
33
|
-
RPC_URL: options.rpcUrl || process.env.RPC_URL || "http://localhost:8545",
|
|
34
|
-
};
|
|
35
|
-
let db = env.DB;
|
|
36
|
-
if (options.db) {
|
|
37
|
-
db = `file:///${path.resolve(options.db)}`;
|
|
38
|
-
}
|
|
39
|
-
const client = createClient({
|
|
40
|
-
url: db,
|
|
41
|
-
});
|
|
42
|
-
const remoteSQL = new RemoteLibSQL(client);
|
|
43
|
-
const app = createServer({
|
|
44
|
-
getDB: () => remoteSQL,
|
|
45
|
-
getEnv: () => env,
|
|
46
|
-
});
|
|
47
|
-
console.log(`setting up db...`);
|
|
48
|
-
const response = await app.fetch(new Request("http://localhost/api/admin/setup-db", {
|
|
49
|
-
method: "POST",
|
|
50
|
-
// headers: {
|
|
51
|
-
// Authorization: `Basic ${btoa(`admin:${TOKEN_ADMIN}`)}`,
|
|
52
|
-
// },
|
|
53
|
-
}));
|
|
54
|
-
console.log(response.ok);
|
|
55
|
-
console.log(await response.text());
|
|
56
|
-
if (options.resetDb) {
|
|
57
|
-
console.log(`resetting db...`);
|
|
58
|
-
await app.fetch(new Request("http://localhost/api/admin/reset-db", {
|
|
59
|
-
method: "POST",
|
|
60
|
-
// headers: {
|
|
61
|
-
// Authorization: `Basic ${btoa(`admin:${TOKEN_ADMIN}`)}`,
|
|
62
|
-
// },
|
|
63
|
-
}));
|
|
64
|
-
}
|
|
65
|
-
// The db belongs to one chain: check the upstream's identity (chain id and
|
|
66
|
-
// block 0's hash) now. On a different chain the db is wiped, as --reset-db
|
|
67
|
-
// does. The same check runs again before requests and before forwarding
|
|
68
|
-
// held transactions, so a node replaced while purgatory runs is followed.
|
|
69
|
-
const identityResponse = await app.fetch(new Request("http://localhost/api/admin/check-chain-identity", {
|
|
70
|
-
method: "POST",
|
|
71
|
-
}));
|
|
72
|
-
const identityResult = (await identityResponse.json());
|
|
73
|
-
if (identityResult.success && identityResult.identity) {
|
|
74
|
-
console.log(`chain identity: ${identityResult.identity.chainId}:${identityResult.identity.genesisHash}`);
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
console.log(`chain identity not checked yet (${identityResult.error}); it will be on the first request`);
|
|
78
|
-
}
|
|
79
|
-
serve({
|
|
80
|
-
fetch: app.fetch,
|
|
81
|
-
port,
|
|
82
|
-
});
|
|
83
|
-
console.log(`Server is running on http://localhost:${port}`);
|
|
84
|
-
console.log(`RPC proxy configured to: ${env.RPC_URL || "(not configured)"}`);
|
|
85
|
-
console.log(`Endpoints:`);
|
|
86
|
-
console.log(` - POST /rpc - JSON-RPC proxy endpoint`);
|
|
87
|
-
console.log(` - GET /health - Health check`);
|
|
88
|
-
console.log(` - GET /health/upstream - Upstream node health check`);
|
|
89
|
-
}
|
|
90
|
-
main();
|
|
91
|
-
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,oBAAoB,CAAC;AAC5B,OAAO,EAAE,YAAY,EAAY,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAEhC,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC;AAEtC,OAAO,CAAC;IACN,cAAc,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,iBAAiB,CAAC;CACxD,CAAC,CAAC;AAMH,KAAK,UAAU,IAAI;IACjB,MAAM,GAAG,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