From e6414ce90ecde768145a7de6091e4eb8244e60cf Mon Sep 17 00:00:00 2001 From: "hinto.janai" Date: Mon, 16 Sep 2024 21:09:18 -0400 Subject: [PATCH] `rpc.rs` docs --- Cargo.lock | 5 ++ constants/Cargo.toml | 7 ++- constants/src/block.rs | 3 ++ constants/src/build.rs | 2 +- constants/src/lib.rs | 1 + constants/src/rpc.rs | 104 +++++++++++++++++++++++++++++++++-------- constants/src/tx.rs | 2 +- 7 files changed, 101 insertions(+), 23 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c6395c9..82c2891 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -602,6 +602,11 @@ dependencies = [ [[package]] name = "cuprate-constants" version = "0.0.0" +dependencies = [ + "hex", + "monero-serai", + "pretty_assertions", +] [[package]] name = "cuprate-cryptonight" diff --git a/constants/Cargo.toml b/constants/Cargo.toml index 37d506c..6facdfa 100644 --- a/constants/Cargo.toml +++ b/constants/Cargo.toml @@ -9,11 +9,16 @@ repository = "https://github.com/Cuprate/cuprate/tree/main/constants" keywords = ["cuprate", "constants"] [features] -default = [] +default = ["monero-serai"] +monero-serai = ["dep:monero-serai"] [dependencies] +monero-serai = { workspace = true, optional = true } [dev-dependencies] +monero-serai = { workspace = true } +hex = { workspace = true, features = ["std"] } +pretty_assertions = { workspace = true } [lints] workspace = true \ No newline at end of file diff --git a/constants/src/block.rs b/constants/src/block.rs index 3059e38..4ecb158 100644 --- a/constants/src/block.rs +++ b/constants/src/block.rs @@ -62,3 +62,6 @@ pub const BULLETPROOF_MAX_OUTPUTS: u64 = 16; /// TODO pub const BULLETPROOF_PLUS_MAX_OUTPUTS: u64 = 16; + +/// TODO +pub const BLOCK_SIZE_SANITY_LEEWAY: usize = 100; diff --git a/constants/src/build.rs b/constants/src/build.rs index af11ef7..37b5ae3 100644 --- a/constants/src/build.rs +++ b/constants/src/build.rs @@ -9,7 +9,7 @@ /// /// ```rust /// # use cuprate_constants::build::*; -/// assert_eq!(COMMIT.is_ascii()); +/// assert!(COMMIT.is_ascii()); /// assert_eq!(COMMIT.as_bytes().len(), 40); /// assert_eq!(COMMIT.to_lowercase(), COMMIT); /// ``` diff --git a/constants/src/lib.rs b/constants/src/lib.rs index a34d96e..78a859f 100644 --- a/constants/src/lib.rs +++ b/constants/src/lib.rs @@ -6,6 +6,7 @@ mod macros; pub mod block; pub mod build; pub mod difficulty; +pub mod genesis; pub mod hard_fork; pub mod money; pub mod net; diff --git a/constants/src/rpc.rs b/constants/src/rpc.rs index be42c4c..4b3806b 100644 --- a/constants/src/rpc.rs +++ b/constants/src/rpc.rs @@ -3,38 +3,102 @@ //! - //! - -/// TODO -pub const MAX_RESTRICTED_FAKE_OUTS_COUNT: usize = 40; +use std::time::Duration; -/// TODO -pub const MAX_RESTRICTED_GLOBAL_FAKE_OUTS_COUNT: usize = 5000; +use crate::macros::monero_definition_link; -/// 3 days max, the wallet requests 1.8: usize = days. -pub const OUTPUT_HISTOGRAM_RECENT_CUTOFF_RESTRICTION: usize = 3 * 86400; - -/// TODO +/// Maximum requestable block header range. +#[doc = monero_definition_link!(a1dc85c5373a30f14aaf7dcfdd95f5a7375d3623, "/src/rpc/core_rpc_server.cpp", 74)] +/// +/// This is the maximum amount of blocks that can be requested +/// per invocation of `get_block_headers` if the RPC server is +/// in restricted mode. +/// +/// Used at: +/// - pub const RESTRICTED_BLOCK_HEADER_RANGE: u64 = 1000; -/// TODO +/// Maximum requestable transaction count. +#[doc = monero_definition_link!(a1dc85c5373a30f14aaf7dcfdd95f5a7375d3623, "/src/rpc/core_rpc_server.cpp", 75)] +/// +/// This is the maximum amount of transactions that can be requested +/// per invocation of `get_transactions` and `get_indexes` if the +/// RPC server is in restricted mode. +/// +/// Used at: +/// - +/// - pub const RESTRICTED_TRANSACTIONS_COUNT: usize = 100; -/// TODO +/// Maximum amount of requestable key image checks. +#[doc = monero_definition_link!(a1dc85c5373a30f14aaf7dcfdd95f5a7375d3623, "/src/rpc/core_rpc_server.cpp", 76)] +/// +/// This is the maximum amount of key images that can be requested +/// to be checked per `/is_key_image_spent` call if the RPC server +/// is in restricted mode. +/// +/// Used at: +/// - +/// - pub const RESTRICTED_SPENT_KEY_IMAGES_COUNT: usize = 5000; -/// TODO +/// Maximum amount of requestable blocks. +#[doc = monero_definition_link!(a1dc85c5373a30f14aaf7dcfdd95f5a7375d3623, "/src/rpc/core_rpc_server.cpp", 77)] +/// +/// This is the maximum amount of blocks that can be +/// requested if the RPC server is in restricted mode. +/// +/// Used at: +/// - +/// - pub const RESTRICTED_BLOCK_COUNT: usize = 1000; -/// TODO -pub const BLOCK_SIZE_SANITY_LEEWAY: usize = 100; +/// Maximum amount of fake outputs. +#[doc = monero_definition_link!(a1dc85c5373a30f14aaf7dcfdd95f5a7375d3623, "/src/rpc/core_rpc_server.cpp", 67)] +/// +/// This is the maximum amount of outputs that can be +/// requested if the RPC server is in restricted mode. +/// +/// Used at: +/// - +/// - +pub const MAX_RESTRICTED_GLOBAL_FAKE_OUTS_COUNT: usize = 5000; -/// TODO -pub const COMMAND_RPC_GET_BLOCKS_FAST_MAX_BLOCK_COUNT: u64 = 1000; +/// Maximum output histrogram cutoff. +#[doc = monero_definition_link!(a1dc85c5373a30f14aaf7dcfdd95f5a7375d3623, "/src/rpc/core_rpc_server.cpp", 69)] +/// +/// This is the maximum cutoff duration allowed in `get_output_histogram` (3 days). +/// +/// ```rust +/// # use cuprate_constants::rpc::*; +/// assert_eq!(OUTPUT_HISTOGRAM_RECENT_CUTOFF_RESTRICTION.as_secs(), 86_400 * 3); +/// ``` +/// +/// Used at: +/// +pub const OUTPUT_HISTOGRAM_RECENT_CUTOFF_RESTRICTION: Duration = Duration::from_secs(86400 * 3); -/// TODO -pub const COMMAND_RPC_GET_BLOCKS_FAST_MAX_TX_COUNT: u64 = 20_000; +/// Maximum amount of requestable blocks in `/get_blocks.bin`. +#[doc = monero_definition_link!(a1dc85c5373a30f14aaf7dcfdd95f5a7375d3623, "/src/cryptonote_config.h", 128)] +pub const GET_BLOCKS_BIN_MAX_BLOCK_COUNT: u64 = 1000; -/// TODO -pub const MAX_RPC_CONTENT_LENGTH: u64 = 1_048_576; // 1 MB +/// Maximum amount of requestable transactions in `/get_blocks.bin`. +#[doc = monero_definition_link!(a1dc85c5373a30f14aaf7dcfdd95f5a7375d3623, "/src/cryptonote_config.h", 129)] +pub const GET_BLOCKS_BIN_MAX_TX_COUNT: u64 = 20_000; -/// TODO +/// Max message content length in the RPC server. +#[doc = monero_definition_link!(a1dc85c5373a30f14aaf7dcfdd95f5a7375d3623, "/src/cryptonote_config.h", 130)] +/// +/// This is the maximum amount of bytes an HTTP request +/// body can be before the RPC server rejects it (1 megabyte). +pub const MAX_RPC_CONTENT_LENGTH: u64 = 1_048_576; + +/// Amount of fails before blocking a remote RPC server. +#[doc = monero_definition_link!(a1dc85c5373a30f14aaf7dcfdd95f5a7375d3623, "/src/cryptonote_config.h", 159)] +/// +/// This is the amount of times an RPC will attempt to +/// connect to another remote IP before blocking it. +/// +/// RPC servers connect to nodes when they themselves +/// lack the data to fulfill the response. pub const RPC_IP_FAILS_BEFORE_BLOCK: u64 = 3; diff --git a/constants/src/tx.rs b/constants/src/tx.rs index 10bd806..824660c 100644 --- a/constants/src/tx.rs +++ b/constants/src/tx.rs @@ -55,7 +55,7 @@ pub const MEMPOOL_TX_LIFETIME: Duration = Duration::from_secs(86_400 * 3); /// # use cuprate_constants::tx::*; /// assert_eq!(MEMPOOL_TX_FROM_ALT_BLOCK_LIVETIME.as_secs(), 86_400 * 7); /// ``` -pub const MEMPOOL_TX_FROM_ALT_BLOCK_LIVETIME: u64 = 86_400 * 7; +pub const MEMPOOL_TX_FROM_ALT_BLOCK_LIVETIME: Duration = Duration::from_secs(86_400 * 7); /// TODO pub const PER_KB_FEE_QUANTIZATION_DECIMALS: u64 = 8;