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 <teor@riseup.net>

* rustfmt

Co-authored-by: teor <teor@riseup.net>
This commit is contained in:
Arya 2022-12-08 22:31:09 -05:00 committed by GitHub
parent a6e6eb5051
commit 5ec6ad59dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 9 deletions

View File

@ -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"] }

View File

@ -142,7 +142,7 @@ pub trait GetBlockTemplateRpc {
&self,
num_blocks: Option<usize>,
height: Option<i32>,
) -> BoxFuture<Result<u128>>;
) -> BoxFuture<Result<u64>>;
/// 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<usize>,
height: Option<i32>,
) -> BoxFuture<Result<u128>> {
) -> BoxFuture<Result<u64>> {
self.get_network_sol_ps(num_blocks, height)
}
}
@ -577,7 +577,7 @@ where
&self,
num_blocks: Option<usize>,
height: Option<i32>,
) -> BoxFuture<Result<u128>> {
) -> BoxFuture<Result<u64>> {
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()
}

View File

@ -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,

View File

@ -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));
}