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:
parent
a6e6eb5051
commit
5ec6ad59dc
|
@ -43,7 +43,7 @@ jsonrpc-http-server = "18.0.0"
|
||||||
num_cpus = "1.14.0"
|
num_cpus = "1.14.0"
|
||||||
|
|
||||||
# zebra-rpc needs the preserve_order feature in serde_json, which is a dependency of jsonrpc-core
|
# 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"] }
|
indexmap = { version = "1.9.2", features = ["serde"] }
|
||||||
|
|
||||||
tokio = { version = "1.23.0", features = ["time", "rt-multi-thread", "macros", "tracing"] }
|
tokio = { version = "1.23.0", features = ["time", "rt-multi-thread", "macros", "tracing"] }
|
||||||
|
|
|
@ -142,7 +142,7 @@ pub trait GetBlockTemplateRpc {
|
||||||
&self,
|
&self,
|
||||||
num_blocks: Option<usize>,
|
num_blocks: Option<usize>,
|
||||||
height: Option<i32>,
|
height: Option<i32>,
|
||||||
) -> BoxFuture<Result<u128>>;
|
) -> BoxFuture<Result<u64>>;
|
||||||
|
|
||||||
/// Returns the estimated network solutions per second based on the last `num_blocks` before `height`.
|
/// Returns the estimated network solutions per second based on the last `num_blocks` before `height`.
|
||||||
/// If `num_blocks` is not supplied, uses 120 blocks.
|
/// If `num_blocks` is not supplied, uses 120 blocks.
|
||||||
|
@ -154,7 +154,7 @@ pub trait GetBlockTemplateRpc {
|
||||||
&self,
|
&self,
|
||||||
num_blocks: Option<usize>,
|
num_blocks: Option<usize>,
|
||||||
height: Option<i32>,
|
height: Option<i32>,
|
||||||
) -> BoxFuture<Result<u128>> {
|
) -> BoxFuture<Result<u64>> {
|
||||||
self.get_network_sol_ps(num_blocks, height)
|
self.get_network_sol_ps(num_blocks, height)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -577,7 +577,7 @@ where
|
||||||
&self,
|
&self,
|
||||||
num_blocks: Option<usize>,
|
num_blocks: Option<usize>,
|
||||||
height: Option<i32>,
|
height: Option<i32>,
|
||||||
) -> BoxFuture<Result<u128>> {
|
) -> BoxFuture<Result<u64>> {
|
||||||
let num_blocks = num_blocks
|
let num_blocks = num_blocks
|
||||||
.map(|num_blocks| num_blocks.max(1))
|
.map(|num_blocks| num_blocks.max(1))
|
||||||
.unwrap_or(DEFAULT_SOLUTION_RATE_WINDOW_SIZE);
|
.unwrap_or(DEFAULT_SOLUTION_RATE_WINDOW_SIZE);
|
||||||
|
@ -606,7 +606,9 @@ where
|
||||||
_ => unreachable!("unmatched response to a solution rate request"),
|
_ => 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()
|
.boxed()
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,10 +6,10 @@ use zebra_chain::parameters::Network;
|
||||||
#[derive(Debug, PartialEq, Eq, serde::Serialize)]
|
#[derive(Debug, PartialEq, Eq, serde::Serialize)]
|
||||||
pub struct Response {
|
pub struct Response {
|
||||||
/// The estimated network solution rate in Sol/s.
|
/// The estimated network solution rate in Sol/s.
|
||||||
networksolps: u128,
|
networksolps: u64,
|
||||||
|
|
||||||
/// The estimated network solution rate in Sol/s.
|
/// The estimated network solution rate in Sol/s.
|
||||||
networkhashps: u128,
|
networkhashps: u64,
|
||||||
|
|
||||||
/// Current network name as defined in BIP70 (main, test, regtest)
|
/// Current network name as defined in BIP70 (main, test, regtest)
|
||||||
chain: String,
|
chain: String,
|
||||||
|
@ -20,7 +20,7 @@ pub struct Response {
|
||||||
|
|
||||||
impl Response {
|
impl Response {
|
||||||
/// Creates a new `getmininginfo` response
|
/// Creates a new `getmininginfo` response
|
||||||
pub fn new(network: Network, networksolps: u128) -> Self {
|
pub fn new(network: Network, networksolps: u64) -> Self {
|
||||||
Self {
|
Self {
|
||||||
networksolps,
|
networksolps,
|
||||||
networkhashps: networksolps,
|
networkhashps: networksolps,
|
||||||
|
|
|
@ -250,6 +250,6 @@ fn snapshot_rpc_getmininginfo(
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Snapshot `getnetworksolps` response, using `cargo insta` and JSON serialization.
|
/// 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));
|
settings.bind(|| insta::assert_json_snapshot!("get_network_sol_ps", get_network_sol_ps));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue