wallet: land the in-process Cuprate chain source on main (ChainSource::InProcessCuprate, cuprate-daemon feature) #110

Merged
sirius merged 1 commit from onionwire/t_04975420-cuprate-land-the-in-process-chain-source into main 2026-09-18 18:05:47 +00:00
Owner

What this is

Part 1 of three (this card, the SDK card, the Android card): ChainSource::InProcessCuprate — the Monero chain daemon runs inside the OnionWire process instead of as a spawned monerod. Cuprate's P2P + consensus + RandomX are compiled in behind an opt-in cuprate-daemon feature, off by default.

The trick that keeps the whole wallet layer still: the in-process daemon binds the same unrestricted loopback RPC (127.0.0.1:18081) that WalletChild::daemon_address already returns for a local source, so wallet_rpc_argv, the RPC client, the payment frames and the receipt-verification path are untouched.

SDK names for the next card (t_48f0f8b6): core variant ChainSource::InProcessCuprate (field: datadir), UniFFI enum variant ChainChoice::InProcessCuprate, core label in-process node, stored record kind = "cuprate", and monerod_datadir is the chain data directory for that kind (no binary path).

Changes

  • Cargo.toml: cuprated git dep pinned at rev 4f8fcd1b + toml, both optional, behind cuprate-daemon. cuprated's default arti feature is off (default-features = false) — its arti-client 0.44 cannot unify with this crate's 0.46 and the daemon is clearnet-only, so there is exactly one Tor stack in the process. Cargo.lock gains the graph.
  • src/cuprate.rs (new): CuprateNode builds the cuprated config as TOML (testnet, unrestricted RPC on loopback, restricted RPC disabled, inbound P2P off, 2 GB memory target, 4 db reader threads), launches it on a runtime it owns, and owns the node. launch is synchronous because WalletChild::start is sync (the TUI calls it from its blocking thread, UniFFI calls it from an async context) and a runtime cannot be started from inside a runtime: the launch runs on a dedicated thread and the node plus its runtime come back over a channel. Drop asks the node to shut down and shutdown_backgrounds the runtime (the only exit that cannot panic when the value is dropped inside another runtime). Without the feature the type still exists and launch fails with the feature name, so the chain-source type, its record and its copy do not fork on a cargo feature.
  • src/wallet.rs: the variant, its label, and the chain-daemon client that the wallet line carried: a typed WalletError, HTTP de-chunking (Cuprate is axum/hyper and answers Transfer-Encoding: chunked), get_height over the URI endpoint (Cuprate 422s it over /json_rpc), and an above-the-tip height as one typed error (Cuprate: bare HTTP 500 with an empty body; monerod: error.code = -2).
  • src/wallet_child.rs: launches/holds/stops the node (no pid — the value is the lifecycle), chain_datadir for the ownership/free-space question, the honest chain_copy line, kind = "cuprate" in the sealed record, and ChildConfig::validate for it.
  • src/tui.rs: the wallet screen's chain line carries the testnet caveat when the configured source is the in-process one. The line is computed at draw time, so Screen::Wallet's shape (which tests construct) does not change.
  • Docs: docs/WALLET.md (the fourth source, the feature flag, the fjall store location, how it is selected, the measured size delta, testnet-only and no-Tor-in-the-chain-path), docs/THREAT_MODEL.md (no daemon operator; the device is now the trust root for chain data; chain store is not the SQLCipher store), docs/cuprate-android-spike.md (in-repo proof + a correction: the two arti families the spike saw came from the PoC manifest enabling cuprated's arti feature, which this crate does not).

Acceptance evidence

1. Default build unchanged (feature off) — cargo test --locked --target x86_64-unknown-linux-gnu:

test result: ok. 345 passed / 0 failed across 33 suites
TEST_EXIT=0
CLIPPY_EXIT=0    (cargo clippy --locked --all-targets --target x86_64-unknown-linux-gnu -- -D warnings)

The cuprated graph is genuinely absent from a default build:

$ cargo tree --locked -e normal -i cuprated
error: package ID specification `cuprated` did not match any packages
$ cargo tree --locked -e normal -i arti-client
arti-client v0.46.0
└── onionwire v0.2.1

2. Feature on, host — cargo test --locked --features cuprate-daemon --target x86_64-unknown-linux-gnu: 347 passed / 0 failed, TEST_EXIT=0, CLIPPY_EXIT=0. The two extra tests are not compile-only:

test wallet_child::tests::in_process_source_launches_a_daemon_and_stop_shuts_it_down ... ok
test an_in_process_cuprate_node_answers_the_typed_daemon_client ... ok

The second one launches the real cuprated node, drives get_info / get_height / get_block through the typed daemon client, asserts an above-the-tip height maps to DaemonHeightOutOfRange, asserts the chain store is under the chain datadir (.../chain/testnet/fjall), and asserts the RPC listener closes when the node is dropped.

3. This repo cross-compiles for aarch64-linux-android (the load-bearing one — the spike proved it on a PoC tree, not here):

$ cargo check --locked --release --target aarch64-linux-android --features cuprate-daemon
    Finished `release` profile [optimized] target(s) in 1m 50s
CHECK_EXIT=0

$ cargo rustc --locked --release --target aarch64-linux-android --features cuprate-daemon --bin onionwire -- <NDK link args>
    Finished `release` profile [optimized] target(s) in 2m 05s
LINK_EXIT=0
$ file <target>/aarch64-linux-android/release/onionwire
ELF 64-bit LSB pie executable, ARM aarch64, version 1 (SYSV), dynamically linked,
interpreter /system/bin/linker64, for Android 26, built by NDK r28c (13676358),
not stripped

Note for anyone reproducing: cargo rustc needs --bin onionwire (or --lib) — this crate has both targets and rustc link args may only be passed to one, which the single-bin PoC never hit.

4. Measured size delta (stripped aarch64 release binary, llvm-strip, same link args):

build bytes
without the feature 24,725,704
--features cuprate-daemon 37,053,472

Delta 12,327,768 bytes (≈ +11.8 MiB) — in docs/WALLET.md. (The +5.6 MB figure that circulated with the spike was an estimate and understated it; the earlier +12.25 MB correction was right.)

Scope deviations, stated plainly

  • src/cuprate.rs and its single src/lib.rs module line are outside the card's allowed list; the card's own deliverable describes this module's behaviour. Nothing else outside the list was touched.
  • crates/onionwire-sdk/src/lib.rs is forbidden by the card, but adding a variant to a pub enum the SDK matches exhaustively breaks the SDK workspace, and the root CI sdk job runs on every PR. One variant plus two match arms land here so the SDK keeps compiling: cargo test --locked and cargo clippy --locked --all-targets -- -D warnings inside crates/onionwire-sdk are both exit 0, and its Cargo.lock needed no change. The rest of the SDK surface (a cuprate-daemon feature passthrough, the config field's semantics for Kotlin, the label/tests, the Android check) stays with the SDK card — a comment on t_48f0f8b6 records exactly what is left.
  • tests/wallet.rs carries the launch test; tests/tui_frames.rs is untouched because main has no ChainChoice to pin. The chain-source picker the card mentions is the unmerged F7 work, so docs/WALLET.md describes how the source is actually selected today (the stored ChildConfig record) instead of describing a picker that does not exist on main.

Caveats that are in the docs, not buried

  • Cuprate is pre-production: its own user book says "do NOT use cuprated for any serious purposes" and RPC parity with monerod is incomplete (Cuprate issue 278). That is why this is an opt-in feature and an explicit stored user choice, never compiled-in and never a default.
  • Testnet only in this build. Mainnet is not validated.
  • No Tor on the chain path: cuprated's arti feature is off, so the daemon's P2P traffic is clearnet. OnionWire's Arti still serves the messenger only.
  • The chain database is fjall, a separate embedded store under the chain data dir — not the SQLCipher store, and not encrypted by its key.
## What this is Part 1 of three (this card, the SDK card, the Android card): `ChainSource::InProcessCuprate` — the Monero chain daemon runs **inside the OnionWire process** instead of as a spawned `monerod`. Cuprate's P2P + consensus + RandomX are compiled in behind an opt-in `cuprate-daemon` feature, off by default. The trick that keeps the whole wallet layer still: the in-process daemon binds the **same unrestricted loopback RPC** (`127.0.0.1:18081`) that `WalletChild::daemon_address` already returns for a local source, so `wallet_rpc_argv`, the RPC client, the payment frames and the receipt-verification path are untouched. **SDK names for the next card (t_48f0f8b6):** core variant `ChainSource::InProcessCuprate` (field: `datadir`), UniFFI enum variant `ChainChoice::InProcessCuprate`, core label `in-process node`, stored record `kind = "cuprate"`, and `monerod_datadir` is the chain data directory for that kind (no binary path). ## Changes - **`Cargo.toml`**: `cuprated` git dep pinned at rev `4f8fcd1b` + `toml`, both optional, behind `cuprate-daemon`. `cuprated`'s default `arti` feature is off (`default-features = false`) — its arti-client 0.44 cannot unify with this crate's 0.46 and the daemon is clearnet-only, so there is exactly one Tor stack in the process. `Cargo.lock` gains the graph. - **`src/cuprate.rs`** (new): `CuprateNode` builds the cuprated config as TOML (testnet, unrestricted RPC on loopback, restricted RPC disabled, inbound P2P off, 2 GB memory target, 4 db reader threads), launches it on a runtime it owns, and owns the node. `launch` is **synchronous** because `WalletChild::start` is sync (the TUI calls it from its blocking thread, UniFFI calls it from an async context) and a runtime cannot be started from inside a runtime: the launch runs on a dedicated thread and the node plus its runtime come back over a channel. `Drop` asks the node to shut down and `shutdown_background`s the runtime (the only exit that cannot panic when the value is dropped inside another runtime). Without the feature the type still exists and `launch` fails with the feature name, so the chain-source type, its record and its copy do not fork on a cargo feature. - **`src/wallet.rs`**: the variant, its label, and the chain-daemon client that the wallet line carried: a typed `WalletError`, HTTP de-chunking (Cuprate is axum/hyper and answers `Transfer-Encoding: chunked`), `get_height` over the **URI endpoint** (Cuprate 422s it over `/json_rpc`), and an above-the-tip height as one typed error (Cuprate: bare HTTP 500 with an empty body; monerod: `error.code = -2`). - **`src/wallet_child.rs`**: launches/holds/stops the node (no pid — the value is the lifecycle), `chain_datadir` for the ownership/free-space question, the honest `chain_copy` line, `kind = "cuprate"` in the sealed record, and `ChildConfig::validate` for it. - **`src/tui.rs`**: the wallet screen's chain line carries the testnet caveat when the configured source is the in-process one. The line is computed at draw time, so `Screen::Wallet`'s shape (which tests construct) does not change. - **Docs**: `docs/WALLET.md` (the fourth source, the feature flag, the fjall store location, how it is selected, the **measured** size delta, testnet-only and no-Tor-in-the-chain-path), `docs/THREAT_MODEL.md` (no daemon operator; the device is now the trust root for chain data; chain store is not the SQLCipher store), `docs/cuprate-android-spike.md` (in-repo proof + a correction: the two `arti` families the spike saw came from the PoC manifest enabling `cuprated`'s `arti` feature, which this crate does not). ## Acceptance evidence **1. Default build unchanged (feature off)** — `cargo test --locked --target x86_64-unknown-linux-gnu`: ``` test result: ok. 345 passed / 0 failed across 33 suites TEST_EXIT=0 CLIPPY_EXIT=0 (cargo clippy --locked --all-targets --target x86_64-unknown-linux-gnu -- -D warnings) ``` The cuprated graph is genuinely absent from a default build: ``` $ cargo tree --locked -e normal -i cuprated error: package ID specification `cuprated` did not match any packages $ cargo tree --locked -e normal -i arti-client arti-client v0.46.0 └── onionwire v0.2.1 ``` **2. Feature on, host** — `cargo test --locked --features cuprate-daemon --target x86_64-unknown-linux-gnu`: `347 passed / 0 failed`, `TEST_EXIT=0`, `CLIPPY_EXIT=0`. The two extra tests are not compile-only: ``` test wallet_child::tests::in_process_source_launches_a_daemon_and_stop_shuts_it_down ... ok test an_in_process_cuprate_node_answers_the_typed_daemon_client ... ok ``` The second one launches the real `cuprated` node, drives `get_info` / `get_height` / `get_block` through the typed daemon client, asserts an above-the-tip height maps to `DaemonHeightOutOfRange`, asserts the chain store is under the chain datadir (`.../chain/testnet/fjall`), and asserts the RPC listener closes when the node is dropped. **3. This repo cross-compiles for aarch64-linux-android** (the load-bearing one — the spike proved it on a PoC tree, not here): ``` $ cargo check --locked --release --target aarch64-linux-android --features cuprate-daemon Finished `release` profile [optimized] target(s) in 1m 50s CHECK_EXIT=0 $ cargo rustc --locked --release --target aarch64-linux-android --features cuprate-daemon --bin onionwire -- <NDK link args> Finished `release` profile [optimized] target(s) in 2m 05s LINK_EXIT=0 $ file <target>/aarch64-linux-android/release/onionwire ELF 64-bit LSB pie executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /system/bin/linker64, for Android 26, built by NDK r28c (13676358), not stripped ``` Note for anyone reproducing: `cargo rustc` needs `--bin onionwire` (or `--lib`) — this crate has both targets and rustc link args may only be passed to one, which the single-bin PoC never hit. **4. Measured size delta** (stripped aarch64 release binary, `llvm-strip`, same link args): | build | bytes | |---|---| | without the feature | 24,725,704 | | `--features cuprate-daemon` | 37,053,472 | Delta **12,327,768 bytes (≈ +11.8 MiB)** — in `docs/WALLET.md`. (The `+5.6 MB` figure that circulated with the spike was an estimate and understated it; the earlier `+12.25 MB` correction was right.) ## Scope deviations, stated plainly - `src/cuprate.rs` and its single `src/lib.rs` module line are outside the card's allowed list; the card's own deliverable describes this module's behaviour. Nothing else outside the list was touched. - `crates/onionwire-sdk/src/lib.rs` is **forbidden by the card**, but adding a variant to a `pub enum` the SDK matches exhaustively breaks the SDK workspace, and the root CI `sdk` job runs on every PR. One variant plus two match arms land here so the SDK keeps compiling: `cargo test --locked` and `cargo clippy --locked --all-targets -- -D warnings` inside `crates/onionwire-sdk` are both exit 0, and its `Cargo.lock` needed no change. The rest of the SDK surface (a `cuprate-daemon` feature passthrough, the config field's semantics for Kotlin, the label/tests, the Android check) stays with the SDK card — a comment on t_48f0f8b6 records exactly what is left. - `tests/wallet.rs` carries the launch test; `tests/tui_frames.rs` is untouched because `main` has no `ChainChoice` to pin. The chain-source picker the card mentions is the unmerged F7 work, so `docs/WALLET.md` describes how the source is actually selected today (the stored `ChildConfig` record) instead of describing a picker that does not exist on `main`. ## Caveats that are in the docs, not buried - Cuprate is **pre-production**: its own user book says "do NOT use cuprated for any serious purposes" and RPC parity with monerod is incomplete (Cuprate issue 278). That is why this is an opt-in feature and an explicit stored user choice, never compiled-in and never a default. - **Testnet only** in this build. Mainnet is not validated. - **No Tor on the chain path**: `cuprated`'s `arti` feature is off, so the daemon's P2P traffic is clearnet. OnionWire's Arti still serves the messenger only. - The chain database is **fjall**, a separate embedded store under the chain data dir — not the SQLCipher store, and not encrypted by its key.
wallet: land the in-process Cuprate chain source on main
All checks were successful
ci / test (pull_request) Successful in 5m39s
ci / sdk (pull_request) Successful in 1m22s
android-ci / android (pull_request) Successful in 8m58s
ci / fuzz (pull_request) Successful in 4m45s
ffea4bf9df
`ChainSource::InProcessCuprate { datadir }` is the fourth chain source: P2P,
consensus and RandomX run inside the OnionWire process instead of as a spawned
`monerod`. The wallet layer does not move — the daemon binds the same loopback
unrestricted RPC (`127.0.0.1:18081`) that `WalletChild::daemon_address` already
returns for a local source, so `wallet_rpc_argv`, the RPC client, the payment
frames and the receipt-verification path are untouched.

- Cargo.toml: `cuprated` (git, rev 4f8fcd1b) + `toml`, both optional, behind the
  `cuprate-daemon` feature, OFF by default. `cuprated`'s own `arti` feature is
  disabled (`default-features = false`): its arti-client 0.44 cannot unify with
  this crate's 0.46, and the in-process daemon is clearnet-only. One Tor stack in
  the process. `Cargo.lock` gains the graph; a default build's
  `cargo tree --locked -e normal -i cuprated` still says "did not match any
  packages", and only `arti-client v0.46.0` is in the lock.
- src/cuprate.rs (new): `CuprateNode` builds the cuprated config as TOML
  (testnet, unrestricted RPC on loopback, restricted RPC disabled, inbound P2P
  off), launches it on a runtime it owns, and owns the node. `launch` is
  synchronous on purpose: `WalletChild::start` is sync (the TUI calls it from its
  blocking thread, UniFFI calls it from an async context) and a runtime cannot be
  started from inside a runtime, so the launch runs on a thread of its own and
  the node + its runtime come back over a channel. Dropping the value asks the
  node to shut down and `shutdown_background`s the runtime, which is the only
  exit that cannot panic when the value is dropped inside another runtime.
  The type exists in every build (feature off: `launch` fails with the feature
  name), so the chain-source type, its stored record and its copy do not fork on
  a cargo feature.
- src/wallet.rs: the variant, its label (`in-process node`), and the chain-daemon
  client the wallet line carried (typed `WalletError`, de-chunked HTTP,
  `get_height` over the URI endpoint, an above-the-tip height as one typed
  error). Cuprate answers those three differently from monerod and the
  in-process source is what makes them the *local* case.
- src/wallet_child.rs: launches/holds/stops the node, `chain_datadir` for the
  free-space/ownership question, the honest `chain_copy` line, `kind =
  "cuprate"` in the sealed record, and `ChildConfig::validate` for it.
- src/tui.rs: the wallet screen's chain line carries the testnet caveat when the
  configured source is the in-process one. It computes the line at draw time, so
  `Screen::Wallet`'s shape (which tests construct) does not change.
- docs/WALLET.md, docs/THREAT_MODEL.md, docs/cuprate-android-spike.md: the
  feature flag and how to enable it, where the (fjall) chain store lives, the
  **measured** +11.8 MiB delta, the pre-production/testnet caveat, and the
  in-repo aarch64-linux-android proof with exit codes.

Scope deviations, stated plainly:
- `src/cuprate.rs` and its one `src/lib.rs` module line are not in the card's
  allowed list; the card's own deliverable describes the module's behaviour.
- `crates/onionwire-sdk/src/lib.rs` is forbidden, but adding a variant to a
  `pub enum` that the SDK matches exhaustively breaks the SDK workspace, and the
  root CI `sdk` job runs on every PR. One variant plus two match arms land here
  so the SDK keeps compiling (`cargo test --locked` + clippy clean); the SDK card
  owns the rest — feature passthrough, the config field's semantics, the label
  and its tests, and the Android check.
- `tests/wallet.rs` carries the launch test. `tests/tui_frames.rs` is untouched:
  main has no `ChainChoice` to pin (the chain-source picker is the unmerged F7
  work, and `docs/WALLET.md` says so rather than describing a picker that does
  not exist).

Proof (all on this tree):
- Default build: `cargo test --locked --target x86_64-unknown-linux-gnu` → 345
  passed / 0 failed across 33 suites, exit 0; `cargo clippy --locked
  --all-targets --target x86_64-unknown-linux-gnu -- -D warnings` exit 0.
- Feature on: `cargo test --locked --features cuprate-daemon --target
  x86_64-unknown-linux-gnu` → 347 passed / 0 failed, exit 0; same clippy with
  `--features cuprate-daemon` exit 0. The two extra tests are the real thing:
  `wallet_child::tests::in_process_source_launches_a_daemon_and_stop_shuts_it_down`
  and `tests/wallet.rs::an_in_process_cuprate_node_answers_the_typed_daemon_client`
  — the latter launches the node, drives `get_info` / `get_height` / `get_block`
  through the typed client, checks the above-the-tip 500 maps to
  `DaemonHeightOutOfRange`, checks the chain store is under the chain datadir,
  and checks the listener dies with the node.
- aarch64: `cargo check --locked --release --target aarch64-linux-android
  --features cuprate-daemon` exit 0 (1m 50s), and the full link exit 0
  (`cargo rustc ... --bin onionwire -- <NDK C++ runtime / compiler-rt link
  args>`) producing `ELF 64-bit LSB pie executable, ARM aarch64, for Android 26,
  built by NDK r28c`.
- Size: stripped aarch64 release binary, 24,725,704 bytes without the feature and
  37,053,472 with it — +12,327,768 bytes (≈ +11.8 MiB), the figure
  `docs/WALLET.md` now quotes.
sirius merged commit 25e029ed4e into main 2026-09-18 18:05:47 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
sirius/onionwire!110
No description provided.