diff --git a/Cargo.lock b/Cargo.lock index 7bb7343..ef9ff1a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2153,21 +2153,6 @@ version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "078e285eafdfb6c4b434e0d31e8cfcb5115b651496faca5749b88fafd4f23bfd" -[[package]] -name = "jsonrpc-core" -version = "18.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14f7f76aef2d054868398427f6c54943cf3d1caa9a7ec7d0c38d69df97a965eb" -dependencies = [ - "futures", - "futures-executor", - "futures-util", - "log", - "serde", - "serde_derive", - "serde_json", -] - [[package]] name = "jsonrpsee" version = "0.24.8" @@ -5514,7 +5499,7 @@ dependencies = [ "hex", "http", "indexmap 2.7.1", - "jsonrpc-core", + "jsonrpsee-core", "lazy-regex", "lmdb", "prost", diff --git a/Cargo.toml b/Cargo.toml index c2a9934..1979e84 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -65,7 +65,7 @@ tonic-build = "0.12" prost = "0.13" serde = "1.0" serde_json = "1.0" -jsonrpc-core = "18.0" +jsonrpsee-core = "0.24" jsonrpsee-types = "0.24" # Hashmaps, channels, DBs diff --git a/docs/internal_spec.md b/docs/internal_spec.md index 421b16b..168ce13 100644 --- a/docs/internal_spec.md +++ b/docs/internal_spec.md @@ -52,7 +52,7 @@ The Zaino repo consists of several crates that collectively provide an indexing - prost - serde - serde_json -- jsonrpc-core +- jsonrpsee-core - jsonrpsee-types **Hashmaps, channels, DBs:** diff --git a/integration-tests/tests/fetch_service.rs b/integration-tests/tests/fetch_service.rs index 4afa242..aec6787 100644 --- a/integration-tests/tests/fetch_service.rs +++ b/integration-tests/tests/fetch_service.rs @@ -1,5 +1,5 @@ use futures::StreamExt as _; -use zaino_fetch::jsonrpc::connector::{test_node_and_return_url, JsonRpcConnector}; +use zaino_fetch::jsonrpsee::connector::{test_node_and_return_url, JsonRpSeeConnector}; use zaino_proto::proto::service::{ AddressList, BlockId, BlockRange, Exclude, GetAddressUtxosArg, GetSubtreeRootsArg, TransparentAddressBlockFilter, TxFilter, @@ -221,7 +221,7 @@ async fn fetch_service_get_raw_mempool(validator: &str) { .as_ref() .expect("Clients are not initialized"); - let json_service = JsonRpcConnector::new_with_basic_auth( + let json_service = JsonRpSeeConnector::new_with_basic_auth( test_node_and_return_url( test_manager.zebrad_rpc_listen_address, false, @@ -586,7 +586,7 @@ async fn fetch_service_get_latest_block(validator: &str) { test_manager.local_net.generate_blocks(1).await.unwrap(); tokio::time::sleep(tokio::time::Duration::from_secs(1)).await; - let json_service = JsonRpcConnector::new_with_basic_auth( + let json_service = JsonRpSeeConnector::new_with_basic_auth( test_node_and_return_url( test_manager.zebrad_rpc_listen_address, false, diff --git a/integration-tests/tests/local_cache.rs b/integration-tests/tests/local_cache.rs index 1d7b182..fc97d01 100644 --- a/integration-tests/tests/local_cache.rs +++ b/integration-tests/tests/local_cache.rs @@ -1,5 +1,5 @@ use core::panic; -use zaino_fetch::jsonrpc::connector::{test_node_and_return_url, JsonRpcConnector}; +use zaino_fetch::jsonrpsee::connector::{test_node_and_return_url, JsonRpSeeConnector}; use zaino_state::{ config::BlockCacheConfig, local_cache::{BlockCache, BlockCacheSubscriber}, @@ -18,7 +18,7 @@ async fn create_test_manager_and_block_cache( enable_clients: bool, ) -> ( TestManager, - JsonRpcConnector, + JsonRpSeeConnector, BlockCache, BlockCacheSubscriber, ) { @@ -34,7 +34,7 @@ async fn create_test_manager_and_block_cache( .await .unwrap(); - let json_service = JsonRpcConnector::new_with_basic_auth( + let json_service = JsonRpSeeConnector::new_with_basic_auth( test_node_and_return_url( test_manager.zebrad_rpc_listen_address, false, diff --git a/integration-tests/tests/wallet_to_validator.rs b/integration-tests/tests/wallet_to_validator.rs index 12ecf39..4be7cfa 100644 --- a/integration-tests/tests/wallet_to_validator.rs +++ b/integration-tests/tests/wallet_to_validator.rs @@ -8,7 +8,7 @@ use zingo_infra_testutils::services::validator::Validator; use zingolib::testutils::lightclient::from_inputs; mod wallet_basic { - use zaino_fetch::jsonrpc::connector::test_node_and_return_url; + use zaino_fetch::jsonrpsee::connector::test_node_and_return_url; use super::*; @@ -199,20 +199,21 @@ mod wallet_basic { test_manager.local_net.generate_blocks(1).await.unwrap(); tokio::time::sleep(std::time::Duration::from_millis(500)).await; - let fetch_service = zaino_fetch::jsonrpc::connector::JsonRpcConnector::new_with_basic_auth( - test_node_and_return_url( - test_manager.zebrad_rpc_listen_address, - false, - None, - Some("xxxxxx".to_string()), - Some("xxxxxx".to_string()), + let fetch_service = + zaino_fetch::jsonrpsee::connector::JsonRpSeeConnector::new_with_basic_auth( + test_node_and_return_url( + test_manager.zebrad_rpc_listen_address, + false, + None, + Some("xxxxxx".to_string()), + Some("xxxxxx".to_string()), + ) + .await + .unwrap(), + "xxxxxx".to_string(), + "xxxxxx".to_string(), ) - .await - .unwrap(), - "xxxxxx".to_string(), - "xxxxxx".to_string(), - ) - .unwrap(); + .unwrap(); println!("\n\nFetching Chain Height!\n"); @@ -543,20 +544,21 @@ mod wallet_basic { // test_manager.local_net.print_stdout(); - let fetch_service = zaino_fetch::jsonrpc::connector::JsonRpcConnector::new_with_basic_auth( - test_node_and_return_url( - test_manager.zebrad_rpc_listen_address, - false, - None, - Some("xxxxxx".to_string()), - Some("xxxxxx".to_string()), + let fetch_service = + zaino_fetch::jsonrpsee::connector::JsonRpSeeConnector::new_with_basic_auth( + test_node_and_return_url( + test_manager.zebrad_rpc_listen_address, + false, + None, + Some("xxxxxx".to_string()), + Some("xxxxxx".to_string()), + ) + .await + .unwrap(), + "xxxxxx".to_string(), + "xxxxxx".to_string(), ) - .await - .unwrap(), - "xxxxxx".to_string(), - "xxxxxx".to_string(), - ) - .unwrap(); + .unwrap(); println!("\n\nFetching Raw Mempool!\n"); diff --git a/zaino-fetch/Cargo.toml b/zaino-fetch/Cargo.toml index bd839b9..877a15a 100644 --- a/zaino-fetch/Cargo.toml +++ b/zaino-fetch/Cargo.toml @@ -40,4 +40,3 @@ base64 = { workspace = true } byteorder = { workspace = true } sha2 = { workspace = true } jsonrpsee-types = { workspace = true } - diff --git a/zaino-fetch/src/jsonrpc.rs b/zaino-fetch/src/jsonrpsee.rs similarity index 100% rename from zaino-fetch/src/jsonrpc.rs rename to zaino-fetch/src/jsonrpsee.rs diff --git a/zaino-fetch/src/jsonrpc/connector.rs b/zaino-fetch/src/jsonrpsee/connector.rs similarity index 87% rename from zaino-fetch/src/jsonrpc/connector.rs rename to zaino-fetch/src/jsonrpsee/connector.rs index 925d81a..f955c3e 100644 --- a/zaino-fetch/src/jsonrpc/connector.rs +++ b/zaino-fetch/src/jsonrpsee/connector.rs @@ -1,7 +1,7 @@ -//! JsonRPC client implementation. +//! JsonRPSee client implementation. //! //! TODO: - Add option for http connector. -//! - Refactor JsonRpcConnectorError into concrete error types and implement fmt::display [https://github.com/zingolabs/zaino/issues/67]. +//! - Refactor JsonRPSeecConnectorError into concrete error types and implement fmt::display [https://github.com/zingolabs/zaino/issues/67]. use base64::{engine::general_purpose, Engine}; use http::Uri; @@ -20,8 +20,8 @@ use std::{ }; use tracing::error; -use crate::jsonrpc::{ - error::JsonRpcConnectorError, +use crate::jsonrpsee::{ + error::JsonRpSeeConnectorError, response::{ GetBalanceResponse, GetBlockResponse, GetBlockchainInfoResponse, GetInfoResponse, GetSubtreesResponse, GetTransactionResponse, GetTreestateResponse, GetUtxosResponse, @@ -45,7 +45,7 @@ struct RpcResponse { error: Option, } -/// Json RPC Error type. +/// Json RPSee Error type. #[derive(Serialize, Deserialize, Debug)] pub struct RpcError { /// Error Code. @@ -102,28 +102,28 @@ enum AuthMethod { Cookie { cookie: String }, } -/// JsonRPC Client config data. +/// JsonRpSee Client config data. #[derive(Debug, Clone)] -pub struct JsonRpcConnector { +pub struct JsonRpSeeConnector { url: Url, id_counter: Arc, client: Client, auth_method: AuthMethod, } -impl JsonRpcConnector { - /// Creates a new JsonRpcConnector with Basic Authentication. +impl JsonRpSeeConnector { + /// Creates a new JsonRpSeeConnector with Basic Authentication. pub fn new_with_basic_auth( url: Url, username: String, password: String, - ) -> Result { + ) -> Result { let client = ClientBuilder::new() .connect_timeout(Duration::from_secs(2)) .timeout(Duration::from_secs(5)) .redirect(reqwest::redirect::Policy::none()) .build() - .map_err(JsonRpcConnectorError::ReqwestError)?; + .map_err(JsonRpSeeConnectorError::ReqwestError)?; Ok(Self { url, @@ -133,13 +133,13 @@ impl JsonRpcConnector { }) } - /// Creates a new JsonRpcConnector with Cookie Authentication. + /// Creates a new JsonRpSeeConnector with Cookie Authentication. pub fn new_with_cookie_auth( url: Url, cookie_path: &Path, - ) -> Result { + ) -> Result { let cookie_content = - fs::read_to_string(cookie_path).map_err(JsonRpcConnectorError::IoError)?; + fs::read_to_string(cookie_path).map_err(JsonRpSeeConnectorError::IoError)?; let cookie = cookie_content.trim().to_string(); let client = ClientBuilder::new() @@ -148,7 +148,7 @@ impl JsonRpcConnector { .redirect(reqwest::redirect::Policy::none()) .cookie_store(true) .build() - .map_err(JsonRpcConnectorError::ReqwestError)?; + .map_err(JsonRpSeeConnectorError::ReqwestError)?; Ok(Self { url, @@ -166,9 +166,9 @@ impl JsonRpcConnector { validator_rpc_user: String, validator_rpc_password: String, validator_cookie_path: Option, - ) -> Result { + ) -> Result { match validator_cookie_auth { - true => JsonRpcConnector::new_with_cookie_auth( + true => JsonRpSeeConnector::new_with_cookie_auth( test_node_and_return_url( validator_rpc_address, validator_cookie_auth, @@ -183,7 +183,7 @@ impl JsonRpcConnector { .expect("validator cookie authentication path missing"), ), ), - false => JsonRpcConnector::new_with_basic_auth( + false => JsonRpSeeConnector::new_with_basic_auth( test_node_and_return_url( validator_rpc_address, false, @@ -198,12 +198,12 @@ impl JsonRpcConnector { } } - /// Returns the http::uri the JsonRpcConnector is configured to send requests to. - pub fn uri(&self) -> Result { + /// Returns the http::uri the JsonRpSeeConnector is configured to send requests to. + pub fn uri(&self) -> Result { Ok(self.url.as_str().parse()?) } - /// Returns the reqwest::url the JsonRpcConnector is configured to send requests to. + /// Returns the reqwest::url the JsonRpSeeConnector is configured to send requests to. pub fn url(&self) -> Url { self.url.clone() } @@ -219,7 +219,7 @@ impl JsonRpcConnector { &self, method: &str, params: T, - ) -> Result { + ) -> Result { let id = self.id_counter.fetch_add(1, Ordering::SeqCst); let req = RpcRequest { jsonrpc: "2.0".to_string(), @@ -252,26 +252,26 @@ impl JsonRpcConnector { } let request_body = - serde_json::to_string(&req).map_err(JsonRpcConnectorError::SerdeJsonError)?; + serde_json::to_string(&req).map_err(JsonRpSeeConnectorError::SerdeJsonError)?; let response = request_builder .body(request_body) .send() .await - .map_err(JsonRpcConnectorError::ReqwestError)?; + .map_err(JsonRpSeeConnectorError::ReqwestError)?; let status = response.status(); let body_bytes = response .bytes() .await - .map_err(JsonRpcConnectorError::ReqwestError)?; + .map_err(JsonRpSeeConnectorError::ReqwestError)?; let body_str = String::from_utf8_lossy(&body_bytes); if body_str.contains("Work queue depth exceeded") { if attempts >= max_attempts { - return Err(JsonRpcConnectorError::new( + return Err(JsonRpSeeConnectorError::new( "Error: The node's rpc queue depth was exceeded after multiple attempts", )); } @@ -280,17 +280,17 @@ impl JsonRpcConnector { } if !status.is_success() { - return Err(JsonRpcConnectorError::new(format!( + return Err(JsonRpSeeConnectorError::new(format!( "Error: Error status from node's rpc server: {}, {}", status, body_str ))); } let response: RpcResponse = serde_json::from_slice(&body_bytes) - .map_err(JsonRpcConnectorError::SerdeJsonError)?; + .map_err(JsonRpSeeConnectorError::SerdeJsonError)?; return match response.error { - Some(error) => Err(JsonRpcConnectorError::new(format!( + Some(error) => Err(JsonRpSeeConnectorError::new(format!( "Error: Error from node's rpc server: {} - {}", error.code, error.message ))), @@ -304,7 +304,7 @@ impl JsonRpcConnector { /// zcashd reference: [`getinfo`](https://zcash.github.io/rpc/getinfo.html) /// method: post /// tags: control - pub async fn get_info(&self) -> Result { + pub async fn get_info(&self) -> Result { self.send_request::<(), GetInfoResponse>("getinfo", ()) .await } @@ -316,7 +316,7 @@ impl JsonRpcConnector { /// tags: blockchain pub async fn get_blockchain_info( &self, - ) -> Result { + ) -> Result { self.send_request::<(), GetBlockchainInfoResponse>("getblockchaininfo", ()) .await } @@ -334,7 +334,7 @@ impl JsonRpcConnector { pub async fn get_address_balance( &self, addresses: Vec, - ) -> Result { + ) -> Result { let params = vec![serde_json::json!({ "addresses": addresses })]; self.send_request("getaddressbalance", params).await } @@ -352,7 +352,7 @@ impl JsonRpcConnector { pub async fn send_raw_transaction( &self, raw_transaction_hex: String, - ) -> Result { + ) -> Result { let params = vec![serde_json::to_value(raw_transaction_hex)?]; self.send_request("sendrawtransaction", params).await } @@ -373,7 +373,7 @@ impl JsonRpcConnector { &self, hash_or_height: String, verbosity: Option, - ) -> Result { + ) -> Result { let params = match verbosity { Some(v) => vec![ serde_json::to_value(hash_or_height)?, @@ -392,7 +392,7 @@ impl JsonRpcConnector { /// zcashd reference: [`getrawmempool`](https://zcash.github.io/rpc/getrawmempool.html) /// method: post /// tags: blockchain - pub async fn get_raw_mempool(&self) -> Result { + pub async fn get_raw_mempool(&self) -> Result { self.send_request::<(), TxidsResponse>("getrawmempool", ()) .await } @@ -409,7 +409,7 @@ impl JsonRpcConnector { pub async fn get_treestate( &self, hash_or_height: String, - ) -> Result { + ) -> Result { let params = vec![serde_json::to_value(hash_or_height)?]; self.send_request("z_gettreestate", params).await } @@ -430,7 +430,7 @@ impl JsonRpcConnector { pool: String, start_index: u16, limit: Option, - ) -> Result { + ) -> Result { let params = match limit { Some(v) => vec![ serde_json::to_value(pool)?, @@ -459,7 +459,7 @@ impl JsonRpcConnector { &self, txid_hex: String, verbose: Option, - ) -> Result { + ) -> Result { let params = match verbose { Some(v) => vec![serde_json::to_value(txid_hex)?, serde_json::to_value(v)?], None => vec![serde_json::to_value(txid_hex)?, serde_json::to_value(0)?], @@ -485,7 +485,7 @@ impl JsonRpcConnector { addresses: Vec, start: u32, end: u32, - ) -> Result { + ) -> Result { let params = serde_json::json!({ "addresses": addresses, "start": start, @@ -507,7 +507,7 @@ impl JsonRpcConnector { pub async fn get_address_utxos( &self, addresses: Vec, - ) -> Result, JsonRpcConnectorError> { + ) -> Result, JsonRpSeeConnectorError> { let params = vec![serde_json::json!({ "addresses": addresses })]; self.send_request("getaddressutxos", params).await } @@ -517,7 +517,7 @@ impl JsonRpcConnector { async fn test_node_connection( url: Url, auth_method: AuthMethod, -) -> Result<(), JsonRpcConnectorError> { +) -> Result<(), JsonRpSeeConnectorError> { let client = Client::builder() .connect_timeout(std::time::Duration::from_secs(2)) .timeout(std::time::Duration::from_secs(5)) @@ -548,13 +548,13 @@ async fn test_node_connection( let response = request_builder .send() .await - .map_err(JsonRpcConnectorError::ReqwestError)?; + .map_err(JsonRpSeeConnectorError::ReqwestError)?; let body_bytes = response .bytes() .await - .map_err(JsonRpcConnectorError::ReqwestError)?; + .map_err(JsonRpSeeConnectorError::ReqwestError)?; let _response: RpcResponse = - serde_json::from_slice(&body_bytes).map_err(JsonRpcConnectorError::SerdeJsonError)?; + serde_json::from_slice(&body_bytes).map_err(JsonRpSeeConnectorError::SerdeJsonError)?; Ok(()) } @@ -565,12 +565,12 @@ pub async fn test_node_and_return_url( cookie_path: Option, user: Option, password: Option, -) -> Result { +) -> Result { let auth_method = match rpc_cookie_auth { true => { let cookie_content = fs::read_to_string(cookie_path.expect("validator rpc cookie path missing")) - .map_err(JsonRpcConnectorError::IoError)?; + .map_err(JsonRpSeeConnectorError::IoError)?; let cookie = cookie_content.trim().to_string(); AuthMethod::Cookie { cookie } diff --git a/zaino-fetch/src/jsonrpc/error.rs b/zaino-fetch/src/jsonrpsee/error.rs similarity index 69% rename from zaino-fetch/src/jsonrpc/error.rs rename to zaino-fetch/src/jsonrpsee/error.rs index b4a2cb6..16a54fd 100644 --- a/zaino-fetch/src/jsonrpc/error.rs +++ b/zaino-fetch/src/jsonrpsee/error.rs @@ -1,11 +1,11 @@ -//! Hold error types for the JsonRpcConnector and related functionality. +//! Hold error types for the JsonRpSeeConnector and related functionality. -/// General error type for handling JsonRpcConnector errors. +/// General error type for handling JsonRpSeeConnector errors. #[derive(Debug, thiserror::Error)] -pub enum JsonRpcConnectorError { +pub enum JsonRpSeeConnectorError { /// Type for errors without an underlying source. #[error("Error: {0}")] - JsonRpcClientError(String), + JsonRpSeeClientError(String), /// Serialization/Deserialization Errors. #[error("Error: Serialization/Deserialization Error: {0}")] @@ -28,24 +28,24 @@ pub enum JsonRpcConnectorError { IoError(#[from] std::io::Error), } -impl JsonRpcConnectorError { +impl JsonRpSeeConnectorError { /// Constructor for errors without an underlying source pub fn new(msg: impl Into) -> Self { - JsonRpcConnectorError::JsonRpcClientError(msg.into()) + JsonRpSeeConnectorError::JsonRpSeeClientError(msg.into()) } - /// Converts JsonRpcConnectorError to tonic::Status + /// Converts JsonRpSeeConnectorError to tonic::Status /// /// TODO: This impl should be changed to return the correct status [https://github.com/zcash/lightwalletd/issues/497] before release, /// however propagating the server error is useful during development. pub fn to_grpc_status(&self) -> tonic::Status { // TODO: Hide server error from clients before release. Currently useful for dev purposes. - tonic::Status::internal(format!("Error: JsonRPC Client Error: {}", self)) + tonic::Status::internal(format!("Error: JsonRpSee Client Error: {}", self)) } } -impl From for tonic::Status { - fn from(err: JsonRpcConnectorError) -> Self { +impl From for tonic::Status { + fn from(err: JsonRpSeeConnectorError) -> Self { err.to_grpc_status() } } diff --git a/zaino-fetch/src/jsonrpc/response.rs b/zaino-fetch/src/jsonrpsee/response.rs similarity index 100% rename from zaino-fetch/src/jsonrpc/response.rs rename to zaino-fetch/src/jsonrpsee/response.rs diff --git a/zaino-fetch/src/lib.rs b/zaino-fetch/src/lib.rs index c08ea3c..98413f7 100644 --- a/zaino-fetch/src/lib.rs +++ b/zaino-fetch/src/lib.rs @@ -6,4 +6,4 @@ #![forbid(unsafe_code)] pub mod chain; -pub mod jsonrpc; +pub mod jsonrpsee; diff --git a/zaino-state/Cargo.toml b/zaino-state/Cargo.toml index d44a579..bc100aa 100644 --- a/zaino-state/Cargo.toml +++ b/zaino-state/Cargo.toml @@ -38,7 +38,7 @@ dashmap = { workspace = true } lmdb = { workspace = true } serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true, features = ["preserve_order"] } -jsonrpc-core = { workspace = true } +jsonrpsee-core = { workspace = true } prost = { workspace = true } [dev-dependencies] diff --git a/zaino-state/src/error.rs b/zaino-state/src/error.rs index bdee485..81aca35 100644 --- a/zaino-state/src/error.rs +++ b/zaino-state/src/error.rs @@ -13,11 +13,11 @@ pub enum StateServiceError { /// Error from JsonRpcConnector. #[error("JsonRpcConnector error: {0}")] - JsonRpcConnectorError(#[from] zaino_fetch::jsonrpc::error::JsonRpcConnectorError), + JsonRpcConnectorError(#[from] zaino_fetch::jsonrpsee::error::JsonRpSeeConnectorError), /// RPC error in compatibility with zcashd. #[error("RPC error: {0:?}")] - RpcError(#[from] zaino_fetch::jsonrpc::connector::RpcError), + RpcError(#[from] zaino_fetch::jsonrpsee::connector::RpcError), /// Tonic gRPC error. #[error("Tonic status error: {0}")] @@ -79,7 +79,7 @@ pub enum FetchServiceError { /// Error from JsonRpcConnector. #[error("JsonRpcConnector error: {0}")] - JsonRpcConnectorError(#[from] zaino_fetch::jsonrpc::error::JsonRpcConnectorError), + JsonRpcConnectorError(#[from] zaino_fetch::jsonrpsee::error::JsonRpSeeConnectorError), /// Error from the block cache. #[error("Mempool error: {0}")] @@ -91,7 +91,7 @@ pub enum FetchServiceError { /// RPC error in compatibility with zcashd. #[error("RPC error: {0:?}")] - RpcError(#[from] zaino_fetch::jsonrpc::connector::RpcError), + RpcError(#[from] zaino_fetch::jsonrpsee::connector::RpcError), /// Tonic gRPC error. #[error("Tonic status error: {0}")] @@ -135,7 +135,7 @@ pub enum MempoolError { /// Error from JsonRpcConnector. #[error("JsonRpcConnector error: {0}")] - JsonRpcConnectorError(#[from] zaino_fetch::jsonrpc::error::JsonRpcConnectorError), + JsonRpcConnectorError(#[from] zaino_fetch::jsonrpsee::error::JsonRpSeeConnectorError), /// Error from a Tokio Watch Receiver. #[error("Join error: {0}")] @@ -167,7 +167,7 @@ pub enum BlockCacheError { /// Error from JsonRpcConnector. #[error("JsonRpcConnector error: {0}")] - JsonRpcConnectorError(#[from] zaino_fetch::jsonrpc::error::JsonRpcConnectorError), + JsonRpcConnectorError(#[from] zaino_fetch::jsonrpsee::error::JsonRpSeeConnectorError), /// Chain parse error. #[error("Chain parse error: {0}")] @@ -207,7 +207,7 @@ pub enum NonFinalisedStateError { /// Error from JsonRpcConnector. #[error("JsonRpcConnector error: {0}")] - JsonRpcConnectorError(#[from] zaino_fetch::jsonrpc::error::JsonRpcConnectorError), + JsonRpcConnectorError(#[from] zaino_fetch::jsonrpsee::error::JsonRpSeeConnectorError), /// Unexpected status-related error. #[error("Status error: {0:?}")] @@ -243,7 +243,7 @@ pub enum FinalisedStateError { /// Error from JsonRpcConnector. #[error("JsonRpcConnector error: {0}")] - JsonRpcConnectorError(#[from] zaino_fetch::jsonrpc::error::JsonRpcConnectorError), + JsonRpcConnectorError(#[from] zaino_fetch::jsonrpsee::error::JsonRpSeeConnectorError), /// std::io::Error #[error("IO error: {0}")] diff --git a/zaino-state/src/fetch.rs b/zaino-state/src/fetch.rs index a8f51c4..882c8fc 100644 --- a/zaino-state/src/fetch.rs +++ b/zaino-state/src/fetch.rs @@ -16,8 +16,9 @@ use zebra_rpc::methods::{ use zaino_fetch::{ chain::{transaction::FullTransaction, utils::ParseFromSlice}, - jsonrpc::connector::{JsonRpcConnector, RpcError}, + jsonrpsee::connector::{JsonRpSeeConnector, RpcError}, }; + use zaino_proto::proto::{ compact_formats::CompactBlock, service::{ @@ -53,7 +54,7 @@ use crate::{ #[derive(Debug)] pub struct FetchService { /// JsonRPC Client. - fetcher: JsonRpcConnector, + fetcher: JsonRpSeeConnector, /// Local compact block cache. block_cache: BlockCache, /// Internal mempool. @@ -73,7 +74,7 @@ impl ZcashService for FetchService { async fn spawn(config: FetchServiceConfig) -> Result { info!("Launching Chain Fetch Service.."); - let fetcher = JsonRpcConnector::new_from_config_parts( + let fetcher = JsonRpSeeConnector::new_from_config_parts( config.validator_cookie_auth, config.validator_rpc_address, config.validator_rpc_user.clone(), @@ -147,7 +148,7 @@ impl Drop for FetchService { #[derive(Debug, Clone)] pub struct FetchServiceSubscriber { /// JsonRPC Client. - pub fetcher: JsonRpcConnector, + pub fetcher: JsonRpSeeConnector, /// Local compact block cache. pub block_cache: BlockCacheSubscriber, /// Internal mempool. diff --git a/zaino-state/src/local_cache.rs b/zaino-state/src/local_cache.rs index eb7b9e0..e20626b 100644 --- a/zaino-state/src/local_cache.rs +++ b/zaino-state/src/local_cache.rs @@ -10,7 +10,7 @@ use non_finalised_state::{NonFinalisedState, NonFinalisedStateSubscriber}; use tracing::info; use zaino_fetch::{ chain::block::FullBlock, - jsonrpc::{connector::JsonRpcConnector, response::GetBlockResponse}, + jsonrpsee::{connector::JsonRpSeeConnector, response::GetBlockResponse}, }; use zaino_proto::proto::compact_formats::{ ChainMetadata, CompactBlock, CompactOrchardAction, CompactTx, @@ -23,7 +23,7 @@ use zebra_state::HashOrHeight; /// Used by the FetchService for efficiency. #[derive(Debug)] pub struct BlockCache { - fetcher: JsonRpcConnector, + fetcher: JsonRpSeeConnector, non_finalised_state: NonFinalisedState, /// The state below the last 100 blocks, determined /// to be probabalistically nonreorgable @@ -34,7 +34,7 @@ pub struct BlockCache { impl BlockCache { /// Spawns a new [`BlockCache`]. pub async fn spawn( - fetcher: &JsonRpcConnector, + fetcher: &JsonRpSeeConnector, config: BlockCacheConfig, ) -> Result { info!("Launching Local Block Cache.."); @@ -100,7 +100,7 @@ impl BlockCache { /// A subscriber to a [`BlockCache`]. #[derive(Debug, Clone)] pub struct BlockCacheSubscriber { - fetcher: JsonRpcConnector, + fetcher: JsonRpSeeConnector, /// the last 100 blocks, stored separately as it could /// be changed by reorgs pub non_finalised_state: NonFinalisedStateSubscriber, @@ -216,7 +216,7 @@ impl BlockCacheSubscriber { /// /// Uses 2 calls as z_get_block verbosity=1 is required to fetch txids from zcashd. pub(crate) async fn fetch_block_from_node( - fetcher: &JsonRpcConnector, + fetcher: &JsonRpSeeConnector, hash_or_height: HashOrHeight, ) -> Result<(Hash, CompactBlock), BlockCacheError> { let (hash, tx, trees) = fetcher diff --git a/zaino-state/src/local_cache/finalised_state.rs b/zaino-state/src/local_cache/finalised_state.rs index fae6ed3..8e362ac 100644 --- a/zaino-state/src/local_cache/finalised_state.rs +++ b/zaino-state/src/local_cache/finalised_state.rs @@ -12,7 +12,7 @@ use zebra_chain::{ }; use zebra_state::HashOrHeight; -use zaino_fetch::jsonrpc::connector::JsonRpcConnector; +use zaino_fetch::jsonrpsee::connector::JsonRpSeeConnector; use zaino_proto::proto::compact_formats::CompactBlock; use crate::{ @@ -98,7 +98,7 @@ impl DbRequest { #[derive(Debug)] pub struct FinalisedState { /// Chain fetch service. - fetcher: JsonRpcConnector, + fetcher: JsonRpSeeConnector, /// LMDB Database Environmant. database: Arc, /// LMDB Databas containing ``. @@ -127,7 +127,7 @@ impl FinalisedState { /// - block_reciever: Channel that recieves new blocks to add to the db. /// - status_signal: Used to send error status signals to outer processes. pub async fn spawn( - fetcher: &JsonRpcConnector, + fetcher: &JsonRpSeeConnector, block_receiver: tokio::sync::mpsc::Receiver<(Height, Hash, CompactBlock)>, config: BlockCacheConfig, ) -> Result { @@ -380,7 +380,7 @@ impl FinalisedState { .get_block(reorg_height.0.to_string(), Some(1)) .await? { - zaino_fetch::jsonrpc::response::GetBlockResponse::Object { hash, .. } => hash.0, + zaino_fetch::jsonrpsee::response::GetBlockResponse::Object { hash, .. } => hash.0, _ => { return Err(FinalisedStateError::Custom( "Unexpected block response type".to_string(), @@ -414,7 +414,7 @@ impl FinalisedState { .get_block(reorg_height.0.to_string(), Some(1)) .await? { - zaino_fetch::jsonrpc::response::GetBlockResponse::Object { hash, .. } => hash.0, + zaino_fetch::jsonrpsee::response::GetBlockResponse::Object { hash, .. } => hash.0, _ => { return Err(FinalisedStateError::Custom( "Unexpected block response type".to_string(), diff --git a/zaino-state/src/local_cache/non_finalised_state.rs b/zaino-state/src/local_cache/non_finalised_state.rs index 9ef908d..916b545 100644 --- a/zaino-state/src/local_cache/non_finalised_state.rs +++ b/zaino-state/src/local_cache/non_finalised_state.rs @@ -3,7 +3,7 @@ use std::collections::HashSet; use tracing::{error, info, warn}; -use zaino_fetch::jsonrpc::connector::JsonRpcConnector; +use zaino_fetch::jsonrpsee::connector::JsonRpSeeConnector; use zaino_proto::proto::compact_formats::CompactBlock; use zebra_chain::block::{Hash, Height}; use zebra_state::HashOrHeight; @@ -22,7 +22,7 @@ use crate::{ #[derive(Debug)] pub struct NonFinalisedState { /// Chain fetch service. - fetcher: JsonRpcConnector, + fetcher: JsonRpSeeConnector, /// Broadcast containing ``. heights_to_hashes: Broadcast, /// Broadcast containing ``. @@ -40,7 +40,7 @@ pub struct NonFinalisedState { impl NonFinalisedState { /// Spawns a new [`NonFinalisedState`]. pub async fn spawn( - fetcher: &JsonRpcConnector, + fetcher: &JsonRpSeeConnector, block_sender: tokio::sync::mpsc::Sender<(Height, Hash, CompactBlock)>, config: BlockCacheConfig, ) -> Result { @@ -208,7 +208,7 @@ impl NonFinalisedState { .get_block(reorg_height.0.to_string(), Some(1)) .await? { - zaino_fetch::jsonrpc::response::GetBlockResponse::Object { hash, .. } => hash.0, + zaino_fetch::jsonrpsee::response::GetBlockResponse::Object { hash, .. } => hash.0, _ => { return Err(NonFinalisedStateError::Custom( "Unexpected block response type".to_string(), @@ -243,7 +243,7 @@ impl NonFinalisedState { .get_block(reorg_height.0.to_string(), Some(1)) .await? { - zaino_fetch::jsonrpc::response::GetBlockResponse::Object { hash, .. } => hash.0, + zaino_fetch::jsonrpsee::response::GetBlockResponse::Object { hash, .. } => hash.0, _ => { return Err(NonFinalisedStateError::Custom( "Unexpected block response type".to_string(), diff --git a/zaino-state/src/mempool.rs b/zaino-state/src/mempool.rs index f71d9ac..2f384f3 100644 --- a/zaino-state/src/mempool.rs +++ b/zaino-state/src/mempool.rs @@ -8,7 +8,7 @@ use crate::{ status::{AtomicStatus, StatusType}, }; use tracing::{info, warn}; -use zaino_fetch::jsonrpc::connector::JsonRpcConnector; +use zaino_fetch::jsonrpsee::connector::JsonRpSeeConnector; use zebra_chain::block::Hash; use zebra_rpc::methods::GetRawTransaction; @@ -30,7 +30,7 @@ pub struct MempoolValue(pub GetRawTransaction); #[derive(Debug)] pub struct Mempool { /// Zcash chain fetch service. - fetcher: JsonRpcConnector, + fetcher: JsonRpSeeConnector, /// Wrapper for a dashmap of mempool transactions. state: Broadcast, /// Mempool sync handle. @@ -42,7 +42,7 @@ pub struct Mempool { impl Mempool { /// Spawns a new [`Mempool`]. pub async fn spawn( - fetcher: &JsonRpcConnector, + fetcher: &JsonRpSeeConnector, capacity_and_shard_amount: Option<(usize, usize)>, ) -> Result { // Wait for mempool in validator to come online. diff --git a/zaino-state/src/state.rs b/zaino-state/src/state.rs index 0092b19..66a0f57 100644 --- a/zaino-state/src/state.rs +++ b/zaino-state/src/state.rs @@ -20,8 +20,8 @@ use tokio::time::timeout; use tonic::async_trait; use tower::Service; -use zaino_fetch::jsonrpc::connector::{JsonRpcConnector, RpcError}; -use zaino_fetch::jsonrpc::response::TxidsResponse; +use zaino_fetch::jsonrpsee::connector::{JsonRpSeeConnector, RpcError}; +use zaino_fetch::jsonrpsee::response::TxidsResponse; use zaino_proto::proto::compact_formats::ChainMetadata; use zaino_proto::proto::compact_formats::{ CompactBlock, CompactOrchardAction, CompactSaplingOutput, CompactSaplingSpend, CompactTx, @@ -83,7 +83,7 @@ pub struct StateService { /// Sync task handle. sync_task_handle: Option>, /// JsonRPC Client. - rpc_client: JsonRpcConnector, + rpc_client: JsonRpSeeConnector, /// Service metadata. data: ServiceMetadata, /// StateService config data. @@ -95,7 +95,7 @@ pub struct StateService { impl StateService { /// Initializes a new StateService instance and starts sync process. pub async fn spawn(config: StateServiceConfig) -> Result { - let rpc_client = JsonRpcConnector::new_from_config_parts( + let rpc_client = JsonRpSeeConnector::new_from_config_parts( config.validator_cookie_auth, config.validator_rpc_address, config.validator_rpc_user.clone(), @@ -826,7 +826,7 @@ impl StateService { .checked_call(zebra_state::ReadRequest::BlockHeader(hash_or_height)) .await .map_err(|_| { - StateServiceError::RpcError(zaino_fetch::jsonrpc::connector::RpcError { + StateServiceError::RpcError(zaino_fetch::jsonrpsee::connector::RpcError { // Compatibility with zcashd. Note that since this function // is reused by getblock(), we return the errors expected // by it (they differ whether a hash or a height was passed) @@ -855,7 +855,7 @@ impl StateService { // This could be `None` if there's a chain reorg between state queries. let sapling_tree = sapling_tree.ok_or_else(|| { - StateServiceError::RpcError(zaino_fetch::jsonrpc::connector::RpcError { + StateServiceError::RpcError(zaino_fetch::jsonrpsee::connector::RpcError { code: LegacyCode::InvalidParameter as i64, message: "missing sapling tree for block".to_string(), data: None, @@ -958,7 +958,7 @@ impl StateService { ) .await .map_err(|_| { - StateServiceError::RpcError(zaino_fetch::jsonrpc::connector::RpcError { + StateServiceError::RpcError(zaino_fetch::jsonrpsee::connector::RpcError { // Compatibility with zcashd. Note that since this function // is reused by getblock(), we return the errors expected // by it (they differ whether a hash or a height was passed) @@ -987,7 +987,7 @@ impl StateService { // This could be `None` if there's a chain reorg between state queries. let sapling_tree = sapling_tree.ok_or_else(|| { - StateServiceError::RpcError(zaino_fetch::jsonrpc::connector::RpcError { + StateServiceError::RpcError(zaino_fetch::jsonrpsee::connector::RpcError { code: LegacyCode::InvalidParameter as i64, message: "missing sapling tree for block".to_string(), data: None, @@ -1067,7 +1067,7 @@ impl StateService { .await? else { return Err(StateServiceError::RpcError( - zaino_fetch::jsonrpc::connector::RpcError { + zaino_fetch::jsonrpsee::connector::RpcError { code: LegacyCode::InvalidParameter as i64, message: "Block not found".to_string(), data: None, diff --git a/zainod/src/error.rs b/zainod/src/error.rs index 2e95dde..07108da 100644 --- a/zainod/src/error.rs +++ b/zainod/src/error.rs @@ -1,6 +1,6 @@ //! Hold error types for the Indexer and related functionality. -use zaino_fetch::jsonrpc::error::JsonRpcConnectorError; +use zaino_fetch::jsonrpsee::error::JsonRpSeeConnectorError; use zaino_serve::server::error::ServerError; use zaino_state::error::FetchServiceError; @@ -13,9 +13,9 @@ pub enum IndexerError { /// Configuration errors. #[error("Configuration error: {0}")] ConfigError(String), - /// JSON RPC connector errors. - #[error("JSON RPC connector error: {0}")] - JsonRpcConnectorError(#[from] JsonRpcConnectorError), + /// JSON RPSee connector errors. + #[error("JSON RPSee connector error: {0}")] + JsonRpSeeConnectorError(#[from] JsonRpSeeConnectorError), /// FetchService errors. #[error("FetchService error: {0}")] FetchServiceError(#[from] FetchServiceError), diff --git a/zainod/src/indexer.rs b/zainod/src/indexer.rs index c74d600..590e165 100644 --- a/zainod/src/indexer.rs +++ b/zainod/src/indexer.rs @@ -3,7 +3,7 @@ use tokio::time::Instant; use tracing::info; -use zaino_fetch::jsonrpc::connector::test_node_and_return_url; +use zaino_fetch::jsonrpsee::connector::test_node_and_return_url; use zaino_serve::server::{config::GrpcConfig, grpc::TonicServer}; use zaino_state::{ config::FetchServiceConfig, @@ -50,7 +50,7 @@ impl Indexer { .await?; info!( - " - Connected to node using JsonRPC at address {}.", + " - Connected to node using JsonRPSee at address {}.", zebrad_uri );