From 7c7f64101f9c695fc86344e4f67d6dbb86b16dff Mon Sep 17 00:00:00 2001 From: "hinto.janai" Date: Mon, 25 Nov 2024 18:04:20 -0500 Subject: [PATCH 1/4] apply diffs --- binaries/cuprated/src/rpc/bin.rs | 25 +++++--- binaries/cuprated/src/rpc/json.rs | 26 ++++---- rpc/interface/src/route/bin.rs | 8 ++- rpc/interface/src/rpc_handler_dummy.rs | 9 ++- rpc/types/README.md | 27 +++----- rpc/types/src/bin.rs | 48 +++++++++++++-- rpc/types/src/json.rs | 85 +++++++++++++------------- test-utils/src/rpc/data/json.rs | 51 +++++++++------- 8 files changed, 164 insertions(+), 115 deletions(-) diff --git a/binaries/cuprated/src/rpc/bin.rs b/binaries/cuprated/src/rpc/bin.rs index b4e676dcc..45e63c125 100644 --- a/binaries/cuprated/src/rpc/bin.rs +++ b/binaries/cuprated/src/rpc/bin.rs @@ -1,13 +1,12 @@ use anyhow::Error; -use cuprate_rpc_types::{ - bin::{ - BinRequest, BinResponse, GetBlocksByHeightRequest, GetBlocksByHeightResponse, - GetBlocksRequest, GetBlocksResponse, GetHashesRequest, GetHashesResponse, - GetOutputIndexesRequest, GetOutputIndexesResponse, GetOutsRequest, GetOutsResponse, - GetTransactionPoolHashesRequest, GetTransactionPoolHashesResponse, - }, - json::{GetOutputDistributionRequest, GetOutputDistributionResponse}, +use cuprate_rpc_types::bin::{ + BinRequest, BinResponse, GetBlocksByHeightRequest, GetBlocksByHeightResponse, GetBlocksRequest, + GetBlocksResponse, GetHashesRequest, GetHashesResponse, GetOutputDistributionRequest, + GetOutputDistributionResponse, GetOutputIndexesRequest, GetOutputIndexesResponse, + GetOutsRequest, GetOutsResponse, GetTransactionPoolBacklogRequest, + GetTransactionPoolBacklogResponse, GetTransactionPoolHashesRequest, + GetTransactionPoolHashesResponse, }; use crate::rpc::CupratedRpcHandler; @@ -29,6 +28,9 @@ pub(super) async fn map_request( Req::GetTransactionPoolHashes(r) => { Resp::GetTransactionPoolHashes(get_transaction_pool_hashes(state, r).await?) } + Req::GetTransactionPoolBacklog(r) => { + Resp::GetTransactionPoolBacklog(get_transaction_pool_backlog(state, r).await?) + } Req::GetOutputDistribution(r) => { Resp::GetOutputDistribution(get_output_distribution(state, r).await?) } @@ -77,6 +79,13 @@ async fn get_transaction_pool_hashes( todo!() } +async fn get_transaction_pool_backlog( + state: CupratedRpcHandler, + request: GetTransactionPoolBacklogRequest, +) -> Result { + todo!() +} + async fn get_output_distribution( state: CupratedRpcHandler, request: GetOutputDistributionRequest, diff --git a/binaries/cuprated/src/rpc/json.rs b/binaries/cuprated/src/rpc/json.rs index 88b38b92f..e377d45d0 100644 --- a/binaries/cuprated/src/rpc/json.rs +++ b/binaries/cuprated/src/rpc/json.rs @@ -1,4 +1,4 @@ -use std::sync::Arc; +use std::{convert::Infallible, sync::Arc}; use anyhow::Error; use tower::ServiceExt; @@ -14,8 +14,8 @@ use cuprate_rpc_types::json::{ GetCoinbaseTxSumRequest, GetCoinbaseTxSumResponse, GetConnectionsRequest, GetConnectionsResponse, GetFeeEstimateRequest, GetFeeEstimateResponse, GetInfoRequest, GetInfoResponse, GetLastBlockHeaderRequest, GetLastBlockHeaderResponse, GetMinerDataRequest, - GetMinerDataResponse, GetOutputHistogramRequest, GetOutputHistogramResponse, - GetTransactionPoolBacklogRequest, GetTransactionPoolBacklogResponse, GetTxIdsLooseRequest, + GetMinerDataResponse, GetOutputHistogramV2Request, GetOutputHistogramV2Response, + GetTransactionPoolBacklogV2Request, GetTransactionPoolBacklogV2Response, GetTxIdsLooseRequest, GetTxIdsLooseResponse, GetVersionRequest, GetVersionResponse, HardForkInfoRequest, HardForkInfoResponse, JsonRpcRequest, JsonRpcResponse, OnGetBlockHashRequest, OnGetBlockHashResponse, PruneBlockchainRequest, PruneBlockchainResponse, RelayTxRequest, @@ -60,8 +60,8 @@ pub(super) async fn map_request( Req::FlushTransactionPool(r) => { Resp::FlushTransactionPool(flush_transaction_pool(state, r).await?) } - Req::GetOutputHistogram(r) => { - Resp::GetOutputHistogram(get_output_histogram(state, r).await?) + Req::GetOutputHistogramV2(r) => { + Resp::GetOutputHistogramV2(get_output_histogram_v2(state, r).await?) } Req::GetCoinbaseTxSum(r) => Resp::GetCoinbaseTxSum(get_coinbase_tx_sum(state, r).await?), Req::GetVersion(r) => Resp::GetVersion(get_version(state, r).await?), @@ -71,8 +71,8 @@ pub(super) async fn map_request( } Req::RelayTx(r) => Resp::RelayTx(relay_tx(state, r).await?), Req::SyncInfo(r) => Resp::SyncInfo(sync_info(state, r).await?), - Req::GetTransactionPoolBacklog(r) => { - Resp::GetTransactionPoolBacklog(get_transaction_pool_backlog(state, r).await?) + Req::GetTransactionPoolBacklogV2(r) => { + Resp::GetTransactionPoolBacklogV2(get_transaction_pool_backlog_v2(state, r).await?) } Req::GetMinerData(r) => Resp::GetMinerData(get_miner_data(state, r).await?), Req::PruneBlockchain(r) => Resp::PruneBlockchain(prune_blockchain(state, r).await?), @@ -195,10 +195,10 @@ async fn flush_transaction_pool( todo!() } -async fn get_output_histogram( +async fn get_output_histogram_v2( state: CupratedRpcHandler, - request: GetOutputHistogramRequest, -) -> Result { + request: GetOutputHistogramV2Request, +) -> Result { todo!() } @@ -244,10 +244,10 @@ async fn sync_info( todo!() } -async fn get_transaction_pool_backlog( +async fn get_transaction_pool_backlog_v2( state: CupratedRpcHandler, - request: GetTransactionPoolBacklogRequest, -) -> Result { + request: GetTransactionPoolBacklogV2Request, +) -> Result { todo!() } diff --git a/rpc/interface/src/route/bin.rs b/rpc/interface/src/route/bin.rs index f7e3a01c0..fac6ed583 100644 --- a/rpc/interface/src/route/bin.rs +++ b/rpc/interface/src/route/bin.rs @@ -8,9 +8,10 @@ use cuprate_epee_encoding::from_bytes; use cuprate_rpc_types::{ bin::{ BinRequest, BinResponse, GetBlocksByHeightRequest, GetBlocksRequest, GetHashesRequest, - GetOutputIndexesRequest, GetOutsRequest, GetTransactionPoolHashesRequest, + GetOutputDistributionRequest, GetOutputIndexesRequest, GetOutsRequest, + GetTransactionPoolBacklogRequest, GetTransactionPoolBacklogResponse, + GetTransactionPoolHashesRequest, }, - json::GetOutputDistributionRequest, RpcCall, }; @@ -102,7 +103,8 @@ generate_endpoints_with_input! { get_hashes => GetHashes, get_o_indexes => GetOutputIndexes, get_outs => GetOuts, - get_output_distribution => GetOutputDistribution + get_output_distribution => GetOutputDistribution, + get_txpool_backlog => GetTransactionPoolBacklog } generate_endpoints_with_no_input! { diff --git a/rpc/interface/src/rpc_handler_dummy.rs b/rpc/interface/src/rpc_handler_dummy.rs index 9d5009e45..1ab4a30eb 100644 --- a/rpc/interface/src/rpc_handler_dummy.rs +++ b/rpc/interface/src/rpc_handler_dummy.rs @@ -75,15 +75,15 @@ impl Service for RpcHandlerDummy { Req::GetBans(_) => Resp::GetBans(Default::default()), Req::Banned(_) => Resp::Banned(Default::default()), Req::FlushTransactionPool(_) => Resp::FlushTransactionPool(Default::default()), - Req::GetOutputHistogram(_) => Resp::GetOutputHistogram(Default::default()), + Req::GetOutputHistogramV2(_) => Resp::GetOutputHistogramV2(Default::default()), Req::GetCoinbaseTxSum(_) => Resp::GetCoinbaseTxSum(Default::default()), Req::GetVersion(_) => Resp::GetVersion(Default::default()), Req::GetFeeEstimate(_) => Resp::GetFeeEstimate(Default::default()), Req::GetAlternateChains(_) => Resp::GetAlternateChains(Default::default()), Req::RelayTx(_) => Resp::RelayTx(Default::default()), Req::SyncInfo(_) => Resp::SyncInfo(Default::default()), - Req::GetTransactionPoolBacklog(_) => { - Resp::GetTransactionPoolBacklog(Default::default()) + Req::GetTransactionPoolBacklogV2(_) => { + Resp::GetTransactionPoolBacklogV2(Default::default()) } Req::GetMinerData(_) => Resp::GetMinerData(Default::default()), Req::PruneBlockchain(_) => Resp::PruneBlockchain(Default::default()), @@ -120,6 +120,9 @@ impl Service for RpcHandlerDummy { Req::GetOutputIndexes(_) => Resp::GetOutputIndexes(Default::default()), Req::GetOuts(_) => Resp::GetOuts(Default::default()), Req::GetTransactionPoolHashes(_) => Resp::GetTransactionPoolHashes(Default::default()), + Req::GetTransactionPoolBacklog(_) => { + Resp::GetTransactionPoolBacklog(Default::default()) + } Req::GetOutputDistribution(_) => Resp::GetOutputDistribution(Default::default()), }; diff --git a/rpc/types/README.md b/rpc/types/README.md index b5a4f65fc..baff3568a 100644 --- a/rpc/types/README.md +++ b/rpc/types/README.md @@ -45,29 +45,16 @@ For example: | [`/get_blocks.bin`](https://www.getmonero.org/resources/developer-guides/daemon-rpc.html#get_blockbin) | [`bin::GetBlocksRequest`] & [`bin::GetBlocksResponse`] | [`/get_height`](https://www.getmonero.org/resources/developer-guides/daemon-rpc.html#get_height) | [`other::GetHeightRequest`] & [`other::GetHeightResponse`] -# Mixed types -Note that some types mix JSON & binary together, i.e., the message overall is JSON, -however some fields contain binary values inside JSON strings, for example: +# Deprecated types +TODO: update after finalizing . -```json -{ - "string": "", - "float": 30.0, - "integer": 30, - "binary": "" -} -``` +- [`crate::json::GetTransactionPoolBacklogV2Response`] +- [`crate::json::GetOutputDistributionV2Response`] -`binary` here is (de)serialized as a normal [`String`]. In order to be clear on which fields contain binary data, the struct fields that have them will use [`crate::misc::BinaryString`] instead of [`String`]. +# Optimized types +TODO: updated after deciding compatability <-> optimization tradeoff. -These mixed types are: -- [`crate::json::GetTransactionPoolBacklogResponse`] -- [`crate::json::GetOutputDistributionResponse`] - -TODO: we need to figure out a type that (de)serializes correctly, `String` errors with `serde_json` - -# Fixed byte containers -TODO +- Fixed byte containers