diff --git a/.forgejo/workflows/android-ci.yml b/.forgejo/workflows/android-ci.yml index 9417544..bed8806 100644 --- a/.forgejo/workflows/android-ci.yml +++ b/.forgejo/workflows/android-ci.yml @@ -55,7 +55,15 @@ env: ONIONWIRE_ANDROID_ABI: arm64-v8a ANDROID_IMAGE: debian:bookworm ANDROID_CMDLINE_TOOLS_URL: https://dl.google.com/android/repository/commandlinetools-linux-11076708_latest.zip - RUST_TOOLCHAIN: "1.91" + # Not the workspace MSRV (`rust-version = "1.91"`, and `ci.yml` stays on it): the + # cuprated graph needs more. `tapes` (a Cuprate dependency) calls + # `VecDeque::pop_front_if`, stable only from **1.93**, so 1.91 dies with + # `error[E0658]: use of unstable library feature 'vec_deque_pop_if'` — 15 minutes + # into the Android job, after 400-odd crates, in a dependency this repo cannot + # patch. 1.98 is the stable release this graph is built and tested with on the dev + # machine. Bumping `ci.yml` too is a separate decision (it would move the MSRV for + # the whole workspace) and is not this workflow's to make. + RUST_TOOLCHAIN: "1.98" DOCKER_STATIC_URL: https://download.docker.com/linux/static/stable/x86_64/docker-27.5.1.tgz # Distinct container prefix: run ids are per-workflow, so this workflow and # android-release.yml can both be holding a container named "-". @@ -111,8 +119,13 @@ jobs: set -euo pipefail export DEBIAN_FRONTEND=noninteractive apt-get update + # `cmake` is for RandomX, the C++ half of the in-process chain daemon: + # without it `randomx-rs`'s build script panics with "failed to execute + # command: No such file or directory … is `cmake` not installed?" and the + # Gradle task dies on "cargo finished with non-zero exit value 101". apt-get install -y --no-install-recommends \ - openjdk-17-jdk-headless python3 unzip curl ca-certificates file build-essential pkg-config git + openjdk-17-jdk-headless python3 unzip curl ca-certificates file build-essential pkg-config git \ + cmake if [ ! -x /opt/android-sdk/cmdline-tools/latest/bin/sdkmanager ]; then mkdir -p /opt/android-sdk/cmdline-tools curl -fsSL "$ANDROID_CMDLINE_TOOLS_URL" -o /tmp/cmdline-tools.zip @@ -161,6 +174,26 @@ jobs: echo "=== unzip lib ===" unzip -l "$apk" | grep -E 'lib/.+\.so' || true unzip -l "$apk" | grep "lib/$abi/libonionwire_sdk.so" + echo "=== in-process chain daemon (cuprate-daemon) is IN this APK ===" + # The build log's "features=cuprate-daemon" line says the feature was + # *requested*; this says it is *in the artifact*. `target_max_memory` is + # a rodata literal from src/cuprate.rs's config TOML, compiled only under + # `#[cfg(feature = "cuprate-daemon")]` — v0.7.0's libonionwire_sdk.so + # contains zero occurrences of it (checked), so its presence is the + # difference between a build that carries the daemon and one that only + # claims to. A missing marker fails the job: an APK whose on-device node + # can only fail is the regression this gate exists to catch. + unzip -p "$apk" "lib/$abi/libonionwire_sdk.so" > /tmp/libonionwire_sdk.so + # `grep -c`, deliberately not `grep -q`: under `set -o pipefail` a `-q` + # match closes the pipe early, `strings` dies on SIGPIPE (141), and the + # pipeline then reports failure even though the marker was there — this + # gate failed its own green build once that way. + marker="$(strings -a /tmp/libonionwire_sdk.so | grep -c 'target_max_memory' || true)" + echo "target_max_memory occurrences: ${marker:-0}" + if [ "${marker:-0}" -lt 1 ]; then + echo "lib/$abi/libonionwire_sdk.so carries no cuprated config string: the cuprate-daemon feature is NOT in this APK" >&2 + exit 1 + fi echo "=== classes.dex + Compose entrypoints ===" unzip -l "$apk" | grep -E 'classes[0-9]*\.dex' | head -n3 echo "=== sha256 ===" @@ -171,6 +204,12 @@ jobs: aapt dump badging "$apk" | sed -n '1,20p' || true echo "=== sizes ===" wc -c "$apk" "$aar" + # The cross-compile volume this build just grew. The cuprated graph is + # ~152 crates plus a C++ RandomX build, so the number is the disk cost + # of the feature on the runner, next to the wall clock above. + echo "=== cargo target volume (after this build) ===" + du -sh /cargo-target 2>/dev/null || true + du -sh /cargo-target/aarch64-linux-android/release 2>/dev/null || true } | tee dist/android-ci-verify.log INNER chmod +x .ci-android-verify.sh diff --git a/.forgejo/workflows/android-release.yml b/.forgejo/workflows/android-release.yml index fac345a..a1d2874 100644 --- a/.forgejo/workflows/android-release.yml +++ b/.forgejo/workflows/android-release.yml @@ -61,7 +61,10 @@ env: ONIONWIRE_REQUIRE_RELEASE_KEY: "true" ANDROID_IMAGE: debian:bookworm ANDROID_CMDLINE_TOOLS_URL: https://dl.google.com/android/repository/commandlinetools-linux-11076708_latest.zip - RUST_TOOLCHAIN: "1.91" + # Same as android-ci.yml: the cuprated graph needs >= 1.93 (`tapes` uses + # `VecDeque::pop_front_if`), and 1.98 is what this graph is built with. The + # workspace MSRV in Cargo.toml is untouched; `ci.yml` and `release.yml` keep 1.91. + RUST_TOOLCHAIN: "1.98" DOCKER_STATIC_URL: https://download.docker.com/linux/static/stable/x86_64/docker-27.5.1.tgz BUILD_CONTAINER: onionwire-android-${{ github.run_id }} SDK_VOLUME: onionwire-android-sdk @@ -225,8 +228,13 @@ jobs: set -euo pipefail export DEBIAN_FRONTEND=noninteractive apt-get update + # `cmake` is for RandomX, the C++ half of the in-process chain daemon + # (`cuprate-daemon`, built into the SDK): without it `randomx-rs`'s build + # script panics with "is `cmake` not installed?" and the Gradle task dies + # on "cargo finished with non-zero exit value 101". Same as android-ci.yml. apt-get install -y --no-install-recommends \ - openjdk-17-jdk-headless python3 unzip curl ca-certificates file build-essential pkg-config git + openjdk-17-jdk-headless python3 unzip curl ca-certificates file build-essential pkg-config git \ + cmake mkdir -p /root/.android cp /src/.ci-android/onionwire-release.jks /root/.android/onionwire-release.jks cp /src/.ci-android/onionwire-release.env /root/.android/onionwire-release.env diff --git a/android/CUPRATE_DAEMON.md b/android/CUPRATE_DAEMON.md new file mode 100644 index 0000000..946b674 --- /dev/null +++ b/android/CUPRATE_DAEMON.md @@ -0,0 +1,174 @@ +# The in-process chain daemon (`cuprate-daemon`) in the APK + +The wallet's third chain source — Cuprate's chain daemon running **inside the +OnionWire process** — is compiled into the Android build. This document is the +provenance record for that: how the feature is enabled, why the link line looks +the way it does, what CI checks, and what has *not* been proven. + +Companion reading: `docs/WALLET.md` ("The in-process chain daemon") for what the +daemon is, `docs/cuprate-android-spike.md` for the cross-compile spike this +plumbing comes from, and `MONERO_BINARIES.md` for the `monero-wallet-rpc` +executable, which is still a child process — Cuprate has no wallet layer. + +## What changed in the build + +`android/sdk/build.gradle.kts`: + +| | | +|---|---| +| Feature | `--features cuprate-daemon` on the **Android** build only | +| Where | `cargoBuildAndroid` (the `cargo ndk` cross-compile) | +| Not where | `cargoHostLib` / `uniffiBindgen` stay feature-free | + +The host cdylib exists only so `uniffi-bindgen --library` can dlopen it. Building +the Cuprate graph there would add ~152 crates and a C++ RandomX build to every +build for a library that never runs the daemon, and the UniFFI surface does not +fork on a cargo feature (`ChainChoice.InProcessCuprate` is present either way, and +`WalletChildStatus` carries the same fields) — so the generated Kotlin bindings are +the same bytes. + +`cargoBuildAndroid` prints the feature it is building with, so the CI log carries +the request rather than only the task name: + +``` +cargo ndk build for arm64-v8a features=cuprate-daemon api=26 ndk=28.2.13676358 +``` + +## The link line + +RandomX is C++ and its aarch64 JIT calls `__clear_cache`, and `randomx-rs`'s build +script emits `rustc-link-lib=static=stdc++` against the NDK's *stub* +`libstdc++.a`. Without libc++ and the compiler-rt builtins the link fails on +`__cxa_allocate_exception` / `std::runtime_error` / `typeinfo` / `__clear_cache`. +`cargo ndk --link-builtins` covers the builtins but not libc++, and +`-static-libstdc++` is ignored by NDK clang, so the full set is spelled out: + +``` +-L$NDK/toolchains/llvm/prebuilt//sysroot/usr/lib/ +-L$NDK/toolchains/llvm/prebuilt//lib/clang//lib/linux +-lclang_rt.builtins--android +-lc++_static +-lc++abi +-Wl,--exclude-libs,libc++_static.a +-Wl,--exclude-libs,libc++abi.a +``` + +Five more things the build has to get right, each of which fails as something +else: + +1. **`ANDROID_NDK` must be exported**, not only `ANDROID_NDK_HOME` / `NDK_HOME`. + `cmake-rs` (RandomX's C++ half) aborts with *"Android: Neither the NDK or a + standalone toolchain was found"*, and `randomx-rs`'s build script then panics + inside `cmake`. The task exports all three. +2. **The linker is the NDK clang driver, named explicitly.** The dev machines' + `~/.cargo/config.toml` pins `[target.aarch64-linux-android] linker` to the + **API 21** wrapper, and API 21 fails this link (`pthread_atfork` is API 23+). + `cargo-ndk`'s own linker wrapper is bypassed so the `-Wl,…` args reach clang as + link args. +3. **The flags are `CARGO_TARGET__RUSTFLAGS`, not `RUSTFLAGS`.** A global + rustflags would also apply to build scripts and proc macros, which are + **host**-targeted, where `-lc++_static` breaks the link. Setting the + per-target variable also *replaces* the `target..rustflags` in + `~/.cargo/config.toml`, so the sysroot `-L` it carried is repeated in the list. +4. **The build image needs `cmake`.** RandomX is built by `randomx-rs`'s build + script through `cmake-rs`, and both Android workflows' `debian:bookworm` + containers install their own package list. Without `cmake` the build gets + ~11 minutes in, compiles 400-odd crates, and then dies with a `randomx-rs` + build-script panic — *failed to execute command: No such file or directory … + is `cmake` not installed?* — surfacing as Gradle's "cargo finished with + non-zero exit value 101", which reads like a Rust error and is not one. + `android-ci.yml` and `android-release.yml` both install it. +5. **The Rust toolchain must be >= 1.93**, not the workspace MSRV of 1.91. + `tapes`, a Cuprate dependency this repo cannot patch, calls + `VecDeque::pop_front_if`, which is stable only from 1.93. On 1.91 the Android job + compiles ~400 crates and then dies with + `error[E0658]: use of unstable library feature 'vec_deque_pop_if'`. + `android-ci.yml` and `android-release.yml` pin `RUST_TOOLCHAIN: "1.98"` (the + stable release this graph is built and tested with); `ci.yml`, `release.yml` and + the `rust-version = "1.91"` MSRV are untouched, because the feature-off workspace + does not need the bump and moving the MSRV is a separate decision. + +## What ends up in the APK + +``` +lib/arm64-v8a/libandroidx.graphics.path.so +lib/arm64-v8a/libjnidispatch.so +lib/arm64-v8a/libmonerowalletrpc.so +lib/arm64-v8a/libonionwire_sdk.so +lib/arm64-v8a/librandomx_rs-.so <- new, see below +``` + +`librandomx_rs-.so` is new and is **not a load-time dependency** of the SDK: +`readelf -d libonionwire_sdk.so` lists `liblog.so` and nothing else, and the +RandomX code is statically inside the SDK's own `.so` (its symbols and strings are +there). `cargo-ndk` copies every cdylib the target directory produced into +`jniLibs`, and `randomx-rs` also builds one. It is left in place rather than +filtered out: it is 1,122,296 bytes uncompressed / 387,996 deflated, and dropping +it would be a packaging rule that silently breaks the day something *does* link it. + +## The CI gate + +`.forgejo/workflows/android-ci.yml` extracts `lib//libonionwire_sdk.so` from +the built APK and greps it for `target_max_memory` — a rodata literal from +`src/cuprate.rs`'s config TOML, compiled only under +`#[cfg(feature = "cuprate-daemon")]`. The job **fails** if it is absent. + +The negative control is v0.7.0's shipped APK: its `libonionwire_sdk.so` contains +**zero** occurrences of that string (and of `randomx` / `cuprated`), so a match +means the daemon is in the artifact, not merely requested. The build log line +above is the other half of the proof — request and artifact, separately checkable. + +## What the wallet screen does with it + +`ui/WalletScreen.kt` grew a third chain source beside the daemon field and +**Receive-only** (`ui/WalletChildStatusText.kt` holds the pure model): + +* Selecting **On-device node (Cuprate)** stores `ChainChoice.InProcessCuprate` with + an **empty** `monerod_datadir`, which the SDK resolves to + `$ONIONWIRE_HOME/chain` — the same directory a spawned `monerod` would use. Kotlin + never invents an absolute path. +* `monero-wallet-rpc` is still required and still a subprocess: Start is gated on + the bundled binary exactly as before, and an in-process node does not bundle + `arti`, so a `.onion` daemon is still refused. +* The status line renders the core's words verbatim and grows a `node ` + segment from `WalletChildStatus.node_state` for this source only. An unrecognised + word is never rendered as ready. +* **No sync height.** `WalletChildStatus` has no height field — the core keeps a + `chain_height()` internally (`src/cuprate.rs`) but does not expose it over + UniFFI, so the screen does not show a number it cannot get. A height on the + status line is a follow-up on the SDK surface, not something the UI can invent. +* **Storage honesty.** The card shows the free space on the filesystem the fjall + store grows into (`StatFs` on the app's data dir) and refuses Start below a + 3 GiB floor, or when that filesystem cannot be read at all. The floor is a + *floor*, not a sync estimate, and the doc comment says why: nothing in this stack + exposes one — `WalletChildStatus` has no size field, and Cuprate's restricted RPC + reports a hardcoded 5 GiB `database_size` placeholder. +* **Pre-production warning**, above the Start button, in a sentence: + `CUPRATE_PREPRODUCTION_WARNING` — quoted user book, testnet-only, and Cuprate + issue #278, assertable in `WalletChildStatusTextTest`. Opt-in, never a default. + +## Not verified + +The daemon was **not executed on a device or an emulator**. There is no +`arm64-v8a` AVD on the build host (the same gap `MONERO_BINARIES.md` records), and +no aarch64 Android sysroot to run it under `qemu-user`. What is proven: it +cross-compiles and links against the NDK's C++ runtime, the feature is in the +shipped `.so`, the artifact packages, and the Kotlin that drives it compiles and +passes its unit tests. What is not: that `cuprated` starts, opens its fjall store +and answers on loopback under Android's runtime — and, on top of that, Cuprate +itself is pre-production and testnet-only. + +To close the gap, on an arm64 device or a software-emulated arm64 AVD: + +```bash +sdkmanager "system-images;android-35;google_apis;arm64-v8a" +avdmanager create avd -n ow-arm64 -k "system-images;android-35;google_apis;arm64-v8a" +emulator -avd ow-arm64 # software-emulated on an x86_64 host: slow +adb install -r dist/onionwire--android-arm64-v8a.apk +``` + +then unlock the node, open Wallet, tap **On-device node (Cuprate)**, read the +warning, press **Start wallet**, and watch the status line for +`connecting → syncing · in-process node · node starting → node syncing`. A wallet +balance needs the chain synced, which on a phone is a long wait — the status line +is the thing to watch, not the balance. diff --git a/android/MONERO_BINARIES.md b/android/MONERO_BINARIES.md index a191105..c9f4185 100644 --- a/android/MONERO_BINARIES.md +++ b/android/MONERO_BINARIES.md @@ -166,3 +166,13 @@ adb install -r dist/onionwire--android-arm64-v8a.apk then unlock the node, open Wallet, type a daemon as `host:port`, Save, and watch the status line for `connecting → syncing → ready`. A `.onion` daemon will stop at the arti notice above. + +## The other chain source: an in-process daemon, not a binary + +The third chain source — Cuprate's chain daemon running inside the OnionWire +process — is a **linked feature of the SDK's `.so`**, not a `jniLibs` executable, +so it has its own record: `android/CUPRATE_DAEMON.md` (feature wiring, the NDK C++ +/ compiler-rt link line, the CI check that greps the shipped `.so` for a +cuprated-only string, and what has not been verified). `monero-wallet-rpc` above +stays a child process for it — Cuprate has no wallet layer. + diff --git a/android/app/src/main/java/com/siriusdevops/onionwire/WireViewModel.kt b/android/app/src/main/java/com/siriusdevops/onionwire/WireViewModel.kt index 6d9bae3..3e5d7d5 100644 --- a/android/app/src/main/java/com/siriusdevops/onionwire/WireViewModel.kt +++ b/android/app/src/main/java/com/siriusdevops/onionwire/WireViewModel.kt @@ -11,6 +11,7 @@ import com.siriusdevops.onionwire.crypto.StoredPassphraseStore import com.siriusdevops.onionwire.keepalive.KeepAliveService import com.siriusdevops.onionwire.keepalive.KeepAliveStatus import com.siriusdevops.onionwire.keepalive.NodeHost +import com.siriusdevops.onionwire.wallet.ChainStorage import com.siriusdevops.onionwire.wallet.NO_WALLET_RPC_MESSAGE import com.siriusdevops.onionwire.wallet.WalletChildBinaries import com.siriusdevops.onionwire.wallet.WalletChildBinaryPaths @@ -722,6 +723,48 @@ class WireViewModel(app: Application) : AndroidViewModel(app) { refreshWalletChild() } + /** + * The third chain source: the chain daemon **inside this app** (Cuprate), no + * `monerod` binary and no remote operator. Stores the setting; [startWalletChild] + * is what launches the node *and* the wallet child (one call in the core). + * + * `monerodDatadir` is left empty on purpose: the SDK resolves that to + * `$ONIONWIRE_HOME/chain`, the same per-identity directory a spawned `monerod` + * would use, so Kotlin never invents an absolute path. `monero-wallet-rpc` is + * still required — Cuprate has no wallet layer, so the subprocess stays, and the + * core rejects a config without it. + */ + suspend fun setInProcessCuprate(bins: WalletChildBinaryPaths): Result = + withContext(Dispatchers.IO) { + runCatching { + requireWire().setChainSource( + ChainConfig( + kind = ChainChoice.IN_PROCESS_CUPRATE, + monerodBin = "", + monerodDatadir = "", + host = "", + port = 0u, + walletRpcBin = bins.walletRpc.orEmpty(), + // Inert for this source: an in-process node is loopback + // clearnet, so the core never spawns the SOCKS child. + artiBin = expectedArtiPath(), + walletFilename = WalletChildBinaries.WALLET_FILENAME, + ), + ) + } + }.onSuccess { + _walletChildError.value = null + refreshChainSource() + refreshWalletChild() + } + + /** + * Free bytes on the filesystem the in-process chain store grows into, or + * `null` when it cannot be read. The screen shows this before the user commits + * to a store on the device; it is a measurement, not an estimate. + */ + fun chainFreeBytes(): Long? = ChainStorage.freeBytes(home) + /** * Spawns the child (and its daemon/SOCKS siblings) and returns what the core * reached. diff --git a/android/app/src/main/java/com/siriusdevops/onionwire/ui/WalletChildStatusText.kt b/android/app/src/main/java/com/siriusdevops/onionwire/ui/WalletChildStatusText.kt index 8ed5faf..247d91b 100644 --- a/android/app/src/main/java/com/siriusdevops/onionwire/ui/WalletChildStatusText.kt +++ b/android/app/src/main/java/com/siriusdevops/onionwire/ui/WalletChildStatusText.kt @@ -2,6 +2,7 @@ package com.siriusdevops.onionwire.ui import com.siriusdevops.onionwire.wallet.NO_WALLET_RPC_MESSAGE import com.siriusdevops.onionwire.wallet.WalletChildBinaryPaths +import java.util.Locale /** * One snapshot of the app-owned wallet child, as the wallet screen sees it. @@ -25,6 +26,25 @@ data class WalletChildInput( val configured: Boolean, /** The core's label: `receive-only` / `local node` / `remote onion daemon` / `remote daemon`. */ val chainSource: String, + /** + * The configured source runs the chain daemon **inside this app** (Cuprate) + * rather than spawning `monerod` or dialling a remote one — the core's + * `chain_in_process`. When true the line grows a node segment, because there + * is no separate daemon process for the state word to describe. + */ + val chainInProcess: Boolean = false, + /** + * This build carries `cuprate-daemon`, so the in-process node can actually + * start — the core's `node_available`. `false` means the option is stored but + * a start can only fail: say so before the user commits, never after. + */ + val nodeAvailable: Boolean = true, + /** + * The node's own word — the core's `node_state`: `off` / `starting` / + * `syncing` / `ready` / `exited`. **Empty** for every other chain source, and + * empty for an in-process source that has not been read yet. + */ + val nodeState: String = "", val lastError: String? = null, ) @@ -133,6 +153,98 @@ sealed interface WalletChildPhase { /** Cells of an unrecognised state word kept on the status line. */ const val UNRECOGNISED_BUDGET: Int = 16 +/** + * The in-process node's own word, for the chain sources that have one. + * + * Same fail-closed rule as [WalletChildPhase]: an unrecognised word is never + * [Ready]. [Absent] is not a node state at all — it is "this chain source has no + * node segment on the line", which is true of receive-only, a spawned `monerod` + * and a remote daemon, and also of an in-process source the core has not reported + * a node word for yet. Nothing is inferred to fill it in. + */ +sealed interface NodePhase { + + /** Stable handle for Compose semantics and tests. */ + val testTag: String + + /** Word drawn after `node`, or empty for [Absent]. */ + val label: String + + /** What a screen reader announces. Always a sentence. */ + val contentDescription: String + + /** No node segment: not an in-process chain source. */ + data object Absent : NodePhase { + override val testTag: String = "node-absent" + override val label: String = "" + override val contentDescription: String = "No on-device node" + } + + /** The app's own node is not running. */ + data object Off : NodePhase { + override val testTag: String = "node-off" + override val label: String = "off" + override val contentDescription: String = "The on-device node is off" + } + + /** The node is up; its loopback RPC has not answered yet. */ + data object Starting : NodePhase { + override val testTag: String = "node-starting" + override val label: String = "starting" + override val contentDescription: String = + "The on-device node is starting; its RPC has not answered yet" + } + + /** The node answers; its chain is not at the tip. */ + data object Syncing : NodePhase { + override val testTag: String = "node-syncing" + override val label: String = "syncing" + override val contentDescription: String = + "The on-device node is syncing; the chain is not at the tip yet" + } + + /** The node answers and its chain is at the tip. */ + data object Ready : NodePhase { + override val testTag: String = "node-ready" + override val label: String = "ready" + override val contentDescription: String = "The on-device node is ready" + } + + /** A started node is gone. */ + data object Exited : NodePhase { + override val testTag: String = "node-exited" + override val label: String = "exited" + override val contentDescription: String = "The on-device node exited" + } + + /** A node word this build does not know. Fail-closed: never [Ready]. */ + data class Unrecognised(val raw: String) : NodePhase { + override val testTag: String = "node-unrecognised" + override val label: String = "unknown (${shortSendReason(raw, UNRECOGNISED_BUDGET)})" + override val contentDescription: String = + "The on-device node reported a state this build does not know" + } +} + +/** + * Maps the core's `node_state` onto a [NodePhase]. + * + * [NodePhase.Absent] for a source that has no node (or no word yet); anything the + * five words do not cover is [NodePhase.Unrecognised] — never [NodePhase.Ready]. + */ +fun nodePhase(input: WalletChildInput?): NodePhase { + if (input == null || !input.chainInProcess) return NodePhase.Absent + return when (val state = input.nodeState.trim().lowercase()) { + "" -> NodePhase.Absent + "off" -> NodePhase.Off + "starting" -> NodePhase.Starting + "syncing" -> NodePhase.Syncing + "ready" -> NodePhase.Ready + "exited" -> NodePhase.Exited + else -> NodePhase.Unrecognised(state) + } +} + /** * Maps the core's `state` word onto a [WalletChildPhase]. Case- and * whitespace-tolerant; anything else is [WalletChildPhase.Unrecognised]. @@ -161,11 +273,18 @@ fun walletChildPhase(input: WalletChildInput?): WalletChildPhase { fun walletChildLine(input: WalletChildInput?): String { val phase = walletChildPhase(input) val source = input?.chainSource?.takeIf { it.isNotBlank() } ?: "no chain source" + val node = nodePhase(input) val why = input?.lastError?.takeIf { it.isNotBlank() } return buildString { append(phase.label) append(" · ") append(source) + // Only an in-process source has a node of its own to name. The node word + // is the core's, rendered as-is — there is no second state machine here. + if (node !is NodePhase.Absent) { + append(" · node ") + append(node.label) + } when { why != null -> append(" — ").append(shortSendReason(why)) phase is WalletChildPhase.Exited -> append(" — the child process is gone") @@ -184,6 +303,80 @@ const val ONION_NEEDS_ARTI_NOTICE: String = /** Shown while the first `wallet_status()` read is still in flight. */ const val READING_CHILD_NOTICE: String = "Reading the wallet child status…" +/** + * The caveat the on-device node is offered with, **before** Start. + * + * Cuprate's own user book says *"do NOT use cuprated for any serious purposes"*, + * its `monerod` RPC parity is incomplete (Cuprate issue #278, and the four gaps + * measured in this repo are in `docs/cuprate-launch-spike.md`), and the daemon + * this app launches is pinned to **testnet** (`src/cuprate.rs`). One sentence, not + * a glyph: the choice is opt-in and never a default, and a user who reads only + * this line still knows what they picked. + */ +const val CUPRATE_PREPRODUCTION_WARNING: String = + "On-device node is Cuprate, which is pre-production: its own user book says do NOT use " + + "cuprated for any serious purposes, it runs testnet only here (mainnet is unvalidated), " + + "and its monerod RPC parity is incomplete (Cuprate issue #278). Try the in-process " + + "path; do not hold funds on it." + +/** + * This build was compiled without the `cuprate-daemon` feature, so the stored + * on-device chain source can be read back but can never start. Mirrors the core's + * own refusal (`onionwire::cuprate::NO_FEATURE_MSG`) rather than inventing a + * second wording for the same fact. + */ +const val CUPRATE_NOT_IN_BUILD_NOTICE: String = + "This build has no in-process chain daemon, so the on-device node cannot start." + +/** + * Free space the chain store's filesystem must have before the on-device node is + * started. + * + * A **floor**, not a sync estimate, and deliberately so: nothing in this stack + * exposes one. `WalletChildStatus` carries no size field, and Cuprate's own + * restricted RPC reports a hardcoded 5 GiB `database_size` placeholder (see + * `src/cuprate.rs`), so a number taken from the node would be fiction. What can be + * measured honestly is the free space on the filesystem the fjall store grows + * into, and the device can be told when that is not enough. + */ +const val CHAIN_FREE_SPACE_FLOOR_BYTES: Long = 3L * 1024 * 1024 * 1024 + +/** + * What the chain store costs, in the user's terms: the free space this device + * actually has, and what the node does *not* tell us. + */ +fun chainStorageLine(freeBytes: Long?): String = when { + freeBytes == null -> + "chain store: free space on this device could not be read." + else -> + "chain store: ${formatBytes(freeBytes)} free on this device — a synced testnet store " + + "grows into it. The node reports no size estimate of its own." +} + +/** + * Why the on-device node must not be started on this device, or `null` when it + * may. Fail-closed on an unreadable filesystem: an unknown free space is not + * reported as enough. + */ +fun chainStorageBlockedReason(freeBytes: Long?): String? = when { + freeBytes == null -> + "Free space on the chain store's filesystem could not be read, so it is not known to fit." + freeBytes < CHAIN_FREE_SPACE_FLOOR_BYTES -> + "Not enough space for the chain store: ${formatBytes(freeBytes)} free, and the " + + "on-device node needs at least ${formatBytes(CHAIN_FREE_SPACE_FLOOR_BYTES)}." + else -> null +} + +/** + * Bytes as a screen-sized string. Binary units (a "GB" that is really a GiB is how + * a store that needs 3 GiB ends up on a device with 2.8). + */ +fun formatBytes(bytes: Long): String = when { + bytes >= 1L shl 30 -> String.format(Locale.US, "%.1f GiB", bytes.toDouble() / (1L shl 30)) + bytes >= 1L shl 20 -> String.format(Locale.US, "%.0f MiB", bytes.toDouble() / (1L shl 20)) + else -> "$bytes B" +} + /** * Why **Start** is not actionable, or `null` when it is. * @@ -200,6 +393,9 @@ fun startBlockedReason( input == null -> READING_CHILD_NOTICE input.running -> "The wallet child is already running." !input.configured -> "No chain source yet: a wallet child needs a daemon to dial." + // The stored source is the app's own node but this build has no daemon: the + // option is readable and unstoppable, so say it before the user presses Start. + input.chainInProcess && !input.nodeAvailable -> CUPRATE_NOT_IN_BUILD_NOTICE onionDaemon && bins.arti == null -> ONION_NEEDS_ARTI_NOTICE else -> null } diff --git a/android/app/src/main/java/com/siriusdevops/onionwire/ui/WalletScreen.kt b/android/app/src/main/java/com/siriusdevops/onionwire/ui/WalletScreen.kt index 4ea8286..3f54179 100644 --- a/android/app/src/main/java/com/siriusdevops/onionwire/ui/WalletScreen.kt +++ b/android/app/src/main/java/com/siriusdevops/onionwire/ui/WalletScreen.kt @@ -80,6 +80,10 @@ fun WalletScreen( // the life of the process. val bins = remember { vm.bundledBinaries() } val childInput = child?.toInput() + // Free space on the filesystem the in-process chain store grows into. Read + // once per composition of the screen: it is the same filesystem for the life + // of the process, and the number is only a commit-time gate. + val nodeFreeBytes = remember { vm.chainFreeBytes() } var showQr by remember { mutableStateOf(false) } var balance by remember { mutableStateOf(null) } var address by remember { mutableStateOf(null) } @@ -221,6 +225,7 @@ fun WalletScreen( bins = bins, input = childInput, chain = chain, + nodeFreeBytes = nodeFreeBytes, actionError = childError, daemonText = daemonText, daemonError = daemonError, @@ -247,6 +252,13 @@ fun WalletScreen( .onFailure { daemonError = it.message ?: it.toString() } } }, + onInProcessNode = { + daemonError = null + scope.launch { + vm.setInProcessCuprate(bins) + .onFailure { daemonError = it.message ?: it.toString() } + } + }, onStart = { scope.launch { vm.startWalletChild() } }, onStop = { scope.launch { vm.stopWalletChild() } }, ) @@ -572,35 +584,50 @@ private fun WalletSetupCard( } /** - * The app-owned `monero-wallet-rpc` control (issue #107). + * The app-owned `monero-wallet-rpc` control (issue #107), now with the third chain + * source: the chain daemon **inside this app** (Cuprate). * * **Start** / **Stop** drive `Wire::start_wallet_child` / `stop_wallet_child` * through [WireViewModel]; the status line is `Wire::wallet_status()` rendered - * verbatim, so a child that died reads `exited` and never `off`. + * verbatim, so a child that died reads `exited` and never `off`, and an in-process + * source grows a `node ` segment that is the core's own `node_state`. * * The card is deliberately talkative about what it *cannot* do: no bundled - * binary, no chain source, or a `.onion` daemon with no bundled `arti` SOCKS - * child each get their own sentence, because a Start button that can only fail - * is worse than no button. There is no "starting…" state to hide behind — the - * only spinner-free words on screen are the core's own. + * binary, no chain source, a `.onion` daemon with no bundled `arti` SOCKS child, + * or a build without `cuprate-daemon` each get their own sentence, because a Start + * button that can only fail is worse than no button. There is no "starting…" state + * to hide behind — the only spinner-free words on screen are the core's own. + * + * The on-device node is opt-in and carries its pre-production warning **above the + * Start button**, plus the free space on the filesystem its fjall store grows + * into. A device that cannot hold the chain is told before it commits, not left to + * fail at sync time. */ @Composable private fun WalletChildCard( bins: WalletChildBinaryPaths, input: WalletChildInput?, chain: ChainConfig?, + nodeFreeBytes: Long?, actionError: String?, daemonText: String, daemonError: String?, onDaemonText: (String) -> Unit, onSaveDaemon: () -> Unit, onReceiveOnly: () -> Unit, + onInProcessNode: () -> Unit, onStart: () -> Unit, onStop: () -> Unit, ) { val phase = walletChildPhase(input) + val node = nodePhase(input) val onionDaemon = chain?.kind == ChainChoice.REMOTE && isOnionHost(chain.host) + // The selection is in-process as soon as it is stored, before the first status + // read comes back: the warning and the storage line must not wait for the + // poller, or the user would press Start having seen neither. + val inProcess = input?.chainInProcess == true || chain?.kind == ChainChoice.IN_PROCESS_CUPRATE val startWhy = startBlockedReason(bins, input, onionDaemon) + ?: if (inProcess) chainStorageBlockedReason(nodeFreeBytes) else null val stopWhy = stopBlockedReason(input) Card( @@ -615,8 +642,9 @@ private fun WalletChildCard( Text("wallet daemon", style = MaterialTheme.typography.titleSmall) Spacer(Modifier.height(6.dp)) - // The core's own words: `ready · remote onion daemon`. Tagged with - // the phase so a UI test can assert `exited` is never `off`. + // The core's own words: `ready · remote onion daemon`, plus + // `· node syncing` for the in-process source. Tagged with the phase so + // a UI test can assert `exited` is never `off`. Text( walletChildLine(input), style = MaterialTheme.typography.bodySmall, @@ -629,6 +657,23 @@ private fun WalletChildCard( }, ) + // The node's own word, when there is one, as its own assertable line: + // an unrecognised node state can never be read as ready. + if (node !is NodePhase.Absent) { + Text( + "node: ${node.label}", + style = MaterialTheme.typography.labelSmall, + fontFamily = FontFamily.Monospace, + color = MaterialTheme.colorScheme.onSurfaceVariant, + modifier = Modifier + .fillMaxWidth() + .testTag(node.testTag) + .semantics(mergeDescendants = true) { + contentDescription = node.contentDescription + }, + ) + } + if (!bins.walletRpcBundled) { Spacer(Modifier.height(6.dp)) Text( @@ -648,8 +693,9 @@ private fun WalletChildCard( label = { Text("daemon host:port") }, supportingText = { Text( - "e.g. 127.0.0.1:18089 for a local daemon you run yourself, " + - "or a node's clearnet address.", + "A daemon on your LAN (e.g. 192.168.1.20:18089) or a public node's " + + "clearnet address. A phone cannot run monerod — for a chain with no " + + "daemon at all, use the on-device node below.", style = MaterialTheme.typography.labelSmall, ) }, @@ -677,6 +723,38 @@ private fun WalletChildCard( ) { Text("Receive-only") } } + // The third chain source. Never a default: selecting it is what stores + // `ChainChoice.InProcessCuprate`, and the warning below is what the user + // reads before Start. + Spacer(Modifier.height(8.dp)) + OutlinedButton( + onClick = onInProcessNode, + modifier = Modifier + .fillMaxWidth() + .testTag("wallet-chain-in-process"), + ) { Text("On-device node (Cuprate)") } + + if (inProcess) { + Spacer(Modifier.height(8.dp)) + Text( + CUPRATE_PREPRODUCTION_WARNING, + style = MaterialTheme.typography.labelSmall, + color = MaterialTheme.colorScheme.onSurfaceVariant, + modifier = Modifier + .fillMaxWidth() + .testTag("wallet-cuprate-warning"), + ) + Spacer(Modifier.height(4.dp)) + Text( + chainStorageLine(nodeFreeBytes), + style = MaterialTheme.typography.labelSmall, + color = MaterialTheme.colorScheme.onSurfaceVariant, + modifier = Modifier + .fillMaxWidth() + .testTag("wallet-chain-storage"), + ) + } + Spacer(Modifier.height(8.dp)) Row( modifier = Modifier.fillMaxWidth(), @@ -738,6 +816,9 @@ internal fun WalletChildStatus.toInput(): WalletChildInput = WalletChildInput( running = running, configured = configured, chainSource = chainSource, + chainInProcess = chainInProcess, + nodeAvailable = nodeAvailable, + nodeState = nodeState, lastError = lastError, ) diff --git a/android/app/src/main/java/com/siriusdevops/onionwire/wallet/ChainStorage.kt b/android/app/src/main/java/com/siriusdevops/onionwire/wallet/ChainStorage.kt new file mode 100644 index 0000000..cd06bab --- /dev/null +++ b/android/app/src/main/java/com/siriusdevops/onionwire/wallet/ChainStorage.kt @@ -0,0 +1,30 @@ +package com.siriusdevops.onionwire.wallet + +import android.os.StatFs +import java.io.File + +/** + * Free space on the filesystem the in-process chain store grows into. + * + * The chain source this is for is Cuprate's fjall store under + * `$ONIONWIRE_HOME/chain` (`WireViewModel.home` is `filesDir/onionwire`), which is + * the same filesystem as `filesDir` — so `StatFs` on the app's own data directory + * answers the question the user is actually being asked: *will this fit here?* + * + * It is a **measurement, not an estimate**: nothing in the SDK exposes a chain + * size (`WalletChildStatus` has no size field, and Cuprate's restricted RPC + * reports a hardcoded 5 GiB placeholder — `src/cuprate.rs`). The floor the screen + * applies to this number is [com.siriusdevops.onionwire.ui.CHAIN_FREE_SPACE_FLOOR_BYTES], + * and it is documented there as a floor rather than a sync estimate. + * + * `null` means "could not be read", and the screen treats that as fail-closed: an + * unknown free space is not reported as enough. Kept out of the JVM unit tests on + * purpose — `StatFs` is an Android class, so the pure formatting and the gate live + * in `ui/WalletChildStatusText.kt` where they are covered without a device. + */ +object ChainStorage { + + /** Free bytes on [path]'s filesystem, or `null` when it cannot be read. */ + fun freeBytes(path: File): Long? = runCatching { StatFs(path.absolutePath).availableBytes } + .getOrNull() +} diff --git a/android/app/src/test/java/com/siriusdevops/onionwire/ui/WalletChildStatusTextTest.kt b/android/app/src/test/java/com/siriusdevops/onionwire/ui/WalletChildStatusTextTest.kt index 8603173..0ad32b9 100644 --- a/android/app/src/test/java/com/siriusdevops/onionwire/ui/WalletChildStatusTextTest.kt +++ b/android/app/src/test/java/com/siriusdevops/onionwire/ui/WalletChildStatusTextTest.kt @@ -26,12 +26,18 @@ class WalletChildStatusTextTest { running: Boolean = false, configured: Boolean = true, chainSource: String = "remote daemon", + chainInProcess: Boolean = false, + nodeAvailable: Boolean = true, + nodeState: String = "", lastError: String? = null, ) = WalletChildInput( state = state, running = running, configured = configured, chainSource = chainSource, + chainInProcess = chainInProcess, + nodeAvailable = nodeAvailable, + nodeState = nodeState, lastError = lastError, ) @@ -240,4 +246,132 @@ class WalletChildStatusTextTest { val parsed = parseDaemonAddress("127.0.0.1:18089")!! assertEquals("127.0.0.1:18089", parsed.text) } + + // --- the on-device node (Cuprate) --------------------------------------- + + private fun node( + state: String = "syncing", + chainSource: String = "in-process node", + nodeState: String, + nodeAvailable: Boolean = true, + running: Boolean = true, + ) = input( + state = state, + running = running, + chainSource = chainSource, + chainInProcess = true, + nodeAvailable = nodeAvailable, + nodeState = nodeState, + ) + + @Test + fun each_core_node_state_maps_to_its_own_phase() { + assertTrue(nodePhase(node(nodeState = "off")) is NodePhase.Off) + assertTrue(nodePhase(node(nodeState = "starting")) is NodePhase.Starting) + assertTrue(nodePhase(node(nodeState = "syncing")) is NodePhase.Syncing) + assertTrue(nodePhase(node(nodeState = "ready")) is NodePhase.Ready) + assertTrue(nodePhase(node(nodeState = "exited")) is NodePhase.Exited) + } + + @Test + fun only_an_in_process_source_has_a_node_segment() { + assertTrue(nodePhase(input("ready", running = true)) is NodePhase.Absent) + assertTrue(nodePhase(null) is NodePhase.Absent) + // In-process, but the core has not reported a node word yet: no segment, + // rather than an invented one. + assertTrue(nodePhase(node(nodeState = "")) is NodePhase.Absent) + } + + @Test + fun an_unknown_node_state_is_never_ready() { + val phase = nodePhase(node(nodeState = "mining")) + assertTrue(phase is NodePhase.Unrecognised) + assertFalse("an unknown node word must not read as ready", phase is NodePhase.Ready) + assertTrue(phase.label.startsWith("unknown")) + } + + @Test + fun the_line_grows_a_node_segment_for_the_in_process_source() { + assertEquals( + "syncing · in-process node · node syncing", + walletChildLine(node(state = "syncing", nodeState = "syncing")), + ) + assertEquals( + "ready · in-process node · node ready", + walletChildLine(node(state = "ready", nodeState = "ready")), + ) + } + + @Test + fun the_line_has_no_node_segment_for_the_other_sources() { + assertFalse(walletChildLine(input("ready", running = true)).contains("node ")) + assertFalse(walletChildLine(input("off", chainSource = "receive-only")).contains("node ")) + } + + @Test + fun start_is_blocked_when_the_build_has_no_in_process_daemon() { + val why = startBlockedReason( + bundled, + node(state = "off", nodeState = "off", nodeAvailable = false, running = false), + ) + assertEquals(CUPRATE_NOT_IN_BUILD_NOTICE, why) + assertNull( + "a build that carries the daemon is not blocked", + startBlockedReason( + bundled, + node(state = "off", nodeState = "off", nodeAvailable = true, running = false), + ), + ) + } + + @Test + fun the_preproduction_warning_is_a_sentence_a_user_can_act_on() { + val warning = CUPRATE_PREPRODUCTION_WARNING + assertTrue("it names the software", warning.contains("Cuprate")) + assertTrue("it quotes the user book", warning.contains("do NOT use cuprated")) + assertTrue("it names the parity gap", warning.contains("Cuprate issue #278")) + assertTrue("it says testnet", warning.contains("testnet")) + assertTrue("it is a sentence, not a glyph", warning.trim().endsWith(".")) + assertTrue("it is long enough to be a sentence", warning.length > 80) + } + + // --- storage honesty ---------------------------------------------------- + + @Test + fun storage_is_blocked_when_free_space_is_unreadable() { + assertTrue(chainStorageBlockedReason(null)!!.contains("could not be read")) + } + + @Test + fun storage_is_blocked_below_the_floor() { + val why = chainStorageBlockedReason(CHAIN_FREE_SPACE_FLOOR_BYTES - 1) + assertNotNull(why) + assertTrue(why!!, why.contains("Not enough space")) + assertTrue("the number is on screen", why.contains("3.0 GiB")) + } + + @Test + fun storage_is_allowed_at_and_above_the_floor() { + assertNull(chainStorageBlockedReason(CHAIN_FREE_SPACE_FLOOR_BYTES)) + assertNull(chainStorageBlockedReason(64L * 1024 * 1024 * 1024)) + } + + @Test + fun the_storage_line_reports_the_measured_number() { + val line = chainStorageLine(41L * 1024 * 1024 * 1024) + assertTrue(line, line.contains("41.0 GiB")) + assertTrue("it says what the number is not", line.contains("no size estimate")) + assertTrue( + "an unreadable filesystem says so", + chainStorageLine(null).contains("could not be read"), + ) + } + + @Test + fun bytes_are_formatted_in_binary_units() { + assertEquals("512 B", formatBytes(512)) + assertEquals("2 MiB", formatBytes(2L * 1024 * 1024)) + assertEquals("1.5 GiB", formatBytes(3L * 1024 * 1024 * 1024 / 2)) + assertEquals("3.0 GiB", formatBytes(CHAIN_FREE_SPACE_FLOOR_BYTES)) + } } diff --git a/android/sdk/build.gradle.kts b/android/sdk/build.gradle.kts index 546f587..ccc4989 100644 --- a/android/sdk/build.gradle.kts +++ b/android/sdk/build.gradle.kts @@ -52,6 +52,87 @@ val onionwireAbis: List = (findProperty("onionwire.abis") as String?) ?.split(',')?.map(String::trim)?.filter(String::isNotEmpty) ?: listOf("arm64-v8a") +/** + * Rust features for the **Android** target build. + * + * `cuprate-daemon` is what puts the in-process Monero chain daemon (Cuprate) in + * the APK — the SDK crate's passthrough to the core + * (`cuprate-daemon = ["onionwire/cuprate-daemon"]`), so `WalletChildStatus.node_available` + * is `true` on the device and `ChainChoice.InProcessCuprate` can actually start. + * + * Deliberately **not** applied to `cargoHostLib` / `uniffiBindgen`: those build a + * host cdylib only so `uniffi-bindgen --library` can dlopen it, the cuprated graph + * (152 crates plus a C++ RandomX build) buys nothing there, and the UniFFI surface + * does not fork on a cargo feature. The Kotlin bindings are byte-identical either + * way, which is what `crates/onionwire-sdk`'s own tests cover. + */ +val onionwireRustFeatures: List = listOf("cuprate-daemon") + +/** `arm64-v8a` -> the Rust triple, the sysroot dir name and the builtins archive. */ +data class AndroidTarget( + val abi: String, + val triple: String, + /** Sysroot library dir under `.../sysroot/usr/lib/`. */ + val sysrootLib: String, + /** `libclang_rt.builtins-.a`, from the NDK clang resource dir. */ + val builtins: String, + /** NDK clang driver prefix: `-clang`. */ + val clangPrefix: String, +) + +val androidTargets: Map = listOf( + AndroidTarget("arm64-v8a", "aarch64-linux-android", "aarch64-linux-android", "aarch64-android", "aarch64-linux-android"), + AndroidTarget("x86_64", "x86_64-linux-android", "x86_64-linux-android", "x86_64-android", "x86_64-linux-android"), + AndroidTarget("armeabi-v7a", "armv7-linux-androideabi", "arm-linux-androideabi", "arm-android", "armv7a-linux-androideabi"), + AndroidTarget("x86", "i686-linux-android", "i686-linux-android", "i386-android", "i686-linux-android"), +).associateBy(AndroidTarget::abi) + +/** The NDK's host tag (`linux-x86_64`, `darwin-x86_64`, …) — exactly one prebuilt tree. */ +val ndkHostTag: String = ndkDir.resolve("toolchains/llvm/prebuilt").listFiles() + ?.filter(File::isDirectory)?.singleOrNull()?.name + ?: error("expected exactly one NDK prebuilt toolchain under $ndkDir/toolchains/llvm/prebuilt") + +/** The NDK clang resource dir (`lib/clang//lib/linux`) — exactly one version. */ +val ndkClangLibDir: File = ndkDir.resolve("toolchains/llvm/prebuilt/$ndkHostTag/lib/clang") + .listFiles()?.filter(File::isDirectory)?.singleOrNull() + ?.resolve("lib/linux") + ?: error("expected exactly one clang resource dir under $ndkDir/toolchains/llvm/prebuilt/$ndkHostTag/lib/clang") + +/** + * Per-ABI link flags for the Android build. + * + * RandomX is C++ and its aarch64 JIT calls `__clear_cache`, and `randomx-rs`'s + * build script emits `rustc-link-lib=static=stdc++` against the NDK's *stub* + * `libstdc++.a`. Without libc++ and the compiler-rt builtins on the link line the + * build dies on `__cxa_allocate_exception` / `std::runtime_error` / `typeinfo` + * (and `__clear_cache`) undefined. `cargo ndk --link-builtins` covers only the + * builtins, not libc++ — and `-static-libstdc++` is ignored by NDK clang — so the + * whole set is spelled out. Recipe and evidence: `docs/cuprate-android-spike.md`. + * + * Exported as `CARGO_TARGET__RUSTFLAGS` rather than `RUSTFLAGS`: a global + * rustflags would also apply to build scripts and proc macros, which are + * **host**-targeted, and `-lc++_static` there breaks the host link. + * + * The same variables also *replace* any `target..rustflags` in + * `~/.cargo/config.toml`, so the sysroot `-L` it carried is repeated here. + */ +fun linkFlags(target: AndroidTarget): String { + val sysrootLib = ndkDir.resolve("toolchains/llvm/prebuilt/$ndkHostTag/sysroot/usr/lib/${target.sysrootLib}") + return listOf( + "-C", "link-arg=-L$sysrootLib", + "-C", "link-arg=-L$ndkClangLibDir", + "-C", "link-arg=-lclang_rt.builtins-${target.builtins}", + "-C", "link-arg=-lc++_static", + "-C", "link-arg=-lc++abi", + "-C", "link-arg=-Wl,--exclude-libs,libc++_static.a", + "-C", "link-arg=-Wl,--exclude-libs,libc++abi.a", + ).joinToString(" ") +} + +/** The NDK clang driver for one ABI at [onionwireApiLevel]. */ +private fun clangDriver(target: AndroidTarget): File = + ndkDir.resolve("toolchains/llvm/prebuilt/$ndkHostTag/bin/${target.clangPrefix}$onionwireApiLevel-clang") + val jniLibsDir = layout.buildDirectory.dir("rustJniLibs") val uniffiKotlinDir = layout.buildDirectory.dir("generated/uniffi") @@ -61,7 +142,16 @@ val cargoTargetDir: File = System.getenv("CARGO_TARGET_DIR")?.let(::File) ?: sdkCrateDir.resolve("target") val hostCdylib: File = cargoTargetDir.resolve("release/libonionwire_sdk.so") -/** Host cdylib. UniFFI's `--library` mode dlopens it, so it must be host-arch. */ +/** + * Host cdylib. UniFFI's `--library` mode dlopens it, so it must be host-arch. + * + * Feature-free **on purpose**: this exists only to emit the Kotlin bindings, and + * `cuprate-daemon` would drag the whole Cuprate graph (152 crates + a C++ RandomX + * build) through a host compile that never runs the daemon. The UniFFI surface + * does not fork on a cargo feature — `ChainChoice.InProcessCuprate` is present in + * both — so the generated Kotlin is the same. `onionwireRustFeatures` is for + * [cargoBuildAndroid] only. + */ val cargoHostLib by tasks.registering(Exec::class) { group = "onionwire" description = "Builds libonionwire_sdk.so for the host (used only to emit bindings)." @@ -99,10 +189,38 @@ val cargoBuildAndroid by tasks.registering(Exec::class) { inputs.file(sdkCrateDir.resolve("Cargo.lock")) inputs.dir(repoRoot.resolve("src")) inputs.file(repoRoot.resolve("Cargo.toml")) + // The feature set is an input: `-Ponionwire.features=` … there is no knob + // (a build that silently dropped `cuprate-daemon` would ship an APK whose + // on-device node can only fail), but the task must not stay "up to date" + // across a change to this list. + inputs.property("rustFeatures", onionwireRustFeatures) outputs.dir(jniLibsDir) environment("ANDROID_HOME", androidSdkDir.absolutePath) environment("ANDROID_NDK_HOME", ndkDir.absolutePath) environment("NDK_HOME", ndkDir.absolutePath) + // `cmake-rs` (RandomX's C++ half) aborts with "Neither the NDK or a standalone + // toolchain was found" unless ANDROID_NDK itself is exported — NDK_HOME and + // ANDROID_NDK_HOME are not enough, and `randomx-rs`'s build script then panics + // inside `cmake`. + environment("ANDROID_NDK", ndkDir.absolutePath) + environment("ANDROID_NDK_ROOT", ndkDir.absolutePath) + // Per-ABI link env. The clang driver is named explicitly because + // `~/.cargo/config.toml` on the dev machines pins the *API 21* wrapper for + // `aarch64-linux-android`, and API 21 fails this link (`pthread_atfork` is + // API 23+); `cargo-ndk`'s own linker wrapper is bypassed on purpose so the + // `-Wl,…` args below reach clang as link args. + onionwireAbis.forEach { abi -> + val target = androidTargets[abi] + ?: error("no Android target mapping for ABI '$abi' — add it to androidTargets in sdk/build.gradle.kts") + val rustFlagsVar = "CARGO_TARGET_${target.triple.uppercase().replace('-', '_')}_RUSTFLAGS" + val linkerVar = "CARGO_TARGET_${target.triple.uppercase().replace('-', '_')}_LINKER" + val linker = clangDriver(target) + require(linker.canExecute()) { + "NDK clang driver for $abi not found at $linker — NDK $onionwireNdkVersion incomplete?" + } + environment(rustFlagsVar, linkFlags(target)) + environment(linkerVar, linker.absolutePath) + } commandLine( buildList { add(cargoExe); add("ndk") @@ -110,8 +228,20 @@ val cargoBuildAndroid by tasks.registering(Exec::class) { add("--platform"); add(onionwireApiLevel.toString()) add("-o"); add(jniLibsDir.get().asFile.absolutePath) add("build"); add("--release"); add("--lib") + if (onionwireRustFeatures.isNotEmpty()) { + add("--features"); add(onionwireRustFeatures.joinToString(",")) + } } ) + // The CI log has to show the feature actually requested, not merely the task + // name: "the feature is in the artifact" is checked against this line. + doFirst { + logger.lifecycle( + "cargo ndk build for ${onionwireAbis.joinToString()} " + + "features=${onionwireRustFeatures.joinToString(",").ifEmpty { "(none)" }} " + + "api=$onionwireApiLevel ndk=$onionwireNdkVersion", + ) + } } // --------------------------------------------------------------------------- diff --git a/crates/onionwire-sdk/Cargo.lock b/crates/onionwire-sdk/Cargo.lock index d674106..fa1d2d2 100644 --- a/crates/onionwire-sdk/Cargo.lock +++ b/crates/onionwire-sdk/Cargo.lock @@ -146,6 +146,15 @@ dependencies = [ "num-traits", ] +[[package]] +name = "arc-swap" +version = "1.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c049c0be4daef0b145cb3555416b3b8ef5b7888a38aea1a3a155801fe7b0810b" +dependencies = [ + "rustversion", +] + [[package]] name = "argon2" version = "0.5.3" @@ -400,12 +409,66 @@ dependencies = [ "bytemuck", ] +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53" +[[package]] +name = "axum" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31b698c5f9a010f6573133b09e0de5408834d0c82f8d7475a89fc1867a71cd90" +dependencies = [ + "axum-core", + "bytes", + "futures-util", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-util", + "itoa", + "matchit", + "memchr", + "mime", + "percent-encoding", + "pin-project-lite", + "serde_core", + "serde_json", + "serde_path_to_error", + "sync_wrapper", + "tokio", + "tower", + "tower-layer", + "tower-service", +] + +[[package]] +name = "axum-core" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08c78f31d7b1291f7ee735c1c6780ccde7785daae9a9206026862dab7d8792d1" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", + "http-body-util", + "mime", + "pin-project-lite", + "sync_wrapper", + "tower-layer", + "tower-service", +] + [[package]] name = "base16ct" version = "0.2.0" @@ -443,6 +506,21 @@ dependencies = [ "unty", ] +[[package]] +name = "bit-set" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08807e080ed7f9d5433fa9b275196cfc35414f66a0c79d864dc51a0d825231a3" +dependencies = [ + "bit-vec", +] + +[[package]] +name = "bit-vec" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e764a1d40d510daf35e07be9eb06e75770908c27d411ee6c92109c9840eaaf7" + [[package]] name = "bitflags" version = "1.3.2" @@ -454,6 +532,10 @@ name = "bitflags" version = "2.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06" +dependencies = [ + "bytemuck", + "serde_core", +] [[package]] name = "bitvec" @@ -476,6 +558,19 @@ dependencies = [ "digest 0.10.7", ] +[[package]] +name = "blake3" +version = "1.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d9e454fc11f76977dc803893aff6304ed33d6a26efae8696573bea74baa27ae" +dependencies = [ + "arrayvec", + "cc", + "cfg-if", + "constant_time_eq", + "cpufeatures 0.3.1", +] + [[package]] name = "blanket" version = "0.3.0" @@ -506,6 +601,30 @@ dependencies = [ "zeroize", ] +[[package]] +name = "borsh" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "553c5d846a6ba5150c65e3b1b8ec073bcf1abc20f9b7220de384a4443ea4e20a" +dependencies = [ + "borsh-derive", + "bytes", + "cfg_aliases", +] + +[[package]] +name = "borsh-derive" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12cdfe656708a01f89b451a7d36466e6fe6c414de0aa18fc54f864f6f9ca9f56" +dependencies = [ + "once_cell", + "proc-macro-crate", + "proc-macro2", + "quote", + "syn 3.0.5", +] + [[package]] name = "bs58" version = "0.5.1" @@ -543,6 +662,20 @@ name = "bytemuck" version = "1.25.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95832e849adfb21180ccb6826a99da14e5d266ae5c2e668e1602cf234f153797" +dependencies = [ + "bytemuck_derive", +] + +[[package]] +name = "bytemuck_derive" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a1f896587b6f2c069c73d2f0913e2d590c3990285cd2f0b6aa02b786b4c679c" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.5", +] [[package]] name = "byteorder" @@ -550,11 +683,26 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" +[[package]] +name = "byteorder-lite" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f1fe948ff07f4bd06c30984e69f5b4899c516a3ef74f34df92a2df2ab535495" + [[package]] name = "bytes" version = "1.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc652a48c352aef3ea3aed32080501cf3ef6ed5da78602a020c991775b0aff04" +dependencies = [ + "serde", +] + +[[package]] +name = "byteview" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d74937895e761d5984206f82ca8ff7725d0fd8021921011921894b41ab1b9f7" [[package]] name = "camino" @@ -622,6 +770,12 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" +[[package]] +name = "cfg_aliases" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f079e83a288787bcd14a6aea84cee5c87a67c5a3e660c30f557a3d24761b3527" + [[package]] name = "chacha20" version = "0.9.1" @@ -711,6 +865,7 @@ dependencies = [ "anstyle", "clap_lex", "strsim 0.11.1", + "terminal_size", ] [[package]] @@ -731,6 +886,15 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c8d4a3bb8b1e0c1050499d1815f5ab16d04f0959b233085fb31653fbfc9d98f9" +[[package]] +name = "cmake" +version = "0.1.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0f78a02292a74a88ac736019ab962ece0bc380e3f977bf72e376c5d78ff0678" +dependencies = [ + "cc", +] + [[package]] name = "cmov" version = "0.5.4" @@ -762,6 +926,12 @@ dependencies = [ "static_assertions", ] +[[package]] +name = "compare" +version = "0.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea0095f6103c2a8b44acd6fd15960c801dafebf02e21940360833e0673f48ba7" + [[package]] name = "compression-codecs" version = "0.4.41" @@ -793,6 +963,34 @@ version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a6ef517f0926dd24a1582492c791b6a4818a4d94e789a334894aa15b0d12f55c" +[[package]] +name = "const_format" +version = "0.2.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4481a617ad9a412be3b97c5d403fef8ed023103368908b9c50af598ff467cc1e" +dependencies = [ + "const_format_proc_macros", + "konst", +] + +[[package]] +name = "const_format_proc_macros" +version = "0.2.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d57c2eccfb16dbac1f4e61e206105db5820c9d26c3c472bc17c774259ef7744" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", + "unicode-xid", +] + +[[package]] +name = "constant_time_eq" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d52eff69cd5e647efe296129160853a42795992097e8af39800e1060caeea9b" + [[package]] name = "convert_case" version = "0.10.0" @@ -850,6 +1048,47 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "crossbeam" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e71406cd8807725f7ac2f999a4cdd32e98f829fdf65f528343cebf945e41df1e" +dependencies = [ + "crossbeam-channel", + "crossbeam-deque", + "crossbeam-epoch", + "crossbeam-queue", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-channel" +version = "0.5.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98b0cc327b5bc766e7fda9c9260cc0fa81b43a8e240440422dff70788e3f9ef1" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "622f3fc73690be383c7214310406f28a90e6edeadc3cea882f9d71e495b9711a" +dependencies = [ + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc74980687109a3b14c72fd458107bf0baa1da1a1a805e178d15501ba9b86d9d" +dependencies = [ + "crossbeam-utils", +] + [[package]] name = "crossbeam-queue" version = "0.3.14" @@ -859,6 +1098,16 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "crossbeam-skiplist" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df29de440c58ca2cc6e587ec3d22347551a32435fbde9d2bff64e78a9ffa151b" +dependencies = [ + "crossbeam-epoch", + "crossbeam-utils", +] + [[package]] name = "crossbeam-utils" version = "0.8.23" @@ -904,6 +1153,17 @@ dependencies = [ "zeroize", ] +[[package]] +name = "crypto-bigint" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a52aa3fcda4e6302a9f48734f234d35d4721b96f8fe07d073f07ce9df4f0271" +dependencies = [ + "cpubits", + "ctutils", + "num-traits", +] + [[package]] name = "crypto-common" version = "0.1.7" @@ -951,6 +1211,491 @@ dependencies = [ "cmov", ] +[[package]] +name = "cuprate-address-book" +version = "0.1.0" +source = "git+https://github.com/Cuprate/cuprate?rev=4f8fcd1bf468f566fcd89c460d50de4adb6825bf#4f8fcd1bf468f566fcd89c460d50de4adb6825bf" +dependencies = [ + "borsh", + "cuprate-constants", + "cuprate-p2p-core", + "cuprate-pruning", + "futures", + "indexmap 2.14.2", + "rand 0.8.8", + "thiserror 2.0.20", + "tokio", + "tokio-util", + "tower", + "tracing", +] + +[[package]] +name = "cuprate-async-buffer" +version = "0.1.0" +source = "git+https://github.com/Cuprate/cuprate?rev=4f8fcd1bf468f566fcd89c460d50de4adb6825bf#4f8fcd1bf468f566fcd89c460d50de4adb6825bf" +dependencies = [ + "futures", + "pin-project", + "thiserror 2.0.20", +] + +[[package]] +name = "cuprate-blockchain" +version = "0.0.0" +source = "git+https://github.com/Cuprate/cuprate?rev=4f8fcd1bf468f566fcd89c460d50de4adb6825bf#4f8fcd1bf468f566fcd89c460d50de4adb6825bf" +dependencies = [ + "arc-swap", + "bytemuck", + "bytes", + "crossbeam", + "cuprate-constants", + "cuprate-helper", + "cuprate-pruning", + "cuprate-types", + "fjall", + "futures", + "indexmap 2.14.2", + "monero-oxide", + "rand 0.8.8", + "rayon", + "serde", + "tapes", + "thiserror 2.0.20", + "tower", + "tracing", +] + +[[package]] +name = "cuprate-consensus" +version = "0.1.0" +source = "git+https://github.com/Cuprate/cuprate?rev=4f8fcd1bf468f566fcd89c460d50de4adb6825bf#4f8fcd1bf468f566fcd89c460d50de4adb6825bf" +dependencies = [ + "cfg-if", + "cuprate-consensus-context", + "cuprate-consensus-rules", + "cuprate-helper", + "cuprate-types", + "hex", + "indexmap 2.14.2", + "monero-oxide", + "rand 0.8.8", + "rayon", + "thiserror 2.0.20", + "thread_local", + "tower", + "tracing", +] + +[[package]] +name = "cuprate-consensus-context" +version = "0.1.0" +source = "git+https://github.com/Cuprate/cuprate?rev=4f8fcd1bf468f566fcd89c460d50de4adb6825bf#4f8fcd1bf468f566fcd89c460d50de4adb6825bf" +dependencies = [ + "arc-swap", + "cuprate-consensus-rules", + "cuprate-helper", + "cuprate-types", + "futures", + "hex", + "monero-oxide", + "randomx-rs", + "rayon", + "strum", + "thread_local", + "tokio", + "tokio-util", + "tower", + "tracing", +] + +[[package]] +name = "cuprate-consensus-rules" +version = "0.1.0" +source = "git+https://github.com/Cuprate/cuprate?rev=4f8fcd1bf468f566fcd89c460d50de4adb6825bf#4f8fcd1bf468f566fcd89c460d50de4adb6825bf" +dependencies = [ + "cfg-if", + "crypto-bigint 0.7.5", + "cuprate-constants", + "cuprate-cryptonight", + "cuprate-helper", + "cuprate-types", + "curve25519-dalek", + "hex", + "hex-literal 1.1.0", + "indexmap 2.14.2", + "monero-oxide", + "rand 0.8.8", + "rayon", + "thiserror 2.0.20", + "tracing", +] + +[[package]] +name = "cuprate-constants" +version = "0.1.0" +source = "git+https://github.com/Cuprate/cuprate?rev=4f8fcd1bf468f566fcd89c460d50de4adb6825bf#4f8fcd1bf468f566fcd89c460d50de4adb6825bf" + +[[package]] +name = "cuprate-cryptonight" +version = "0.1.0" +source = "git+https://github.com/Cuprate/cuprate?rev=4f8fcd1bf468f566fcd89c460d50de4adb6825bf#4f8fcd1bf468f566fcd89c460d50de4adb6825bf" +dependencies = [ + "digest 0.10.7", + "groestl", + "jh", + "keccak 0.1.6", + "seq-macro", + "sha3 0.10.9", + "skein", + "thiserror 2.0.20", +] + +[[package]] +name = "cuprate-dandelion-tower" +version = "0.1.0" +source = "git+https://github.com/Cuprate/cuprate?rev=4f8fcd1bf468f566fcd89c460d50de4adb6825bf#4f8fcd1bf468f566fcd89c460d50de4adb6825bf" +dependencies = [ + "futures", + "rand 0.8.8", + "rand_distr", + "thiserror 2.0.20", + "tokio", + "tokio-util", + "tower", + "tracing", +] + +[[package]] +name = "cuprate-epee-encoding" +version = "0.5.0" +source = "git+https://github.com/Cuprate/cuprate?rev=4f8fcd1bf468f566fcd89c460d50de4adb6825bf#4f8fcd1bf468f566fcd89c460d50de4adb6825bf" +dependencies = [ + "bytes", + "cuprate-fixed-bytes", + "cuprate-hex", + "paste", + "ref-cast", + "thiserror 2.0.20", +] + +[[package]] +name = "cuprate-fast-sync" +version = "0.1.0" +source = "git+https://github.com/Cuprate/cuprate?rev=4f8fcd1bf468f566fcd89c460d50de4adb6825bf#4f8fcd1bf468f566fcd89c460d50de4adb6825bf" +dependencies = [ + "blake3", + "clap", + "cuprate-blockchain", + "cuprate-consensus", + "cuprate-consensus-context", + "cuprate-helper", + "cuprate-hex", + "cuprate-p2p", + "cuprate-p2p-core", + "cuprate-types", + "fjall", + "futures", + "hex", + "monero-oxide", + "rayon", + "serde_json", + "tokio", + "tower", + "tracing-subscriber", +] + +[[package]] +name = "cuprate-fixed-bytes" +version = "0.1.0" +source = "git+https://github.com/Cuprate/cuprate?rev=4f8fcd1bf468f566fcd89c460d50de4adb6825bf#4f8fcd1bf468f566fcd89c460d50de4adb6825bf" +dependencies = [ + "bytes", + "serde", + "thiserror 2.0.20", +] + +[[package]] +name = "cuprate-helper" +version = "0.1.0" +source = "git+https://github.com/Cuprate/cuprate?rev=4f8fcd1bf468f566fcd89c460d50de4adb6825bf#4f8fcd1bf468f566fcd89c460d50de4adb6825bf" +dependencies = [ + "chrono", + "cuprate-constants", + "curve25519-dalek", + "dirs", + "futures", + "libc", + "monero-oxide", + "rayon", + "serde", + "windows", +] + +[[package]] +name = "cuprate-hex" +version = "0.0.0" +source = "git+https://github.com/Cuprate/cuprate?rev=4f8fcd1bf468f566fcd89c460d50de4adb6825bf#4f8fcd1bf468f566fcd89c460d50de4adb6825bf" +dependencies = [ + "hex", + "serde", +] + +[[package]] +name = "cuprate-json-rpc" +version = "0.0.0" +source = "git+https://github.com/Cuprate/cuprate?rev=4f8fcd1bf468f566fcd89c460d50de4adb6825bf#4f8fcd1bf468f566fcd89c460d50de4adb6825bf" +dependencies = [ + "serde", + "serde_json", + "thiserror 2.0.20", +] + +[[package]] +name = "cuprate-levin" +version = "0.1.0" +source = "git+https://github.com/Cuprate/cuprate?rev=4f8fcd1bf468f566fcd89c460d50de4adb6825bf#4f8fcd1bf468f566fcd89c460d50de4adb6825bf" +dependencies = [ + "bitflags 2.13.2", + "bytes", + "cfg-if", + "cuprate-helper", + "thiserror 2.0.20", + "tokio-util", + "tracing", +] + +[[package]] +name = "cuprate-p2p" +version = "0.1.0" +source = "git+https://github.com/Cuprate/cuprate?rev=4f8fcd1bf468f566fcd89c460d50de4adb6825bf#4f8fcd1bf468f566fcd89c460d50de4adb6825bf" +dependencies = [ + "borsh", + "bytes", + "cuprate-address-book", + "cuprate-async-buffer", + "cuprate-constants", + "cuprate-fixed-bytes", + "cuprate-helper", + "cuprate-p2p-core", + "cuprate-pruning", + "cuprate-types", + "cuprate-wire", + "futures", + "indexmap 2.14.2", + "monero-oxide", + "pin-project", + "rand 0.8.8", + "rand_distr", + "rayon", + "thiserror 2.0.20", + "tokio", + "tokio-stream", + "tokio-util", + "tower", + "tracing", +] + +[[package]] +name = "cuprate-p2p-core" +version = "0.1.0" +source = "git+https://github.com/Cuprate/cuprate?rev=4f8fcd1bf468f566fcd89c460d50de4adb6825bf#4f8fcd1bf468f566fcd89c460d50de4adb6825bf" +dependencies = [ + "async-trait", + "borsh", + "cfg-if", + "cuprate-helper", + "cuprate-pruning", + "cuprate-types", + "cuprate-wire", + "futures", + "hex", + "hex-literal 1.1.0", + "rand 0.8.8", + "thiserror 2.0.20", + "tokio", + "tokio-stream", + "tokio-util", + "tower", + "tracing", +] + +[[package]] +name = "cuprate-p2p-transport" +version = "0.1.0" +source = "git+https://github.com/Cuprate/cuprate?rev=4f8fcd1bf468f566fcd89c460d50de4adb6825bf#4f8fcd1bf468f566fcd89c460d50de4adb6825bf" +dependencies = [ + "async-trait", + "cuprate-p2p-core", + "cuprate-wire", + "futures", + "tokio", + "tokio-socks", + "tokio-util", +] + +[[package]] +name = "cuprate-pruning" +version = "0.1.0" +source = "git+https://github.com/Cuprate/cuprate?rev=4f8fcd1bf468f566fcd89c460d50de4adb6825bf#4f8fcd1bf468f566fcd89c460d50de4adb6825bf" +dependencies = [ + "borsh", + "cuprate-constants", + "thiserror 2.0.20", +] + +[[package]] +name = "cuprate-rpc-interface" +version = "0.0.0" +source = "git+https://github.com/Cuprate/cuprate?rev=4f8fcd1bf468f566fcd89c460d50de4adb6825bf#4f8fcd1bf468f566fcd89c460d50de4adb6825bf" +dependencies = [ + "anyhow", + "axum", + "cuprate-epee-encoding", + "cuprate-helper", + "cuprate-json-rpc", + "cuprate-rpc-types", + "futures", + "paste", + "serde", + "serde_json", + "tower", +] + +[[package]] +name = "cuprate-rpc-types" +version = "0.0.0" +source = "git+https://github.com/Cuprate/cuprate?rev=4f8fcd1bf468f566fcd89c460d50de4adb6825bf#4f8fcd1bf468f566fcd89c460d50de4adb6825bf" +dependencies = [ + "cuprate-epee-encoding", + "cuprate-fixed-bytes", + "cuprate-helper", + "cuprate-hex", + "cuprate-p2p-core", + "cuprate-types", + "hex", + "monero-oxide", + "paste", + "serde", + "serde_json", +] + +[[package]] +name = "cuprate-txpool" +version = "0.0.0" +source = "git+https://github.com/Cuprate/cuprate?rev=4f8fcd1bf468f566fcd89c460d50de4adb6825bf#4f8fcd1bf468f566fcd89c460d50de4adb6825bf" +dependencies = [ + "bitflags 2.13.2", + "blake3", + "bytemuck", + "cuprate-helper", + "cuprate-types", + "fjall", + "futures", + "hex", + "monero-oxide", + "rayon", + "thiserror 2.0.20", + "tower", +] + +[[package]] +name = "cuprate-types" +version = "0.0.0" +source = "git+https://github.com/Cuprate/cuprate?rev=4f8fcd1bf468f566fcd89c460d50de4adb6825bf#4f8fcd1bf468f566fcd89c460d50de4adb6825bf" +dependencies = [ + "bitflags 2.13.2", + "bytes", + "cfg-if", + "cuprate-epee-encoding", + "cuprate-fixed-bytes", + "cuprate-helper", + "cuprate-hex", + "indexmap 2.14.2", + "monero-oxide", + "proptest", + "proptest-derive", + "serde", + "strum", + "thiserror 2.0.20", +] + +[[package]] +name = "cuprate-wire" +version = "0.1.0" +source = "git+https://github.com/Cuprate/cuprate?rev=4f8fcd1bf468f566fcd89c460d50de4adb6825bf#4f8fcd1bf468f566fcd89c460d50de4adb6825bf" +dependencies = [ + "bitflags 2.13.2", + "borsh", + "bytes", + "cuprate-epee-encoding", + "cuprate-fixed-bytes", + "cuprate-helper", + "cuprate-levin", + "cuprate-types", + "serde", + "thiserror 2.0.20", +] + +[[package]] +name = "cuprated" +version = "0.1.0-preview" +source = "git+https://github.com/Cuprate/cuprate?rev=4f8fcd1bf468f566fcd89c460d50de4adb6825bf#4f8fcd1bf468f566fcd89c460d50de4adb6825bf" +dependencies = [ + "anyhow", + "axum", + "borsh", + "bytes", + "clap", + "const_format", + "cuprate-address-book", + "cuprate-blockchain", + "cuprate-consensus", + "cuprate-consensus-context", + "cuprate-consensus-rules", + "cuprate-constants", + "cuprate-cryptonight", + "cuprate-dandelion-tower", + "cuprate-fast-sync", + "cuprate-fixed-bytes", + "cuprate-helper", + "cuprate-hex", + "cuprate-p2p", + "cuprate-p2p-core", + "cuprate-p2p-transport", + "cuprate-pruning", + "cuprate-rpc-interface", + "cuprate-rpc-types", + "cuprate-txpool", + "cuprate-types", + "cuprate-wire", + "dashmap", + "fjall", + "futures", + "hex", + "hyper", + "hyper-util", + "indexmap 2.14.2", + "monero-address", + "monero-oxide", + "nu-ansi-term", + "pin-project-lite", + "rayon", + "serde", + "serde_json", + "sysinfo", + "thiserror 2.0.20", + "tokio", + "tokio-util", + "toml 1.1.6+spec-1.1.0", + "toml_edit 0.25.14+spec-1.1.0", + "tower", + "tower-http", + "tracing", + "tracing-appender", + "tracing-subscriber", +] + [[package]] name = "curve25519-dalek" version = "4.1.3" @@ -1081,6 +1826,20 @@ dependencies = [ "syn 3.0.5", ] +[[package]] +name = "dashmap" +version = "6.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6361d5c062261c78a176addb82d4c821ae42bed6089de0e12603cd25de2059c" +dependencies = [ + "cfg-if", + "crossbeam-utils", + "hashbrown 0.14.5", + "lock_api", + "once_cell", + "parking_lot_core", +] + [[package]] name = "data-encoding" version = "2.11.1" @@ -1384,7 +2143,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" dependencies = [ "base16ct", - "crypto-bigint", + "crypto-bigint 0.5.5", "digest 0.10.7", "ff", "generic-array", @@ -1542,6 +2301,23 @@ version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3e0f1c7c3a72c66fd80abe965175f7523475c0489a87d3ff9d6e8c87d87a9d2d" +[[package]] +name = "fjall" +version = "3.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd201c93927cdf4712e8f7d4c9c8d34d68c7534380c05d4a58864a309f91c33f" +dependencies = [ + "byteorder-lite", + "byteview", + "dashmap", + "flume", + "log", + "lsm-tree", + "lz4_flex", + "tempfile", + "xxhash-rust", +] + [[package]] name = "flate2" version = "1.1.10" @@ -1559,6 +2335,15 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "749cff877dc1af878a0b31a41dd221a753634401ea0ef2f87b62d3171522485a" +[[package]] +name = "flume" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e139bc46ca777eb5efaf62df0ab8cc5fd400866427e56c68b22e414e53bd3be" +dependencies = [ + "spin 0.9.9", +] + [[package]] name = "fnv" version = "1.0.7" @@ -1824,6 +2609,15 @@ dependencies = [ "scroll", ] +[[package]] +name = "groestl" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "343cfc165f92a988fd60292f7a0bfde4352a5a0beff9fbec29251ca4e9676e4d" +dependencies = [ + "digest 0.10.7", +] + [[package]] name = "group" version = "0.13.0" @@ -1853,6 +2647,12 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +[[package]] +name = "hashbrown" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" + [[package]] name = "hashbrown" version = "0.15.5" @@ -1904,6 +2704,21 @@ name = "hex" version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +dependencies = [ + "serde", +] + +[[package]] +name = "hex-literal" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" + +[[package]] +name = "hex-literal" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e712f64ec3850b98572bffac52e2c6f282b29fe6c5fa6d42334b30be438d95c1" [[package]] name = "hkdf" @@ -1939,6 +2754,29 @@ dependencies = [ "itoa", ] +[[package]] +name = "http-body" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca2a8f2913ee65f60facd6a5905613afaa448497a0230cc41ce022d93290bc2c" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23169fe34a5fbcdd3f3862e78fb9b6fccd5f02a6dc6f732547005d45631ce71c" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", + "pin-project-lite", +] + [[package]] name = "httparse" version = "1.10.1" @@ -1977,6 +2815,41 @@ dependencies = [ "zeroize", ] +[[package]] +name = "hyper" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "27b501faa50e7a26c3d3560ca625132f4078a17771f4810baf70475ae48cbe43" +dependencies = [ + "atomic-waker", + "bytes", + "futures-channel", + "futures-core", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", +] + +[[package]] +name = "hyper-util" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96547c2556ec9d12fb1578c4eaf448b04993e7fb79cbaad930a656880a6bdfa0" +dependencies = [ + "bytes", + "http", + "http-body", + "hyper", + "pin-project-lite", + "tokio", + "tower-service", +] + [[package]] name = "iana-time-zone" version = "0.1.65" @@ -2140,6 +3013,7 @@ checksum = "cc4e190f5d26ca7051642629da2c52fc03bde85a03197c99408dcd291734c855" dependencies = [ "equivalent", "hashbrown 0.17.1", + "rayon", "serde", "serde_core", ] @@ -2204,6 +3078,15 @@ dependencies = [ "syn 3.0.5", ] +[[package]] +name = "interval-heap" +version = "0.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11274e5e8e89b8607cfedc2910b6626e998779b48a019151c7604d0adcb86ac6" +dependencies = [ + "compare", +] + [[package]] name = "inventory" version = "0.3.24" @@ -2252,6 +3135,17 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" +[[package]] +name = "jh" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f65735f9e73adc203417d2e05352aef71d7e832ec090f65de26c96c9ec563aa5" +dependencies = [ + "digest 0.10.7", + "hex-literal 0.4.1", + "ppv-lite86", +] + [[package]] name = "jiff" version = "0.2.35" @@ -2366,6 +3260,21 @@ dependencies = [ "cpufeatures 0.3.1", ] +[[package]] +name = "konst" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "128133ed7824fcd73d6e7b17957c5eb7bacb885649bd8c69708b2331a10bcefb" +dependencies = [ + "konst_macro_rules", +] + +[[package]] +name = "konst_macro_rules" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4933f3f57a8e9d9da04db23fb153356ecaf00cbd14aee46279c33dc80925c37" + [[package]] name = "kqueue" version = "1.2.1" @@ -2392,7 +3301,7 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" dependencies = [ - "spin", + "spin 0.9.9", ] [[package]] @@ -2499,6 +3408,37 @@ dependencies = [ "hashbrown 0.17.1", ] +[[package]] +name = "lsm-tree" +version = "3.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5498808f4d41cf785079d3ef3f28716f1b4364af1b512f3097bfb651bded1b3e" +dependencies = [ + "byteorder-lite", + "byteview", + "crossbeam-skiplist", + "enum_dispatch", + "interval-heap", + "log", + "lz4_flex", + "quick_cache", + "rustc-hash", + "self_cell", + "sfa", + "tempfile", + "varint-rs", + "xxhash-rust", +] + +[[package]] +name = "lz4_flex" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ef0d4ed8669f8f8826eb00dc878084aa8f253506c4fd5e8f58f5bce72ddb97e" +dependencies = [ + "twox-hash", +] + [[package]] name = "matchers" version = "0.2.0" @@ -2508,6 +3448,12 @@ dependencies = [ "regex-automata", ] +[[package]] +name = "matchit" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47e1ffaa40ddd1f3ed91f717a33c8c0ee23fff369e3aa8772b9605cc1d22f4c3" + [[package]] name = "md-5" version = "0.10.6" @@ -2545,6 +3491,12 @@ dependencies = [ "zeroize", ] +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + [[package]] name = "minimal-lexical" version = "0.2.1" @@ -2573,6 +3525,147 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "monero-address" +version = "0.1.0" +source = "git+https://github.com/monero-oxide/monero-oxide.git?rev=946ec5f#946ec5f00ff071b129758ee8cba5528539fccfe4" +dependencies = [ + "monero-base58", + "monero-ed25519", + "monero-io", + "monero-primitives", + "thiserror 2.0.20", + "zeroize", +] + +[[package]] +name = "monero-base58" +version = "0.1.0" +source = "git+https://github.com/monero-oxide/monero-oxide.git?rev=946ec5f#946ec5f00ff071b129758ee8cba5528539fccfe4" +dependencies = [ + "monero-primitives", + "std-shims", +] + +[[package]] +name = "monero-borromean" +version = "0.1.0" +source = "git+https://github.com/monero-oxide/monero-oxide.git?rev=946ec5f#946ec5f00ff071b129758ee8cba5528539fccfe4" +dependencies = [ + "curve25519-dalek", + "monero-ed25519", + "monero-io", + "std-shims", + "zeroize", +] + +[[package]] +name = "monero-bulletproofs" +version = "0.1.0" +source = "git+https://github.com/monero-oxide/monero-oxide.git?rev=946ec5f#946ec5f00ff071b129758ee8cba5528539fccfe4" +dependencies = [ + "curve25519-dalek", + "monero-bulletproofs-generators", + "monero-ed25519", + "monero-io", + "monero-primitives", + "rand_core 0.6.4", + "std-shims", + "thiserror 2.0.20", + "zeroize", +] + +[[package]] +name = "monero-bulletproofs-generators" +version = "0.1.0" +source = "git+https://github.com/monero-oxide/monero-oxide.git?rev=946ec5f#946ec5f00ff071b129758ee8cba5528539fccfe4" +dependencies = [ + "curve25519-dalek", + "monero-ed25519", + "monero-io", + "monero-primitives", + "std-shims", +] + +[[package]] +name = "monero-clsag" +version = "0.1.0" +source = "git+https://github.com/monero-oxide/monero-oxide.git?rev=946ec5f#946ec5f00ff071b129758ee8cba5528539fccfe4" +dependencies = [ + "curve25519-dalek", + "group", + "monero-ed25519", + "monero-io", + "rand_chacha 0.3.1", + "rand_core 0.6.4", + "std-shims", + "subtle", + "thiserror 2.0.20", + "zeroize", +] + +[[package]] +name = "monero-ed25519" +version = "0.1.0" +source = "git+https://github.com/monero-oxide/monero-oxide.git?rev=946ec5f#946ec5f00ff071b129758ee8cba5528539fccfe4" +dependencies = [ + "crypto-bigint 0.5.5", + "curve25519-dalek", + "monero-io", + "rand_core 0.6.4", + "sha3 0.10.9", + "std-shims", + "subtle", + "zeroize", +] + +[[package]] +name = "monero-io" +version = "0.1.0" +source = "git+https://github.com/monero-oxide/monero-oxide.git?rev=946ec5f#946ec5f00ff071b129758ee8cba5528539fccfe4" +dependencies = [ + "std-shims", +] + +[[package]] +name = "monero-mlsag" +version = "0.1.0" +source = "git+https://github.com/monero-oxide/monero-oxide.git?rev=946ec5f#946ec5f00ff071b129758ee8cba5528539fccfe4" +dependencies = [ + "curve25519-dalek", + "monero-ed25519", + "monero-io", + "std-shims", + "thiserror 2.0.20", + "zeroize", +] + +[[package]] +name = "monero-oxide" +version = "0.1.4-alpha" +source = "git+https://github.com/monero-oxide/monero-oxide.git?rev=946ec5f#946ec5f00ff071b129758ee8cba5528539fccfe4" +dependencies = [ + "curve25519-dalek", + "hex-literal 1.1.0", + "monero-borromean", + "monero-bulletproofs", + "monero-clsag", + "monero-ed25519", + "monero-io", + "monero-mlsag", + "monero-primitives", + "std-shims", + "zeroize", +] + +[[package]] +name = "monero-primitives" +version = "0.1.0" +source = "git+https://github.com/monero-oxide/monero-oxide.git?rev=946ec5f#946ec5f00ff071b129758ee8cba5528539fccfe4" +dependencies = [ + "sha3 0.10.9", +] + [[package]] name = "nom" version = "7.1.3" @@ -2766,6 +3859,7 @@ dependencies = [ "argon2", "arti-client", "chacha20poly1305", + "cuprated", "ed25519-dalek", "futures", "hkdf", @@ -2783,6 +3877,7 @@ dependencies = [ "sha3 0.10.9", "snow", "tokio", + "toml 0.8.23", "tor-cell", "tor-hsservice", "tor-rtcompat", @@ -3214,6 +4309,36 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "proptest" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b45fcc2344c680f5025fe57779faef368840d0bd1f42f216291f0dc4ace4744" +dependencies = [ + "bit-set", + "bit-vec", + "bitflags 2.13.2", + "num-traits", + "rand 0.9.5", + "rand_chacha 0.9.0", + "rand_xorshift", + "regex-syntax", + "rusty-fork", + "tempfile", + "unarray", +] + +[[package]] +name = "proptest-derive" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c57924a81864dddafba92e1bf92f9bf82f97096c44489548a60e888e1547549b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + [[package]] name = "pwd-grp" version = "1.0.2" @@ -3232,6 +4357,22 @@ version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d68782463e408eb1e668cf6152704bd856c78c5b6417adaee3203d8f4c1fc9ec" +[[package]] +name = "quick-error" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" + +[[package]] +name = "quick_cache" +version = "0.6.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9c6658afe513a3b484e3abfdaa0d03ef3c0bbf017542c178dd55f94eb3051f9" +dependencies = [ + "equivalent", + "hashbrown 0.16.1", +] + [[package]] name = "quote" version = "1.0.47" @@ -3270,6 +4411,16 @@ dependencies = [ "rand_core 0.6.4", ] +[[package]] +name = "rand" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9ef1d0d795eb7d84685bca4f72f3649f064e6641543d3a8c415898726a57b41" +dependencies = [ + "rand_chacha 0.9.0", + "rand_core 0.9.5", +] + [[package]] name = "rand" version = "0.10.2" @@ -3291,6 +4442,16 @@ dependencies = [ "rand_core 0.6.4", ] +[[package]] +name = "rand_chacha" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" +dependencies = [ + "ppv-lite86", + "rand_core 0.9.5", +] + [[package]] name = "rand_chacha" version = "0.10.0" @@ -3310,12 +4471,31 @@ dependencies = [ "getrandom 0.2.17", ] +[[package]] +name = "rand_core" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76afc826de14238e6e8c374ddcc1fa19e374fd8dd986b0d2af0d02377261d83c" +dependencies = [ + "getrandom 0.3.4", +] + [[package]] name = "rand_core" version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69" +[[package]] +name = "rand_distr" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32cb0b9bc82b0a0876c2dd994a7e7a2683d3e7390ca40e6886785ef0c7e3ee31" +dependencies = [ + "num-traits", + "rand 0.8.8", +] + [[package]] name = "rand_jitter" version = "0.6.1" @@ -3327,6 +4507,27 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "rand_xorshift" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "513962919efc330f829edb2535844d1b912b0fbe2ca165d613e4e8788bb05a5a" +dependencies = [ + "rand_core 0.9.5", +] + +[[package]] +name = "randomx-rs" +version = "1.4.1" +source = "git+https://github.com/Cuprate/randomx-rs.git?rev=76c2385#76c2385771ca5aca941e0991ebd822e6edb8d94d" +dependencies = [ + "bitflags 1.3.2", + "cc", + "cmake", + "libc", + "thiserror 1.0.69", +] + [[package]] name = "rangemap" version = "1.8.0" @@ -3399,6 +4600,26 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "rayon" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb39b166781f92d482534ef4b4b1b2568f42613b53e5b6c160e24cfbfa30926d" +dependencies = [ + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22e18b0f0062d30d4230b2e85ff77fdfe4326feb054b9783a3460d8435c8ab91" +dependencies = [ + "crossbeam-deque", + "crossbeam-utils", +] + [[package]] name = "rdrand" version = "0.9.0" @@ -3656,6 +4877,18 @@ version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f" +[[package]] +name = "rusty-fork" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc6bf79ff24e648f6da1f8d1f011e9cac26491b619e6b9280f2b47f1774e6ee2" +dependencies = [ + "fnv", + "quick-error", + "tempfile", + "wait-timeout", +] + [[package]] name = "ryu" version = "1.0.23" @@ -3763,6 +4996,12 @@ dependencies = [ "zeroize", ] +[[package]] +name = "self_cell" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ab42ca02749e120097e328d91d415325bdf43b1c72c4c8badf37375fe40a813" + [[package]] name = "semver" version = "1.0.28" @@ -3773,6 +5012,12 @@ dependencies = [ "serde_core", ] +[[package]] +name = "seq-macro" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bc711410fbe7399f390ca1c3b60ad0f53f80e95c5eb935e52268a0e2cd49acc" + [[package]] name = "serde" version = "1.0.229" @@ -3846,6 +5091,17 @@ dependencies = [ "zmij", ] +[[package]] +name = "serde_path_to_error" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10a9ff822e371bb5403e391ecd83e182e0e77ba7f6fe0160b795797109d1b457" +dependencies = [ + "itoa", + "serde", + "serde_core", +] + [[package]] name = "serde_spanned" version = "0.6.9" @@ -3897,6 +5153,17 @@ dependencies = [ "syn 3.0.5", ] +[[package]] +name = "sfa" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1296838937cab56cd6c4eeeb8718ec777383700c33f060e2869867bd01d1175" +dependencies = [ + "byteorder-lite", + "log", + "xxhash-rust", +] + [[package]] name = "sha1" version = "0.10.7" @@ -4019,6 +5286,16 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ee5873ec9cce0195efcb7a4e9507a04cd49aec9c83d0389df45b1ef7ba2e649" +[[package]] +name = "skein" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96a90a220ab98dbbfeabeae7c558a79f37839c10b9ef55c77082a741a463cab7" +dependencies = [ + "digest 0.10.7", + "threefish", +] + [[package]] name = "slab" version = "0.4.12" @@ -4092,6 +5369,15 @@ name = "spin" version = "0.9.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3763264f6b73151db08c50ff20d7d8a0b8796e021cdea7ceedad07b80155fa0e" +dependencies = [ + "lock_api", +] + +[[package]] +name = "spin" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "023a211cb3138dbc438680b32560ad89f699977624c9f8dbb95a47d5b4c07dd3" [[package]] name = "spki" @@ -4163,6 +5449,17 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +[[package]] +name = "std-shims" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "227c4f8561598188d0df96dbe749824576174bba278b5b6bb2eacff1066067d0" +dependencies = [ + "hashbrown 0.16.1", + "rustversion", + "spin 0.10.1", +] + [[package]] name = "strsim" version = "0.10.0" @@ -4202,6 +5499,12 @@ version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" +[[package]] +name = "symlink" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7973cce6668464ea31f176d85b13c7ab3bba2cb3b77a2ed26abd7801688010a" + [[package]] name = "syn" version = "1.0.109" @@ -4272,6 +5575,18 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" +[[package]] +name = "tapes" +version = "0.2.0" +source = "git+https://github.com/Cuprate/Tapes.git?rev=04562f4#04562f44fd8e029ce0caf7dfa993682ffe69837d" +dependencies = [ + "blake2", + "borsh", + "bytemuck", + "parking_lot", + "slab", +] + [[package]] name = "tempfile" version = "3.27.0" @@ -4285,6 +5600,16 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "terminal_size" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "230a1b821ccbd75b185820a1f1ff7b14d21da1e442e22c0863ea5f08771a8874" +dependencies = [ + "rustix", + "windows-sys 0.59.0", +] + [[package]] name = "textwrap" version = "0.16.3" @@ -4344,6 +5669,12 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "threefish" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a693d0c8cf16973fac5a93fbe47b8c6452e7097d4fcac49f3d7a18e39c76e62e" + [[package]] name = "time" version = "0.3.55" @@ -4411,6 +5742,7 @@ dependencies = [ "bytes", "libc", "mio", + "parking_lot", "pin-project-lite", "signal-hook-registry", "socket2", @@ -4429,6 +5761,29 @@ dependencies = [ "syn 3.0.5", ] +[[package]] +name = "tokio-socks" +version = "0.5.2" +source = "git+https://github.com/Cuprate/tokio-socks.git?rev=8737caf#8737caf429a86ab181954444fac4f9b917795b19" +dependencies = [ + "either", + "futures-util", + "thiserror 1.0.69", + "tokio", +] + +[[package]] +name = "tokio-stream" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3d06f0b082ba57c26b79407372e57cf2a1e28124f78e9479fe80322cf53420b" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", + "tokio-util", +] + [[package]] name = "tokio-util" version = "0.7.19" @@ -4439,8 +5794,12 @@ dependencies = [ "futures-core", "futures-io", "futures-sink", + "futures-util", + "libc", "pin-project-lite", + "slab", "tokio", + "tracing", ] [[package]] @@ -4511,6 +5870,7 @@ dependencies = [ "indexmap 2.14.2", "toml_datetime 1.1.1+spec-1.1.0", "toml_parser", + "toml_writer", "winnow 1.0.4", ] @@ -5650,6 +7010,54 @@ dependencies = [ "tor-memquota", ] +[[package]] +name = "tower" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebe5ef63511595f1344e2d5cfa636d973292adc0eec1f0ad45fae9f0851ab1d4" +dependencies = [ + "futures-core", + "futures-util", + "pin-project-lite", + "sync_wrapper", + "tokio", + "tokio-util", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower-http" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08a05a66a4fdd61cbbe0a1d755ffe0ca6aba159dd4820936a0ff8a8278245b9c" +dependencies = [ + "bitflags 2.13.2", + "bytes", + "http", + "http-body", + "http-body-util", + "percent-encoding", + "pin-project-lite", + "tokio", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + [[package]] name = "tracing" version = "0.1.44" @@ -5661,6 +7069,19 @@ dependencies = [ "tracing-core", ] +[[package]] +name = "tracing-appender" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "050686193eb999b4bb3bc2acfa891a13da00f79734704c4b8b4ef1a10b368a3c" +dependencies = [ + "crossbeam-channel", + "symlink", + "thiserror 2.0.20", + "time", + "tracing-subscriber", +] + [[package]] name = "tracing-attributes" version = "0.1.31" @@ -5732,6 +7153,12 @@ dependencies = [ "syn 2.0.119", ] +[[package]] +name = "twox-hash" +version = "2.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5283634e518fe9e82c7b20520bb4bc209009fd16c82077c802f8111ecbb0117a" + [[package]] name = "typed-index-collections" version = "3.5.0" @@ -5748,6 +7175,12 @@ version = "1.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20" +[[package]] +name = "unarray" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eaea85b334db583fe3274d12b4cd1880032beab409c0d774be044d4480ab9a94" + [[package]] name = "uncased" version = "0.9.10" @@ -5970,6 +7403,12 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" +[[package]] +name = "varint-rs" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa6c38708f6257f1ec2ca7e5a11f9bbf58a27d7060078b6b333624968183d96" + [[package]] name = "vcpkg" version = "0.2.15" @@ -5999,6 +7438,15 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" +[[package]] +name = "wait-timeout" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ac3b126d3914f9849036f826e054cbabdc8519970b8998ddaf3b5bd3c65f11" +dependencies = [ + "libc", +] + [[package]] name = "walkdir" version = "2.5.0" diff --git a/crates/onionwire-sdk/Cargo.toml b/crates/onionwire-sdk/Cargo.toml index a1a8227..5f209ec 100644 --- a/crates/onionwire-sdk/Cargo.toml +++ b/crates/onionwire-sdk/Cargo.toml @@ -17,6 +17,16 @@ resolver = "2" name = "onionwire_sdk" crate-type = ["cdylib", "lib"] +[features] +default = [] + +# The in-process Monero chain daemon (Cuprate). Off by default: it pulls a +# pinned `cuprated` git revision, ~152 crates and a C++ RandomX cross-build +# (+11.8 MiB on an aarch64 release binary). Without it the SDK can still store +# and read back a `ChainChoice.InProcessCuprate` setting — starting one fails +# with the core's "rebuild with --features cuprate-daemon" message. +cuprate-daemon = ["onionwire/cuprate-daemon"] + [dependencies] onionwire = { path = "../..", default-features = false, features = ["rustls"] } # `static-sqlite`: Android has no system libsqlite3 to link against. diff --git a/crates/onionwire-sdk/src/lib.rs b/crates/onionwire-sdk/src/lib.rs index ad2f077..24bc2fb 100644 --- a/crates/onionwire-sdk/src/lib.rs +++ b/crates/onionwire-sdk/src/lib.rs @@ -25,7 +25,7 @@ //! The façade deliberately exposes only plain data (records + hex strings) so //! no TUI/ratatui type leaks into the AAR. -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use std::sync::{Arc, Mutex, OnceLock}; use onionwire::Message; @@ -35,7 +35,7 @@ use onionwire::outbox::{DEFAULT_MAX_ATTEMPTS, OutboxEntry, OutboxStatus}; use onionwire::pay; use onionwire::qr; use onionwire::wallet::ChainSource; -use onionwire::wallet_child::ChildConfig; +use onionwire::wallet_child::{ChildConfig, WalletChildState}; uniffi::setup_scaffolding!(); @@ -244,6 +244,10 @@ pub struct FlushOutcome { #[derive(uniffi::Object)] pub struct Wire { node: Mutex>>, + /// `$ONIONWIRE_HOME` exactly as [`open_wire`] was given it. The SDK resolves + /// the per-identity defaults a caller cannot know (the in-process chain + /// data directory) against it, so Kotlin never has to invent a path. + home: PathBuf, } impl Wire { @@ -279,11 +283,13 @@ pub async fn open_wire(home: String, passphrase: String) -> WResult> { // with "Could not automatically determine the process-level CryptoProvider" // if no provider is resolvable. See `install_crypto_provider`. install_crypto_provider(); - let node = Node::start_with_passphrase(PathBuf::from(home), &passphrase) + let home = PathBuf::from(home); + let node = Node::start_with_passphrase(home.clone(), &passphrase) .await .map_err(WireError::new)?; Ok(Arc::new(Wire { node: Mutex::new(Some(node)), + home, })) } @@ -616,7 +622,8 @@ impl Wire { pub async fn start_wallet_child(&self) -> WResult { let node = self.node()?; node.start_wallet_child().map_err(WireError::new)?; - Ok(child_status(node.wallet_child_refresh().await)) + let source = node.wallet_child_config().source; + Ok(child_status(node.wallet_child_refresh().await, &source)) } /// Stop the wallet child and its daemon/SOCKS siblings. Idempotent: stopping @@ -632,7 +639,9 @@ impl Wire { /// /// Synchronous on purpose — it is safe to call from a UI refresh loop. pub fn wallet_status(&self) -> WResult { - Ok(child_status(self.node()?.wallet_child_status())) + let node = self.node()?; + let source = node.wallet_child_config().source; + Ok(child_status(node.wallet_child_status(), &source)) } /// The chain-source + binary settings the child spawns with, as stored. @@ -652,7 +661,7 @@ impl Wire { /// binary the caller named explicitly. pub fn set_chain_source(&self, config: ChainConfig) -> WResult<()> { self.node()? - .set_wallet_child_config(&child_config(config)) + .set_wallet_child_config(&child_config(config, &self.home)) .map_err(WireError::new) } @@ -720,7 +729,13 @@ fn from_core_flush(o: CoreFlushOutcome) -> FlushOutcome { } /// The core child settings a [`ChainConfig`] describes. -fn child_config(cfg: ChainConfig) -> ChildConfig { +/// +/// `home` is the `$ONIONWIRE_HOME` the identity was opened with. An in-process +/// chain source with an empty `monerod_datadir` resolves to `home/chain` — the +/// per-identity directory the core documents for a local chain — so a Kotlin +/// caller never has to invent an absolute path. Every other kind uses exactly +/// what it was given (or the core's own default), unchanged. +fn child_config(cfg: ChainConfig, home: &Path) -> ChildConfig { let source = match cfg.kind { ChainChoice::None => ChainSource::None, ChainChoice::Local => ChainSource::Local { @@ -728,7 +743,11 @@ fn child_config(cfg: ChainConfig) -> ChildConfig { datadir: PathBuf::from(cfg.monerod_datadir), }, ChainChoice::InProcessCuprate => ChainSource::InProcessCuprate { - datadir: PathBuf::from(cfg.monerod_datadir), + datadir: if cfg.monerod_datadir.trim().is_empty() { + home.join("chain") + } else { + PathBuf::from(cfg.monerod_datadir) + }, }, ChainChoice::Remote => ChainSource::Remote { host: cfg.host, @@ -791,16 +810,56 @@ fn chain_config(cfg: &ChildConfig) -> ChainConfig { } /// The core child snapshot as the SDK record. -fn child_status(status: onionwire::wallet_child::WalletChildStatus) -> WalletChildStatus { +/// +/// `source` is the configured chain source the snapshot came from: it is what +/// makes the node-scoped fields possible without the core exposing a second +/// liveness signal for the in-process daemon. +fn child_status( + status: onionwire::wallet_child::WalletChildStatus, + source: &ChainSource, +) -> WalletChildStatus { + let in_process = matches!(source, ChainSource::InProcessCuprate { .. }); WalletChildStatus { state: status.state.as_str().to_string(), running: status.running, configured: status.configured, chain_source: status.chain_source, + chain_in_process: in_process, + node_available: onionwire::cuprate::available(), + node_state: if in_process { + node_state(status.state).to_string() + } else { + String::new() + }, last_error: status.last_error, } } +/// The node-scoped word for the in-process daemon, derived from the core's own +/// child state. A projection, not a second state machine: no input here is a +/// timer, an env var, or a file. +/// +/// For an in-process source the wallet child is a client of *this app's* node, +/// so the core's own sequence is the node's: it cannot answer before the +/// daemon's loopback RPC is up (`connecting`), it answers but is behind the tip +/// while the daemon syncs (`syncing`), and `ready` requires a synced chain. +/// +/// Limit, stated rather than papered over: the core exposes no separate +/// liveness signal for the in-process node (it is a value this app owns, not a +/// process with a pid), so a daemon that dies *after* its wallet child came up +/// cannot be reported as `exited` — the chain probe fails and the state stays +/// `syncing`. It is never reported `ready`, and `exited` still means what it +/// says: the `monero-wallet-rpc` child is gone. +fn node_state(state: WalletChildState) -> &'static str { + match state { + WalletChildState::Off => "off", + WalletChildState::Connecting => "starting", + WalletChildState::Syncing => "syncing", + WalletChildState::Ready => "ready", + WalletChildState::Exited => "exited", + } +} + fn hex(bytes: &[u8]) -> String { let mut s = String::with_capacity(bytes.len() * 2); for b in bytes { @@ -916,7 +975,10 @@ pub struct ChainConfig { /// `Local` only. Data directory for the local daemon. /// /// `InProcessCuprate` also uses this field, as the chain data directory the - /// in-process daemon stores its (fjall) chain in. + /// in-process daemon stores its (fjall) chain in. For that kind an empty + /// string means "use the per-identity default" (`$ONIONWIRE_HOME/chain`, + /// resolved by the SDK), so Kotlin never has to invent an absolute path; + /// `Local` still requires a real one. pub monerod_datadir: String, /// `Remote` only. Daemon host. pub host: String, @@ -950,6 +1012,23 @@ pub struct WalletChildStatus { pub configured: bool, /// The chain-source label. pub chain_source: String, + /// The configured source runs the chain daemon **inside this app** (Cuprate) + /// rather than spawning `monerod` or dialling a remote one. When true, + /// `state` — and `node_state` — describe this app's own node *and* its + /// wallet child: there is no separate daemon process to report on, and the + /// wallet child is a client of the in-process node, not a peer of one. + pub chain_in_process: bool, + /// This build can actually start the in-process daemon (`cuprate-daemon`). + /// `false` means the option is offered by the store but a start can only + /// fail — grey it out before the user commits, do not start and catch. + pub node_available: bool, + /// The in-process daemon's own state, for a status line that names the + /// node: `off` / `starting` / `syncing` / `ready` / `exited`. Empty for + /// every other chain source, so a Kotlin line shows no node segment for a + /// spawned `monerod`. `starting` is the core's `connecting` read from the + /// node's side (the daemon's loopback RPC has not answered yet); it is + /// never persisted, polled from a file, or inferred from a timeout. + pub node_state: String, /// The last failure, display-ready. Never carries the generated login. pub last_error: Option, } @@ -1168,6 +1247,7 @@ mod tests { fn stopped_wire() -> Wire { Wire { node: Mutex::new(None), + home: PathBuf::from("/tmp/onionwire-sdk-stopped"), } } @@ -1611,4 +1691,184 @@ mod tests { assert!(matches!(err, WireError::Stopped { .. }), "got {err:?}"); } } + + /// The `$ONIONWIRE_HOME` a caller opened the identity with. `Wire` keeps it + /// internally; these tests drive the same two pure helpers + /// `set_chain_source` / `chain_source` go through. + fn sdk_home() -> PathBuf { + PathBuf::from("/data/user/0/dev.sirius.onionwire/files") + } + + /// A request as Kotlin builds one: only the fields the chosen kind uses are + /// set. + fn request(kind: ChainChoice, datadir: &str) -> ChainConfig { + ChainConfig { + kind, + monerod_bin: String::new(), + monerod_datadir: datadir.to_string(), + host: String::new(), + port: 0, + wallet_rpc_bin: "/data/app/nativeLibraryDir/libmonerowalletrpc.so".to_string(), + arti_bin: "/data/app/nativeLibraryDir/libarti.so".to_string(), + wallet_filename: "wallet".to_string(), + } + } + + /// Kotlin must not have to invent a chain data directory: an empty + /// `monerod_datadir` on the in-process source resolves to the per-identity + /// `chain` directory the core documents (`$ONIONWIRE_HOME/chain`), and no + /// binary path is involved at all. + #[test] + fn an_empty_in_process_datadir_resolves_under_the_wire_home() { + let child = child_config(request(ChainChoice::InProcessCuprate, ""), &sdk_home()); + assert_eq!( + child.source, + ChainSource::InProcessCuprate { + datadir: sdk_home().join("chain") + } + ); + assert_eq!(child.source_label(), "in-process node"); + } + + #[test] + fn an_explicit_in_process_datadir_is_taken_as_given() { + let given = "/data/user/0/dev.sirius.onionwire/files/chain-heavy"; + let child = child_config(request(ChainChoice::InProcessCuprate, given), &sdk_home()); + assert_eq!( + child.source, + ChainSource::InProcessCuprate { + datadir: PathBuf::from(given) + } + ); + } + + /// Every kind survives the round trip a settings screen does (`ChainConfig` + /// -> core `ChildConfig` -> `ChainConfig`), so a prefill shows what was + /// stored rather than a default. + #[test] + fn every_chain_choice_round_trips_through_the_sdk_mapping() { + for kind in [ + ChainChoice::None, + ChainChoice::Local, + ChainChoice::InProcessCuprate, + ChainChoice::Remote, + ] { + let mut req = request(kind, ""); + match kind { + ChainChoice::Local => { + req.monerod_bin = "/data/app/nativeLibraryDir/libmonerod.so".to_string(); + req.monerod_datadir = sdk_home().join("chain").display().to_string(); + } + ChainChoice::Remote => { + req.host = "peer.onion".to_string(); + req.port = 18081; + } + ChainChoice::None | ChainChoice::InProcessCuprate => {} + } + let back = chain_config(&child_config(req.clone(), &sdk_home())); + assert_eq!(back.kind, kind, "kind lost for {kind:?}"); + assert_eq!(back.wallet_rpc_bin, req.wallet_rpc_bin); + assert_eq!(back.arti_bin, req.arti_bin); + assert_eq!(back.wallet_filename, req.wallet_filename); + match kind { + ChainChoice::InProcessCuprate => { + assert_eq!( + back.monerod_datadir, + sdk_home().join("chain").display().to_string() + ); + assert!( + back.monerod_bin.is_empty(), + "no binary for an in-process node" + ); + } + ChainChoice::Local => { + assert_eq!(back.monerod_bin, req.monerod_bin); + assert_eq!(back.monerod_datadir, req.monerod_datadir); + } + ChainChoice::Remote => { + assert_eq!(back.host, "peer.onion"); + assert_eq!(back.port, 18081); + } + ChainChoice::None => { + assert_eq!(back.monerod_datadir, ""); + assert_eq!(back.host, ""); + } + } + } + } + + fn core_status(state: WalletChildState) -> onionwire::wallet_child::WalletChildStatus { + onionwire::wallet_child::WalletChildStatus { + state, + running: true, + configured: true, + chain_source: "in-process node".to_string(), + last_error: None, + } + } + + /// `wallet_status` speaks about the app's own node for the in-process + /// source: the five core states map to node-scoped words, and no state + /// becomes `ready` that the core did not report as ready. + #[test] + fn node_state_names_the_apps_own_chain_for_the_in_process_source() { + let source = ChainSource::InProcessCuprate { + datadir: sdk_home().join("chain"), + }; + let cases = [ + (WalletChildState::Off, "off"), + (WalletChildState::Connecting, "starting"), + (WalletChildState::Syncing, "syncing"), + (WalletChildState::Ready, "ready"), + (WalletChildState::Exited, "exited"), + ]; + for (state, want) in cases { + let status = child_status(core_status(state), &source); + assert_eq!(status.node_state, want, "state {state:?}"); + assert!(status.chain_in_process, "state {state:?}"); + // The core's own word is still carried verbatim, for a caller that + // renders `state` instead. + assert_eq!(status.state, state.as_str()); + } + } + + /// A source that is not the in-process node reports no node segment, so a + /// Kotlin status line cannot show a node word for a spawned `monerod` or a + /// remote daemon — and `state` still passes straight through. + #[test] + fn node_state_is_empty_for_every_other_chain_source() { + for source in [ + ChainSource::None, + ChainSource::Local { + monerod_bin: PathBuf::from("monerod"), + datadir: PathBuf::from("/chain"), + }, + ChainSource::Remote { + host: "peer.onion".to_string(), + port: 18081, + }, + ] { + let status = child_status(core_status(WalletChildState::Ready), &source); + assert!( + !status.chain_in_process, + "{} is not in-process", + source.label() + ); + assert_eq!( + status.node_state, + "", + "{} must have no node state", + source.label() + ); + assert_eq!(status.state, "ready"); + } + } + + /// Whether *this* build can start the node is a build fact the picker greys + /// the option out with before a start is attempted. + #[test] + fn node_available_reports_whether_this_build_has_the_daemon() { + let status = child_status(core_status(WalletChildState::Off), &ChainSource::None); + assert_eq!(status.node_available, onionwire::cuprate::available()); + } } diff --git a/docs/WALLET.md b/docs/WALLET.md index 4dd38eb..0adc25d 100644 --- a/docs/WALLET.md +++ b/docs/WALLET.md @@ -142,8 +142,8 @@ cargo build --release --features cuprate-daemon of work. What selects this source today is a `ChainSource::InProcessCuprate` record with a `datadir` written through `Node::set_wallet_child_config` (the SDK's `ChainConfig` path), and the daemon then starts with the child when the - wallet is started. The SDK gains its own chain-choice variant in a follow-up - card; until then `kind = "cuprate"` is the record's spelling. + wallet is started. The SDK's `ChainChoice.InProcessCuprate` is that variant + over UniFFI, and `kind = "cuprate"` is the record's spelling. ### Chain traffic over Tor (`.onion` daemons) @@ -329,9 +329,9 @@ wallet screen (F6): The state shown next to the wallet readouts is `off` / `connecting` / `syncing` / `ready` / `exited`, plus the chain-source label (`receive-only`, -`local node`, `remote onion daemon`, `remote daemon`). It is derived from the -real process (`try_wait`) and the last probe — **never** from env-var presence, -and `ready` is never reported for a child that has died. +`local node`, `in-process node`, `remote onion daemon`, `remote daemon`). It is +derived from the real process (`try_wait`) and the last probe — **never** from +env-var presence, and `ready` is never reported for a child that has died. - **`off`** — nothing started (or stopped). The default state. - **`connecting`** — the `monero-wallet-rpc` process is alive but has not @@ -357,7 +357,15 @@ credentials live*), so they survive a restart: - Android (UniFFI): `set_chain_source(ChainConfig)` / `chain_source()`, `start_wallet_child()`, `stop_wallet_child()`, `wallet_status()`. Pass absolute paths for `wallet_rpc_bin` / `arti_bin` (`nativeLibraryDir`); the - core never resolves a binary the caller named explicitly. + core never resolves a binary the caller named explicitly. `ChainChoice` has a + fourth variant, `InProcessCuprate`, for the in-process daemon: no binary path + and, with an empty `monerod_datadir`, the SDK resolves the chain directory to + `$ONIONWIRE_HOME/chain`. `start_wallet_child()` is the whole lifecycle for it + (the core launches the node *and* the wallet child in that one call), and + `wallet_status()` carries `chain_in_process` (this app's node is the source), + `node_available` (this build has `cuprate-daemon`) and `node_state` + (`off` / `starting` / `syncing` / `ready` / `exited`, empty for every other + source) beside the core's own five `state` words. So local mode is **available**, not wired off: a local chain source spawns `monerod` from the path you set, a `.onion` daemon spawns the `arti` SOCKS