diff --git a/Cargo.lock b/Cargo.lock index eb3ed33..be9cf36 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -847,15 +847,15 @@ dependencies = [ [[package]] name = "ant-core" -version = "0.1.1" +version = "0.2.0" dependencies = [ "alloy", "ant-node", + "ant-protocol", "anyhow", "async-stream", "axum", "bytes", - "evmlib", "flate2", "fs2", "futures", @@ -869,7 +869,6 @@ dependencies = [ "rand 0.8.6", "reqwest 0.12.28", "rmp-serde", - "saorsa-pqc 0.5.1", "self-replace", "self_encryption", "semver 1.0.28", @@ -903,11 +902,11 @@ dependencies = [ [[package]] name = "ant-node" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dac042e69f7dff2136deee542d66fceb5631474869ea4da9875185a9ad3329cc" +version = "0.11.0" +source = "git+https://github.com/WithAutonomi/ant-node?branch=anselme%2Fextract-ant-protocol#dd076513cbed325c5edd72924ba5c7de387e57e0" dependencies = [ "aes-gcm-siv", + "ant-protocol", "blake3", "bytes", "chrono", @@ -951,6 +950,24 @@ dependencies = [ "zip", ] +[[package]] +name = "ant-protocol" +version = "2.0.0" +source = "git+https://github.com/WithAutonomi/ant-protocol?rev=597dbdb1b680a43d80a082d77076ff2080444079#597dbdb1b680a43d80a082d77076ff2080444079" +dependencies = [ + "blake3", + "bytes", + "evmlib", + "hex", + "postcard", + "rmp-serde", + "saorsa-core", + "saorsa-pqc 0.5.1", + "serde", + "tokio", + "tracing", +] + [[package]] name = "anyhow" version = "1.0.102" @@ -4486,7 +4503,7 @@ dependencies = [ "once_cell", "socket2 0.6.3", "tracing", - "windows-sys 0.60.2", + "windows-sys 0.59.0", ] [[package]] @@ -6934,15 +6951,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "windows-sys" -version = "0.60.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" -dependencies = [ - "windows-targets 0.53.5", -] - [[package]] name = "windows-sys" version = "0.61.2" @@ -6991,30 +6999,13 @@ dependencies = [ "windows_aarch64_gnullvm 0.52.6", "windows_aarch64_msvc 0.52.6", "windows_i686_gnu 0.52.6", - "windows_i686_gnullvm 0.52.6", + "windows_i686_gnullvm", "windows_i686_msvc 0.52.6", "windows_x86_64_gnu 0.52.6", "windows_x86_64_gnullvm 0.52.6", "windows_x86_64_msvc 0.52.6", ] -[[package]] -name = "windows-targets" -version = "0.53.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3" -dependencies = [ - "windows-link", - "windows_aarch64_gnullvm 0.53.1", - "windows_aarch64_msvc 0.53.1", - "windows_i686_gnu 0.53.1", - "windows_i686_gnullvm 0.53.1", - "windows_i686_msvc 0.53.1", - "windows_x86_64_gnu 0.53.1", - "windows_x86_64_gnullvm 0.53.1", - "windows_x86_64_msvc 0.53.1", -] - [[package]] name = "windows_aarch64_gnullvm" version = "0.42.2" @@ -7033,12 +7024,6 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53" - [[package]] name = "windows_aarch64_msvc" version = "0.42.2" @@ -7057,12 +7042,6 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" -[[package]] -name = "windows_aarch64_msvc" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006" - [[package]] name = "windows_i686_gnu" version = "0.42.2" @@ -7081,24 +7060,12 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" -[[package]] -name = "windows_i686_gnu" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3" - [[package]] name = "windows_i686_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" -[[package]] -name = "windows_i686_gnullvm" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c" - [[package]] name = "windows_i686_msvc" version = "0.42.2" @@ -7117,12 +7084,6 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" -[[package]] -name = "windows_i686_msvc" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2" - [[package]] name = "windows_x86_64_gnu" version = "0.42.2" @@ -7141,12 +7102,6 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" -[[package]] -name = "windows_x86_64_gnu" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499" - [[package]] name = "windows_x86_64_gnullvm" version = "0.42.2" @@ -7165,12 +7120,6 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1" - [[package]] name = "windows_x86_64_msvc" version = "0.42.2" @@ -7189,12 +7138,6 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" -[[package]] -name = "windows_x86_64_msvc" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" - [[package]] name = "winnow" version = "0.7.15" diff --git a/Cargo.toml b/Cargo.toml index f3978b2..cca943d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,3 +1,10 @@ [workspace] members = ["ant-core", "ant-cli"] resolver = "2" + +# While ant-protocol 2.0.0 and ant-node 0.11.0 are unpublished, resolve +# both through git pins against their open PR branches. Remove this +# block when both crates are on crates.io. +[patch.crates-io] +ant-protocol = { git = "https://github.com/WithAutonomi/ant-protocol", rev = "597dbdb1b680a43d80a082d77076ff2080444079" } +ant-node = { git = "https://github.com/WithAutonomi/ant-node", branch = "anselme/extract-ant-protocol" } diff --git a/ant-core/CHANGELOG.md b/ant-core/CHANGELOG.md new file mode 100644 index 0000000..dc39515 --- /dev/null +++ b/ant-core/CHANGELOG.md @@ -0,0 +1,57 @@ +# Changelog + +All notable changes to the `ant-core` library will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [0.2.0] — Unreleased + +This release decouples `ant-core` from `ant-node` at runtime. The wire +protocol was extracted into the new [`ant-protocol`] crate; `ant-core` +now depends on `ant-protocol` and keeps `ant-node` only as an optional +dependency (for `LocalDevnet`) and a dev-dependency (for the test +harness that spins up real nodes). + +[`ant-protocol`]: https://crates.io/crates/ant-protocol + +### Breaking + +- **`ant-node` is no longer a default runtime dependency.** The + `LocalDevnet` wrapper and its types (`DevnetManifest` re-export) now + require `features = ["devnet"]`. Downstream `Cargo.toml`: + ```toml + ant-core = { version = "0.2", features = ["devnet"] } + ``` +- `Client::with_evm_network` now takes `ant_protocol::evm::Network` + instead of `evmlib::Network`. Both paths resolve to the same + underlying type (`ant_protocol::evm` is a re-export of `evmlib`), so + the fix for downstream callers is a one-line path change. +- `impl From for Error` has been removed. Call sites + that used `?` to propagate an `ant_node::Error` into an `ant-core` + `Error` must now map explicitly: + ```rust + foo().await.map_err(|e| Error::Network(e.to_string()))?; + ``` +- `ant_core::data::LocalDevnet` is now behind the `devnet` feature. + Code that previously imported it unconditionally must either enable + the feature or use the `DevnetManifest` type alone (available + unconditionally via `ant_core::data::DevnetManifest`). + +### Changed + +- `ant-core` no longer declares direct dependencies on `evmlib`, + `saorsa-core`, or `saorsa-pqc`. Those transitive dependencies are + consumed through `ant_protocol::{evm, transport, pqc}` so Cargo + enforces a single version pin shared with `ant-node`. +- `DevnetManifest` and `DevnetEvmInfo` moved to + `ant_protocol::devnet_manifest`. The `ant_core::data::DevnetManifest` + path is unchanged; only the origin crate differs. The on-disk JSON + format is byte-for-byte compatible. +- All internal `ant_node::{ant_protocol, client, payment}::*` imports + rewritten to `ant_protocol::*` paths. + +### Added + +- `devnet` feature flag (off by default) that pulls in `ant-node` as an + optional runtime dependency to enable `LocalDevnet`. diff --git a/ant-core/Cargo.toml b/ant-core/Cargo.toml index e15abd7..64a1206 100644 --- a/ant-core/Cargo.toml +++ b/ant-core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ant-core" -version = "0.1.1" +version = "0.2.0" edition = "2021" [dependencies] @@ -27,7 +27,12 @@ zip = "2" tower-http = { version = "0.6.8", features = ["cors"] } # Data operations -evmlib = "0.8" +# Wire protocol crate: gives us `ant_protocol::{chunk, payment, …}` plus +# re-exports of `evmlib`, `saorsa-core` (transport), and `saorsa-pqc` +# under `ant_protocol::{evm, transport, pqc}`. This is the ONE pin for +# those three deps — do not add direct evmlib/saorsa-core/saorsa-pqc +# deps here or the version can skew between ant-client and ant-node. +ant-protocol = "2" xor_name = "5" self_encryption = "0.35.0" futures = "0.3" @@ -38,8 +43,10 @@ tracing = "0.1" bytes = "1" lru = "0.16" rand = "0.8" -ant-node = "0.10.1" -saorsa-pqc = "0.5" +# ant-node is optional. It is only linked for the `LocalDevnet` wrapper +# that spawns a local in-process network for development and testing. +# Enable with `--features devnet`. +ant-node = { version = "0.11", optional = true } tracing-subscriber = { version = "0.3", features = ["env-filter"] } [target.'cfg(unix)'.dependencies] @@ -52,7 +59,20 @@ openssl = { version = "0.10", features = ["vendored"] } [target.'cfg(windows)'.dependencies] windows-sys = { version = "0.61", features = ["Win32_Foundation", "Win32_System_Console", "Win32_System_Threading"] } +[features] +# No features enabled by default — consumers that want to spawn a local +# devnet opt in with `features = ["devnet"]`. +default = [] +# Enable `LocalDevnet` (ant-core/src/node/devnet.rs) which wraps +# `ant_node::devnet::Devnet` and an Anvil EVM testnet. +devnet = ["dep:ant-node"] + [dev-dependencies] +# Test infrastructure in tests/support/mod.rs spawns real ant-nodes +# in-process to exercise the wire protocol end-to-end. ant-node is a +# dev-dep here (separate from the optional runtime dep above) so tests +# always compile even without the `devnet` feature. +ant-node = "0.11" serial_test = "3" anyhow = "1" alloy = { version = "1.6", features = ["node-bindings"] } @@ -61,6 +81,10 @@ tokio-test = "0.4" [[example]] name = "start-local-devnet" path = "examples/start-local-devnet.rs" +# `LocalDevnet` (and therefore this example) is gated behind `devnet`. +# Running under default features would produce a confusing "LocalDevnet +# not found" error, so require the feature explicitly. +required-features = ["devnet"] [[test]] name = "e2e_chunk" diff --git a/ant-core/src/data/client/batch.rs b/ant-core/src/data/client/batch.rs index ff3c575..80e0450 100644 --- a/ant-core/src/data/client/batch.rs +++ b/ant-core/src/data/client/batch.rs @@ -8,14 +8,16 @@ use crate::data::client::file::UploadEvent; use crate::data::client::payment::peer_id_to_encoded; use crate::data::client::Client; use crate::data::error::{Error, Result}; -use ant_node::ant_protocol::DATA_TYPE_CHUNK; -use ant_node::client::{compute_address, XorName}; -use ant_node::core::{MultiAddr, PeerId}; -use ant_node::payment::{serialize_single_node_proof, PaymentProof, SingleNodePayment}; +use ant_protocol::evm::{ + Amount, EncodedPeerId, PayForQuotesError, PaymentQuote, ProofOfPayment, QuoteHash, + RewardsAddress, TxHash, +}; +use ant_protocol::transport::{MultiAddr, PeerId}; +use ant_protocol::{ + compute_address, serialize_single_node_proof, PaymentProof, SingleNodePayment, XorName, + DATA_TYPE_CHUNK, +}; use bytes::Bytes; -use evmlib::common::{Amount, QuoteHash, TxHash}; -use evmlib::wallet::PayForQuotesError; -use evmlib::{EncodedPeerId, PaymentQuote, ProofOfPayment, RewardsAddress}; use futures::stream::{self, StreamExt}; use std::collections::{HashMap, HashSet}; use std::time::Duration; @@ -628,8 +630,7 @@ mod send_assertions { #[allow(clippy::unwrap_used)] mod tests { use super::*; - use ant_node::payment::single_node::QuotePaymentInfo; - use ant_node::CLOSE_GROUP_SIZE; + use ant_protocol::{QuotePaymentInfo, CLOSE_GROUP_SIZE}; /// Median index in the quotes array. const MEDIAN_INDEX: usize = CLOSE_GROUP_SIZE / 2; diff --git a/ant-core/src/data/client/cache.rs b/ant-core/src/data/client/cache.rs index 3e8957e..893d6c3 100644 --- a/ant-core/src/data/client/cache.rs +++ b/ant-core/src/data/client/cache.rs @@ -3,7 +3,7 @@ //! Caches recently fetched chunks in memory to avoid re-fetching //! the same content-addressed data from the network. -use ant_node::client::XorName; +use ant_protocol::XorName; use bytes::Bytes; use lru::LruCache; use std::num::NonZeroUsize; diff --git a/ant-core/src/data/client/chunk.rs b/ant-core/src/data/client/chunk.rs index 592e6a0..4b00f1c 100644 --- a/ant-core/src/data/client/chunk.rs +++ b/ant-core/src/data/client/chunk.rs @@ -5,13 +5,12 @@ use crate::data::client::Client; use crate::data::error::{Error, Result}; -use ant_node::ant_protocol::{ - ChunkGetRequest, ChunkGetResponse, ChunkMessage, ChunkMessageBody, ChunkPutRequest, - ChunkPutResponse, +use ant_protocol::transport::{MultiAddr, PeerId}; +use ant_protocol::{ + compute_address, send_and_await_chunk_response, ChunkGetRequest, ChunkGetResponse, + ChunkMessage, ChunkMessageBody, ChunkPutRequest, ChunkPutResponse, DataChunk, XorName, + CLOSE_GROUP_MAJORITY, }; -use ant_node::client::{compute_address, send_and_await_chunk_response, DataChunk, XorName}; -use ant_node::core::{MultiAddr, PeerId}; -use ant_node::CLOSE_GROUP_MAJORITY; use bytes::Bytes; use futures::stream::{FuturesUnordered, StreamExt}; use std::future::Future; diff --git a/ant-core/src/data/client/data.rs b/ant-core/src/data/client/data.rs index 8c588dc..4c6534e 100644 --- a/ant-core/src/data/client/data.rs +++ b/ant-core/src/data/client/data.rs @@ -11,8 +11,7 @@ use crate::data::client::file::{ExternalPaymentInfo, PreparedUpload}; use crate::data::client::merkle::PaymentMode; use crate::data::client::Client; use crate::data::error::{Error, Result}; -use ant_node::ant_protocol::DATA_TYPE_CHUNK; -use ant_node::client::compute_address; +use ant_protocol::{compute_address, DATA_TYPE_CHUNK}; use bytes::Bytes; use futures::stream::{self, StreamExt, TryStreamExt}; use self_encryption::{decrypt, encrypt, DataMap, EncryptedChunk}; diff --git a/ant-core/src/data/client/file.rs b/ant-core/src/data/client/file.rs index acc4c31..49d008f 100644 --- a/ant-core/src/data/client/file.rs +++ b/ant-core/src/data/client/file.rs @@ -17,11 +17,9 @@ use crate::data::client::merkle::{ }; use crate::data::client::Client; use crate::data::error::{Error, Result}; -use ant_node::ant_protocol::DATA_TYPE_CHUNK; -use ant_node::client::compute_address; +use ant_protocol::evm::{QuoteHash, TxHash}; +use ant_protocol::{compute_address, DATA_TYPE_CHUNK}; use bytes::Bytes; -use evmlib::common::QuoteHash; -use evmlib::common::TxHash; use fs2::FileExt; use futures::stream::{self, StreamExt}; use self_encryption::{get_root_data_map_parallel, stream_encrypt, streaming_decrypt, DataMap}; @@ -898,7 +896,7 @@ impl Client { progress: Option<&mpsc::Sender>, ) -> Result<(usize, String, u128)> { let mut total_stored = 0usize; - let mut total_storage = evmlib::common::Amount::ZERO; + let mut total_storage = ant_protocol::evm::Amount::ZERO; let mut total_gas: u128 = 0; let total_chunks = spill.len(); let waves: Vec<&[[u8; 32]]> = spill.waves().collect(); @@ -928,7 +926,7 @@ impl Client { .batch_upload_chunks_with_events(wave_data, progress, total_stored, total_chunks) .await?; total_stored += addresses.len(); - if let Ok(cost) = wave_storage.parse::() { + if let Ok(cost) = wave_storage.parse::() { total_storage += cost; } total_gas = total_gas.saturating_add(wave_gas); diff --git a/ant-core/src/data/client/merkle.rs b/ant-core/src/data/client/merkle.rs index 1ef32b1..f7bf18d 100644 --- a/ant-core/src/data/client/merkle.rs +++ b/ant-core/src/data/client/merkle.rs @@ -6,19 +6,15 @@ use crate::data::client::Client; use crate::data::error::{Error, Result}; -use ant_node::ant_protocol::{ +use ant_protocol::evm::{ + Amount, MerklePaymentCandidateNode, MerklePaymentCandidatePool, MerklePaymentProof, MerkleTree, + MidpointProof, PoolCommitment, CANDIDATES_PER_POOL, MAX_LEAVES, +}; +use ant_protocol::{ + send_and_await_chunk_response, serialize_merkle_proof, verify_merkle_candidate_signature, ChunkMessage, ChunkMessageBody, MerkleCandidateQuoteRequest, MerkleCandidateQuoteResponse, }; -use ant_node::client::send_and_await_chunk_response; -use ant_node::payment::quote::verify_merkle_candidate_signature; -use ant_node::payment::serialize_merkle_proof; use bytes::Bytes; -use evmlib::common::Amount; -use evmlib::merkle_batch_payment::PoolCommitment; -use evmlib::merkle_payments::{ - MerklePaymentCandidateNode, MerklePaymentCandidatePool, MerklePaymentProof, MerkleTree, - MidpointProof, CANDIDATES_PER_POOL, MAX_LEAVES, -}; use futures::stream::{self, FuturesUnordered, StreamExt}; use std::collections::HashMap; use std::time::Duration; @@ -452,7 +448,7 @@ impl Client { futures: &mut FuturesUnordered< impl std::future::Future< Output = ( - ant_node::core::PeerId, + ant_protocol::transport::PeerId, std::result::Result, ), >, @@ -623,9 +619,7 @@ mod send_assertions { #[allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)] mod tests { use super::*; - use evmlib::common::Amount; - use evmlib::merkle_payments::{MerkleTree, CANDIDATES_PER_POOL}; - use evmlib::RewardsAddress; + use ant_protocol::evm::{Amount, MerkleTree, RewardsAddress, CANDIDATES_PER_POOL}; // ========================================================================= // should_use_merkle (free function, no Client needed) @@ -742,10 +736,8 @@ mod tests { #[test] fn test_merkle_proof_serialize_deserialize_roundtrip() { - use ant_node::payment::{deserialize_merkle_proof, serialize_merkle_proof}; - use evmlib::common::Amount; - use evmlib::merkle_payments::MerklePaymentCandidateNode; - use evmlib::RewardsAddress; + use ant_protocol::evm::{Amount, MerklePaymentCandidateNode, RewardsAddress}; + use ant_protocol::{deserialize_merkle_proof, serialize_merkle_proof}; let addrs = make_test_addresses(4); let xornames: Vec = addrs.iter().map(|a| XorName(*a)).collect(); @@ -802,8 +794,8 @@ mod tests { // Simulates what collect_validated_candidates checks let candidate = MerklePaymentCandidateNode { pub_key: vec![0u8; 32], - price: evmlib::common::Amount::ZERO, - reward_address: evmlib::RewardsAddress::new([0u8; 20]), + price: Amount::ZERO, + reward_address: RewardsAddress::new([0u8; 20]), merkle_payment_timestamp: 1000, signature: vec![0u8; 64], }; @@ -897,7 +889,7 @@ mod tests { #[test] fn test_finalize_merkle_batch_proofs_are_deserializable() { - use ant_node::payment::deserialize_merkle_proof; + use ant_protocol::deserialize_merkle_proof; let prepared = make_prepared_merkle_batch(8); let winner_hash = prepared.candidate_pools[0].hash(); diff --git a/ant-core/src/data/client/mod.rs b/ant-core/src/data/client/mod.rs index ccce50d..bc1c6ca 100644 --- a/ant-core/src/data/client/mod.rs +++ b/ant-core/src/data/client/mod.rs @@ -15,10 +15,9 @@ pub mod quote; use crate::data::client::cache::ChunkCache; use crate::data::error::{Error, Result}; use crate::data::network::Network; -use ant_node::client::XorName; -use ant_node::core::{MultiAddr, P2PNode, PeerId}; -use ant_node::CLOSE_GROUP_SIZE; -use evmlib::wallet::Wallet; +use ant_protocol::evm::Wallet; +use ant_protocol::transport::{MultiAddr, P2PNode, PeerId}; +use ant_protocol::{XorName, CLOSE_GROUP_SIZE}; use std::sync::atomic::{AtomicU64, Ordering}; use std::sync::Arc; use tracing::debug; @@ -101,7 +100,7 @@ pub struct Client { config: ClientConfig, network: Network, wallet: Option>, - evm_network: Option, + evm_network: Option, chunk_cache: ChunkCache, next_request_id: AtomicU64, } @@ -166,7 +165,7 @@ impl Client { /// This enables token approval and contract interactions /// for external-signer flows where the private key lives outside Rust. #[must_use] - pub fn with_evm_network(mut self, network: evmlib::Network) -> Self { + pub fn with_evm_network(mut self, network: ant_protocol::evm::Network) -> Self { self.evm_network = Some(network); self } @@ -176,7 +175,7 @@ impl Client { /// # Errors /// /// Returns an error if neither `with_evm_network` nor `with_wallet` was called. - pub(crate) fn require_evm_network(&self) -> Result<&evmlib::Network> { + pub(crate) fn require_evm_network(&self) -> Result<&ant_protocol::evm::Network> { if let Some(ref net) = self.evm_network { return Ok(net); } diff --git a/ant-core/src/data/client/payment.rs b/ant-core/src/data/client/payment.rs index 651bdb6..ee487e6 100644 --- a/ant-core/src/data/client/payment.rs +++ b/ant-core/src/data/client/payment.rs @@ -5,10 +5,9 @@ use crate::data::client::Client; use crate::data::error::{Error, Result}; -use ant_node::core::{MultiAddr, PeerId}; -use ant_node::payment::{serialize_single_node_proof, PaymentProof, SingleNodePayment}; -use evmlib::wallet::Wallet; -use evmlib::{EncodedPeerId, ProofOfPayment}; +use ant_protocol::evm::{EncodedPeerId, ProofOfPayment, Wallet}; +use ant_protocol::transport::{MultiAddr, PeerId}; +use ant_protocol::{serialize_single_node_proof, PaymentProof, SingleNodePayment}; use std::sync::Arc; use tracing::{debug, info}; @@ -110,7 +109,7 @@ impl Client { let vault_address = evm_network.payment_vault_address(); wallet - .approve_to_spend_tokens(*vault_address, evmlib::common::U256::MAX) + .approve_to_spend_tokens(*vault_address, ant_protocol::evm::U256::MAX) .await .map_err(|e| Error::Payment(format!("Token approval failed: {e}")))?; info!("Token spend approved for payment vault contract"); @@ -119,7 +118,8 @@ impl Client { } } -/// Convert an ant-node `PeerId` to an `EncodedPeerId` for payment proofs. +/// Convert a saorsa-core `PeerId` (re-exported via `ant_protocol::transport`) +/// to an `EncodedPeerId` suitable for payment proofs. pub(crate) fn peer_id_to_encoded(peer_id: &PeerId) -> Result { Ok(EncodedPeerId::new(*peer_id.as_bytes())) } diff --git a/ant-core/src/data/client/quote.rs b/ant-core/src/data/client/quote.rs index 3e13626..7865cc6 100644 --- a/ant-core/src/data/client/quote.rs +++ b/ant-core/src/data/client/quote.rs @@ -5,14 +5,12 @@ use crate::data::client::Client; use crate::data::error::{Error, Result}; -use ant_node::ant_protocol::{ - ChunkMessage, ChunkMessageBody, ChunkQuoteRequest, ChunkQuoteResponse, +use ant_protocol::evm::{Amount, PaymentQuote}; +use ant_protocol::transport::{MultiAddr, PeerId}; +use ant_protocol::{ + send_and_await_chunk_response, ChunkMessage, ChunkMessageBody, ChunkQuoteRequest, + ChunkQuoteResponse, CLOSE_GROUP_MAJORITY, CLOSE_GROUP_SIZE, }; -use ant_node::client::send_and_await_chunk_response; -use ant_node::core::{MultiAddr, PeerId}; -use ant_node::{CLOSE_GROUP_MAJORITY, CLOSE_GROUP_SIZE}; -use evmlib::common::Amount; -use evmlib::PaymentQuote; use futures::stream::{FuturesUnordered, StreamExt}; use std::time::Duration; use tracing::{debug, warn}; diff --git a/ant-core/src/data/error.rs b/ant-core/src/data/error.rs index e571fa5..6073163 100644 --- a/ant-core/src/data/error.rs +++ b/ant-core/src/data/error.rs @@ -86,11 +86,10 @@ pub enum Error { }, } -impl From for Error { - fn from(e: ant_node::Error) -> Self { - Self::Network(e.to_string()) - } -} +// The `From` conversion used before 0.2.0 lived here +// because ant-core depended on ant-node at runtime. ant-node is now +// optional (behind the `devnet` feature); the `LocalDevnet` wrapper +// maps node errors inline via `map_err`. See `src/node/devnet.rs`. #[cfg(test)] #[allow(clippy::unwrap_used, clippy::expect_used)] diff --git a/ant-core/src/data/mod.rs b/ant-core/src/data/mod.rs index 7d5c676..c6b9a02 100644 --- a/ant-core/src/data/mod.rs +++ b/ant-core/src/data/mod.rs @@ -12,11 +12,12 @@ pub use client::{Client, ClientConfig}; pub use error::{Error, Result}; pub use network::Network; -// Re-export LocalDevnet from its new home in the node module +// Re-export LocalDevnet from its new home in the node module (requires `devnet` feature) +#[cfg(feature = "devnet")] pub use crate::node::devnet::LocalDevnet; -// Re-export commonly used types from ant-node -pub use ant_node::client::{compute_address, DataChunk, XorName}; +// Re-export commonly used wire types from ant-protocol. +pub use ant_protocol::{compute_address, DataChunk, XorName}; // Re-export client data types pub use client::batch::{finalize_batch_payment, PaidChunk, PaymentIntent, PreparedChunk}; @@ -32,13 +33,18 @@ pub use client::merkle::{ // Re-export self-encryption types pub use self_encryption::DataMap; -// Re-export networking types needed by CLI for P2P node creation -pub use ant_node::ant_protocol::{MAX_CHUNK_SIZE, MAX_WIRE_MESSAGE_SIZE}; -pub use ant_node::core::{CoreNodeConfig, MultiAddr, NodeMode, P2PNode}; -pub use ant_node::devnet::DevnetManifest; +// Re-export protocol constants + transport types needed by CLI for P2P node creation +pub use ant_protocol::transport::{CoreNodeConfig, MultiAddr, NodeMode, P2PNode}; +pub use ant_protocol::{MAX_CHUNK_SIZE, MAX_WIRE_MESSAGE_SIZE}; -// Re-export EVM types needed by CLI for wallet and network setup -pub use evmlib::common::{Address as EvmAddress, U256}; -pub use evmlib::wallet::Wallet; -pub use evmlib::CustomNetwork; -pub use evmlib::Network as EvmNetwork; +// DevnetManifest is a pure-data handoff file between the devnet +// launcher and clients that want to connect — no ant-node runtime +// dep needed to read or write it. +pub use ant_protocol::DevnetManifest; + +// Re-export EVM types needed by CLI for wallet and network setup. Sourced +// through ant-protocol so ant-core keeps no direct evmlib dep — that pin +// is owned by ant-protocol. +pub use ant_protocol::evm::{ + Address as EvmAddress, CustomNetwork, Network as EvmNetwork, Wallet, U256, +}; diff --git a/ant-core/src/data/network.rs b/ant-core/src/data/network.rs index da0835a..a37793f 100644 --- a/ant-core/src/data/network.rs +++ b/ant-core/src/data/network.rs @@ -1,11 +1,12 @@ -//! Network layer wrapping ant-node's P2P node. +//! Network layer wrapping the saorsa-core `P2PNode` (re-exported via +//! `ant_protocol::transport`). //! //! Provides peer discovery, message sending, and DHT operations //! for the client library. use crate::data::error::{Error, Result}; -use ant_node::ant_protocol::MAX_WIRE_MESSAGE_SIZE; -use ant_node::core::{CoreNodeConfig, MultiAddr, NodeMode, P2PNode, PeerId}; +use ant_protocol::transport::{CoreNodeConfig, MultiAddr, NodeMode, P2PNode, PeerId}; +use ant_protocol::MAX_WIRE_MESSAGE_SIZE; use std::net::SocketAddr; use std::sync::Arc; diff --git a/ant-core/src/node/devnet.rs b/ant-core/src/node/devnet.rs index 9d1f012..922b40c 100644 --- a/ant-core/src/node/devnet.rs +++ b/ant-core/src/node/devnet.rs @@ -1,16 +1,18 @@ //! Local devnet launcher for development and testing. //! -//! Wraps [`ant_node::devnet::Devnet`] and `evmlib::testnet::Testnet` (Anvil) -//! to spin up a local network with EVM payments in a few lines of code. +//! Wraps `ant_node::devnet::Devnet` and the Anvil testnet re-exported as +//! `ant_protocol::evm::testnet::Testnet` to spin up a local network with +//! EVM payments in a few lines of code. +//! +//! Available only when `ant-core` is built with `features = ["devnet"]`. use crate::data::client::ClientConfig; use crate::data::error::{Error, Result}; use crate::data::Client; -use ant_node::core::MultiAddr; use ant_node::devnet::{Devnet, DevnetConfig, DevnetEvmInfo, DevnetManifest}; -use evmlib::testnet::Testnet; -use evmlib::wallet::Wallet; -use evmlib::Network as EvmNetwork; +use ant_protocol::evm::testnet::Testnet; +use ant_protocol::evm::{Network as EvmNetwork, Wallet}; +use ant_protocol::transport::MultiAddr; use std::path::Path; use std::time::SystemTime; use tracing::info; diff --git a/ant-core/src/node/mod.rs b/ant-core/src/node/mod.rs index 9392479..d86aea4 100644 --- a/ant-core/src/node/mod.rs +++ b/ant-core/src/node/mod.rs @@ -1,5 +1,10 @@ pub mod binary; pub mod daemon; +/// In-process devnet wrapper around `ant_node::devnet::Devnet`. +/// +/// Only available with the `devnet` feature, which also pulls in the +/// `ant-node` runtime dependency. +#[cfg(feature = "devnet")] pub mod devnet; pub mod events; pub mod process; diff --git a/ant-core/src/update.rs b/ant-core/src/update.rs index 071fdce..10bee1e 100644 --- a/ant-core/src/update.rs +++ b/ant-core/src/update.rs @@ -1,7 +1,7 @@ use std::path::{Path, PathBuf}; +use ant_protocol::pqc::api::{ml_dsa_65, MlDsaPublicKey, MlDsaSignature, MlDsaVariant}; use futures_util::StreamExt; -use saorsa_pqc::api::sig::{ml_dsa_65, MlDsaPublicKey, MlDsaSignature, MlDsaVariant}; use serde::{Deserialize, Serialize}; use crate::error::{Error, Result}; diff --git a/ant-core/tests/e2e_payment.rs b/ant-core/tests/e2e_payment.rs index e999aa6..d64b3a4 100644 --- a/ant-core/tests/e2e_payment.rs +++ b/ant-core/tests/e2e_payment.rs @@ -292,7 +292,7 @@ async fn test_chunk_put_fails_with_insufficient_funds() { // Create a wallet with zero balance by using a random private key // (not the Anvil-funded default key) let evm_network = testnet.evm_network().clone(); - let empty_wallet = evmlib::wallet::Wallet::new_from_private_key( + let empty_wallet = ant_protocol::evm::Wallet::new_from_private_key( evm_network, "0x0000000000000000000000000000000000000000000000000000000000000001", ) diff --git a/ant-core/tests/e2e_security.rs b/ant-core/tests/e2e_security.rs index 072bff7..4156823 100644 --- a/ant-core/tests/e2e_security.rs +++ b/ant-core/tests/e2e_security.rs @@ -8,11 +8,10 @@ mod support; use ant_core::data::{compute_address, Client, ClientConfig}; -use ant_node::core::PeerId; -use ant_node::payment::{serialize_single_node_proof, PaymentProof, SingleNodePayment}; +use ant_protocol::evm::{Amount, EncodedPeerId, ProofOfPayment, RewardsAddress, TxHash}; +use ant_protocol::transport::PeerId; +use ant_protocol::{serialize_single_node_proof, PaymentProof, SingleNodePayment}; use bytes::Bytes; -use evmlib::common::{Amount, TxHash}; -use evmlib::{EncodedPeerId, ProofOfPayment, RewardsAddress}; use serial_test::serial; use std::sync::Arc; use support::{MiniTestnet, DEFAULT_NODE_COUNT, MEDIAN_QUOTE_INDEX}; diff --git a/ant-core/tests/e2e_upload_costs.rs b/ant-core/tests/e2e_upload_costs.rs index 47e3fb3..d0a00e2 100644 --- a/ant-core/tests/e2e_upload_costs.rs +++ b/ant-core/tests/e2e_upload_costs.rs @@ -69,7 +69,7 @@ struct CostResult { /// Measure ANT and gas cost for a single upload. async fn measure_upload_cost( client: &Client, - wallet: &evmlib::wallet::Wallet, + wallet: &ant_protocol::evm::Wallet, path: &Path, mode: PaymentMode, file_size_mb: u64, diff --git a/ant-core/tests/support/mod.rs b/ant-core/tests/support/mod.rs index 166a130..29a1cdd 100644 --- a/ant-core/tests/support/mod.rs +++ b/ant-core/tests/support/mod.rs @@ -15,20 +15,21 @@ clippy::used_underscore_binding )] -use ant_node::ant_protocol::MAX_WIRE_MESSAGE_SIZE; -use ant_node::core::{ +// Wire surface and transitive deps come through ant-protocol (single pin). +use ant_protocol::evm::testnet::Testnet; +use ant_protocol::evm::{Network as EvmNetwork, RewardsAddress, Wallet}; +use ant_protocol::transport::{ CoreNodeConfig, IPDiversityConfig, MlDsa65, MultiAddr, NodeIdentity, P2PEvent, P2PNode, }; +use ant_protocol::{CLOSE_GROUP_SIZE, MAX_WIRE_MESSAGE_SIZE}; + +// Node-internal pieces (storage, payment verifier, quote generator) stay +// with a direct ant-node dep — the test harness needs to *be* a node. use ant_node::payment::{ EvmVerifierConfig, PaymentVerifier, PaymentVerifierConfig, QuoteGenerator, QuotingMetricsTracker, }; use ant_node::storage::{AntProtocol, LmdbStorage, LmdbStorageConfig}; -use ant_node::CLOSE_GROUP_SIZE; -use evmlib::testnet::Testnet; -use evmlib::wallet::Wallet; -use evmlib::Network as EvmNetwork; -use evmlib::RewardsAddress; use rand::Rng; use std::net::{IpAddr, Ipv4Addr, SocketAddr}; use std::sync::Arc; @@ -162,7 +163,7 @@ impl MiniTestnet { // Approve token spend for the unified payment vault contract let vault_address = evm_network.payment_vault_address(); wallet - .approve_to_spend_tokens(*vault_address, evmlib::common::U256::MAX) + .approve_to_spend_tokens(*vault_address, ant_protocol::evm::U256::MAX) .await .expect("approve payment vault token spend"); @@ -255,11 +256,11 @@ impl MiniTestnet { let pub_key_bytes = identity.public_key().as_bytes().to_vec(); let sk_bytes = identity.secret_key_bytes().to_vec(); let sk = { - use saorsa_pqc::pqc::types::MlDsaSecretKey; + use ant_protocol::pqc::ops::MlDsaSecretKey; MlDsaSecretKey::from_bytes(&sk_bytes).expect("deserialize ML-DSA-65 secret key") }; quote_generator.set_signer(pub_key_bytes, move |msg| { - use saorsa_pqc::pqc::MlDsaOperations; + use ant_protocol::pqc::ops::MlDsaOperations; let ml_dsa = MlDsa65::new(); ml_dsa .sign(&sk, msg) @@ -289,7 +290,7 @@ impl MiniTestnet { let node = Arc::clone(&handler_node); let topic_clone = topic.clone(); tokio::spawn(async move { - if topic_clone != ant_node::CHUNK_PROTOCOL_ID { + if topic_clone != ant_protocol::CHUNK_PROTOCOL_ID { return; } match protocol.try_handle_request(&data).await {