architecture book

This commit is contained in:
hinto.janai 2024-12-06 19:30:17 -05:00
parent f2e7af779f
commit 3c25374b03
No known key found for this signature in database
GPG key ID: D47CE05FA175A499
13 changed files with 33 additions and 31 deletions

1
Cargo.lock generated
View file

@ -1217,6 +1217,7 @@ dependencies = [
"cuprate-fast-sync", "cuprate-fast-sync",
"cuprate-fixed-bytes", "cuprate-fixed-bytes",
"cuprate-helper", "cuprate-helper",
"cuprate-hex",
"cuprate-json-rpc", "cuprate-json-rpc",
"cuprate-levin", "cuprate-levin",
"cuprate-p2p", "cuprate-p2p",

View file

@ -28,6 +28,7 @@ members = [
"p2p/bucket", "p2p/bucket",
"p2p/dandelion-tower", "p2p/dandelion-tower",
"p2p/address-book", "p2p/address-book",
"p2p/async-buffer",
# Storage # Storage
"storage/blockchain", "storage/blockchain",
@ -39,7 +40,6 @@ members = [
"types/types", "types/types",
"types/hex", "types/hex",
"types/fixed-bytes", "types/fixed-bytes",
"types/async-buffer",
# RPC # RPC
"rpc/json-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-epee-encoding = { path = "net/epee-encoding", default-features = false }
cuprate-levin = { path = "net/levin", default-features = false } cuprate-levin = { path = "net/levin", default-features = false }
cuprate-wire = { path = "net/wire", 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 = { path = "p2p/p2p", default-features = false }
cuprate-p2p-core = { path = "p2p/p2p-core", default-features = false } cuprate-p2p-core = { path = "p2p/p2p-core", default-features = false }
cuprate-p2p-bucket = { path = "p2p/p2p-bucket", 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-types = { path = "types/types", default-features = false }
cuprate-hex = { path = "types/hex", default-features = false } cuprate-hex = { path = "types/hex", default-features = false }
cuprate-fixed-bytes = { path = "types/fixed-bytes", 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-json-rpc = { path = "rpc/json-rpc", default-features = false }
cuprate-rpc-types = { path = "rpc/types", default-features = false } cuprate-rpc-types = { path = "rpc/types", default-features = false }
cuprate-rpc-interface = { path = "rpc/interface", default-features = false } cuprate-rpc-interface = { path = "rpc/interface", default-features = false }

View file

@ -32,6 +32,7 @@ cuprate-database = { workspace = true, features = ["serde"] }
cuprate-pruning = { workspace = true } cuprate-pruning = { workspace = true }
cuprate-test-utils = { workspace = true } cuprate-test-utils = { workspace = true }
cuprate-types = { workspace = true, features = ["json"] } cuprate-types = { workspace = true, features = ["json"] }
cuprate-hex = { workspace = true }
cuprate-json-rpc = { workspace = true } cuprate-json-rpc = { workspace = true }
cuprate-rpc-interface = { workspace = true } cuprate-rpc-interface = { workspace = true }
cuprate-rpc-types = { workspace = true, features = ["from"] } cuprate-rpc-types = { workspace = true, features = ["from"] }

View file

@ -22,6 +22,7 @@ use cuprate_helper::{
cast::{u32_to_usize, u64_to_usize, usize_to_u64}, cast::{u32_to_usize, u64_to_usize, usize_to_u64},
map::split_u128_into_low_high_bits, map::split_u128_into_low_high_bits,
}; };
use cuprate_hex::Hex;
use cuprate_p2p_core::{client::handshaker::builder::DummyAddressBook, ClearNet, Network}; use cuprate_p2p_core::{client::handshaker::builder::DummyAddressBook, ClearNet, Network};
use cuprate_rpc_interface::RpcHandler; use cuprate_rpc_interface::RpcHandler;
use cuprate_rpc_types::{ use cuprate_rpc_types::{
@ -51,7 +52,6 @@ use cuprate_rpc_types::{
CORE_RPC_VERSION, CORE_RPC_VERSION,
}; };
use cuprate_types::{ use cuprate_types::{
hex::Hex,
rpc::{AuxPow, CoinbaseTxSum, GetMinerDataTxBacklogEntry, HardForkEntry, TxBacklogEntry}, rpc::{AuxPow, CoinbaseTxSum, GetMinerDataTxBacklogEntry, HardForkEntry, TxBacklogEntry},
HardFork, HardFork,
}; };

View file

@ -24,7 +24,6 @@ cargo doc --open --package cuprate-blockchain
| Crate | In-tree path | Purpose | | 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-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-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 | [`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-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` | [`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 ## RPC
| Crate | In-tree path | Purpose | | 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-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-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-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 ## Benchmarks
| Crate | In-tree path | Purpose | | Crate | In-tree path | Purpose |

View file

@ -10,7 +10,7 @@ keywords = ["cuprate", "rpc", "types", "monero"]
[features] [features]
default = ["serde", "epee", "from"] 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"] epee = ["dep:cuprate-epee-encoding", "cuprate-types/epee"]
from = [ from = [
"dep:cuprate-helper", "dep:cuprate-helper",
@ -29,9 +29,9 @@ cuprate-types = { workspace = true, default-features = false }
cuprate-helper = { workspace = true, optional = true, default-features = false } cuprate-helper = { workspace = true, optional = true, default-features = false }
cuprate-p2p-core = { workspace = true, optional = true, default-features = false } cuprate-p2p-core = { workspace = true, optional = true, default-features = false }
paste = { workspace = true } paste = { workspace = true }
serde = { workspace = true, optional = true } serde = { workspace = true, optional = true }
hex = { workspace = true, optional = true } hex = { workspace = true, optional = true }
[dev-dependencies] [dev-dependencies]
cuprate-test-utils = { workspace = true } cuprate-test-utils = { workspace = true }

View file

@ -9,12 +9,11 @@ repository = "https://github.com/Cuprate/cuprate/tree/main/types"
keywords = ["cuprate", "hex"] keywords = ["cuprate", "hex"]
[features] [features]
default = ["serde"] default = []
serde = ["dep:serde", "hex/serde"]
[dependencies] [dependencies]
hex = { workspace = true, features = ["alloc"] } hex = { workspace = true, features = ["alloc", "serde"] }
serde = { workspace = true, features = ["std", "derive"], optional = true } serde = { workspace = true, features = ["std", "derive"] }
[dev-dependencies] [dev-dependencies]
serde_json = { workspace = true, features = ["std"] } serde_json = { workspace = true, features = ["std"] }

View file

@ -3,8 +3,8 @@
//! This module provides transparent wrapper types for //! This module provides transparent wrapper types for
//! arrays that (de)serialize from hexadecimal input/output. //! arrays that (de)serialize from hexadecimal input/output.
#[cfg(feature = "serde")] use hex::{FromHex, FromHexError};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Deserializer, Serialize};
/// Wrapper type for a byte array that (de)serializes from/to hexadecimal strings. /// Wrapper type for a byte array that (de)serializes from/to hexadecimal strings.
/// ///
@ -23,25 +23,21 @@ use serde::{Deserialize, Serialize};
/// ///
/// # Deserialization /// # Deserialization
/// This struct has a custom deserialization that only applies to certain /// 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`:
/// <https://docs.rs/hex/0.4.3/src/hex/lib.rs.html#220-230> /// <https://docs.rs/hex/0.4.3/src/hex/lib.rs.html#220-230>
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize)]
#[cfg_attr(feature = "serde", derive(Serialize))] #[serde(transparent)]
#[cfg_attr(feature = "serde", serde(transparent))]
#[repr(transparent)] #[repr(transparent)]
pub struct Hex<const N: usize>( pub struct Hex<const N: usize>(#[serde(with = "hex::serde")] pub [u8; N]);
#[cfg_attr(feature = "serde", serde(with = "hex::serde"))] pub [u8; N],
);
#[cfg(feature = "serde")]
impl<'de, const N: usize> Deserialize<'de> for Hex<N> impl<'de, const N: usize> Deserialize<'de> for Hex<N>
where where
[u8; N]: hex::FromHex, [u8; N]: FromHex,
<[u8; N] as hex::FromHex>::Error: std::fmt::Display, <[u8; N] as FromHex>::Error: std::fmt::Display,
{ {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where where
D: serde::Deserializer<'de>, D: Deserializer<'de>,
{ {
Ok(Self(hex::serde::deserialize(deserializer)?)) Ok(Self(hex::serde::deserialize(deserializer)?))
} }
@ -67,18 +63,18 @@ impl<const N: usize> From<[u8; N]> for Hex<N> {
} }
impl<const N: usize> TryFrom<String> for Hex<N> { impl<const N: usize> TryFrom<String> for Hex<N> {
type Error = hex::FromHexError; type Error = FromHexError;
fn try_from(value: String) -> Result<Self, Self::Error> { fn try_from(value: String) -> Result<Self, Self::Error> {
let vec = hex::decode(value)?; let vec = hex::decode(value)?;
match <[u8; N]>::try_from(vec) { match <[u8; N]>::try_from(vec) {
Ok(s) => Ok(Self(s)), Ok(s) => Ok(Self(s)),
Err(_) => Err(hex::FromHexError::InvalidStringLength), Err(_) => Err(FromHexError::InvalidStringLength),
} }
} }
} }
impl<const N: usize> TryFrom<&str> for Hex<N> { impl<const N: usize> TryFrom<&str> for Hex<N> {
type Error = hex::FromHexError; type Error = FromHexError;
fn try_from(value: &str) -> Result<Self, Self::Error> { fn try_from(value: &str) -> Result<Self, Self::Error> {
let mut bytes = [0; N]; let mut bytes = [0; N];
hex::decode_to_slice(value, &mut bytes).map(|()| Self(bytes)) hex::decode_to_slice(value, &mut bytes).map(|()| Self(bytes))

View file

@ -21,7 +21,7 @@ rpc = ["dep:cuprate-hex", "json"]
cuprate-epee-encoding = { workspace = true, optional = true, features = ["std"] } cuprate-epee-encoding = { workspace = true, optional = true, features = ["std"] }
cuprate-helper = { workspace = true, optional = true, features = ["cast"] } cuprate-helper = { workspace = true, optional = true, features = ["cast"] }
cuprate-fixed-bytes = { workspace = true, features = ["std", "serde"] } 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 } bytes = { workspace = true }
cfg-if = { workspace = true } cfg-if = { workspace = true }

View file

@ -10,7 +10,7 @@ repository = "https://github.com/Cuprate/cuprate/tree/main/zmq/types"
[dependencies] [dependencies]
serde = { workspace = true, features = ["derive"] } serde = { workspace = true, features = ["derive"] }
hex = { workspace = true, features = ["std", "serde"] } hex = { workspace = true, features = ["std", "serde"] }
cuprate-hex = { workspace = true, features = ["serde"] } cuprate-hex = { workspace = true }
[dev-dependencies] [dev-dependencies]
serde_json = { workspace = true, features = ["std"] } serde_json = { workspace = true, features = ["std"] }