Skip to content

Commit

Permalink
change(rpc): return u64 from get_network_sol_ps and remove `arbitra…
Browse files Browse the repository at this point in the history
…ry_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>
  • Loading branch information
arya2 and teor2345 authored Dec 9, 2022
1 parent a6e6eb5 commit 5ec6ad5
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion zebra-rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
10 changes: 6 additions & 4 deletions zebra-rpc/src/methods/get_block_template_rpcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
}
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

0 comments on commit 5ec6ad5

Please sign in to comment.