From 5ec6ad59dc6dd563dca4d958125b2001a9a60d9d Mon Sep 17 00:00:00 2001 From: Arya Date: Thu, 8 Dec 2022 22:31:09 -0500 Subject: [PATCH] change(rpc): return u64 from `get_network_sol_ps` and remove `arbitrary_precision` feature from serde (#5829) * return u64 instead of u128 from get_network_sol_ps * Update zebra-rpc/src/methods/get_block_template_rpcs.rs Co-authored-by: teor * rustfmt Co-authored-by: teor --- zebra-rpc/Cargo.toml | 2 +- zebra-rpc/src/methods/get_block_template_rpcs.rs | 10 ++++++---- .../get_block_template_rpcs/types/get_mining_info.rs | 6 +++--- .../methods/tests/snapshot/get_block_template_rpcs.rs | 2 +- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/zebra-rpc/Cargo.toml b/zebra-rpc/Cargo.toml index 119e9ece8..283c4c514 100644 --- a/zebra-rpc/Cargo.toml +++ b/zebra-rpc/Cargo.toml @@ -43,7 +43,7 @@ jsonrpc-http-server = "18.0.0" num_cpus = "1.14.0" # zebra-rpc needs the preserve_order feature in serde_json, which is a dependency of jsonrpc-core -serde_json = { version = "1.0.89", features = ["preserve_order", "arbitrary_precision"] } +serde_json = { version = "1.0.89", features = ["preserve_order"] } indexmap = { version = "1.9.2", features = ["serde"] } tokio = { version = "1.23.0", features = ["time", "rt-multi-thread", "macros", "tracing"] } diff --git a/zebra-rpc/src/methods/get_block_template_rpcs.rs b/zebra-rpc/src/methods/get_block_template_rpcs.rs index bfe98f553..e15677e1b 100644 --- a/zebra-rpc/src/methods/get_block_template_rpcs.rs +++ b/zebra-rpc/src/methods/get_block_template_rpcs.rs @@ -142,7 +142,7 @@ pub trait GetBlockTemplateRpc { &self, num_blocks: Option, height: Option, - ) -> BoxFuture>; + ) -> BoxFuture>; /// Returns the estimated network solutions per second based on the last `num_blocks` before `height`. /// If `num_blocks` is not supplied, uses 120 blocks. @@ -154,7 +154,7 @@ pub trait GetBlockTemplateRpc { &self, num_blocks: Option, height: Option, - ) -> BoxFuture> { + ) -> BoxFuture> { self.get_network_sol_ps(num_blocks, height) } } @@ -577,7 +577,7 @@ where &self, num_blocks: Option, height: Option, - ) -> BoxFuture> { + ) -> BoxFuture> { let num_blocks = num_blocks .map(|num_blocks| num_blocks.max(1)) .unwrap_or(DEFAULT_SOLUTION_RATE_WINDOW_SIZE); @@ -606,7 +606,9 @@ where _ => unreachable!("unmatched response to a solution rate request"), }; - Ok(solution_rate) + Ok(solution_rate + .try_into() + .expect("per-second solution rate always fits in u64")) } .boxed() } diff --git a/zebra-rpc/src/methods/get_block_template_rpcs/types/get_mining_info.rs b/zebra-rpc/src/methods/get_block_template_rpcs/types/get_mining_info.rs index a75984489..3ac548596 100644 --- a/zebra-rpc/src/methods/get_block_template_rpcs/types/get_mining_info.rs +++ b/zebra-rpc/src/methods/get_block_template_rpcs/types/get_mining_info.rs @@ -6,10 +6,10 @@ use zebra_chain::parameters::Network; #[derive(Debug, PartialEq, Eq, serde::Serialize)] pub struct Response { /// The estimated network solution rate in Sol/s. - networksolps: u128, + networksolps: u64, /// The estimated network solution rate in Sol/s. - networkhashps: u128, + networkhashps: u64, /// Current network name as defined in BIP70 (main, test, regtest) chain: String, @@ -20,7 +20,7 @@ pub struct Response { impl Response { /// Creates a new `getmininginfo` response - pub fn new(network: Network, networksolps: u128) -> Self { + pub fn new(network: Network, networksolps: u64) -> Self { Self { networksolps, networkhashps: networksolps, diff --git a/zebra-rpc/src/methods/tests/snapshot/get_block_template_rpcs.rs b/zebra-rpc/src/methods/tests/snapshot/get_block_template_rpcs.rs index 9162a9983..4c0f33791 100644 --- a/zebra-rpc/src/methods/tests/snapshot/get_block_template_rpcs.rs +++ b/zebra-rpc/src/methods/tests/snapshot/get_block_template_rpcs.rs @@ -250,6 +250,6 @@ fn snapshot_rpc_getmininginfo( } /// Snapshot `getnetworksolps` response, using `cargo insta` and JSON serialization. -fn snapshot_rpc_getnetworksolps(get_network_sol_ps: u128, settings: &insta::Settings) { +fn snapshot_rpc_getnetworksolps(get_network_sol_ps: u64, settings: &insta::Settings) { settings.bind(|| insta::assert_json_snapshot!("get_network_sol_ps", get_network_sol_ps)); }