Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

json-rpc: update jsonrpsee dependency to 0.24.7 #20775

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
342 changes: 200 additions & 142 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 1 addition & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -373,13 +373,7 @@ integer-encoding = "3.0.1"
ipnetwork = "0.20.0"
itertools = "0.13.0"
jemalloc-ctl = "^0.5"
jsonrpsee = { git = "https://github.com/wlmyng/jsonrpsee.git", rev = "b1b300784795f6a64d0fcdf8f03081a9bc38bde8", features = [
"server",
"macros",
"ws-client",
"http-client",
"jsonrpsee-core",
] }
jsonrpsee = { version = "0.24.7", features = ["server", "macros", "ws-client", "http-client", "jsonrpsee-core"] }
json_to_table = { git = "https://github.com/zhiburt/tabled/", rev = "e449317a1c02eb6b29e409ad6617e5d9eb7b3bd4" }
leb128 = "0.2.5"
lru = "0.10"
Expand Down
15 changes: 6 additions & 9 deletions crates/sui-e2e-tests/tests/traffic_control_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
use core::panic;
use fastcrypto::encoding::Base64;
use jsonrpsee::{
core::{client::ClientT, RpcResult},
rpc_params,
};
use jsonrpsee::{core::client::ClientT, rpc_params};
use std::fs::File;
use std::num::NonZeroUsize;
use std::time::Duration;
Expand Down Expand Up @@ -201,7 +198,7 @@ async fn test_fullnode_traffic_control_dry_run() -> Result<(), anyhow::Error> {

// it should take no more than 4 requests to be added to the blocklist
for _ in 0..txn_count {
let response: RpcResult<SuiTransactionBlockResponse> = jsonrpc_client
let response: Result<SuiTransactionBlockResponse, _> = jsonrpc_client
.request("sui_getTransactionBlock", rpc_params![*tx_digest])
.await;
assert!(
Expand Down Expand Up @@ -307,7 +304,7 @@ async fn test_fullnode_traffic_control_spam_blocked() -> Result<(), anyhow::Erro

// it should take no more than 4 requests to be added to the blocklist
for _ in 0..txn_count {
let response: RpcResult<SuiTransactionBlockResponse> = jsonrpc_client
let response: Result<SuiTransactionBlockResponse, _> = jsonrpc_client
.request("sui_getTransactionBlock", rpc_params![*tx_digest])
.await;
if let Err(err) = response {
Expand Down Expand Up @@ -362,7 +359,7 @@ async fn test_fullnode_traffic_control_error_blocked() -> Result<(), anyhow::Err
SuiTransactionBlockResponseOptions::new(),
ExecuteTransactionRequestType::WaitForLocalExecution
];
let response: RpcResult<SuiTransactionBlockResponse> = jsonrpc_client
let response: Result<SuiTransactionBlockResponse, _> = jsonrpc_client
.request("sui_executeTransactionBlock", params.clone())
.await;
if let Err(err) = response {
Expand Down Expand Up @@ -517,7 +514,7 @@ async fn test_fullnode_traffic_control_spam_delegated() -> Result<(), anyhow::Er
assert!(confirmed_local_execution.unwrap());

for _ in 0..txn_count {
let response: RpcResult<SuiTransactionBlockResponse> = jsonrpc_client
let response: Result<SuiTransactionBlockResponse, _> = jsonrpc_client
.request("sui_getTransactionBlock", rpc_params![*tx_digest])
.await;
assert!(response.is_ok(), "Expected request to succeed");
Expand Down Expand Up @@ -845,7 +842,7 @@ async fn assert_validator_traffic_control_dry_run(

// it should take no more than 4 requests to be added to the blocklist
for _ in 0..txn_count {
let response: RpcResult<SuiTransactionBlockResponse> = jsonrpc_client
let response: Result<SuiTransactionBlockResponse, _> = jsonrpc_client
.request("sui_getTransactionBlock", rpc_params![*tx_digest])
.await;
assert!(
Expand Down
26 changes: 9 additions & 17 deletions crates/sui-indexer-alt-jsonrpc/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ use diesel::query_dsl::methods::LimitDsl;
use diesel::result::Error as DieselError;
use diesel_async::methods::LoadQuery;
use diesel_async::RunQueryDsl;
use jsonrpsee::core::Error as RpcError;
use jsonrpsee::types::{
error::{CallError, INTERNAL_ERROR_CODE},
ErrorObject,
};
use jsonrpsee::types::{error::INTERNAL_ERROR_CODE, ErrorObject};
use sui_pg_db as db;
use tracing::debug;

Expand Down Expand Up @@ -49,20 +45,16 @@ impl<'p> Connection<'p> {
}
}

impl From<DbError> for RpcError {
fn from(err: DbError) -> RpcError {
impl From<DbError> for ErrorObject<'static> {
fn from(err: DbError) -> Self {
match err {
DbError::Connect(err) => RpcError::Call(CallError::Custom(ErrorObject::owned(
INTERNAL_ERROR_CODE,
err.to_string(),
None::<()>,
))),
DbError::Connect(err) => {
ErrorObject::owned(INTERNAL_ERROR_CODE, err.to_string(), None::<()>)
}

DbError::RunQuery(err) => RpcError::Call(CallError::Custom(ErrorObject::owned(
INTERNAL_ERROR_CODE,
err.to_string(),
None::<()>,
))),
DbError::RunQuery(err) => {
ErrorObject::owned(INTERNAL_ERROR_CODE, err.to_string(), None::<()>)
}
}
}
}
4 changes: 1 addition & 3 deletions crates/sui-indexer-alt-jsonrpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ impl RpcService {

info!("Starting JSON-RPC service on {listen_address}",);

let handle = server
.start(modules)
.context("Failed to start JSON-RPC service")?;
let handle = server.start(modules);

Ok(tokio::spawn(async move {
handle.stopped().await;
Expand Down
10 changes: 4 additions & 6 deletions crates/sui-indexer/src/apis/extended_api.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use crate::indexer_reader::IndexerReader;
use crate::{errors::IndexerError, indexer_reader::IndexerReader};
use jsonrpsee::{core::RpcResult, RpcModule};
use sui_json_rpc::SuiRpcModule;
use sui_json_rpc_api::{validate_limit, ExtendedApiServer, QUERY_MAX_RESULT_LIMIT_CHECKPOINTS};
Expand Down Expand Up @@ -29,7 +29,8 @@ impl ExtendedApiServer for ExtendedApi {
limit: Option<usize>,
descending_order: Option<bool>,
) -> RpcResult<EpochPage> {
let limit = validate_limit(limit, QUERY_MAX_RESULT_LIMIT_CHECKPOINTS)?;
let limit = validate_limit(limit, QUERY_MAX_RESULT_LIMIT_CHECKPOINTS)
.map_err(IndexerError::from)?;
let mut epochs = self
.inner
.get_epochs(
Expand Down Expand Up @@ -60,10 +61,7 @@ impl ExtendedApiServer for ExtendedApi {
_cursor: Option<CheckpointedObjectID>,
_limit: Option<usize>,
) -> RpcResult<QueryObjectsPage> {
Err(jsonrpsee::types::error::CallError::Custom(
jsonrpsee::types::error::ErrorCode::MethodNotFound.into(),
)
.into())
Err(jsonrpsee::types::error::ErrorCode::MethodNotFound.into())
}

async fn get_total_transactions(&self) -> RpcResult<BigInt<u64>> {
Expand Down
36 changes: 22 additions & 14 deletions crates/sui-indexer/src/apis/indexer_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@

use async_trait::async_trait;
use jsonrpsee::core::RpcResult;
use jsonrpsee::types::SubscriptionEmptyError;
use jsonrpsee::types::SubscriptionResult;
use jsonrpsee::{RpcModule, SubscriptionSink};
use jsonrpsee::core::SubscriptionResult;
use jsonrpsee::{PendingSubscriptionSink, RpcModule};
use tap::TapFallible;

use sui_json_rpc::name_service::{Domain, NameRecord, NameServiceConfig, NameServiceError};
Expand Down Expand Up @@ -67,7 +66,7 @@ impl IndexerApi {
.collect::<Result<Vec<_>, _>>()
.map_err(|e| {
tracing::error!("Error joining object read futures.");
jsonrpsee::core::Error::Custom(format!("Error joining object read futures. {}", e))
crate::errors::IndexerError::from(e)
})?
.into_iter()
.collect::<Result<Vec<_>, _>>()
Expand Down Expand Up @@ -119,9 +118,11 @@ impl IndexerApi {
.await
.into_iter()
.collect::<Result<Vec<_>, _>>()
.map_err(|e: tokio::task::JoinError| anyhow::anyhow!(e))?
.map_err(|e: tokio::task::JoinError| anyhow::anyhow!(e))
.map_err(IndexerError::from)?
.into_iter()
.collect::<Result<Vec<_>, anyhow::Error>>()?;
.collect::<Result<Vec<_>, anyhow::Error>>()
.map_err(IndexerError::from)?;

Ok(Page {
data,
Expand Down Expand Up @@ -168,8 +169,7 @@ impl IndexerApiServer for IndexerApi {
limit + 1,
descending_order.unwrap_or(false),
)
.await
.map_err(|e: IndexerError| anyhow::anyhow!(e))?;
.await?;

let has_next_page = results.len() > limit;
results.truncate(limit);
Expand Down Expand Up @@ -254,7 +254,9 @@ impl IndexerApiServer for IndexerApi {
| sui_types::object::ObjectRead::Deleted(_) => {}
sui_types::object::ObjectRead::Exists(object_ref, o, layout) => {
return Ok(SuiObjectResponse::new_with_data(
(object_ref, o, layout, options, None).try_into()?,
(object_ref, o, layout, options, None)
.try_into()
.map_err(IndexerError::from)?,
));
}
}
Expand All @@ -274,7 +276,9 @@ impl IndexerApiServer for IndexerApi {
| sui_types::object::ObjectRead::Deleted(_) => {}
sui_types::object::ObjectRead::Exists(object_ref, o, layout) => {
return Ok(SuiObjectResponse::new_with_data(
(object_ref, o, layout, options, None).try_into()?,
(object_ref, o, layout, options, None)
.try_into()
.map_err(IndexerError::from)?,
));
}
}
Expand All @@ -284,16 +288,20 @@ impl IndexerApiServer for IndexerApi {
))
}

fn subscribe_event(&self, _sink: SubscriptionSink, _filter: EventFilter) -> SubscriptionResult {
Err(SubscriptionEmptyError)
fn subscribe_event(
&self,
_sink: PendingSubscriptionSink,
_filter: EventFilter,
) -> SubscriptionResult {
Err("disabled".into())
}

fn subscribe_transaction(
&self,
_sink: SubscriptionSink,
_sink: PendingSubscriptionSink,
_filter: TransactionFilter,
) -> SubscriptionResult {
Err(SubscriptionEmptyError)
Err("disabled".into())
}

async fn resolve_name_service_address(&self, name: String) -> RpcResult<Option<SuiAddress>> {
Expand Down
39 changes: 11 additions & 28 deletions crates/sui-indexer/src/apis/read_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,32 +142,23 @@ impl ReadApiServer for ReadApi {
_version: SequenceNumber,
_options: Option<SuiObjectDataOptions>,
) -> RpcResult<SuiPastObjectResponse> {
Err(jsonrpsee::types::error::CallError::Custom(
jsonrpsee::types::error::ErrorCode::MethodNotFound.into(),
)
.into())
Err(jsonrpsee::types::error::ErrorCode::MethodNotFound.into())
}

async fn try_get_object_before_version(
&self,
_: ObjectID,
_: SequenceNumber,
) -> RpcResult<SuiPastObjectResponse> {
Err(jsonrpsee::types::error::CallError::Custom(
jsonrpsee::types::error::ErrorCode::MethodNotFound.into(),
)
.into())
Err(jsonrpsee::types::error::ErrorCode::MethodNotFound.into())
}

async fn try_multi_get_past_objects(
&self,
_past_objects: Vec<SuiGetPastObjectRequest>,
_options: Option<SuiObjectDataOptions>,
) -> RpcResult<Vec<SuiPastObjectResponse>> {
Err(jsonrpsee::types::error::CallError::Custom(
jsonrpsee::types::error::ErrorCode::MethodNotFound.into(),
)
.into())
Err(jsonrpsee::types::error::ErrorCode::MethodNotFound.into())
}

async fn get_latest_checkpoint_sequence_number(&self) -> RpcResult<BigInt<u64>> {
Expand Down Expand Up @@ -209,20 +200,6 @@ impl ReadApiServer for ReadApi {
})
}

async fn get_checkpoints_deprecated_limit(
&self,
cursor: Option<BigInt<u64>>,
limit: Option<BigInt<u64>>,
descending_order: bool,
) -> RpcResult<CheckpointPage> {
self.get_checkpoints(
cursor,
limit.map(|l| l.into_inner() as usize),
descending_order,
)
.await
}

async fn get_events(&self, transaction_digest: TransactionDigest) -> RpcResult<Vec<SuiEvent>> {
self.inner
.get_transaction_events(transaction_digest)
Expand Down Expand Up @@ -282,7 +259,11 @@ async fn object_read_to_object_response(
Ok(rendered_fields) => display_fields = Some(rendered_fields),
Err(e) => {
return Ok(SuiObjectResponse::new(
Some((object_ref, o, layout, options, None).try_into()?),
Some(
(object_ref, o, layout, options, None)
.try_into()
.map_err(IndexerError::from)?,
),
Some(SuiObjectResponseError::DisplayError {
error: e.to_string(),
}),
Expand All @@ -291,7 +272,9 @@ async fn object_read_to_object_response(
}
}
Ok(SuiObjectResponse::new_with_data(
(object_ref, o, layout, options, display_fields).try_into()?,
(object_ref, o, layout, options, display_fields)
.try_into()
.map_err(IndexerError::from)?,
))
}
ObjectRead::Deleted((object_id, version, digest)) => Ok(SuiObjectResponse::new_with_error(
Expand Down
9 changes: 7 additions & 2 deletions crates/sui-indexer/src/apis/write_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ impl WriteApiServer for WriteApi {
let sui_transaction_response = self
.fullnode
.execute_transaction_block(tx_bytes, signatures, options.clone(), request_type)
.await?;
.await
.map_err(crate::errors::client_error_to_error_object)?;
Ok(SuiTransactionBlockResponseWithOptions {
response: sui_transaction_response,
options: options.unwrap_or_default(),
Expand All @@ -69,13 +70,17 @@ impl WriteApiServer for WriteApi {
additional_args,
)
.await
.map_err(crate::errors::client_error_to_error_object)
}

async fn dry_run_transaction_block(
&self,
tx_bytes: Base64,
) -> RpcResult<DryRunTransactionBlockResponse> {
self.fullnode.dry_run_transaction_block(tx_bytes).await
self.fullnode
.dry_run_transaction_block(tx_bytes)
.await
.map_err(crate::errors::client_error_to_error_object)
}
}

Expand Down
22 changes: 19 additions & 3 deletions crates/sui-indexer/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

use fastcrypto::error::FastCryptoError;
use jsonrpsee::core::Error as RpcError;
use jsonrpsee::types::error::CallError;
use jsonrpsee::types::ErrorObjectOwned as RpcError;
use sui_json_rpc::name_service::NameServiceError;
use thiserror::Error;

Expand Down Expand Up @@ -155,7 +154,11 @@ impl<T> Context<T> for Result<T, IndexerError> {

impl From<IndexerError> for RpcError {
fn from(e: IndexerError) -> Self {
RpcError::Call(CallError::Failed(e.into()))
RpcError::owned(
jsonrpsee::types::error::CALL_EXECUTION_FAILED_CODE,
e.to_string(),
None::<()>,
)
}
}

Expand All @@ -170,3 +173,16 @@ impl From<diesel_async::pooled_connection::bb8::RunError> for IndexerError {
Self::PgPoolConnectionError(value.to_string())
}
}

pub(crate) fn client_error_to_error_object(
e: jsonrpsee::core::ClientError,
) -> jsonrpsee::types::ErrorObjectOwned {
match e {
jsonrpsee::core::ClientError::Call(e) => e,
_ => jsonrpsee::types::ErrorObjectOwned::owned(
jsonrpsee::types::error::UNKNOWN_ERROR_CODE,
e.to_string(),
None::<()>,
),
}
}
Loading
Loading