# Cuprate in-process launch spike (Phase 1, Spike A) **Question:** does `cuprated::Node::launch(config).await` start a real Monero chain daemon *inside the OnionWire process* on testnet, and does the resulting JSON-RPC endpoint at `127.0.0.1:18089` answer `get_info`, `get_height` and `get_block` the way `monerod` does — i.e. is the §7a Phase 1 shape (Cuprate in-process for chain, `monero-wallet-rpc` as a subprocess pointing at it) worth building? **Verdict: VALIDATED, with four `get_info`/error-path parity gaps to fix or work around.** Status: exploration only. Nothing in `src/` changes here, and no `cuprated` dependency is added to the repo by this spike. Compile-level feasibility was already proven by the preceding card; this card proves **runtime** feasibility (launch, RPC, P2P, sync, shutdown). ## Method Throwaway spike crate (not in this repo): `/home/lancelot/.hermes/tmp/cuprate-poc/` (`src/main.rs`, `run-1.log`, `run-2.log`, `rpc-evidence/`). * `cuprated` git dep at the rev already in the POC lock file: `4f8fcd1bf468f566fcd89c460d50de4adb6825bf` (`cuprated` 0.1.0-preview, features `["arti"]`), alongside `arti-client` 0.46. Both `arti-client` 0.44.0 (pulled by Cuprate) and 0.46.0 (OnionWire's pin) resolve side by side in the one lock file (693 packages), and `tor-hsservice` likewise carries 0.44.0 and 0.46.0. * The node is launched **in-process**: `Node::launch(config).await` inside a `#[tokio::main]`. No `cuprated` binary, no `monerod`, no subprocess of any kind for the chain. * Config: `network = "Testnet"`, `target_max_memory = 2 GB`, `fast_sync = true`, `p2p.tor_net.enabled = false` (so no Arti bootstrap in this spike), `p2p.clear_net.enable_inbound = false`, unrestricted RPC on `127.0.0.1:18089`, restricted RPC on `127.0.0.1:28089`, data dir under the spike tree. * RPC probes are raw HTTP/1.1 over `tokio::net::TcpStream` (no HTTP client dependency), with `cuprated::logging::init_logging` enabled so cuprated's own tracing lands in the log. * CUPRATE's own `get_info` reports the network as `"nettype":"testnet"`, `"testnet":true`. ## Results ### Launch and listener ``` ==== LAUNCH OK in 953.837093ms (resume, data dir with 1160 blocks) ==== LAUNCH OK in 2.842708694s (cold, empty data dir) ==== network=Testnet in-process chain_height=1 ==== RPC socket 127.0.0.1:18089 accepting connections ``` Both RPC ports (`18089` unrestricted, `28089` restricted) were bound and accepting TCP within 0.2 s of `Node::launch` returning. Dropping the `Node` handle shuts the node down and the process exits cleanly (no hung tokio tasks, no orphan process). ### The three endpoints the card asked for | Probe | Status | Payload | |---|---|---| | `POST /json_rpc {"method":"get_info"}` | 200 | full daemon-info JSON, `"status":"OK"`, `nettype: testnet`, `height`, `target_height`, `synchronized`, `top_block_hash`, `difficulty`, `cumulative_difficulty`, `block_size_limit`, `version: "0.1.0-preview-release"` | | `GET /get_info` | 200 | same object (both the JSON-RPC route and the URI route are served, as monerod does) | | `GET /get_height` | 200 | `{"status":"OK","hash":"7458280c…","height":23758}` | | `POST /json_rpc {"method":"get_block_count"}` | 200 | `{"count":23758}` | | `POST /json_rpc {"method":"get_block","params":{"height":H}}` | 200 | `blob` (hex block), `block_header` (monerod-shaped: `height`, `hash`, `prev_hash`, `reward`, `timestamp`, `num_txes`, `difficulty`, `cumulative_difficulty`, `long_term_weight`, `major_version`, `minor_version`, …), `miner_tx_hash`, `tx_hashes`, `json` | `get_block` succeeded for heights **0, 1, 2 and 1000** (after sync): e.g. height 1000 returned a 640-hex-char blob with `block_header.height = 1000`, and the genesis block returned `block_header.hash = 48ca7cd3…`, the same hash `/get_height` reported at height 1. Two naming facts worth recording, because the card's wording ("get_height via /json_rpc") does not match either daemon: * `get_height` is **not** a JSON-RPC 2.0 method in monerod — it is registered as a URI endpoint only (`MAP_URI_AUTO_JON2("/get_height", …)` and `"/getheight"` in `src/rpc/core_rpc_server.h:92-93`), while the JSON-RPC method is `MAP_JON_RPC("get_block_count", …)` (line 134). Cuprate mirrors exactly that split: `/get_height` answers, `{"method":"get_height"}` over `/json_rpc` is rejected 422 ("unknown variant `get_height`"), and `get_block_count` answers. This is parity, not a gap. * Cuprate's router also carries the monerod aliases (`/getinfo`, `/getheight`, `/getblockcount`, `/gethashes.bin`, …). ### Real testnet P2P sync in-process ``` INFO net{zone="ClearNet"}: Starting outbound connection maintainer, target outbound connections: 32 INFO net{zone="ClearNet"}:connect_to_random_seeds: Failed to connect to seed node 51.79.173.165:28080: Connection refused INFO incoming_block_batch{start_height=17968 len=100}: Successfully added block batch fast_sync=false ... t+ 0s height=1160 target_height=0 in-process_chain_height=1160 t+ 40s height=4549 target_height=3090939 in-process_chain_height=4549 t+ 80s height=14068 target_height=3090939 in-process_chain_height=14068 t+ 120s height=23758 target_height=3090939 in-process_chain_height=23758 ``` Testnet sync runs from inside the OnionWire-style process at roughly **200 blocks/s** (~23.7k blocks in 120 s against a 3.09M-block target), and the RPC `height` tracks the in-process `node.blockchain.context().chain_height` at every sample — the RPC reads live chain state, so a wallet child pointed at it sees progress as it happens. ### Binary cost Spike binary (arti 0.46 + cuprated + tokio + harness), release, stripped: **33,256,328 bytes (31.7 MiB)**; unstripped 48,489,392 bytes. This is consistent with the earlier +5.6 MB stripped delta over OnionWire's own 25.6 MB release binary. ## Parity gaps observed (must be handled before Phase 1 lands) 1. **Out-of-range `get_block` returns a bare HTTP 500 with an empty body.** Requesting `height = chain_height + 1_000_000` produced `HTTP/1.1 500 Internal Server Error` with a zero-byte body. monerod answers HTTP 200 with an epee JSON-RPC error object instead: `error_resp.code = CORE_RPC_ERROR_CODE_TOO_BIG_HEIGHT; error_resp.message = "Requested block height: N greater than current top block height: M"` (`src/rpc/core_rpc_server.cpp`, `on_get_block`). A wallet child or our own `wallet.rs` has to treat a 500-with-no-body as an error it cannot decode, where monerod gave it a machine-readable code. 2. **`get_info` always reports zero peers**, including while actively downloading blocks: `outgoing_connections_count = 0`, `incoming_connections_count = 0` in every sample while `height` climbed 1,160 → 23,758. monerod reports live counts there. Any UI that shows peer count or "connected" from `get_info` will show zero on a syncing node. 3. **Restricted `get_info` returns placeholder values**: `database_size = 5368709120` (exactly 5 GiB, `0x1_4000_0000`) and `version = ""`, where the unrestricted server on the same process/DB returned the real size and `"0.1.0-preview-release"`. `free_space` is `18446744073709551615` (u64::MAX) on both servers — a placeholder, not a measurement. `monero-wallet-rpc` polling the restricted endpoint would show a bogus database size and a blank version. 4. **Version string** is the pre-release label `0.1.0-preview-release`; anything doing a monerod version comparison against it will not recognise it. Not tested here (out of scope for this card): `get_transfers`-shaped flows through a real `monero-wallet-rpc`, mainnet sync, prune behaviour, Tor zone, and field-by-field equality against a live `monerod` (no `monerod` binary on this host — the comparison above is against monerod's source, `core_rpc_server.h` / `core_rpc_server.cpp`). ## Recommendation Phase 1 is **viable**: the chain daemon genuinely runs in-process, its RPC is monerod-shaped for the three endpoints a wallet needs, and real testnet P2P sync works with no external binary. Before wiring `monero-wallet-rpc` to it: * decide how to handle the 500-on-bad-height path (fix upstream, or treat 5xx as a typed error in `src/wallet.rs`); * do not source peer count, database size, free space or version from `get_info` for UI claims — the restricted server returns placeholders, and the daemon reports zero peers; * keep the pre-production warning honest in `docs/WALLET.md` / `docs/THREAT_MODEL.md`: Cuprate's own user book says not to use `cuprated` for anything serious, and RPC parity (`Cuprate/cuprate#278`) is still open. ## Reproduction ```sh cd /home/lancelot/.hermes/tmp/cuprate-poc CARGO_TARGET_DIR=/home/lancelot/.hermes/tmp/cuprate-poc-target \ TMPDIR=/home/lancelot/.hermes/tmp/cuprate-poc-tmp \ cargo run --release --offline ``` The run log (`run-2.log`) and every raw RPC response body (`rpc-evidence/`) are kept in the spike directory; the data dir (`data/testnet/`) is a 53 MB fjall store after 23.7k testnet blocks, so restarting the spike resumes instead of re-syncing.