diff --git a/Cargo.lock b/Cargo.lock index 245f4e0..5e71765 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -125,6 +125,18 @@ dependencies = [ "libc", ] +[[package]] +name = "anstyle" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "940b3a0ca603d1eade50a4846a2afffd5ef57a9feac2c0e2ec2e14f9ead76000" + +[[package]] +name = "anyhow" +version = "1.0.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470" + [[package]] name = "approx" version = "0.5.1" @@ -134,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" @@ -334,12 +355,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" @@ -368,6 +443,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" @@ -379,6 +469,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" @@ -401,6 +495,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" @@ -431,6 +538,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" @@ -468,6 +599,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" @@ -475,11 +620,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 = "caret" @@ -514,6 +674,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" @@ -584,6 +750,55 @@ dependencies = [ "zeroize", ] +[[package]] +name = "clap" +version = "4.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa8876b300ab35ba921adea3dfd70157a46249b33f95c9084ae5709785478946" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0797fb7aeb1406c84efac526901f7ec3ead2124f946b494e72879d4b54704d" +dependencies = [ + "anstyle", + "clap_lex", + "strsim 0.11.1", + "terminal_size", +] + +[[package]] +name = "clap_derive" +version = "4.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9c751b79415d4e559e3d1fcf128e09e720eb673a06d26cf6f392d37d75b66e0" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 3.0.5", +] + +[[package]] +name = "clap_lex" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c133bc6a41be0d194c306b5506d15e6feeea7b1d6604bd3f8310dfb2ca96486" + +[[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" @@ -615,6 +830,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" @@ -646,6 +867,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" @@ -713,6 +962,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" @@ -722,6 +1012,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" @@ -767,6 +1067,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" @@ -814,6 +1125,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.5+spec-1.1.0", + "toml_edit 0.25.13+spec-1.1.0", + "tower", + "tower-http", + "tracing", + "tracing-appender", + "tracing-subscriber", +] + [[package]] name = "curve25519-dalek" version = "4.1.3" @@ -944,6 +1740,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" @@ -1247,7 +2057,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", @@ -1405,6 +2215,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" @@ -1422,6 +2249,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" @@ -1676,6 +2512,15 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9985c9503b412198aa4197559e9a318524ebc4519c229bfa05a535828c950b9d" +[[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" @@ -1705,6 +2550,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" @@ -1756,6 +2607,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" @@ -1791,6 +2657,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" @@ -1829,6 +2718,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" @@ -1992,6 +2916,7 @@ checksum = "cc4e190f5d26ca7051642629da2c52fc03bde85a03197c99408dcd291734c855" dependencies = [ "equivalent", "hashbrown 0.17.1", + "rayon", "serde", "serde_core", ] @@ -2056,6 +2981,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" @@ -2104,6 +3038,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" @@ -2218,6 +3163,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" @@ -2244,7 +3204,7 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" dependencies = [ - "spin", + "spin 0.9.9", ] [[package]] @@ -2351,6 +3311,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" @@ -2360,6 +3351,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" @@ -2397,6 +3394,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" @@ -2425,6 +3428,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 = "native-tls" version = "0.2.18" @@ -2635,6 +3779,7 @@ dependencies = [ "argon2", "arti-client", "chacha20poly1305", + "cuprated", "ed25519-dalek", "futures", "md-5", @@ -2650,6 +3795,7 @@ dependencies = [ "snow", "tempfile", "tokio", + "toml 0.8.23", "tor-cell", "tor-hsservice", "tor-rtcompat", @@ -3095,6 +4241,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" @@ -3113,6 +4289,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" @@ -3151,6 +4343,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" @@ -3172,6 +4374,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" @@ -3191,12 +4403,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" @@ -3208,6 +4439,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" @@ -3280,6 +4532,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" @@ -3459,6 +4731,12 @@ dependencies = [ "time", ] +[[package]] +name = "rustc-hash" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b1e7f9a428571be2dc5bc0505c13fb6bf936822b894ec87abf8a08a4e51742d" + [[package]] name = "rustc_version" version = "0.4.1" @@ -3530,6 +4808,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" @@ -3649,12 +4939,24 @@ dependencies = [ "libc", ] +[[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" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd" +[[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" @@ -3728,6 +5030,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" @@ -3779,6 +5092,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" @@ -3901,6 +5225,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" @@ -3968,6 +5302,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" @@ -4039,6 +5382,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" @@ -4078,6 +5432,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" @@ -4148,6 +5508,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" @@ -4161,6 +5533,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 = "thiserror" version = "1.0.69" @@ -4210,6 +5592,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" @@ -4277,6 +5665,7 @@ dependencies = [ "bytes", "libc", "mio", + "parking_lot", "pin-project-lite", "signal-hook-registry", "socket2", @@ -4295,6 +5684,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" @@ -4305,8 +5717,12 @@ dependencies = [ "futures-core", "futures-io", "futures-sink", + "futures-util", + "libc", "pin-project-lite", + "slab", "tokio", + "tracing", ] [[package]] @@ -4377,6 +5793,7 @@ dependencies = [ "indexmap 2.14.2", "toml_datetime 1.1.1+spec-1.1.0", "toml_parser", + "toml_writer", "winnow 1.0.4", ] @@ -5518,6 +6935,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" @@ -5529,6 +6994,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" @@ -5600,6 +7078,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" @@ -5616,6 +7100,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" @@ -5716,6 +7206,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" @@ -5745,6 +7241,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/Cargo.toml b/Cargo.toml index 260e0fe..4dab346 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,6 +20,17 @@ repository = "https://github.com/sirius0xdev/onionwire" default = ["native-tls"] native-tls = ["arti-client/native-tls"] rustls = ["arti-client/rustls"] +# In-process Monero chain daemon (Cuprate) as the local chain source, instead of +# spawning `monerod`. OFF by default: `cuprated` is a pre-1.0 project that is not +# published to crates.io, so this pins a git revision and pulls a large tree +# (randomx, fjall, axum/hyper, rayon). See `docs/WALLET.md`, "In-process chain +# daemon". +# +# Cuprate's own `arti` feature stays OFF: it would link a second, older Tor +# stack (arti-client 0.44, which cannot unify with this crate's 0.46) next to +# OnionWire's. The in-process daemon runs clearnet-only; OnionWire's Arti is the +# only Tor in the process. +cuprate-daemon = ["dep:cuprated", "dep:toml"] [dependencies] arti-client = { version = "0.46", default-features = false, features = [ @@ -49,6 +60,10 @@ md-5 = "0.10" rpassword = "7" zeroize = { version = "1", features = ["derive"] } qrcode = { version = "0.14", default-features = false } +cuprated = { git = "https://github.com/Cuprate/cuprate", rev = "4f8fcd1bf468f566fcd89c460d50de4adb6825bf", default-features = false, optional = true } +# `cuprated::config::Config` is deserialized, not built field by field: the +# struct's nested types move with the pinned revision, a TOML document does not. +toml = { version = "0.8", features = ["parse", "display"], optional = true } [dev-dependencies] tempfile = "3" diff --git a/docs/WALLET.md b/docs/WALLET.md index f83f3d9..2ea6117 100644 --- a/docs/WALLET.md +++ b/docs/WALLET.md @@ -55,17 +55,23 @@ not something the app stores for you. ## Chain source The wallet needs a daemon for scan, verify, and spend. You pick one; OnionWire -does not pick a public remote node for you. The three shapes are: +does not pick a public remote node for you. The four shapes are: ``` ChainSource::None receive-only; no child, no daemon ChainSource::Local { monerod_bin, datadir } the app spawns monerod on this box +ChainSource::InProcessCuprate { datadir } the daemon is inside this app ChainSource::Remote { host, port } a daemon address you typed ``` 1. **Local `monerod`.** Chain traffic stays on the box. You accept disk, first sync, and (on Android) the daemon not always running. -2. **A daemon address you supply** — becomes `--daemon-address` on the wallet +2. **An in-process daemon** ([Cuprate](https://github.com/Cuprate/cuprate) + running inside the OnionWire process). No `monerod` binary to install or + spawn, chain on this device, and the wallet child dials the same loopback + port. **Testnet only** in this build, and it needs the `cuprate-daemon` + feature — see "The in-process chain daemon" below. +3. **A daemon address you supply** — becomes `--daemon-address` on the wallet child. Loopback if you already run `monerod`. `.onion` if you want chain traffic over Tor — that needs a SOCKS proxy for the wallet child and is **not implemented here**: configuring a `.onion` host today fails with a clear error @@ -75,15 +81,61 @@ ChainSource::Remote { host, port } a daemon address you typed The port is a convention, not a constant: restricted RPC on `18089` is common, but you supply it. +### The in-process chain daemon (`cuprate-daemon`) + +Cuprate's chain daemon — P2P, consensus, RandomX — can run **inside the OnionWire +process** instead of as a spawned `monerod`. The wallet layer does not change: +`monero-wallet-rpc` is still a child, and it still dials the unrestricted loopback +RPC, `127.0.0.1:18081`, the same address a spawned `monerod` gets. + +``` +cargo build --release --features cuprate-daemon +``` + +- **Off by default.** `cuprated` is pre-1.0 and is not published to crates.io, so + it is a git dependency pinned to a revision. Without the feature the picker + still shows the row — the chain-source type and its stored record do not fork + on a cargo feature — but starting it fails with `this build has no in-process + chain daemon — rebuild with --features cuprate-daemon`. +- **+12.3 MB** on a stripped release binary, measured here: 26,942,168 bytes + without the feature and 39,193,032 with it (`cargo build --release` with and + without `--features cuprate-daemon`, then `strip` both). The +5.6 MB figure + that circulated with the spike was an estimate and understates it. It also + pulls a large build tree (RandomX, fjall, axum/hyper, rayon) — a cold build + compiles ~586 crates in release — so a build from cold is noticeably longer + than a plain TUI build. +- **Testnet only.** Cuprate is pre-production and its `monerod` RPC parity is + incomplete (`docs/cuprate-launch-spike.md` §Parity gaps). The config pins + `network = "Testnet"`; pointing a mainnet wallet at it is not something this + build claims to do. The picker row and the chain block both say so. +- **No Tor in the chain path.** Cuprate's own `arti` feature is *not* enabled: + its Tor stack is `arti-client` 0.44, which cannot unify with this crate's 0.46, + and running two Tor stacks in one process is not a trade this app makes. + OnionWire's Arti is the only Tor here, and it serves the messenger. That means + the in-process daemon's P2P traffic is **clearnet**: your ISP can see that this + device talks to Monero testnet peers, exactly as a spawned `monerod` would. +- **Inbound connections are off** and the restricted RPC listener is disabled: + this is a wallet's daemon, not a public node, and the restricted server only + answers placeholder metrics (see below). +- **It is not a child process.** There is no pid to watch or signal: the node is + a value the app owns, and dropping it shuts the daemon down. `n` in the wallet + screen stops it with the wallet child, and it does not outlive the app. +- **The chain lives in `$ONIONWIRE_HOME/chain`** — the same per-identity + directory a spawned `monerod` would use, so the two local sources are + interchangeable on disk. Storage gate: the wallet screen reports free space + there either way. + ### The daemon you point at has to be its *unrestricted* RPC Both the app-owned child and the chain probe behind the wallet screen dial the daemon's unrestricted listener: `--rpc-bind-port` for the `monerod` this app -spawns (`127.0.0.1:18081`), and whatever port an in-process Cuprate binds for -`[rpc.unrestricted]`. Never the restricted listener — it answers, so getting -this wrong shows up as a *wrong number* rather than as an error. On Cuprate its -restricted server reports a placeholder `database_size` (exactly 5 GiB), an -empty `version`, and `free_space = u64::MAX` on both servers. +spawns, and `[rpc.unrestricted]` for the in-process Cuprate — `127.0.0.1:18081` +either way, which is why the chain source does not change the wallet child's +argv. Never the restricted listener — it answers, so getting this wrong shows up +as a *wrong number* rather than as an error. On Cuprate its restricted server +reports a placeholder `database_size` (exactly 5 GiB), an empty `version`, and +`free_space = u64::MAX` on both servers; the in-process daemon's restricted +listener is disabled outright (`enable = false`). What the wallet client reads from the daemon is chain height, and nothing else: `daemon_get_info` / `daemon_get_height` in `src/wallet.rs`. No peer count, no diff --git a/src/cuprate.rs b/src/cuprate.rs new file mode 100644 index 0000000..be5cb1f --- /dev/null +++ b/src/cuprate.rs @@ -0,0 +1,200 @@ +//! In-process Monero chain daemon (Cuprate) as OnionWire's local chain source. +//! +//! This is Phase 1 of the Cuprate strategy (`docs/payment-integration-plan.md` +//! §7a): the chain daemon — P2P, consensus, RandomX — runs **in this process** +//! instead of a spawned `monerod`. The app then ships one fewer native binary +//! (~52 MB) and `monero-wallet-rpc` keeps dialling loopback RPC exactly as it +//! does today, so no wallet-layer code changes. +//! +//! Locked facts this module encodes: +//! +//! * `cuprated` is a **git** dependency pinned to a revision and gated behind +//! the `cuprate-daemon` feature, off by default. Cuprate is pre-1.0 and not +//! published to crates.io; a pinned revision is the only honest way to depend +//! on it. +//! * Cuprate's own `arti` feature stays **off**. Its Tor stack is arti 0.44, +//! which cannot unify with this crate's arti 0.46, and the in-process daemon +//! is clearnet-only: OnionWire's Arti is the only Tor in the process. +//! * The **unrestricted** RPC listener binds `127.0.0.1:` — the address +//! `WalletChild::daemon_address` already returns. The restricted listener is +//! disabled: nothing here dials it, and its metrics are placeholders (a 5 GiB +//! `database_size`, an empty `version`, `free_space = u64::MAX`). +//! * The network is **testnet**. Mainnet is not validated: Cuprate is +//! pre-production and its monerod RPC parity is incomplete +//! (`docs/cuprate-launch-spike.md` §Parity gaps). Pointing a mainnet wallet +//! at it is not something this build claims to do. +//! * `Node::launch` is async and the node's tasks run on the calling runtime, so +//! the caller supplies the app's Tokio handle. +//! +//! # Building without the feature +//! +//! [`CuprateNode`] exists in every build with the same `launch` signature, so +//! the chain-source type and its persistence do not fork on a cargo feature. In +//! a build without `cuprate-daemon`, `launch` fails with the feature name +//! instead of silently doing nothing. + +/// The one-line caveat every surface that offers the in-process daemon has to +/// carry, so the picker, the chain block and the docs cannot drift apart. +/// +/// Unconditional — *not* feature-gated: a build without `cuprate-daemon` says +/// the same thing rather than describing a daemon it cannot start. +pub const TESTNET_ONLY: &str = "testnet only — mainnet is unvalidated"; + +/// Can this build actually start the daemon? `false` without the feature. +pub const fn available() -> bool { + cfg!(feature = "cuprate-daemon") +} + +/// Why starting the daemon fails in a build without the feature. One string, so +/// the refusal cannot drift between this module and its callers. +pub const NO_FEATURE_MSG: &str = + "this build has no in-process chain daemon — rebuild with --features cuprate-daemon"; + +#[cfg(feature = "cuprate-daemon")] +mod imp { + use std::path::Path; + + use cuprated::Node; + use cuprated::config::{Config, resolve_max_memory}; + + /// The network this daemon runs. Testnet, deliberately — see the module + /// docs. Cuprate spells this `Testnet`. + pub const NETWORK: &str = "Testnet"; + + /// What the daemon aims to stay under, in bytes. Cuprate would otherwise + /// read total system memory, which on a phone with a wallet on it is not a + /// number this app gets to choose. + const TARGET_MAX_MEMORY: u64 = 2_000_000_000; + + /// Threads for the tx-pool + blockchain reader pool. Small on purpose: this + /// runs next to the messenger, not on its own box. + const READER_THREADS: usize = 4; + + /// A running in-process chain daemon. + /// + /// Owning it *is* the lifecycle: `cuprated::Node` implements `Drop` and + /// shuts its services down there, so dropping this value stops the daemon. + /// There is no `shutdown` method to forget to call, and no pid to signal. + pub struct CuprateNode { + node: Node, + } + + impl CuprateNode { + /// Launch the daemon with its chain in `datadir`, unrestricted RPC on + /// loopback `port`. + /// + /// Must be awaited on a Tokio runtime: the node spawns its services onto + /// the current one. + pub async fn launch(datadir: &Path, port: u16) -> Result { + let text = config_toml(datadir, port); + let mut config: Config = toml::from_str(&text).map_err(|e| format!("config: {e}"))?; + resolve_max_memory(&mut config).map_err(|e| format!("config: {e}"))?; + let node = Node::launch(config) + .await + .map_err(|e| format!("launch: {e}"))?; + Ok(Self { node }) + } + + /// Ask the node's services to stop. + /// + /// `&self` and non-blocking: this cancels the node's shutdown token, and + /// the services then drain on the runtime that launched them. Dropping + /// the value afterwards closes the rest. Calling it before the drop is + /// what gives them the chance. + pub fn shutdown(&self) { + self.node.shutdown(); + } + + /// Blocks the daemon has, from its own consensus context. The RPC + /// answer is the same number; this one needs no HTTP round trip. + /// + /// `&mut self` because cuprated's blockchain handle reads its context + /// mutably; through [`crate::wallet_child`] that borrow happens under + /// the node's own lock. + pub fn chain_height(&mut self) -> u64 { + self.node.blockchain.context().chain_height as u64 + } + } + + /// The cuprated config this app launches with, as TOML. + /// + /// A TOML document rather than a struct literal: cuprated's nested config + /// types move between revisions, and `Config` is `Deserialize` with + /// `deny_unknown_fields`, so a typo is a parse error instead of a default + /// silently standing in for the setting that was meant. + /// + /// No data directory is created here — the caller owns the 0700 wallet dir. + pub fn config_toml(datadir: &Path, port: u16) -> String { + let datadir = datadir.display(); + format!( + r#"network = "{NETWORK}" +offline = false +fast_sync = true +target_max_memory = {TARGET_MAX_MEMORY} + +[fs] +fast_data_directory = "{datadir}" +slow_data_directory = "{datadir}" +cache_directory = "{datadir}/cache" + +[storage] +reader_threads = {READER_THREADS} + +# The unrestricted listener: this is the one the wallet child dials, and the one +# with real numbers. The restricted listener is off — its metrics are +# placeholders, and nothing in this app reads them. +[rpc.unrestricted] +address = "127.0.0.1" +port = {port} +enable = true + +[rpc.restricted] +address = "127.0.0.1" +port = 0 +enable = false + +# Inbound connections are off: this is a wallet's daemon, not a public node. +# Tor P2P stays off too — OnionWire already runs Arti for the messenger, and +# chain traffic on loopback-only clearnet does not need a second Tor stack. +[p2p.clear_net] +enable_inbound = false +enable_inbound_v6 = false + +[p2p.tor_net] +enabled = false + +[tor] +mode = "Auto" +"# + ) + } +} + +#[cfg(not(feature = "cuprate-daemon"))] +mod imp { + use std::path::Path; + + /// Placeholder for a build without `cuprate-daemon`. + /// + /// It has no state because nothing can ever be launched: [`launch`] always + /// fails. It exists so the chain-source type, its persistence and the TUI + /// picker do not fork on a cargo feature. + /// + /// [`launch`]: CuprateNode::launch + pub struct CuprateNode(()); + + impl CuprateNode { + /// Always fails: this build has no in-process daemon. + pub async fn launch(_datadir: &Path, _port: u16) -> Result { + Err(super::NO_FEATURE_MSG.into()) + } + + /// Nothing to stop: no daemon was ever launched. + pub fn shutdown(&self) {} + } +} + +pub use imp::CuprateNode; + +#[cfg(feature = "cuprate-daemon")] +pub use imp::{NETWORK, config_toml}; diff --git a/src/lib.rs b/src/lib.rs index 4a4e517..e52e82f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,5 @@ pub mod backup; +pub mod cuprate; pub mod dispatch; pub mod file; pub mod frame; diff --git a/src/node.rs b/src/node.rs index 26053cf..5efc702 100644 --- a/src/node.rs +++ b/src/node.rs @@ -655,6 +655,16 @@ impl Node { } } + /// What "run an in-process daemon" means for this identity: Cuprate inside + /// this process, with its chain in the same per-identity directory a local + /// `monerod` would use. Requires the `cuprate-daemon` feature to actually + /// start; without it, the child reports the feature name. + pub fn default_in_process_chain_source(&self) -> ChainSource { + ChainSource::InProcessCuprate { + datadir: self.home.join("chain"), + } + } + /// The state the wallet screen draws. Cheap: no dial, no spawn. pub fn wallet_child_state(&self) -> WalletChildState { // Read the (store-backed) choice first: never hold the child lock while @@ -677,7 +687,11 @@ impl Node { /// Owning the child is the whole point: balance, receive address, `/tip` and /// receipt verification then all go through it, so a "start node" button /// cannot describe a daemon the wallet does not use. - pub fn wallet_child_start(&self) -> Result<(), String> { + /// + /// `runtime` is the app's Tokio handle, needed only by + /// [`ChainSource::InProcessCuprate`]: that daemon's tasks run on the app's + /// runtime, and this call happens on the TUI's blocking thread. + pub fn wallet_child_start(&self, runtime: &tokio::runtime::Handle) -> Result<(), String> { self.ensure_running()?; let source = self.wallet_chain_source(); if matches!(source, ChainSource::None) { @@ -687,7 +701,8 @@ impl Node { return Err("wallet child already running".into()); } let child = WalletChild::new(source, self.home.join("wallet"), None) - .map_err(|e| e.to_string())?; + .map_err(|e| e.to_string())? + .with_runtime(runtime.clone()); let client = { let store = self.store.lock().map_err(|e| e.to_string())?; match child.start(&store) { @@ -748,13 +763,13 @@ impl Node { } } - /// Free space on the filesystem a *local* daemon would store the chain on, - /// in whole GiB. `None` for a remote source (their disk, not ours) and when - /// the answer cannot be read — never a guessed number. + /// Free space on the filesystem a *local* daemon would store the chain on + /// — the spawned `monerod`'s or the in-process Cuprate node's, same + /// directory — in whole GiB. `None` for a remote source (their disk, not + /// ours) and when the answer cannot be read — never a guessed number. pub fn wallet_chain_free_gb(&self) -> Option { - let ChainSource::Local { datadir, .. } = &self.wallet_chain_source() else { - return None; - }; + let source = self.wallet_chain_source(); + let datadir = WalletChild::chain_datadir(&source)?; // monerod creates the datadir on first run; before that, the volume that // will hold it is the one `home` is on. let path = if datadir.exists() { datadir } else { &self.home }; diff --git a/src/tui.rs b/src/tui.rs index fa4dca2..32831c5 100644 --- a/src/tui.rs +++ b/src/tui.rs @@ -1425,31 +1425,41 @@ pub const PRUNED_NOTE: &str = "pruned nodes are not archives: a deep seed restor pub const ONION_NO_SOCKS_MSG: &str = "a remote .onion daemon needs a local SOCKS listener.\nthis build does not have one yet — pick a local monerod,\nor a clearnet/loopback daemon you run yourself."; -/// The three choices the picker offers, in order. A public node is never one of +/// The four choices the picker offers, in order. A public node is never one of /// them and a remote daemon is never preselected. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum ChainChoice { ReceiveOnly, LocalMonerod, + InProcessCuprate, RemoteDaemon, } impl ChainChoice { - pub const ALL: [ChainChoice; 3] = [Self::ReceiveOnly, Self::LocalMonerod, Self::RemoteDaemon]; + pub const ALL: [ChainChoice; 4] = [ + Self::ReceiveOnly, + Self::LocalMonerod, + Self::InProcessCuprate, + Self::RemoteDaemon, + ]; pub fn label(self) -> &'static str { match self { Self::ReceiveOnly => "receive-only (no daemon)", Self::LocalMonerod => "spawn a local monerod", + Self::InProcessCuprate => "run an in-process daemon", Self::RemoteDaemon => "enter a daemon address", } } - /// One line under the label, so the choice is not a mystery. + /// One line under the label, so the choice is not a mystery. The in-process + /// row carries [`crate::cuprate::TESTNET_ONLY`]'s fact: it is not a daemon + /// the user can treat as a mainnet node yet. pub fn detail(self) -> &'static str { match self { Self::ReceiveOnly => "chain traffic stays off this device entirely", Self::LocalMonerod => "the app owns monerod; chain stays on this device", + Self::InProcessCuprate => "Cuprate in this app: testnet only, no binary", Self::RemoteDaemon => "someone else's daemon: they see your addresses", } } @@ -1460,6 +1470,7 @@ impl ChainChoice { match source { ChainSource::None => Self::ReceiveOnly, ChainSource::Local { .. } => Self::LocalMonerod, + ChainSource::InProcessCuprate { .. } => Self::InProcessCuprate, ChainSource::Remote { .. } => Self::RemoteDaemon, } } @@ -1598,6 +1609,13 @@ pub fn chain_view_with_progress( monerod_bin.display(), datadir.display() ), + ChainSource::InProcessCuprate { datadir } => format!( + // The caveat is not decoration: this daemon runs testnet, and a + // user who reads it as a mainnet node would be misled. + "chain: in-process daemon — {}; chain in {}", + crate::cuprate::TESTNET_ONLY, + datadir.display() + ), ChainSource::Remote { host, port } => format!("chain: remote daemon {host}:{port}"), }; let child_line = match child { @@ -1608,10 +1626,14 @@ pub fn chain_view_with_progress( .to_string(); let sync_text = sync_line(sync, previous_height); let storage_line = match (source, free_gb) { - (ChainSource::Local { .. }, Some(gb)) => format!( + // Both local sources put the chain on this device's disk; only the + // *owner* of the daemon differs. + (ChainSource::Local { .. } | ChainSource::InProcessCuprate { .. }, Some(gb)) => format!( "storage: {gb} GB free here — pruned mainnet wants ~50-60 GB, a full node ~200 GB" ), - (ChainSource::Local { .. }, None) => "storage: could not read free space".to_string(), + (ChainSource::Local { .. } | ChainSource::InProcessCuprate { .. }, None) => { + "storage: could not read free space".to_string() + } (ChainSource::Remote { .. }, _) => { "storage: on the daemon operator's disk, not yours".to_string() } @@ -1715,6 +1737,13 @@ impl App { continue; } if let Some(exit) = self.handle_key(key)? { + // The children this app owns are not detached. Without this, + // `monero-wallet-rpc` (and a spawned `monerod`) would outlive the + // app as orphans, and an in-process Cuprate node would never get + // its shutdown asked for. + if let Err(e) = self.node.wallet_child_stop() { + eprintln!("wallet child on exit: {e}"); + } return Ok(exit); } } @@ -2315,7 +2344,7 @@ impl App { } let result = match self.node.wallet_child_state() { WalletChildState::Running => self.node.wallet_child_stop(), - _ => self.node.wallet_child_start(), + _ => self.node.wallet_child_start(&self.rt), }; self.status_note = Some(match result { Ok(()) => match self.node.wallet_child_state() { @@ -2386,6 +2415,16 @@ impl App { let source = self.node.default_local_chain_source(); self.apply_chain_source(source, None); } + ChainChoice::InProcessCuprate => { + let source = self.node.default_in_process_chain_source(); + // The saved note says the caveat again: the picker's row is + // gone once this screen closes. + let note = format!( + "chain source saved — in-process daemon, {}", + crate::cuprate::TESTNET_ONLY + ); + self.apply_chain_source(source, Some(note)); + } } return Ok(()); } diff --git a/src/wallet.rs b/src/wallet.rs index b790afb..d224c9f 100644 --- a/src/wallet.rs +++ b/src/wallet.rs @@ -44,6 +44,17 @@ pub enum ChainSource { /// not a constant. port: u16, }, + /// A chain daemon **inside this process** (Cuprate), with its chain in + /// `datadir`. Nothing is spawned; the wallet child still dials loopback + /// RPC, so this is a [`ChainSource::Local`] with a different owner. + /// + /// Two consequences the UI has to state: the chain is on this device, and + /// the in-process daemon is **testnet-only** in this build (Cuprate is + /// pre-1.0 and its mainnet RPC parity is unvalidated). + InProcessCuprate { + /// Data directory for the daemon's chain database. + datadir: PathBuf, + }, } /// Remote-mode wallet config: the `monero-wallet-rpc` the user already runs diff --git a/src/wallet_child.rs b/src/wallet_child.rs index f73a738..1328469 100644 --- a/src/wallet_child.rs +++ b/src/wallet_child.rs @@ -1,6 +1,7 @@ //! Wallet child lifecycle: the app owns `monero-wallet-rpc` — and, when the -//! user chose a local chain source, `monerod` — instead of asking the user to -//! start them and export an env var. +//! user chose a local chain source, either `monerod` or an **in-process +//! Cuprate node** ([`crate::cuprate`], behind the `cuprate-daemon` feature) — +//! instead of asking the user to start them and export an env var. //! //! Locked shape: //! @@ -12,6 +13,9 @@ //! compiled-in public node. A `.onion` daemon needs a SOCKS proxy, which is a //! separate card: here it is refused with a clear error. //! * `--trusted-daemon` is never passed: a remote daemon is untrusted. +//! * The in-process daemon is *not* a child: it is a value owned by this struct, +//! and dropping it shuts the node down. It still serves the same loopback RPC +//! port, so everything downstream of `--daemon-address` is unchanged. use std::fs; use std::os::unix::fs::PermissionsExt; @@ -22,11 +26,15 @@ use std::sync::Mutex; use rand::RngCore; use zeroize::Zeroizing; +use crate::cuprate::CuprateNode; use crate::store::Store; use crate::wallet::{self, ChainSource, Wallet}; /// `monerod` RPC port for a local chain source. This is the *unrestricted* /// server (`--rpc-bind-port`); the wallet child is the only thing that dials it. +/// +/// An in-process Cuprate node binds the same port in its config, so the wallet +/// child's `--daemon-address` does not change with the chain source. pub const DEFAULT_MONEROD_RPC_PORT: u16 = 18081; /// `monerod`'s *restricted* RPC port (`--rpc-restricted-bind-port`). Nothing in @@ -60,7 +68,8 @@ impl std::error::Error for ChildError {} type Result = std::result::Result; -/// The app-owned wallet child pair (`monerod` when local, `monero-wallet-rpc`). +/// The app-owned wallet child pair (`monerod` when local, `monero-wallet-rpc`), +/// plus the in-process chain daemon when that is the chosen source. pub struct WalletChild { source: ChainSource, wallet_rpc_bin: PathBuf, @@ -68,6 +77,14 @@ pub struct WalletChild { wallet_filename: String, monerod: Mutex>, wallet_rpc: Mutex>, + /// The in-process Cuprate node, when [`ChainSource::InProcessCuprate`] is + /// the source. Owning it is the lifecycle: dropping it shuts the daemon + /// down. Never a child process, so there is no pid to watch or signal. + cuprate: Mutex>, + /// The app's Tokio handle. Required only to launch the in-process daemon: + /// its tasks run on the app's runtime, and [`WalletChild::start`] is called + /// from the TUI's blocking thread, which has no runtime context of its own. + runtime: Option, } impl WalletChild { @@ -93,9 +110,18 @@ impl WalletChild { wallet_filename, monerod: Mutex::new(None), wallet_rpc: Mutex::new(None), + cuprate: Mutex::new(None), + runtime: None, }) } + /// The app's runtime, needed by [`ChainSource::InProcessCuprate`]. Without + /// it, starting that source fails with a reason rather than blocking. + pub fn with_runtime(mut self, runtime: tokio::runtime::Handle) -> Self { + self.runtime = Some(runtime); + self + } + /// Point at a specific `monero-wallet-rpc` binary (explicit config, tests). pub fn with_wallet_rpc_bin(mut self, bin: PathBuf) -> Self { self.wallet_rpc_bin = bin; @@ -122,8 +148,17 @@ impl WalletChild { /// Is a tracked child still alive? Polls the process table; an exited child /// is reaped here so a later `stop` is a no-op. + /// + /// The in-process daemon has no process to poll: it counts as running for as + /// long as this struct holds it. pub fn running(&self) -> bool { let _ = self.reap_exited(); + self.launched_processes() || self.cuprate.lock().map(|g| g.is_some()).unwrap_or(false) + } + + /// True when a tracked *child* (monerod / monero-wallet-rpc) is alive. The + /// in-process daemon is not one, so it is never reported here. + fn launched_processes(&self) -> bool { self.monerod.lock().map(|g| g.is_some()).unwrap_or(false) || self.wallet_rpc.lock().map(|g| g.is_some()).unwrap_or(false) } @@ -154,16 +189,30 @@ impl WalletChild { } /// The `--daemon-address` for each chain source. A local source is the - /// loopback daemon this struct owns; a remote one is exactly what the user - /// typed. + /// loopback daemon this struct owns — spawned `monerod` or in-process + /// Cuprate, same port; a remote one is exactly what the user typed. pub fn daemon_address(source: &ChainSource) -> Option { match source { ChainSource::None => None, - ChainSource::Local { .. } => Some(format!("127.0.0.1:{DEFAULT_MONEROD_RPC_PORT}")), + ChainSource::Local { .. } | ChainSource::InProcessCuprate { .. } => { + Some(format!("127.0.0.1:{DEFAULT_MONEROD_RPC_PORT}")) + } ChainSource::Remote { host, port } => Some(format!("{host}:{port}")), } } + /// The directory a local chain source stores its chain in: the spawned + /// daemon's and the in-process daemon's are the same idea on disk. `None` + /// for a remote source (their disk, not ours) and for receive-only. + pub fn chain_datadir(source: &ChainSource) -> Option<&Path> { + match source { + ChainSource::Local { datadir, .. } | ChainSource::InProcessCuprate { datadir } => { + Some(datadir) + } + ChainSource::None | ChainSource::Remote { .. } => None, + } + } + /// Bind a loopback port and hand it back. The listener is dropped /// immediately; the port is only used to keep two instances from colliding. pub fn pick_port() -> Result { @@ -258,6 +307,12 @@ impl WalletChild { *guard = Some(child); } + // In-process chain source: start the daemon in this process, before the + // wallet child is pointed at its loopback RPC. + if let ChainSource::InProcessCuprate { datadir } = &self.source { + self.start_in_process_daemon(datadir)?; + } + let (user, pass) = self.creds(store)?; let port = Self::pick_port()?; let login = format!("{user}:{}", pass.as_str()); @@ -289,9 +344,52 @@ impl WalletChild { })) } + /// Launch the in-process Cuprate daemon and hold it. + /// + /// Blocking on the app's runtime from this thread is deliberate: `start` runs + /// on the TUI's blocking thread (no runtime context of its own), and the + /// app's runtime is alive for the whole session, so its worker threads drive + /// the node's services while this call waits for `launch` to return. + fn start_in_process_daemon(&self, datadir: &Path) -> Result<()> { + // Feature first: in a build without it, "no runtime handle" would be a + // misleading answer to "why is there no daemon". + if !crate::cuprate::available() { + return Err(ChildError(crate::cuprate::NO_FEATURE_MSG.into())); + } + // Resolve the runtime before touching the disk: a refusal must leave + // nothing behind. + let runtime = self.runtime.as_ref().ok_or_else(|| { + ChildError("in-process daemon needs the app's Tokio runtime handle".into()) + })?; + create_dir_700(datadir).map_err(|e| ChildError(format!("chain datadir: {e}")))?; + let node = runtime + .block_on(CuprateNode::launch(datadir, DEFAULT_MONEROD_RPC_PORT)) + .map_err(|e| ChildError(format!("in-process daemon: {e}")))?; + let mut guard = self + .cuprate + .lock() + .map_err(|e| ChildError(format!("cuprate lock: {e}")))?; + *guard = Some(node); + Ok(()) + } + /// Stop both children. Idempotent, and tolerant of a child that already - /// exited on its own. + /// exited on its own. The in-process daemon goes first: it is not a process, + /// and dropping it is its shutdown. pub fn stop(&self) -> Result<()> { + let node = self + .cuprate + .lock() + .map_err(|e| ChildError(format!("cuprate lock: {e}")))? + .take(); + if let Some(node) = node { + // Ask before the value goes out of scope: the services drain on the + // runtime, and dropping alone would cut them off. (Bind and let it + // drop rather than `drop(node)`: without the feature this type has + // no `Drop` impl at all, and `clippy::drop_non_drop` is right to say + // so.) + node.shutdown(); + } kill_slot(&self.wallet_rpc, "monero-wallet-rpc")?; kill_slot(&self.monerod, "monerod")?; Ok(()) @@ -438,6 +536,10 @@ fn source_to_json(source: &ChainSource) -> serde_json::Value { "host": host, "port": port, }), + ChainSource::InProcessCuprate { datadir } => serde_json::json!({ + "kind": "cuprate", + "datadir": datadir.display().to_string(), + }), } } @@ -455,6 +557,9 @@ fn parse_source(v: Option<&serde_json::Value>) -> Option { host: v.get("host")?.as_str()?.to_string(), port: u16::try_from(v.get("port")?.as_u64()?).ok()?, }), + "cuprate" => Some(ChainSource::InProcessCuprate { + datadir: PathBuf::from(v.get("datadir")?.as_str()?), + }), _ => None, } } @@ -956,6 +1061,131 @@ mod tests { ); } + /// The in-process source is a local daemon in every sense the caller cares + /// about: same loopback port, same datadir idea, nothing remote about it. + #[test] + fn the_in_process_source_is_a_local_daemon_on_the_same_port() { + let datadir = PathBuf::from("/tmp/onionwire-chain"); + let source = ChainSource::InProcessCuprate { + datadir: datadir.clone(), + }; + assert_eq!( + WalletChild::daemon_address(&source), + Some(format!("127.0.0.1:{DEFAULT_MONEROD_RPC_PORT}")), + "the wallet child dials the same port either way" + ); + assert_eq!( + WalletChild::daemon_address(&source), + WalletChild::daemon_address(&local_source(Path::new("/tmp"), PathBuf::from("monerod"))), + "spawned and in-process local sources are the same address" + ); + assert_eq!( + WalletChild::chain_datadir(&source), + Some(datadir.as_path()), + "the chain is on this device's disk" + ); + assert_eq!(WalletChild::chain_datadir(&ChainSource::None), None); + assert_eq!( + WalletChild::chain_datadir(&ChainSource::Remote { + host: "node.example.com".into(), + port: 18089, + }), + None, + "a remote daemon's chain is not ours" + ); + let dir = tmp_dir("cuprate-enabled"); + assert!( + WalletChild::new(source, dir.join("wallet"), None) + .unwrap() + .is_enabled(), + "an in-process source is a chain source: `n` must have something to start" + ); + } + + /// The picker's choice has to survive a restart without a child ever + /// starting, exactly like the other two. + #[test] + fn the_in_process_choice_round_trips_through_the_sealed_record() { + let dir = tmp_dir("source-cuprate"); + let store = open_store(&dir); + let source = ChainSource::InProcessCuprate { + datadir: dir.join("chain"), + }; + save_chain_source(&store, &source).unwrap(); + assert_eq!(load_chain_source(&store).unwrap(), Some(source.clone())); + // ...and it is read back as itself, never as receive-only. + assert_ne!(load_chain_source(&store).unwrap(), Some(ChainSource::None)); + + // The stored record names the source for the next reader, too. + let raw = store.load_wallet_child().unwrap().expect("sealed record"); + let json: serde_json::Value = serde_json::from_str(&raw).unwrap(); + assert_eq!(json["source"]["kind"], "cuprate"); + assert_eq!( + json["source"]["datadir"].as_str().unwrap(), + source_datadir(&source) + ); + } + + fn source_datadir(source: &ChainSource) -> &str { + match source { + ChainSource::InProcessCuprate { datadir } => datadir.to_str().unwrap(), + other => panic!("not an in-process source: {other:?}"), + } + } + + /// Starting the in-process source without the daemon compiled in fails with + /// the feature name — never a silent no-op, and never a spawned + /// `monero-wallet-rpc` pointed at a daemon that does not exist. + #[cfg(not(feature = "cuprate-daemon"))] + #[test] + fn in_process_source_without_the_feature_names_the_feature() { + let dir = tmp_dir("cuprate-off"); + let store = open_store(&dir); + let child = WalletChild::new( + ChainSource::InProcessCuprate { + datadir: dir.join("chain"), + }, + dir.join("wallet"), + None, + ) + .unwrap() + .with_wallet_rpc_bin(fake_bin(&dir, "monero-wallet-rpc", &dir.join("rpc.argv"))); + let err = child.start(&store).unwrap_err().to_string(); + assert!(err.contains("cuprate-daemon"), "got {err}"); + assert!(!child.running(), "nothing may be left running: {err}"); + assert_eq!( + fs::read_to_string(dir.join("rpc.argv")).unwrap_or_default(), + "", + "the wallet RPC child must not be spawned against a daemon that never started" + ); + child.stop().unwrap(); + } + + /// With the daemon compiled in, the missing piece is the app's runtime + /// handle, and the refusal says which one it is. + #[cfg(feature = "cuprate-daemon")] + #[test] + fn in_process_source_without_a_runtime_handle_says_so() { + let dir = tmp_dir("cuprate-no-rt"); + let store = open_store(&dir); + let child = WalletChild::new( + ChainSource::InProcessCuprate { + datadir: dir.join("chain"), + }, + dir.join("wallet"), + None, + ) + .unwrap(); + let err = child.start(&store).unwrap_err().to_string(); + assert!(err.contains("runtime"), "got {err}"); + assert!(!child.running(), "nothing may be left running: {err}"); + // No daemon, no datadir either: the refusal happens before any of it. + assert!( + !dir.join("chain").exists(), + "an unstarted source writes nothing" + ); + } + /// A record with an unknown `kind` is receive-only; a corrupt record is an /// error (fail-closed — do not silently overwrite it). #[test] diff --git a/tests/tui_frames.rs b/tests/tui_frames.rs index 825cf5b..5a25afe 100644 --- a/tests/tui_frames.rs +++ b/tests/tui_frames.rs @@ -819,10 +819,22 @@ fn chain_choice_never_preselects_a_remote_daemon() { }, ChainChoice::RemoteDaemon, ), + // The in-process daemon is its own row: it is local (this device's + // chain, this app's process) but it is not a `monerod` spawn. + ( + ChainSource::InProcessCuprate { + datadir: std::path::PathBuf::from("/tmp/chain"), + }, + ChainChoice::InProcessCuprate, + ), ] { assert_eq!(ChainChoice::of(&source), want); } - assert_eq!(ChainChoice::ALL.len(), 3, "three choices, never a public node"); + assert_eq!( + ChainChoice::ALL.len(), + 4, + "four choices, never a public node" + ); for choice in ChainChoice::ALL { assert!(!choice.label().is_empty()); assert!(!choice.detail().is_empty()); diff --git a/tests/tui_spec.rs b/tests/tui_spec.rs index a815160..c669c87 100644 --- a/tests/tui_spec.rs +++ b/tests/tui_spec.rs @@ -1,15 +1,18 @@ +//! Spec implementation tests for docs/TUI.md. +//! Does not own `tests/tui_frames.rs` (PR #23). + use onionwire::Message; +use onionwire::Payment; use onionwire::node::{DaemonSync, WalletChildState}; use onionwire::outbox::{OutboxEntry, OutboxStatus}; -use onionwire::Payment; use onionwire::qr; use onionwire::tui::{ - OutboxSummary, WALLET_LINE_MAX, alert_line, ascii_chrome, chain_view_with_progress, - chat_with_delivery, delivery_tag, draw_chat, draw_share, draw_text_overlay, - empty_friend_chat_text, help_overlay_text, is_onion_host, main_footer_hints, main_header_line, - parse_daemon_addr, paste_screen_text, retry_in_text, roster_col_width, short_send_reason, - status_footer, sync_line, wallet_readiness, wrap_invite, - ConfigField, ConfigStatus, WalletConfigScreen, + ChainChoice, ConfigField, ConfigStatus, OutboxSummary, WALLET_LINE_MAX, WalletConfigScreen, + alert_line, ascii_chrome, chain_view_with_progress, chat_with_delivery, delivery_tag, + draw_chat, draw_history, draw_share, draw_text_overlay, empty_friend_chat_text, + help_overlay_text, history_detail, history_row_text, is_onion_host, main_footer_hints, + main_header_line, parse_daemon_addr, paste_screen_text, retry_in_text, roster_col_width, + short_send_reason, status_footer, sync_line, wallet_readiness, wrap_invite, }; use onionwire::wallet::{ChainSource, PingResult}; use ratatui::Frame; @@ -19,6 +22,745 @@ use ratatui::layout::{Constraint, Layout}; use ratatui::widgets::{Block, Borders, List, ListItem, Paragraph, Wrap}; use std::sync::Mutex; +const FP: &str = "abcdef0123456789deadbeefcafebabe"; +static ASCII_ENV: Mutex<()> = Mutex::new(()); +const ONION: &str = "abcdefghijklmnopqrstuvwxyz234567abcdefghijklmnopqrstuvwx.onion"; + +fn screen_from(buf: &ratatui::buffer::Buffer, w: u16, h: u16) -> String { + let mut screen = String::new(); + for y in 0..h { + for x in 0..w { + screen.push_str(buf[(x, y)].symbol()); + } + screen.push('\n'); + } + screen +} + +#[test] +fn status_footer_keeps_send_failed_and_chrome() { + let note = "send failed: peer onion down"; + for w in [80u16, 120, 200] { + let line = status_footer(w, FP, ONION, Some(note), main_footer_hints()); + assert!( + line.chars().count() <= w as usize, + "footer wider than {w}: {} {line:?}", + line.chars().count() + ); + assert!( + line.contains("send failed"), + "{w} dropped fail-closed note: {line:?}" + ); + assert!(line.contains("TOR"), "{w} missing TOR: {line:?}"); + assert!(line.contains("me:"), "{w} missing me:: {line:?}"); + assert!(line.contains("? help"), "{w} missing ? help: {line:?}"); + } +} + +#[test] +fn main_header_is_one_line_at_80() { + let line = main_header_line(80, FP, ONION); + assert!(!line.contains('\n'), "header must be one line: {line:?}"); + assert!( + line.chars().count() <= 80, + "header wider than 80: {} {line:?}", + line.chars().count() + ); + assert!(line.to_ascii_lowercase().contains("onionwire"), "{line:?}"); + assert!(line.contains("me:"), "{line:?}"); +} + +#[test] +fn roster_is_fixed_cells_not_percent() { + assert_eq!(roster_col_width(80), 22); + assert_eq!(roster_col_width(119), 22); + assert_eq!(roster_col_width(120), 28); + assert_eq!(roster_col_width(200), 28); +} + +#[test] +fn help_overlay_at_80x24_is_fullscreen_last_line_visible() { + let backend = TestBackend::new(80, 24); + let mut terminal = Terminal::new(backend).expect("terminal"); + terminal + .draw(|f| { + f.render_widget( + Paragraph::new(" .-~~-. ONIONWIRE\n┌roster junk\n┌composer"), + f.area(), + ); + draw_text_overlay(f, "? help", help_overlay_text()); + }) + .expect("draw"); + let buf = terminal.backend().buffer(); + let screen = screen_from(buf, 80, 24); + assert!( + screen.contains("Esc closes this overlay"), + "last help line clipped:\n{screen}" + ); + assert!( + !screen.contains(".-~~-."), + "help punched through banner:\n{screen}" + ); + assert!( + !screen.contains("┌roster"), + "help punched through roster:\n{screen}" + ); + assert!(screen.contains("? help"), "help title missing:\n{screen}"); +} + +fn draw_main_standin(f: &mut Frame, empty_roster: bool, composer: &str, note: Option<&str>) { + let area = f.area(); + let header = main_header_line(area.width, FP, ONION); + let cols = Layout::vertical([ + Constraint::Length(1), + Constraint::Min(3), + Constraint::Length(3), + Constraint::Length(1), + ]) + .split(area); + f.render_widget(Paragraph::new(header), cols[0]); + let roster_w = roster_col_width(area.width).min(cols[1].width.saturating_sub(10)); + let panes = + Layout::horizontal([Constraint::Length(roster_w), Constraint::Min(10)]).split(cols[1]); + let items = if empty_roster { + vec![ListItem::new("no friends")] + } else { + vec![ListItem::new("alice aaaaaaaa…")] + }; + f.render_stateful_widget( + List::new(items) + .highlight_symbol("> ") + .block(Block::default().borders(Borders::ALL).title("roster 0")), + panes[0], + &mut ratatui::widgets::ListState::default(), + ); + f.render_widget( + Paragraph::new("no friends yet") + .wrap(Wrap { trim: false }) + .block(Block::default().borders(Borders::ALL).title(" chat")), + panes[1], + ); + f.render_widget( + Paragraph::new(format!("> {composer}")).wrap(Wrap { trim: false }), + cols[2], + ); + let footer = status_footer(area.width, FP, ONION, note, main_footer_hints()); + f.render_widget(Paragraph::new(footer), cols[3]); +} + +#[test] +fn reconstructed_main_empty_roster_and_composer() { + let backend = TestBackend::new(80, 24); + let mut terminal = Terminal::new(backend).expect("terminal"); + terminal + .draw(|f| draw_main_standin(f, true, "message", None)) + .expect("draw"); + let screen = screen_from(terminal.backend().buffer(), 80, 24); + let row0: String = screen.lines().next().unwrap_or("").to_string(); + assert!( + !row0.contains(".-~~-."), + "80x24 main still uses 3-line wordmark:\n{screen}" + ); + assert!( + screen.contains("no friends"), + "empty roster blank:\n{screen}" + ); + assert!( + screen.contains("message"), + "composer missing placeholder:\n{screen}" + ); + assert!( + !screen.contains("/wipe"), + "composer still dumps slash list:\n{screen}" + ); +} + +#[test] +fn reconstructed_main_keeps_send_failed_on_footer() { + let backend = TestBackend::new(80, 24); + let mut terminal = Terminal::new(backend).expect("terminal"); + terminal + .draw(|f| draw_main_standin(f, false, "hello", Some("send failed: peer onion down"))) + .expect("draw"); + let screen = screen_from(terminal.backend().buffer(), 80, 24); + assert!( + screen.contains("send failed"), + "fail-closed missing from frame:\n{screen}" + ); +} + +#[test] +fn dump_spec_frames() { + let _guard = ASCII_ENV.lock().expect("ascii env lock"); + unsafe { std::env::remove_var("ONIONWIRE_ASCII") }; + for (w, h) in [(80u16, 24u16), (120, 40)] { + let backend = TestBackend::new(w, h); + let mut terminal = Terminal::new(backend).expect("terminal"); + terminal + .draw(|f| { + draw_main_standin( + f, + false, + "hello from composer", + Some("send failed: peer onion down"), + ) + }) + .expect("draw"); + println!("===== AFTER main {w}x{h} ====="); + print!("{}", screen_from(terminal.backend().buffer(), w, h)); + + let backend = TestBackend::new(w, h); + let mut terminal = Terminal::new(backend).expect("terminal"); + terminal + .draw(|f| { + draw_main_standin(f, true, "message", None); + draw_text_overlay(f, "? help", help_overlay_text()); + }) + .expect("draw"); + println!("===== AFTER help {w}x{h} ====="); + print!("{}", screen_from(terminal.backend().buffer(), w, h)); + + let invite = sample_invite(); + let backend = TestBackend::new(w, h); + let mut terminal = Terminal::new(backend).expect("terminal"); + terminal.draw(|f| draw_share(f, &invite)).expect("draw"); + println!("===== AFTER share {w}x{h} ====="); + print!("{}", screen_from(terminal.backend().buffer(), w, h)); + } +} + +fn sample_invite() -> String { + let sk = [7u8; 32]; + qr::encode(&sk, ONION, &[1u8; 32]).expect("encode") +} + +fn invite_line_ok(line: &str) -> bool { + let t = line.trim(); + t.is_empty() + || t.starts_with("onionwire:") + || t.starts_with("k=") + || t.starts_with("o=") + || t.starts_with("spk=") + || t.starts_with("sig=") + || t.chars().all(|c| c.is_ascii_hexdigit()) +} + +#[test] +fn alert_line_truncates_to_frame_width() { + let long = "passphrases do not match and then a lot more context that would collide with the roster on the next row if left unwrapped"; + let line = alert_line(long, 80); + assert!( + line.chars().count() <= 80, + "alert wider than 80: {} {line:?}", + line.chars().count() + ); + assert!( + line.contains('…') || line.contains("..."), + "long alert was not truncated: {line:?}" + ); + assert!( + !line.contains("roster on the next row"), + "alert still has overflow tail: {line:?}" + ); +} + +#[test] +fn wrap_invite_breaks_on_field_boundaries() { + let invite = sample_invite(); + assert!(invite.len() > 78, "fixture too short to wrap: {invite}"); + let wrapped = wrap_invite(&invite, 78); + for line in wrapped.lines() { + assert!( + line.chars().count() <= 78, + "invite line wider than 78: {} {line:?}", + line.chars().count() + ); + assert!( + invite_line_ok(line), + "invite wrapped mid-token: {line:?}\n{wrapped}" + ); + } + assert!( + wrapped.contains("onionwire:v1:"), + "lost invite prefix:\n{wrapped}" + ); + assert!(wrapped.contains("k="), "lost k= field:\n{wrapped}"); + assert!(wrapped.contains("spk="), "lost spk= field:\n{wrapped}"); + let joined: String = wrapped.lines().map(str::trim).collect(); + assert_eq!( + joined, invite, + "wrap must be newline-joinable back to payload" + ); +} + +#[test] +fn draw_share_invite_does_not_wrap_mid_token() { + let invite = sample_invite(); + let backend = TestBackend::new(80, 24); + let mut terminal = Terminal::new(backend).expect("terminal"); + terminal.draw(|f| draw_share(f, &invite)).expect("draw"); + let screen = screen_from(terminal.backend().buffer(), 80, 24); + assert!( + screen.contains("onionwire:v1:"), + "missing prefix:\n{screen}" + ); + for raw in screen.lines() { + let inner = raw.trim_start_matches(['│', '|', ' ']); + let inner = inner.trim_end_matches(['│', '|', ' ']); + if inner.starts_with("onionwire:") + || inner.starts_with("k=") + || inner.starts_with("o=") + || inner.starts_with("spk=") + || inner.starts_with("sig=") + || inner.chars().all(|c| c.is_ascii_hexdigit()) + { + assert!( + invite_line_ok(inner), + "share pane mid-token wrap: {inner:?}\n{screen}" + ); + } + if inner.starts_with('c') && inner.contains(":o=") { + panic!("share still wraps mid-hex into :o=: {inner:?}\n{screen}"); + } + } +} + +#[test] +fn empty_friend_chat_has_send_hint() { + let text = empty_friend_chat_text(); + assert!(text.contains("no messages"), "{text:?}"); + assert!(text.contains("type below, Enter sends"), "{text:?}"); +} + +#[test] +fn paste_error_keeps_resubmit_hint() { + let body = paste_screen_text("", Some("bad invite")); + assert!(body.contains("bad invite"), "{body:?}"); + assert!(body.contains("Enter resubmits"), "{body:?}"); + assert!(body.contains("Esc back"), "{body:?}"); + let ok = paste_screen_text("onionwire:v1:k=x", None); + assert!( + ok.contains("paste onionwire:v1 payload"), + "happy-path hint lost: {ok:?}" + ); +} + +#[test] +fn ascii_switch_80x24_frame_is_pure_ascii() { + let _guard = ASCII_ENV.lock().expect("ascii env lock"); + unsafe { std::env::set_var("ONIONWIRE_ASCII", "1") }; + assert!( + ascii_chrome(), + "ONIONWIRE_ASCII set but ascii_chrome() is false" + ); + let footer = status_footer(80, FP, ONION, None, main_footer_hints()); + assert!( + footer.contains("..."), + "ASCII truncation marker missing: {footer:?}" + ); + assert!( + !footer.contains('…'), + "unicode ellipsis still in footer: {footer:?}" + ); + + let invite = sample_invite(); + let backend = TestBackend::new(80, 24); + let mut terminal = Terminal::new(backend).expect("terminal"); + terminal.draw(|f| draw_share(f, &invite)).expect("draw"); + let screen = screen_from(terminal.backend().buffer(), 80, 24); + let non_ascii: Vec = screen.chars().filter(|c| !c.is_ascii()).collect(); + assert!( + non_ascii.is_empty(), + "ASCII switch ignored, non-ASCII in 80x24 frame: {non_ascii:?}\n{screen}" + ); + assert!( + screen.contains("..."), + "truncation marker missing from ASCII frame:\n{screen}" + ); + assert!( + screen.contains('+') && screen.contains('|') && screen.contains('-'), + "ASCII borders missing:\n{screen}" + ); + println!("===== AFTER ascii share 80x24 =====\n{screen}"); + unsafe { std::env::remove_var("ONIONWIRE_ASCII") }; +} + +// --------------------------------------------------------------------------- +// Outbox delivery state (card t_d9a5b065) +// +// States come from the outbox API (`Outbox::pending` → `Queued` / `Sending` / +// `Failed`; delivered rows are deleted, so absence means `Sent`). No new wire +// prefix, no parallel state model. +// --------------------------------------------------------------------------- + +fn out_msg(id: i64, body: &str) -> Message { + Message { + id, + dir: "out".into(), + plaintext: body.as_bytes().to_vec(), + } +} + +fn in_msg(id: i64, body: &str) -> Message { + Message { + id, + dir: "in".into(), + plaintext: body.as_bytes().to_vec(), + } +} + +fn pending_row( + message_id: i64, + body: &str, + status: OutboxStatus, + attempts: u32, + next_in: i64, + now: i64, +) -> OutboxEntry { + OutboxEntry { + id: 1, + friend_pk: vec![9u8; 32], + message_id, + body: body.as_bytes().to_vec(), + attempts, + next_attempt_at: now + next_in, + created_at: now, + status, + last_error: None, + } +} + +fn queued_row(message_id: i64, body: &str, attempts: u32, next_in: i64, now: i64) -> OutboxEntry { + pending_row( + message_id, + body, + OutboxStatus::Queued, + attempts, + next_in, + now, + ) +} + +fn sending_row(message_id: i64, body: &str, now: i64) -> OutboxEntry { + pending_row(message_id, body, OutboxStatus::Sending, 1, 0, now) +} + +fn failed_row(message_id: i64, body: &str, why: &str, now: i64) -> OutboxEntry { + pending_row( + message_id, + body, + OutboxStatus::Failed(why.into()), + 8, + 0, + now, + ) +} + +/// Marker is everything after the two-space separator the render helper uses. +fn marker_of(line: &str) -> &str { + line.rsplit(" ").next().unwrap_or("") +} + +/// Force the non-ASCII (unicode glyph) path. Caller holds `ASCII_ENV`. +fn force_unicode_mode() { + unsafe { + std::env::remove_var("ONIONWIRE_ASCII"); + std::env::remove_var("NO_COLOR"); + } +} + +#[test] +fn queued_and_delivered_messages_render_different_markers() { + let guard = ASCII_ENV.lock().expect("ascii env lock"); + force_unicode_mode(); + let _guard = guard; + let now = 1_700_000_000; + let msgs = vec![out_msg(1, "ping"), out_msg(2, "pong")]; + let pending = vec![queued_row(2, "pong", 2, 45, now)]; + + let (lines, summary) = chat_with_delivery(&msgs, &pending, now); + + assert!( + lines[0].contains('✓'), + "delivered row lost its mark: {:?}", + lines[0] + ); + assert!(!lines[0].contains("queued"), "{:?}", lines[0]); + assert!( + lines[1].contains('◷'), + "queued row lost its glyph: {:?}", + lines[1] + ); + assert!(lines[1].contains("queued"), "{:?}", lines[1]); + assert!( + lines[1].contains("try 2/8"), + "attempt count missing: {:?}", + lines[1] + ); + assert!( + lines[1].contains("retry 45s"), + "retry age missing: {:?}", + lines[1] + ); + assert_ne!( + marker_of(&lines[0]), + marker_of(&lines[1]), + "queued and delivered must not share a marker" + ); + assert_eq!(summary.queued, 1); + assert_eq!(summary.failed, 0); +} + +/// The case the body match got wrong: the same text sent twice, only the +/// *older* send still queued. Joined by body, the (single) pending row lands on +/// the newest send and the actually-queued row shows `✓` — which is exactly +/// false delivery. The join is on `Message::id` / `OutboxEntry::message_id`. +#[test] +fn identical_bodies_join_by_message_id_not_body() { + let guard = ASCII_ENV.lock().expect("ascii env lock"); + force_unicode_mode(); + let _guard = guard; + let now = 1_700_000_000; + let msgs = vec![out_msg(7, "same text"), out_msg(8, "same text")]; + let pending = vec![queued_row(7, "same text", 1, 30, now)]; + + let (lines, summary) = chat_with_delivery(&msgs, &pending, now); + + assert!( + lines[0].contains('◷') && lines[0].contains("queued"), + "queued marker must land on the queued row (id 7): {:?}", + lines[0] + ); + assert!( + !lines[0].contains('✓'), + "queued row must not claim delivery: {:?}", + lines[0] + ); + assert_eq!( + marker_of(&lines[1]), + "✓", + "delivered row (id 8) must keep its mark: {:?}", + lines[1] + ); + assert_eq!(summary.note().as_deref(), Some("1 queued")); +} + +#[test] +fn delivery_markers_have_exercised_ascii_fallbacks() { + let _guard = ASCII_ENV.lock().expect("ascii env lock"); + unsafe { + std::env::set_var("ONIONWIRE_ASCII", "1"); + std::env::remove_var("NO_COLOR"); + } + let now = 500; + let msgs = vec![ + out_msg(1, "alpha"), + out_msg(2, "beta"), + out_msg(3, "gamma"), + out_msg(4, "delta"), + in_msg(5, "epsilon"), + ]; + let pending = vec![ + failed_row( + 1, + "alpha", + "connect peer.onion:80: connection timed out", + now, + ), + queued_row(2, "beta", 1, 30, now), + sending_row(3, "gamma", now), + ]; + + let (lines, summary) = chat_with_delivery(&msgs, &pending, now); + for line in &lines { + assert!( + line.is_ascii(), + "ASCII fallback missing, non-ASCII in {line:?}" + ); + } + assert_eq!(marker_of(&lines[0]), "failed: connection timed out"); + assert_eq!(marker_of(&lines[1]), "queued (try 1/8, retry 30s)"); + assert_eq!(marker_of(&lines[2]), "sending"); + assert_eq!(marker_of(&lines[3]), "ok", "delivered fallback is `ok`"); + assert_eq!(lines[4], "them: epsilon", "inbound rows carry no state"); + assert_eq!(summary.queued, 2, "queued + sending are both outstanding"); + assert_eq!(summary.failed, 1); + + unsafe { std::env::remove_var("ONIONWIRE_ASCII") }; +} + +#[test] +fn retry_age_and_failure_reason_are_short_forms() { + assert_eq!(retry_in_text(45), "retry 45s"); + assert_eq!(retry_in_text(59), "retry 59s"); + assert_eq!(retry_in_text(60), "retry 1m"); + assert_eq!(retry_in_text(720), "retry 12m"); + assert_eq!(retry_in_text(0), "retry now"); + assert_eq!(retry_in_text(-30), "retry now"); + + assert_eq!( + short_send_reason("connect abcdef.onion:80: connection timed out", 24), + "connection timed out" + ); + let long = short_send_reason("a-really-long-failure-description-here", 12); + assert!(long.chars().count() <= 12, "{long:?}"); + assert!( + long.contains('…') || long.contains("..."), + "truncation marker missing: {long:?}" + ); + assert_eq!(short_send_reason("nope", 24), "nope"); +} + +#[test] +fn delivery_tag_reads_the_outbox_status_enum() { + let guard = ASCII_ENV.lock().expect("ascii env lock"); + force_unicode_mode(); + let _guard = guard; + assert_eq!(delivery_tag(&OutboxStatus::Sent, 0, 0), "✓"); + assert_eq!( + delivery_tag(&OutboxStatus::Queued, 3, 120), + "◷ queued (try 3/8, retry 2m)" + ); + assert_eq!(delivery_tag(&OutboxStatus::Sending, 1, 0), "» sending"); + assert_eq!( + delivery_tag(&OutboxStatus::Failed("connect x:80: nope".into()), 8, 0), + "✗ failed: nope" + ); +} + +#[test] +fn footer_summary_counts_queued_and_keeps_fail_closed() { + let none = OutboxSummary::default(); + assert_eq!(none.note(), None); + + let queued = OutboxSummary { + queued: 2, + failed: 0, + first_error: None, + }; + assert_eq!(queued.note().as_deref(), Some("2 queued")); + + let failed = OutboxSummary { + queued: 0, + failed: 1, + first_error: Some("connect peer.onion:80: connection timed out".into()), + }; + let note = failed.note().expect("failed rows must produce a note"); + assert!(note.starts_with("send failed:"), "{note:?}"); + assert!(note.contains("connection timed out"), "{note:?}"); + + let mixed = OutboxSummary { + queued: 3, + failed: 1, + first_error: Some("connect peer.onion:80: connection timed out".into()), + }; + let mixed_note = mixed.note().expect("mixed rows must produce a note"); + assert!(mixed_note.contains("3 queued"), "{mixed_note:?}"); + assert!(mixed_note.contains("send failed"), "{mixed_note:?}"); + + // Fail-closed copy stays visible in the real footer at the 80-col floor. + let line = status_footer(80, FP, ONION, Some(¬e), main_footer_hints()); + assert!( + line.chars().count() <= 80, + "{} {line:?}", + line.chars().count() + ); + assert!(line.contains("send failed"), "footer dropped it: {line:?}"); + assert!(line.contains("TOR") && line.contains("? help"), "{line:?}"); + + let queued_line = status_footer(80, FP, ONION, queued.note().as_deref(), main_footer_hints()); + assert!(queued_line.contains("2 queued"), "{queued_line:?}"); + assert!(queued_line.chars().count() <= 80); + + // `! ` ornament (colour off) still lands on the derived failing note. + let _guard = ASCII_ENV.lock().expect("ascii env lock"); + unsafe { std::env::set_var("NO_COLOR", "1") }; + let no_color = status_footer(80, FP, ONION, Some(¬e), main_footer_hints()); + assert!(no_color.contains("! send failed"), "{no_color:?}"); + unsafe { std::env::remove_var("NO_COLOR") }; +} + +/// The card's width criterion: draw the real helpers at the documented floor +/// (80x24) and prove nothing in the chat/footer region exceeds the width, and +/// that an over-long row wraps in the pane instead of being clipped. +#[test] +fn chat_and_footer_rows_fit_80x24_and_wrap_instead_of_clipping() { + let guard = ASCII_ENV.lock().expect("ascii env lock"); + force_unicode_mode(); + let _guard = guard; + let now = 1_700_000_000; + let long = "this is a very long chat line that should wrap inside the chat pane instead of running off the right edge of an 80-column terminal and colliding with the roster border"; + let msgs = vec![out_msg(1, "ok"), in_msg(2, "pong"), out_msg(3, long)]; + let pending = vec![queued_row(3, long, 3, 45, now)]; + + let (lines, summary) = chat_with_delivery(&msgs, &pending, now); + for line in lines.iter().take(2) { + assert!( + line.chars().count() <= 80, + "short row wider than 80: {} {line:?}", + line.chars().count() + ); + } + let footer = status_footer( + 80, + FP, + ONION, + summary.note().as_deref(), + main_footer_hints(), + ); + assert!(footer.chars().count() <= 80, "{footer:?}"); + + let backend = TestBackend::new(80, 24); + let mut terminal = Terminal::new(backend).expect("terminal"); + terminal + .draw(|f| { + let area = f.area(); + let cols = Layout::vertical([Constraint::Min(3), Constraint::Length(1)]).split(area); + draw_chat(f, cols[0], &lines, Some("alice"), true, 0); + f.render_widget(Paragraph::new(footer.clone()), cols[1]); + }) + .expect("draw"); + + let buf = terminal.backend().buffer(); + let mut screen = String::new(); + for y in 0..24u16 { + for x in 0..80u16 { + screen.push_str(buf[(x, y)].symbol()); + } + screen.push('\n'); + } + for (y, row) in screen.lines().enumerate() { + assert!( + row.chars().count() <= 80, + "80x24 chat/footer row {y} wider than the terminal: {} {row:?}", + row.chars().count() + ); + } + assert!( + screen.contains('◷'), + "queued glyph missing from frame:\n{screen}" + ); + assert!(screen.contains("queued"), "queued word missing:\n{screen}"); + assert!(screen.contains('✓'), "delivered glyph missing:\n{screen}"); + assert!( + screen.contains("with the roster border"), + "long row was clipped, not wrapped:\n{screen}" + ); + assert!( + screen.contains("1 queued"), + "footer summary missing:\n{screen}" + ); + println!("===== AFTER outbox 80x24 (real draw_chat + status_footer) =====\n{screen}"); +} + +/// The renderer consumes the real outbox API, not a hand-written fixture: a +/// genuine unreachable-onion send leaves a `Queued` row, and that row is what +/// the chat line and the footer note are built from. +#[tokio::test] +async fn renders_a_queued_row_from_a_real_outbox_send() { + use onionwire::Store; + use onionwire::outbox::{BoxFut, Deliverer, Outbox}; + use std::sync::Arc; struct Dead; impl Deliverer for Dead { @@ -111,6 +853,108 @@ fn daemon_addresses_parse_or_are_refused() { } } +/// The picker has to *offer* the in-process daemon, and the row has to say +/// testnet: a user who reads it as a mainnet node has been misled by the app. +#[test] +fn the_chain_picker_offers_the_in_process_daemon_and_says_testnet() { + let rows: Vec<&'static str> = ChainChoice::ALL.iter().map(|c| c.label()).collect(); + assert!( + rows.iter().any(|l| l.contains("in-process daemon")), + "the picker never offers it: {rows:?}" + ); + assert_eq!( + ChainChoice::ALL + .iter() + .filter(|c| **c == ChainChoice::InProcessCuprate) + .count(), + 1, + "one row, not two spellings of it" + ); + let detail = ChainChoice::of(&ChainSource::InProcessCuprate { + datadir: std::path::PathBuf::from("/tmp/chain"), + }) + .detail(); + assert!( + detail.contains("testnet"), + "the caveat is the row: {detail}" + ); + assert!( + detail.contains("Cuprate"), + "the row has to name what runs: {detail}" + ); + for choice in ChainChoice::ALL { + assert!(!choice.label().is_empty() && !choice.detail().is_empty()); + } +} + +/// A remote daemon is still never preselected: the fourth row did not introduce +/// a default, and the two local rows are the only ones that mean "this device". +#[test] +fn the_fourth_picker_row_did_not_preselect_anything() { + assert_eq!( + ChainChoice::of(&ChainSource::None), + ChainChoice::ReceiveOnly + ); + assert_eq!( + ChainChoice::of(&ChainSource::InProcessCuprate { + datadir: std::path::PathBuf::from("/tmp/chain"), + }), + ChainChoice::InProcessCuprate + ); + assert_eq!( + ChainChoice::ALL.first(), + Some(&ChainChoice::ReceiveOnly), + "receive-only is still the first row" + ); +} + +/// The chain block on the in-process source: the testnet caveat is on the +/// screen, the chain is described as this device's, and nothing about it is +/// dressed up as a remote daemon. +#[test] +fn the_chain_block_names_the_in_process_daemon_and_its_testnet_limit() { + let source = ChainSource::InProcessCuprate { + datadir: std::path::PathBuf::from("/home/user/.local/share/onionwire/chain"), + }; + let view = chain_view_with_progress( + &source, + WalletChildState::Stopped, + &DaemonSync { + reachable: false, + height: 0, + target_height: 0, + note: Some("127.0.0.1:18081: Connection refused".into()), + }, + Some(50), + wallet_readiness(false, false, false), + None, + ); + assert!( + view.source_line.contains("in-process daemon"), + "{}", + view.source_line + ); + assert!( + view.source_line.contains(onionwire::cuprate::TESTNET_ONLY), + "the caveat must come from the one const: {}", + view.source_line + ); + assert!( + !view.source_line.contains("remote daemon"), + "a local daemon must not read as someone else's: {}", + view.source_line + ); + // The chain is on this device, so the storage line is the local one. + assert!( + view.storage_line.contains("free here"), + "{}", + view.storage_line + ); + for line in view.lines() { + assert!(line.chars().count() <= WALLET_LINE_MAX, "too long: {line}"); + } +} + #[test] fn onion_hosts_are_recognised_before_any_spawn() { assert!(is_onion_host("abc234.onion")); @@ -120,6 +964,711 @@ fn onion_hosts_are_recognised_before_any_spawn() { assert!(!is_onion_host("notonion")); } +// --------------------------------------------------------------------------- +// Payment history rows (card t_935bf84e) +// +// Tests over test-local `Payment` fixtures — no store access from the render +// path. Direction marker, amount via `pay::atomic_to_xmr_str`, verified word +// + glyph, txid truncation, "awaiting receipt" for None txid, and hostile +// memo sanitization. +// --------------------------------------------------------------------------- + +#[allow(clippy::too_many_arguments)] +fn payment( + id: i64, + dir: &str, + kind: &str, + amount_atomic: &str, + address: &str, + memo: &str, + txid: Option, + verified: bool, + created_at: i64, +) -> Payment { + Payment { + id, + dir: dir.to_string(), + kind: kind.to_string(), + amount_atomic: amount_atomic.to_string(), + address: address.to_string(), + memo: memo.to_string(), + txid, + verified, + created_at, + } +} + +const NOW: i64 = 1_700_000_000; + +#[test] +fn history_row_outbound_verified_has_marker_word_and_glyph() { + let _guard = ASCII_ENV.lock().expect("ascii env lock"); + force_unicode_mode(); + let p = payment( + 1, + "out", + "tip", + "1000000000", + "addr", + "coffee", + Some("abcd1234".into()), + true, + 1_699_999_000, + ); + let row = history_row_text(&p, 76, NOW); + assert!( + row.starts_with("> "), + "outbound row must start with '> ': {row:?}" + ); + assert!(row.contains('✓'), "verified glyph missing: {row:?}"); + assert!(row.contains("verified"), "verified word missing: {row:?}"); + assert!(row.contains("0.001"), "amount missing: {row:?}"); +} + +#[test] +fn history_row_outbound_unverified_has_word_no_check() { + let _guard = ASCII_ENV.lock().expect("ascii env lock"); + force_unicode_mode(); + let p = payment( + 2, + "out", + "invoice", + "500000000", + "addr", + "", + Some("ef12".into()), + false, + 1_700_000_000, + ); + let row = history_row_text(&p, 76, NOW); + assert!( + row.starts_with("> "), + "outbound row must start with '> ': {row:?}" + ); + assert!( + row.contains("unverified"), + "unverified word missing: {row:?}" + ); + assert!( + !row.contains('✓'), + "unverified must not have check glyph: {row:?}" + ); +} + +#[test] +fn history_row_inbound_uses_left_marker() { + let _guard = ASCII_ENV.lock().expect("ascii env lock"); + force_unicode_mode(); + let p = payment( + 3, + "in", + "payment", + "2500000000", + "addr", + "", + Some("deadbeef".into()), + true, + 1_700_000_000, + ); + let row = history_row_text(&p, 76, NOW); + assert!( + row.starts_with("< "), + "inbound row must start with '< ': {row:?}" + ); + assert!(row.contains("verified"), "verified word missing: {row:?}"); +} + +#[test] +fn history_row_no_txid_says_awaiting_receipt_not_dash() { + let _guard = ASCII_ENV.lock().expect("ascii env lock"); + force_unicode_mode(); + let p = payment( + 4, + "in", + "payment", + "1000000000", + "addr", + "", + None, + false, + 1_700_000_000, + ); + let row = history_row_text(&p, 76, NOW); + assert!( + row.contains("awaiting receipt"), + "missing 'awaiting receipt': {row:?}" + ); + assert!( + !row.contains("--"), + "bare dash instead of 'awaiting receipt': {row:?}" + ); +} + +#[test] +fn history_row_truncates_txid_within_width() { + let _guard = ASCII_ENV.lock().expect("ascii env lock"); + force_unicode_mode(); + let p = payment( + 5, + "out", + "tip", + "1000", + "addr", + "memo", + Some("a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3".into()), + true, + 1_700_000_000, + ); + let row = history_row_text(&p, 40, NOW); + assert!( + row.chars().count() <= 40, + "row wider than 40: {} {row:?}", + row.chars().count() + ); +} + +#[test] +fn history_row_ascii_fallback_has_no_emoji_glyphs() { + let _guard = ASCII_ENV.lock().expect("ascii env lock"); + unsafe { std::env::set_var("ONIONWIRE_ASCII", "1") }; + let p = payment( + 1, + "out", + "tip", + "1000000000", + "addr", + "", + Some("abcd".into()), + true, + 1_700_000_000, + ); + let row = history_row_text(&p, 76, NOW); + assert!(row.is_ascii(), "ASCII fallback not pure ASCII: {row:?}"); + assert!( + row.contains("verified"), + "ASCII verified word missing: {row:?}" + ); + unsafe { std::env::remove_var("ONIONWIRE_ASCII") }; +} + +#[test] +fn history_detail_shows_all_fields_sanitized() { + let p = payment( + 7, + "out", + "tip", + "2000000000", + "1A2B3C4D5E6F", + "for pizza", + Some("abcdef0123456789abcdef0123456789".into()), + true, + 1_700_000_000, + ); + let detail = history_detail(&p, 76, NOW); + let all = detail.join("\n"); + assert!( + all.contains("abcdef0123456789abcdef0123456789"), + "full txid missing: {all:?}" + ); + assert!(all.contains("1A2B3C4D5E6F"), "address missing: {all:?}"); + assert!(all.contains("for pizza"), "memo missing: {all:?}"); + assert!(all.contains("0.002"), "amount missing: {all:?}"); + assert!(all.contains("outbound"), "direction missing: {all:?}"); + assert!(all.contains("verified"), "verified state missing: {all:?}"); + assert!( + all.contains("1700000000") || all.contains("Nov"), + "timestamp missing: {all:?}" + ); + for line in &detail { + assert!( + line.chars().count() <= 76, + "detail line wider than 76: {} {line:?}", + line.chars().count() + ); + } +} + +// F7 wallet-config screen (card t_7719eda3) +// --------------------------------------------------------------------------- + +/// Fixture password that must NEVER appear in any rendered frame. +const FIXTURE_PASS: &str = "supersecret123"; + +/// Build a WalletConfigScreen for testing, with the given fields. +fn make_config( + rpc_url: &str, + rpc_login: &str, + no_spend: bool, + reveal: bool, + focus: ConfigField, + status: ConfigStatus, +) -> WalletConfigScreen { + WalletConfigScreen { + rpc_url: rpc_url.to_string(), + rpc_login: rpc_login.to_string(), + no_spend, + reveal, + focus, + status, + } +} + +/// Render the F7 config screen through the real `draw_wallet_config` at the +/// given size and collect the result as a string. +fn config_screen_at(w: u16, h: u16, s: &WalletConfigScreen) -> String { + let backend = TestBackend::new(w, h); + let mut terminal = Terminal::new(backend).expect("terminal"); + terminal + .draw(|f| onionwire::tui::draw_wallet_config(f, s)) + .expect("draw"); + screen_from(terminal.backend().buffer(), w, h) +} + +#[test] +fn wallet_config_screen_renders_fields_and_footer() { + let s = make_config( + "http://127.0.0.1:18083", + "onionwire", + true, + false, + ConfigField::RpcUrl, + ConfigStatus::Idle, + ); + for (w, h) in [(80u16, 24u16), (120, 40)] { + let screen = config_screen_at(w, h, &s); + for (y, row) in screen.lines().enumerate() { + if row.chars().count() > w as usize { + panic!("{w}x{h} row {y} wider than frame: {row:?}"); + } + } + assert!(screen.contains("wallet config"), "{w}x{h}: title missing"); + assert!(screen.contains("rpc_url"), "{w}x{h}: rpc_url label missing"); + assert!( + screen.contains("http://127.0.0.1:18083"), + "{w}x{h}: url value missing" + ); + assert!( + screen.contains("rpc_login"), + "{w}x{h}: rpc_login label missing" + ); + assert!( + screen.contains("no_spend"), + "{w}x{h}: no_spend label missing" + ); + assert!( + screen.contains("/tip disabled") || screen.contains("/tip off"), + "{w}x{h}: no_spend consequence missing" + ); + assert!(screen.contains("> "), "{w}x{h}: focus marker missing"); + assert!(screen.contains("Esc back"), "{w}x{h}: Esc back missing"); + assert!(screen.contains("Tab"), "{w}x{h}: Tab hint missing"); + } +} + +#[test] +fn history_detail_hostile_memo_is_sanitized_inert_text() { + // C0 control chars + bidi override — must render as inert text, not affect + // the terminal or carry hidden directionality. + let hostile = "pay\x01now\u{202E}\u{202E}reverse"; + let p = payment( + 8, + "in", + "payment", + "500000000", + "addr", + hostile, + Some("cafebabe".into()), + false, + 1_700_000_000, + ); + let detail = history_detail(&p, 76, NOW); + let all = detail.join("\n"); + // Bidi override must be stripped — the word "reverse" must appear in + // reading order, not visually flipped by a leftover override mark. + assert!( + !all.contains('\u{202E}'), + "bidi override survived sanitize: {all:?}" + ); + assert!( + !all.contains('\x01'), + "C0 control survived sanitize: {all:?}" + ); + assert!(all.contains("reverse"), "sanitized memo text lost: {all:?}"); +} + +#[test] +fn history_detail_no_txid_shows_awaiting_receipt() { + let p = payment( + 9, + "in", + "payment", + "1000", + "addr", + "", + None, + false, + 1_700_000_000, + ); + let detail = history_detail(&p, 76, NOW); + let all = detail.join("\n"); + assert!( + all.contains("awaiting receipt"), + "detail missing 'awaiting receipt': {all:?}" + ); +} + +#[test] +fn draw_history_list_at_80x24_fits_and_shows_rows() { + let _guard = ASCII_ENV.lock().expect("ascii env lock"); + force_unicode_mode(); + let payments = vec![ + payment( + 1, + "out", + "tip", + "1000000000", + "addr", + "coffee", + Some("abcd1234".into()), + true, + 1_699_999_000, + ), + payment( + 2, + "in", + "payment", + "2500000000", + "addr", + "", + Some("deadbeef".into()), + true, + 1_700_000_001, + ), + payment( + 3, + "out", + "invoice", + "500000000", + "addr", + "", + None, + false, + 1_700_000_002, + ), + ]; + let backend = TestBackend::new(80, 24); + let mut terminal = Terminal::new(backend).expect("terminal"); + terminal + .draw(|f| draw_history(f, &payments, 1, false, "alice", NOW)) + .expect("draw"); + let screen = screen_from(terminal.backend().buffer(), 80, 24); + for line in screen.lines() { + assert!( + line.chars().count() <= 80, + "80x24 history row wider than 80: {} {line:?}", + line.chars().count() + ); + } + assert!( + screen.contains("alice"), + "friend name missing from title: {screen}" + ); + assert!(screen.contains("> "), "outbound marker missing: {screen}"); + assert!(screen.contains("< "), "inbound marker missing: {screen}"); + assert!( + screen.contains("awaiting receipt"), + "awaiting receipt missing: {screen}" + ); + assert!(screen.contains("Enter detail"), "hint missing: {screen}"); + assert!(screen.contains("Esc back"), "hint missing: {screen}"); +} + +#[test] +fn draw_history_empty_at_80x24_shows_designed_copy() { + let _guard = ASCII_ENV.lock().expect("ascii env lock"); + force_unicode_mode(); + let backend = TestBackend::new(80, 24); + let mut terminal = Terminal::new(backend).expect("terminal"); + terminal + .draw(|f| draw_history(f, &[], 0, false, "bob", NOW)) + .expect("draw"); + let screen = screen_from(terminal.backend().buffer(), 80, 24); + for line in screen.lines() { + assert!(line.chars().count() <= 80, "row wider than 80: {line:?}"); + } + assert!( + screen.contains("no payments with this friend yet"), + "empty copy missing: {screen}" + ); +} + +#[test] +fn draw_history_detail_at_80x24_fits() { + let _guard = ASCII_ENV.lock().expect("ascii env lock"); + force_unicode_mode(); + let p = payment( + 1, + "out", + "tip", + "1000000000", + "1A2B3C4D5E6F", + "coffee", + Some("abcdef0123456789abcdef0123456789".into()), + true, + 1_700_000_000, + ); + let backend = TestBackend::new(80, 24); + let mut terminal = Terminal::new(backend).expect("terminal"); + terminal + .draw(|f| draw_history(f, std::slice::from_ref(&p), 0, true, "alice", NOW)) + .expect("draw"); + let screen = screen_from(terminal.backend().buffer(), 80, 24); + for line in screen.lines() { + assert!( + line.chars().count() <= 80, + "detail row wider than 80: {} {line:?}", + line.chars().count() + ); + } + assert!( + screen.contains("awaiting receipt") || screen.contains("abcdef0123456789"), + "detail content missing: {screen}" + ); +} +#[test] +fn wallet_config_login_is_masked_by_default() { + let s = make_config( + "http://127.0.0.1:18083", + &format!("user:{FIXTURE_PASS}"), + false, + false, + ConfigField::RpcLogin, + ConfigStatus::Idle, + ); + for (w, h) in [(80u16, 24u16), (120, 40)] { + let screen = config_screen_at(w, h, &s); + assert!( + !screen.contains(FIXTURE_PASS), + "{w}x{h}: fixture password leaked in frame:\n{screen}" + ); + assert!(screen.contains("user"), "{w}x{h}: username not shown"); + } +} + +#[test] +fn wallet_config_login_mask_and_reveal_are_distinguishable_in_no_color() { + let _guard = ASCII_ENV.lock().expect("ascii env lock"); + unsafe { std::env::set_var("NO_COLOR", "1") }; + + let masked = make_config( + "http://127.0.0.1:18083", + &format!("user:{FIXTURE_PASS}"), + false, + false, + ConfigField::RpcLogin, + ConfigStatus::Idle, + ); + let screen = config_screen_at(80, 24, &masked); + assert!( + !screen.contains(FIXTURE_PASS), + "NO_COLOR frame leaked password:\n{screen}" + ); + + let revealed = make_config( + "http://127.0.0.1:18083", + &format!("user:{FIXTURE_PASS}"), + false, + true, + ConfigField::RpcLogin, + ConfigStatus::Idle, + ); + let screen = config_screen_at(80, 24, &revealed); + assert!( + !screen.contains(FIXTURE_PASS), + "NO_COLOR revealed frame leaked password:\n{screen}" + ); + + let masked_ascii = config_screen_at(80, 24, &masked); + let revealed_ascii = config_screen_at(80, 24, &revealed); + assert!( + masked_ascii.contains('.') || masked_ascii.contains("reveal"), + "masked NO_COLOR frame has no distinguishing marker:\n{masked_ascii}" + ); + assert!( + revealed_ascii.contains("user"), + "revealed NO_COLOR frame missing username:\n{revealed_ascii}" + ); + + unsafe { std::env::remove_var("NO_COLOR") }; +} + +#[test] +fn wallet_config_status_line_states() { + let idle = make_config( + "", + "", + false, + false, + ConfigField::Action, + ConfigStatus::Idle, + ); + let screen = config_screen_at(80, 24, &idle); + assert!( + !screen.contains("connected") && !screen.contains("saved") && !screen.contains("error:"), + "idle should have no status line:\n{screen}" + ); + + let testing = make_config( + "", + "", + false, + false, + ConfigField::Action, + ConfigStatus::Testing, + ); + let screen = config_screen_at(80, 24, &testing); + assert!( + screen.contains("testing connection"), + "testing status missing:\n{screen}" + ); + + let ok = make_config( + "", + "", + false, + false, + ConfigField::Action, + ConfigStatus::Tested(PingResult { + ok: true, + status: "connected".into(), + error: None, + }), + ); + let screen = config_screen_at(80, 24, &ok); + assert!( + screen.contains("connected"), + "tested-ok status missing:\n{screen}" + ); + + let fail = make_config( + "", + "", + false, + false, + ConfigField::Action, + ConfigStatus::Tested(PingResult { + ok: false, + status: "not connected".into(), + error: Some("connection refused".into()), + }), + ); + let screen = config_screen_at(80, 24, &fail); + assert!( + screen.contains("not connected"), + "tested-fail status missing:\n{screen}" + ); + assert!( + screen.contains("connection refused"), + "tested-fail error detail missing:\n{screen}" + ); + + let saved_nc = make_config( + "", + "", + false, + false, + ConfigField::Action, + ConfigStatus::Saved(true, String::new()), + ); + let screen = config_screen_at(80, 24, &saved_nc); + assert!( + screen.contains("saved"), + "saved-not-connected status missing:\n{screen}" + ); + + let saved_fail = make_config( + "", + "", + false, + false, + ConfigField::Action, + ConfigStatus::Saved(false, "bad url".into()), + ); + let screen = config_screen_at(80, 24, &saved_fail); + assert!( + screen.contains("error:"), + "saved-fail status missing:\n{screen}" + ); + assert!( + screen.contains("bad url"), + "saved-fail reason missing:\n{screen}" + ); +} + +#[test] +fn wallet_config_password_never_leaks_in_any_status() { + let cases: Vec<(&str, ConfigStatus)> = vec![ + ("idle", ConfigStatus::Idle), + ("testing", ConfigStatus::Testing), + ( + "tested-ok", + ConfigStatus::Tested(PingResult { + ok: true, + status: "connected".into(), + error: None, + }), + ), + ( + "tested-fail", + ConfigStatus::Tested(PingResult { + ok: false, + status: "not connected".into(), + error: Some(format!("{} leaked", FIXTURE_PASS)), + }), + ), + ("saved-ok", ConfigStatus::Saved(true, String::new())), + ( + "saved-fail", + ConfigStatus::Saved(false, format!("error mentions {}", FIXTURE_PASS)), + ), + ]; + for (name, status) in cases { + let s = make_config( + "http://127.0.0.1:18083", + &format!("user:{FIXTURE_PASS}"), + true, + false, + ConfigField::RpcUrl, + status, + ); + let screen = config_screen_at(80, 24, &s); + assert!( + !screen.contains(FIXTURE_PASS), + "password leaked in {name} frame:\n{screen}" + ); + } +} + +#[test] +fn help_overlay_lists_f7_and_send_flow() { + let help = help_overlay_text(); + for needle in ["F7", "F6 h", "send chat", "/pay", "/tip", "copy"] { + assert!(help.contains(needle), "help overlay missing {needle:?}"); + } +} + +#[test] +fn wallet_config_focus_cycles_through_fields() { + assert_eq!(ConfigField::RpcUrl.next(), ConfigField::RpcLogin); + assert_eq!(ConfigField::RpcLogin.next(), ConfigField::NoSpend); + assert_eq!(ConfigField::NoSpend.next(), ConfigField::Action); + assert_eq!(ConfigField::Action.next(), ConfigField::RpcUrl); + assert_eq!(ConfigField::RpcUrl.prev(), ConfigField::Action); + assert_eq!(ConfigField::RpcLogin.prev(), ConfigField::RpcUrl); + assert_eq!(ConfigField::NoSpend.prev(), ConfigField::RpcLogin); + assert_eq!(ConfigField::Action.prev(), ConfigField::NoSpend); +} + // --------------------------------------------------------------------------- // The chain view against a Cuprate daemon: connectivity is inferred from // block-height movement, never from `get_info`'s peer counts (zero while it diff --git a/tests/wallet.rs b/tests/wallet.rs index f2be004..f06571e 100644 --- a/tests/wallet.rs +++ b/tests/wallet.rs @@ -1348,6 +1348,109 @@ async fn a_transport_failure_is_not_a_height_error() { assert!(!err.is_height_out_of_range(), "{err}"); } +// --------------------------------------------------------------------------- +// The in-process chain daemon (feature `cuprate-daemon`). +// +// The only test in the suite that runs a real chain daemon: it launches the +// cuprated node OnionWire embeds, asks it through the *same* typed daemon client +// a remote `monerod` is asked through, and then proves the listener dies with +// the node. It needs no network — a testnet node with no peers answers RPC and +// stays at genesis. +// --------------------------------------------------------------------------- + +/// `WalletChild::pick_port` is the app's own "give me a free loopback port". +#[cfg(feature = "cuprate-daemon")] +fn freed_port() -> u16 { + onionwire::wallet_child::WalletChild::pick_port().expect("free loopback port") +} + +#[cfg(feature = "cuprate-daemon")] +#[tokio::test(flavor = "multi_thread", worker_threads = 4)] +async fn an_in_process_cuprate_node_answers_the_typed_daemon_client() { + let dir = tempfile::tempdir().expect("tempdir"); + let datadir = dir.path().join("chain"); + let port = freed_port(); + let addr = format!("127.0.0.1:{port}"); + + let mut node = onionwire::cuprate::CuprateNode::launch(&datadir, port) + .await + .expect("launch the in-process testnet daemon"); + + // `launch` returns with the services started; the RPC listener can still be + // a moment behind, so poll with a deadline instead of racing it. + let budget = Duration::from_secs(5); + let mut info = None; + for _ in 0..40 { + if let Ok(got) = wallet::daemon_get_info(&addr, budget).await { + info = Some(got); + break; + } + tokio::time::sleep(Duration::from_millis(250)).await; + } + let info = info.expect("the in-process daemon never answered get_info on /json_rpc"); + + // A fresh testnet chain: genesis is height 1 and there is nothing to sync + // towards. The daemon's own consensus context is the reference, and the RPC + // answer may trail it by a block or two while it is running. + assert!(info.height >= 1, "genesis is height 1: {info:?}"); + let context_height = node.chain_height(); + assert!(context_height >= 1, "in-process height: {context_height}"); + assert!( + info.height.abs_diff(context_height) <= 2, + "get_info ({}) and the node's own context ({context_height}) disagree", + info.height + ); + assert_eq!( + info.target_height, 0, + "a testnet node with no peers reports no target, not a caught-up chain" + ); + + // `get_height` is the URI endpoint (Cuprate rejects it over /json_rpc), and + // it has to agree with `get_info`. + let height = wallet::daemon_get_height(&addr, budget) + .await + .expect("get_height on the URI endpoint"); + assert!(height >= 1, "{height}"); + assert!( + height.abs_diff(info.height) <= 2, + "get_height ({height}) and get_info ({}) disagree", + info.height + ); + + // Genesis is always retrievable, and a height above the tip is the bare-500 + // answer the typed client normalizes. + let genesis = wallet::daemon_get_block(&addr, 0, Duration::from_secs(30)) + .await + .expect("get_block at genesis"); + assert!( + genesis.len() > 70, + "a genesis block with a header and one tx is longer than this: {}", + genesis.len() + ); + let far = + wallet::daemon_get_block(&addr, info.height + 1_000_000, Duration::from_secs(30)).await; + assert!( + matches!(far, Err(WalletError::DaemonHeightOutOfRange)), + "an above-the-tip height must map to the typed height error: {far:?}" + ); + + // Dropping the node *is* the shutdown. The listener has to go with it, or + // the app would leave a chain daemon behind after quitting. + drop(node); + let mut closed = false; + for _ in 0..40 { + if tokio::net::TcpStream::connect(&addr).await.is_err() { + closed = true; + break; + } + tokio::time::sleep(Duration::from_millis(250)).await; + } + assert!( + closed, + "the unrestricted RPC was still accepting after shutdown" + ); +} + #[test] fn only_the_height_error_reports_itself_as_one() { assert!(WalletError::DaemonHeightOutOfRange.is_height_out_of_range());