diff --git a/Cargo.lock b/Cargo.lock index 2c802e8..661e5f2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1217,6 +1217,7 @@ dependencies = [ "cuprate-fast-sync", "cuprate-fixed-bytes", "cuprate-helper", + "cuprate-hex", "cuprate-json-rpc", "cuprate-levin", "cuprate-p2p", diff --git a/Cargo.toml b/Cargo.toml index 5e50fe8..1c9b5b6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,6 +28,7 @@ members = [ "p2p/bucket", "p2p/dandelion-tower", "p2p/address-book", + "p2p/async-buffer", # Storage "storage/blockchain", @@ -39,7 +40,6 @@ members = [ "types/types", "types/hex", "types/fixed-bytes", - "types/async-buffer", # RPC "rpc/json-rpc", @@ -90,6 +90,7 @@ cuprate-helper = { path = "helper", default-featur cuprate-epee-encoding = { path = "net/epee-encoding", default-features = false } cuprate-levin = { path = "net/levin", default-features = false } cuprate-wire = { path = "net/wire", default-features = false } +cuprate-async-buffer = { path = "p2p/async-buffer", default-features = false } cuprate-p2p = { path = "p2p/p2p", default-features = false } cuprate-p2p-core = { path = "p2p/p2p-core", default-features = false } cuprate-p2p-bucket = { path = "p2p/p2p-bucket", default-features = false } @@ -104,7 +105,6 @@ cuprate-test-utils = { path = "test-utils", default-featur cuprate-types = { path = "types/types", default-features = false } cuprate-hex = { path = "types/hex", default-features = false } cuprate-fixed-bytes = { path = "types/fixed-bytes", default-features = false } -cuprate-async-buffer = { path = "types/async-buffer", default-features = false } cuprate-json-rpc = { path = "rpc/json-rpc", default-features = false } cuprate-rpc-types = { path = "rpc/types", default-features = false } cuprate-rpc-interface = { path = "rpc/interface", default-features = false } diff --git a/binaries/cuprated/Cargo.toml b/binaries/cuprated/Cargo.toml index e1d0573..24e824b 100644 --- a/binaries/cuprated/Cargo.toml +++ b/binaries/cuprated/Cargo.toml @@ -32,6 +32,7 @@ cuprate-database = { workspace = true, features = ["serde"] } cuprate-pruning = { workspace = true } cuprate-test-utils = { workspace = true } cuprate-types = { workspace = true, features = ["json"] } +cuprate-hex = { workspace = true } cuprate-json-rpc = { workspace = true } cuprate-rpc-interface = { workspace = true } cuprate-rpc-types = { workspace = true, features = ["from"] } diff --git a/binaries/cuprated/src/rpc/json.rs b/binaries/cuprated/src/rpc/json.rs index c42d6e4..462b140 100644 --- a/binaries/cuprated/src/rpc/json.rs +++ b/binaries/cuprated/src/rpc/json.rs @@ -22,6 +22,7 @@ use cuprate_helper::{ cast::{u32_to_usize, u64_to_usize, usize_to_u64}, map::split_u128_into_low_high_bits, }; +use cuprate_hex::Hex; use cuprate_p2p_core::{client::handshaker::builder::DummyAddressBook, ClearNet, Network}; use cuprate_rpc_interface::RpcHandler; use cuprate_rpc_types::{ @@ -51,7 +52,6 @@ use cuprate_rpc_types::{ CORE_RPC_VERSION, }; use cuprate_types::{ - hex::Hex, rpc::{AuxPow, CoinbaseTxSum, GetMinerDataTxBacklogEntry, HardForkEntry, TxBacklogEntry}, HardFork, }; diff --git a/books/architecture/src/appendix/crates.md b/books/architecture/src/appendix/crates.md index 5124180..d63576a 100644 --- a/books/architecture/src/appendix/crates.md +++ b/books/architecture/src/appendix/crates.md @@ -24,7 +24,6 @@ cargo doc --open --package cuprate-blockchain | Crate | In-tree path | Purpose | |-------|--------------|---------| | [`cuprate-epee-encoding`](https://doc.cuprate.org/cuprate_epee_encoding) | [`net/epee-encoding/`](https://github.com/Cuprate/cuprate/tree/main/net/epee-encoding) | Epee (de)serialization -| [`cuprate-fixed-bytes`](https://doc.cuprate.org/cuprate_fixed_bytes) | [`net/fixed-bytes/`](https://github.com/Cuprate/cuprate/tree/main/net/fixed-bytes) | Fixed byte containers backed by `byte::Byte` | [`cuprate-levin`](https://doc.cuprate.org/cuprate_levin) | [`net/levin/`](https://github.com/Cuprate/cuprate/tree/main/net/levin) | Levin bucket protocol implementation | [`cuprate-wire`](https://doc.cuprate.org/cuprate_wire) | [`net/wire/`](https://github.com/Cuprate/cuprate/tree/main/net/wire) | TODO @@ -46,6 +45,13 @@ cargo doc --open --package cuprate-blockchain | [`cuprate-database-service`](https://doc.cuprate.org/cuprate_database_service) | [`storage/database-service/`](https://github.com/Cuprate/cuprate/tree/main/storage/database-service) | `tower::Service` + thread-pool abstraction built on-top of `cuprate-database` | [`cuprate-txpool`](https://doc.cuprate.org/cuprate_txpool) | [`storage/txpool/`](https://github.com/Cuprate/cuprate/tree/main/storage/txpool) | Transaction pool database built on-top of `cuprate-database` & `cuprate-database-service` +## Types +| Crate | In-tree path | Purpose | +|-------|--------------|---------| +| [`cuprate-types`](https://doc.cuprate.org/cuprate_types) | [`types/types/`](https://github.com/Cuprate/cuprate/tree/main/types/types) | General types used throughout Cuprate | +| [`cuprate-hex`](https://doc.cuprate.org/cuprate_hex) | [`types/hex/`](https://github.com/Cuprate/cuprate/tree/main/types/hex) | Hexadecimal data types | +| [`cuprate-fixed-bytes`](https://doc.cuprate.org/cuprate_fixed_bytes) | [`net/fixed-bytes/`](https://github.com/Cuprate/cuprate/tree/main/net/fixed-bytes) | Fixed byte containers backed by `byte::Byte` + ## RPC | Crate | In-tree path | Purpose | |-------|--------------|---------| @@ -67,7 +73,6 @@ cargo doc --open --package cuprate-blockchain | [`cuprate-pruning`](https://doc.cuprate.org/cuprate_pruning) | [`pruning/`](https://github.com/Cuprate/cuprate/tree/main/pruning) | Monero pruning logic/types | [`cuprate-helper`](https://doc.cuprate.org/cuprate_helper) | [`helper/`](https://github.com/Cuprate/cuprate/tree/main/helper) | Kitchen-sink helper crate for Cuprate | [`cuprate-test-utils`](https://doc.cuprate.org/cuprate_test_utils) | [`test-utils/`](https://github.com/Cuprate/cuprate/tree/main/test-utils) | Testing utilities for Cuprate -| [`cuprate-types`](https://doc.cuprate.org/cuprate_types) | [`types/`](https://github.com/Cuprate/cuprate/tree/main/types) | Shared types across Cuprate ## Benchmarks | Crate | In-tree path | Purpose | diff --git a/types/async-buffer/Cargo.toml b/p2p/async-buffer/Cargo.toml similarity index 100% rename from types/async-buffer/Cargo.toml rename to p2p/async-buffer/Cargo.toml diff --git a/types/async-buffer/src/lib.rs b/p2p/async-buffer/src/lib.rs similarity index 100% rename from types/async-buffer/src/lib.rs rename to p2p/async-buffer/src/lib.rs diff --git a/types/async-buffer/tests/basic.rs b/p2p/async-buffer/tests/basic.rs similarity index 100% rename from types/async-buffer/tests/basic.rs rename to p2p/async-buffer/tests/basic.rs diff --git a/rpc/types/Cargo.toml b/rpc/types/Cargo.toml index 3570626..4d721e9 100644 --- a/rpc/types/Cargo.toml +++ b/rpc/types/Cargo.toml @@ -10,7 +10,7 @@ keywords = ["cuprate", "rpc", "types", "monero"] [features] default = ["serde", "epee", "from"] -serde = ["dep:serde", "cuprate-fixed-bytes/serde", "cuprate-types/serde", "cuprate-hex/serde"] +serde = ["dep:serde", "cuprate-fixed-bytes/serde", "cuprate-types/serde"] epee = ["dep:cuprate-epee-encoding", "cuprate-types/epee"] from = [ "dep:cuprate-helper", @@ -29,9 +29,9 @@ cuprate-types = { workspace = true, default-features = false } cuprate-helper = { workspace = true, optional = true, default-features = false } cuprate-p2p-core = { workspace = true, optional = true, default-features = false } -paste = { workspace = true } -serde = { workspace = true, optional = true } -hex = { workspace = true, optional = true } +paste = { workspace = true } +serde = { workspace = true, optional = true } +hex = { workspace = true, optional = true } [dev-dependencies] cuprate-test-utils = { workspace = true } diff --git a/types/hex/Cargo.toml b/types/hex/Cargo.toml index 128b113..7391f26 100644 --- a/types/hex/Cargo.toml +++ b/types/hex/Cargo.toml @@ -9,12 +9,11 @@ repository = "https://github.com/Cuprate/cuprate/tree/main/types" keywords = ["cuprate", "hex"] [features] -default = ["serde"] -serde = ["dep:serde", "hex/serde"] +default = [] [dependencies] -hex = { workspace = true, features = ["alloc"] } -serde = { workspace = true, features = ["std", "derive"], optional = true } +hex = { workspace = true, features = ["alloc", "serde"] } +serde = { workspace = true, features = ["std", "derive"] } [dev-dependencies] serde_json = { workspace = true, features = ["std"] } diff --git a/types/hex/src/hex.rs b/types/hex/src/hex.rs index 8c5dcae..ecf2222 100644 --- a/types/hex/src/hex.rs +++ b/types/hex/src/hex.rs @@ -3,8 +3,8 @@ //! This module provides transparent wrapper types for //! arrays that (de)serialize from hexadecimal input/output. -#[cfg(feature = "serde")] -use serde::{Deserialize, Serialize}; +use hex::{FromHex, FromHexError}; +use serde::{Deserialize, Deserializer, Serialize}; /// Wrapper type for a byte array that (de)serializes from/to hexadecimal strings. /// @@ -23,25 +23,21 @@ use serde::{Deserialize, Serialize}; /// /// # Deserialization /// This struct has a custom deserialization that only applies to certain -/// `N` lengths because [`hex::FromHex`] does not implement for a generic `N`: +/// `N` lengths because [`FromHex`] does not implement for a generic `N`: /// -#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize))] -#[cfg_attr(feature = "serde", serde(transparent))] +#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize)] +#[serde(transparent)] #[repr(transparent)] -pub struct Hex( - #[cfg_attr(feature = "serde", serde(with = "hex::serde"))] pub [u8; N], -); +pub struct Hex(#[serde(with = "hex::serde")] pub [u8; N]); -#[cfg(feature = "serde")] impl<'de, const N: usize> Deserialize<'de> for Hex where - [u8; N]: hex::FromHex, - <[u8; N] as hex::FromHex>::Error: std::fmt::Display, + [u8; N]: FromHex, + <[u8; N] as FromHex>::Error: std::fmt::Display, { fn deserialize(deserializer: D) -> Result where - D: serde::Deserializer<'de>, + D: Deserializer<'de>, { Ok(Self(hex::serde::deserialize(deserializer)?)) } @@ -67,18 +63,18 @@ impl From<[u8; N]> for Hex { } impl TryFrom for Hex { - type Error = hex::FromHexError; + type Error = FromHexError; fn try_from(value: String) -> Result { let vec = hex::decode(value)?; match <[u8; N]>::try_from(vec) { Ok(s) => Ok(Self(s)), - Err(_) => Err(hex::FromHexError::InvalidStringLength), + Err(_) => Err(FromHexError::InvalidStringLength), } } } impl TryFrom<&str> for Hex { - type Error = hex::FromHexError; + type Error = FromHexError; fn try_from(value: &str) -> Result { let mut bytes = [0; N]; hex::decode_to_slice(value, &mut bytes).map(|()| Self(bytes)) diff --git a/types/types/Cargo.toml b/types/types/Cargo.toml index 8aade17..84901a3 100644 --- a/types/types/Cargo.toml +++ b/types/types/Cargo.toml @@ -21,7 +21,7 @@ rpc = ["dep:cuprate-hex", "json"] cuprate-epee-encoding = { workspace = true, optional = true, features = ["std"] } cuprate-helper = { workspace = true, optional = true, features = ["cast"] } cuprate-fixed-bytes = { workspace = true, features = ["std", "serde"] } -cuprate-hex = { workspace = true, optional = true, features = ["serde"] } +cuprate-hex = { workspace = true, optional = true } bytes = { workspace = true } cfg-if = { workspace = true } diff --git a/zmq/types/Cargo.toml b/zmq/types/Cargo.toml index ad60765..4cd346e 100644 --- a/zmq/types/Cargo.toml +++ b/zmq/types/Cargo.toml @@ -10,7 +10,7 @@ repository = "https://github.com/Cuprate/cuprate/tree/main/zmq/types" [dependencies] serde = { workspace = true, features = ["derive"] } hex = { workspace = true, features = ["std", "serde"] } -cuprate-hex = { workspace = true, features = ["serde"] } +cuprate-hex = { workspace = true } [dev-dependencies] serde_json = { workspace = true, features = ["std"] }