Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rpc: replace binary string endpoints/types #349

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions binaries/cuprated/src/rpc/bin.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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?)
}
Expand Down Expand Up @@ -77,6 +79,13 @@ async fn get_transaction_pool_hashes(
todo!()
}

async fn get_transaction_pool_backlog(
state: CupratedRpcHandler,
request: GetTransactionPoolBacklogRequest,
) -> Result<GetTransactionPoolBacklogResponse, Error> {
todo!()
}

async fn get_output_distribution(
state: CupratedRpcHandler,
request: GetOutputDistributionRequest,
Expand Down
37 changes: 24 additions & 13 deletions binaries/cuprated/src/rpc/json.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::sync::Arc;
use std::{convert::Infallible, sync::Arc};

use anyhow::Error;
use tower::ServiceExt;
Expand All @@ -14,13 +14,14 @@ use cuprate_rpc_types::json::{
GetCoinbaseTxSumRequest, GetCoinbaseTxSumResponse, GetConnectionsRequest,
GetConnectionsResponse, GetFeeEstimateRequest, GetFeeEstimateResponse, GetInfoRequest,
GetInfoResponse, GetLastBlockHeaderRequest, GetLastBlockHeaderResponse, GetMinerDataRequest,
GetMinerDataResponse, GetOutputHistogramRequest, GetOutputHistogramResponse,
GetTransactionPoolBacklogRequest, GetTransactionPoolBacklogResponse, GetTxIdsLooseRequest,
GetTxIdsLooseResponse, GetVersionRequest, GetVersionResponse, HardForkInfoRequest,
HardForkInfoResponse, JsonRpcRequest, JsonRpcResponse, OnGetBlockHashRequest,
OnGetBlockHashResponse, PruneBlockchainRequest, PruneBlockchainResponse, RelayTxRequest,
RelayTxResponse, SetBansRequest, SetBansResponse, SubmitBlockRequest, SubmitBlockResponse,
SyncInfoRequest, SyncInfoResponse,
GetMinerDataResponse, GetOutputDistributionV2Request, GetOutputDistributionV2Response,
GetOutputHistogramRequest, GetOutputHistogramResponse, GetTransactionPoolBacklogV2Request,
GetTransactionPoolBacklogV2Response, GetTxIdsLooseRequest, GetTxIdsLooseResponse,
GetVersionRequest, GetVersionResponse, HardForkInfoRequest, HardForkInfoResponse,
JsonRpcRequest, JsonRpcResponse, OnGetBlockHashRequest, OnGetBlockHashResponse,
PruneBlockchainRequest, PruneBlockchainResponse, RelayTxRequest, RelayTxResponse,
SetBansRequest, SetBansResponse, SubmitBlockRequest, SubmitBlockResponse, SyncInfoRequest,
SyncInfoResponse,
};

use crate::rpc::CupratedRpcHandler;
Expand Down Expand Up @@ -71,8 +72,11 @@ 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::GetOutputDistributionV2(r) => {
Resp::GetOutputDistributionV2(get_output_distribution_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?),
Expand Down Expand Up @@ -244,10 +248,17 @@ async fn sync_info(
todo!()
}

async fn get_transaction_pool_backlog(
async fn get_transaction_pool_backlog_v2(
state: CupratedRpcHandler,
request: GetTransactionPoolBacklogV2Request,
) -> Result<GetTransactionPoolBacklogV2Response, Error> {
todo!()
}

async fn get_output_distribution_v2(
state: CupratedRpcHandler,
request: GetTransactionPoolBacklogRequest,
) -> Result<GetTransactionPoolBacklogResponse, Error> {
request: GetOutputDistributionV2Request,
) -> Result<GetOutputDistributionV2Response, Error> {
todo!()
}

Expand Down
7 changes: 4 additions & 3 deletions rpc/interface/src/route/bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use cuprate_epee_encoding::from_bytes;
use cuprate_rpc_types::{
bin::{
BinRequest, BinResponse, GetBlocksByHeightRequest, GetBlocksRequest, GetHashesRequest,
GetOutputIndexesRequest, GetOutsRequest, GetTransactionPoolHashesRequest,
GetOutputDistributionRequest, GetOutputIndexesRequest, GetOutsRequest,
GetTransactionPoolBacklogRequest, GetTransactionPoolHashesRequest,
},
json::GetOutputDistributionRequest,
RpcCall,
};

Expand Down Expand Up @@ -102,7 +102,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! {
Expand Down
1 change: 1 addition & 0 deletions rpc/interface/src/router_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ generate_router_builder! {
bin_get_o_indexes => "/get_o_indexes.bin" => bin::get_o_indexes => (get, post),
bin_get_outs => "/get_outs.bin" => bin::get_outs => (get, post),
bin_get_transaction_pool_hashes => "/get_transaction_pool_hashes.bin" => bin::get_transaction_pool_hashes => (get, post),
bin_get_txpool_backlog => "/get_txpool_backlog.bin" => bin::get_txpool_backlog => (get, post),
bin_get_output_distribution => "/get_output_distribution.bin" => bin::get_output_distribution => (get, post),
}

Expand Down
8 changes: 6 additions & 2 deletions rpc/interface/src/rpc_handler_dummy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ impl Service<JsonRpcRequest> for RpcHandlerDummy {
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::GetOutputDistributionV2(_) => Resp::GetOutputDistributionV2(Default::default()),
Req::GetMinerData(_) => Resp::GetMinerData(Default::default()),
Req::PruneBlockchain(_) => Resp::PruneBlockchain(Default::default()),
Req::CalcPow(_) => Resp::CalcPow(Default::default()),
Expand Down Expand Up @@ -120,6 +121,9 @@ impl Service<BinRequest> 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()),
};

Expand Down
27 changes: 7 additions & 20 deletions rpc/types/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/monero-project/monero/issues/9422>.

```json
{
"string": "",
"float": 30.0,
"integer": 30,
"binary": "<serialized 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 compatibility <-> 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

<!--

Expand Down
48 changes: 44 additions & 4 deletions rpc/types/src/bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,52 @@ use cuprate_types::BlockCompleteEntry;
use crate::{
base::AccessResponseBase,
macros::{define_request, define_request_and_response, define_request_and_response_doc},
misc::{BlockOutputIndices, GetOutputsOut, OutKeyBin, PoolTxInfo, Status},
misc::{
BlockOutputIndices, Distribution, GetOutputsOut, OutKeyBin, PoolTxInfo, Status,
TxBacklogEntry,
},
rpc_call::RpcCallValue,
};

#[cfg(any(feature = "epee", feature = "serde"))]
use crate::defaults::{default_false, default_zero};
use crate::defaults::{default_false, default_true, default_zero};
#[cfg(feature = "epee")]
use crate::misc::PoolInfoExtent;

//---------------------------------------------------------------------------------------------------- Definitions
define_request_and_response! {
get_txpool_backlogbin,
cc73fe71162d564ffda8e549b79a350bca53c454 =>
core_rpc_server_commands_defs.h => 1637..=1664,
GetTransactionPoolBacklog (empty),
Request {},

AccessResponseBase {
backlog: Vec<TxBacklogEntry>,
}
}

define_request_and_response! {
get_output_distributionbin,
cc73fe71162d564ffda8e549b79a350bca53c454 =>
core_rpc_server_commands_defs.h => 2445..=2520,

GetOutputDistribution,

Request {
amounts: Vec<u64>,
binary: bool = default_true(), "default_true",
compress: bool = default_false(), "default_false",
cumulative: bool = default_false(), "default_false",
from_height: u64 = default_zero::<u64>(), "default_zero",
to_height: u64 = default_zero::<u64>(), "default_zero",
},

AccessResponseBase {
distributions: Vec<Distribution>,
}
}

define_request_and_response! {
get_blocks_by_heightbin,
cc73fe71162d564ffda8e549b79a350bca53c454 =>
Expand Down Expand Up @@ -403,7 +439,8 @@ pub enum BinRequest {
GetOutputIndexes(GetOutputIndexesRequest),
GetOuts(GetOutsRequest),
GetTransactionPoolHashes(GetTransactionPoolHashesRequest),
GetOutputDistribution(crate::json::GetOutputDistributionRequest),
GetTransactionPoolBacklog(GetTransactionPoolBacklogRequest),
GetOutputDistribution(GetOutputDistributionRequest),
}

impl RpcCallValue for BinRequest {
Expand All @@ -415,6 +452,7 @@ impl RpcCallValue for BinRequest {
Self::GetOutputIndexes(x) => x.is_restricted(),
Self::GetOuts(x) => x.is_restricted(),
Self::GetTransactionPoolHashes(x) => x.is_restricted(),
Self::GetTransactionPoolBacklog(x) => x.is_restricted(),
Self::GetOutputDistribution(x) => x.is_restricted(),
}
}
Expand All @@ -427,6 +465,7 @@ impl RpcCallValue for BinRequest {
Self::GetOutputIndexes(x) => x.is_empty(),
Self::GetOuts(x) => x.is_empty(),
Self::GetTransactionPoolHashes(x) => x.is_empty(),
Self::GetTransactionPoolBacklog(x) => x.is_empty(),
Self::GetOutputDistribution(x) => x.is_empty(),
}
}
Expand All @@ -448,7 +487,8 @@ pub enum BinResponse {
GetOutputIndexes(GetOutputIndexesResponse),
GetOuts(GetOutsResponse),
GetTransactionPoolHashes(GetTransactionPoolHashesResponse),
GetOutputDistribution(crate::json::GetOutputDistributionResponse),
GetTransactionPoolBacklog(GetTransactionPoolBacklogResponse),
GetOutputDistribution(GetOutputDistributionResponse),
}

//---------------------------------------------------------------------------------------------------- Tests
Expand Down
Loading
Loading