From 13eedc6d800ed9d0857dd442ceffb6ca6cdaa5dd Mon Sep 17 00:00:00 2001 From: "hinto.janai" Date: Thu, 17 Oct 2024 18:32:47 -0400 Subject: [PATCH] sig docs, remove `HardForks` request --- Cargo.lock | 1 + binaries/cuprated/Cargo.toml | 1 + binaries/cuprated/src/rpc/json.rs | 24 ++++++++++++------- .../cuprated/src/rpc/request/blockchain.rs | 16 ------------- storage/blockchain/src/service/read.rs | 6 ----- storage/txpool/src/service/interface.rs | 12 ++++++---- storage/txpool/src/tx.rs | 9 +++---- types/src/blockchain.rs | 19 ++++----------- 8 files changed, 36 insertions(+), 52 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 089236a2..76ad13f0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1010,6 +1010,7 @@ dependencies = [ "serde", "serde_bytes", "serde_json", + "strum", "thiserror", "thread_local", "tokio", diff --git a/binaries/cuprated/Cargo.toml b/binaries/cuprated/Cargo.toml index 7ec85796..dc504d8d 100644 --- a/binaries/cuprated/Cargo.toml +++ b/binaries/cuprated/Cargo.toml @@ -65,6 +65,7 @@ rayon = { workspace = true } serde_bytes = { workspace = true } serde_json = { workspace = true } serde = { workspace = true } +strum = { workspace = true } thiserror = { workspace = true } thread_local = { workspace = true } tokio-util = { workspace = true } diff --git a/binaries/cuprated/src/rpc/json.rs b/binaries/cuprated/src/rpc/json.rs index a8ee552b..ed080296 100644 --- a/binaries/cuprated/src/rpc/json.rs +++ b/binaries/cuprated/src/rpc/json.rs @@ -5,7 +5,9 @@ use std::{ use anyhow::{anyhow, Error}; use cuprate_p2p_core::{client::handshaker::builder::DummyAddressBook, ClearNet}; +use futures::TryFutureExt; use monero_serai::block::Block; +use strum::{EnumCount, VariantArray}; use tower::{Service, ServiceExt}; use cuprate_consensus::{BlockchainReadRequest, BlockchainResponse}; @@ -673,14 +675,20 @@ async fn get_version( let current_height = helper::top_height(&mut state).await?.0; let target_height = blockchain_manager::target_height(&mut state.blockchain_manager).await?; - let hard_forks = blockchain::hard_forks(&mut state.blockchain_read) - .await? - .into_iter() - .map(|(height, hf)| HardforkEntry { - height: usize_to_u64(height), - hf_version: hf.as_u8(), - }) - .collect(); + let mut hard_forks = Vec::with_capacity(HardFork::COUNT); + + // FIXME: use an iterator `collect()` version. + for hf in HardFork::VARIANTS { + if let Ok(hf) = blockchain_context::hard_fork_info(&mut state.blockchain_context, *hf).await + { + let entry = HardforkEntry { + height: hf.earliest_height, + hf_version: hf.version, + }; + + hard_forks.push(entry); + } + } Ok(GetVersionResponse { base: ResponseBase::OK, diff --git a/binaries/cuprated/src/rpc/request/blockchain.rs b/binaries/cuprated/src/rpc/request/blockchain.rs index 36f43fa9..97c7f48b 100644 --- a/binaries/cuprated/src/rpc/request/blockchain.rs +++ b/binaries/cuprated/src/rpc/request/blockchain.rs @@ -344,22 +344,6 @@ pub(crate) async fn coinbase_tx_sum( Ok(sum) } -/// [`BlockchainReadRequest::HardForks`] -pub(crate) async fn hard_forks( - blockchain_read: &mut BlockchainReadHandle, -) -> Result, Error> { - let BlockchainResponse::HardForks(hfs) = blockchain_read - .ready() - .await? - .call(BlockchainReadRequest::HardForks) - .await? - else { - unreachable!(); - }; - - Ok(hfs) -} - /// [`BlockchainReadRequest::AltChains`] pub(crate) async fn alt_chains( blockchain_read: &mut BlockchainReadHandle, diff --git a/storage/blockchain/src/service/read.rs b/storage/blockchain/src/service/read.rs index 76d44a27..e3c01802 100644 --- a/storage/blockchain/src/service/read.rs +++ b/storage/blockchain/src/service/read.rs @@ -121,7 +121,6 @@ fn map_request( R::DatabaseSize => database_size(env), R::OutputHistogram(input) => output_histogram(env, input), R::CoinbaseTxSum { height, count } => coinbase_tx_sum(env, height, count), - R::HardForks => hard_forks(env), R::AltChains => alt_chains(env), R::AltChainCount => alt_chain_count(env), } @@ -652,11 +651,6 @@ fn coinbase_tx_sum(env: &ConcreteEnv, height: usize, count: u64) -> ResponseResu Ok(BlockchainResponse::CoinbaseTxSum(todo!())) } -/// [`BlockchainReadRequest::HardForks`] -fn hard_forks(env: &ConcreteEnv) -> ResponseResult { - Ok(BlockchainResponse::HardForks(todo!())) -} - /// [`BlockchainReadRequest::AltChains`] fn alt_chains(env: &ConcreteEnv) -> ResponseResult { Ok(BlockchainResponse::AltChains(todo!())) diff --git a/storage/txpool/src/service/interface.rs b/storage/txpool/src/service/interface.rs index 394162a0..931154e1 100644 --- a/storage/txpool/src/service/interface.rs +++ b/storage/txpool/src/service/interface.rs @@ -22,12 +22,16 @@ pub enum TxpoolReadRequest { /// Get information on all transactions in the pool. Backlog, - /// TODO + /// Get information on all transactions in + /// the pool for block template purposes. + /// + /// This is only slightly different to [`TxpoolReadRequest::Backlog`]. BlockTemplateBacklog, /// Get the number of transactions in the pool. Size { - /// TODO + /// If this is [`true`], the size returned will + /// include private transactions in the pool. include_sensitive_txs: bool, }, } @@ -47,13 +51,13 @@ pub enum TxpoolReadResponse { /// Response to [`TxpoolReadRequest::Backlog`]. /// - /// The inner `Vec` contains information on all + /// The inner [`Vec`] contains information on all /// the transactions currently in the pool. Backlog(Vec), /// Response to [`TxpoolReadRequest::BlockTemplateBacklog`]. /// - /// TODO + /// The inner [`Vec`] contains information on transactions BlockTemplateBacklog(Vec), /// Response to [`TxpoolReadRequest::Size`]. diff --git a/storage/txpool/src/tx.rs b/storage/txpool/src/tx.rs index 7daff156..03cc48c4 100644 --- a/storage/txpool/src/tx.rs +++ b/storage/txpool/src/tx.rs @@ -13,15 +13,16 @@ pub struct TxEntry { pub time_in_pool: std::time::Duration, } -/// TODO +/// Data about a transaction in the pool +/// for use in a block template. /// /// Used in [`TxpoolReadResponse::BlockTemplateBacklog`](crate::service::interface::TxpoolReadResponse::BlockTemplateBacklog). #[derive(Copy, Clone, Debug, Ord, PartialOrd, Eq, PartialEq, Hash)] pub struct BlockTemplateTxEntry { - /// TODO + /// The transaction's ID (hash). pub id: [u8; 32], - /// TODO + /// The transaction's weight. pub weight: u64, - /// TODO + /// The transaction's fee. pub fee: u64, } diff --git a/types/src/blockchain.rs b/types/src/blockchain.rs index 49fec073..c39c0bd8 100644 --- a/types/src/blockchain.rs +++ b/types/src/blockchain.rs @@ -4,7 +4,7 @@ //! responses are also tested in Cuprate's blockchain database crate. //---------------------------------------------------------------------------------------------------- Import use std::{ - collections::{BTreeMap, HashMap, HashSet}, + collections::{HashMap, HashSet}, ops::Range, }; @@ -12,7 +12,7 @@ use monero_serai::block::Block; use crate::{ types::{Chain, ExtendedBlockHeader, OutputOnChain, VerifiedBlockInformation}, - AltBlockInformation, ChainId, ChainInfo, CoinbaseTxSum, HardFork, OutputHistogramEntry, + AltBlockInformation, ChainId, ChainInfo, CoinbaseTxSum, OutputHistogramEntry, OutputHistogramInput, }; @@ -130,13 +130,10 @@ pub enum BlockchainReadRequest { /// TODO: document fields after impl. CoinbaseTxSum { height: usize, count: u64 }, - /// TODO - HardForks, - - /// TODO + /// Get information on all alternative chains. AltChains, - /// TODO + /// Get the amount of alternative chains that exist. AltChainCount, } @@ -286,13 +283,7 @@ pub enum BlockchainResponse { /// Response to [`BlockchainReadRequest::CoinbaseTxSum`]. CoinbaseTxSum(CoinbaseTxSum), - /// Response to [`BlockchainReadRequest::HardForks`]. - /// - /// - Key = height at which the hardfork activated - /// - Value = hardfork version - HardForks(BTreeMap), - - /// TODO + /// Response to [`BlockchainReadRequest::AltChains`]. AltChains(Vec), /// Response to [`BlockchainReadRequest::AltChainCount`].