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

[deps] update rpc deps #2044

Merged
merged 4 commits into from
Jul 2, 2024
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
570 changes: 415 additions & 155 deletions Cargo.lock

Large diffs are not rendered by default.

13 changes: 6 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ futures = "0.3.28"
hex = "0.4.3"
rustc-hex = "2.1"
itertools = "0.13.0"
jsonrpsee = { version = "0.16.3", features = ["full"] }
jsonrpsee = { version = "0.23.2", features = ["full"] }
jpst = "0.1.1"
lazy_static = "1.5.0"
linked-hash-map = "0.5.6"
Expand Down Expand Up @@ -226,8 +226,8 @@ nostr = "0.22"
serde-reflection = "0.3.6"
serde-generate = "0.25.1"
bcs-ext = { path = "moveos/moveos-commons/bcs_ext" }
tower = { version = "0.4.12", features = ["full", "util", "timeout", "load-shed", "limit"] }
tower-http = { version = "0.4.4", features = ["cors", "full", "trace", "set-header", "propagate-header"] }
tower = { version = "0.4.13", features = ["full", "util", "timeout", "load-shed", "limit"] }
tower-http = { version = "0.5.2", features = ["cors", "full", "trace", "set-header", "propagate-header"] }
mirai-annotations = "1.12.0"
lru = "0.11.0"
bs58 = "0.5.1"
Expand All @@ -251,8 +251,7 @@ diesel = { version = "2.2.1", features = [
] }
diesel-derive-enum = { version = "2.1.0", features = ["sqlite"] }
diesel_migrations = { version = "2.2.0" }
axum = { version = "0.6.6", default-features = false, features = [
"headers",
axum = { version = "0.7.5", default-features = false, features = [
"tokio",
"http1",
"http2",
Expand All @@ -263,8 +262,8 @@ axum = { version = "0.6.6", default-features = false, features = [
"query",
"ws",
] }
axum-extra = "0.4.2"
axum-server = { version = "0.5.1", default-features = false, features = [
axum-extra = "0.9.3"
axum-server = { version = "0.6.0", default-features = false, features = [
"tls-rustls",
] }
serenity = { version = "0.12.2", default-features = false, features = [
Expand Down
1 change: 1 addition & 0 deletions crates/rooch-faucet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ serenity = { features = [
"model",
], workspace = true }
axum = { workspace = true }
axum-server = { workspace = true }
tracing = { workspace = true}
tower = { workspace = true }
tower-http = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/rooch-faucet/src/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ pub async fn serve(app: App, web_config: WebConfig) -> Result<(), anyhow::Error>

let addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), web_config.port);

axum::Server::bind(&addr)
axum_server::bind(addr)
.serve(router.into_make_service())
.await?;

Expand Down
2 changes: 1 addition & 1 deletion crates/rooch-rpc-api/src/api/btc_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use crate::jsonrpc_types::btc::ord::InscriptionFilterView;
use crate::jsonrpc_types::btc::utxo::UTXOFilterView;
use crate::jsonrpc_types::{InscriptionPageView, StrView, UTXOPageView};
use jsonrpsee::core::RpcResult;
use crate::RpcResult;
use jsonrpsee::proc_macros::rpc;
use rooch_open_rpc_macros::open_rpc;
use rooch_types::indexer::state::IndexerStateID;
Expand Down
2 changes: 1 addition & 1 deletion crates/rooch-rpc-api/src/api/rooch_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::jsonrpc_types::{
ObjectIDView, ObjectStateFilterView, ObjectStateView, QueryOptions, StateOptions,
StatePageView, StateView, StrView, StructTagView, TransactionWithInfoPageView, TxOptions,
};
use jsonrpsee::core::RpcResult;
use crate::RpcResult;
use jsonrpsee::proc_macros::rpc;
use moveos_types::{access_path::AccessPath, state::KeyState};
use rooch_open_rpc_macros::open_rpc;
Expand Down
31 changes: 31 additions & 0 deletions crates/rooch-rpc-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,34 @@

pub mod api;
pub mod jsonrpc_types;

pub type RpcResult<T> = Result<T, RpcError>;
use jsonrpsee::types::{ErrorObject, ErrorObjectOwned};
use rooch_types::error::RoochError;
use thiserror::Error;

#[derive(Debug, Error)]
pub enum RpcError {
#[error(transparent)]
RoochError(#[from] RoochError),

#[error(transparent)]
InternalError(#[from] anyhow::Error),

#[error("Deserialization error: {0}")]
BcsError(#[from] bcs::Error),

#[error("Unexpected error: {0}")]
UnexpectedError(String),
}

impl From<RpcError> for ErrorObjectOwned {
fn from(err: RpcError) -> Self {
match err {
RpcError::RoochError(err) => ErrorObject::owned(1, err.to_string(), None::<()>),
RpcError::InternalError(err) => ErrorObject::owned(2, err.to_string(), None::<()>),
RpcError::BcsError(err) => ErrorObject::owned(3, err.to_string(), None::<()>),
RpcError::UnexpectedError(err) => ErrorObject::owned(4, err.to_string(), None::<()>),
}
}
}
9 changes: 2 additions & 7 deletions crates/rooch-rpc-client/src/client_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use std::fmt::{Display, Formatter, Write};
use std::path::PathBuf;

pub const DEFAULT_EXPIRATION_SECS: u64 = 30;
pub const ROOCH_DEV_NET_URL: &str = "https://dev-seed.rooch.network:443/";
pub const ROOCH_TEST_NET_URL: &str = "https://test-seed.rooch.network:443/";
pub const ROOCH_DEV_NET_URL: &str = "https://dev-seed.rooch.network";
pub const ROOCH_TEST_NET_URL: &str = "https://test-seed.rooch.network";

#[derive(Serialize, Deserialize, Debug)]
pub struct ClientConfig {
Expand Down Expand Up @@ -77,18 +77,13 @@ impl Env {
pub async fn create_rpc_client(
&self,
request_timeout: std::time::Duration,
max_concurrent_requests: Option<u64>,
) -> Result<Client, anyhow::Error> {
let mut builder = ClientBuilder::default();
builder = builder.request_timeout(request_timeout);
if let Some(ws_url) = &self.ws {
builder = builder.ws_url(ws_url);
}

if let Some(max_concurrent_requests) = max_concurrent_requests {
builder = builder.max_concurrent_requests(max_concurrent_requests as usize);
}

builder.build(&self.rpc).await
}

Expand Down
10 changes: 1 addition & 9 deletions crates/rooch-rpc-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ pub mod wallet_context;

pub struct ClientBuilder {
request_timeout: Duration,
max_concurrent_requests: usize,
ws_url: Option<String>,
}

Expand All @@ -35,11 +34,6 @@ impl ClientBuilder {
self
}

pub fn max_concurrent_requests(mut self, max_concurrent_requests: usize) -> Self {
self.max_concurrent_requests = max_concurrent_requests;
self
}

pub fn ws_url(mut self, url: impl AsRef<str>) -> Self {
self.ws_url = Some(url.as_ref().to_string());
self
Expand All @@ -50,8 +44,7 @@ impl ClientBuilder {

let http_client = Arc::new(
HttpClientBuilder::default()
.max_request_body_size(2 << 30)
.max_concurrent_requests(self.max_concurrent_requests)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

新版本的 jsonrpsee 移除了max_concurrent_requests支持?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是的
参考这个:paritytech/jsonrpsee#1377

.max_request_size(2 << 30)
.request_timeout(self.request_timeout)
.build(http)?,
);
Expand All @@ -67,7 +60,6 @@ impl Default for ClientBuilder {
fn default() -> Self {
Self {
request_timeout: Duration::from_secs(60),
max_concurrent_requests: 256,
ws_url: None,
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/rooch-rpc-client/src/wallet_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl WalletContext {
let client = self
.client_config
.get_active_env()?
.create_rpc_client(Duration::from_secs(DEFAULT_EXPIRATION_SECS), None)
.create_rpc_client(Duration::from_secs(DEFAULT_EXPIRATION_SECS))
.await?;

self.client.write().await.insert(client).clone()
Expand Down
4 changes: 2 additions & 2 deletions crates/rooch-rpc-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ schemars = { workspace = true }
serde_with = { workspace = true }
rand = { workspace = true }
fastcrypto = { workspace = true, features = ["copy_key"] }
hyper = { workspace = true }
axum = { workspace = true }
log = { workspace = true }
lazy_static = { workspace = true }
rpassword = { workspace = true }
Expand Down Expand Up @@ -68,4 +68,4 @@ rooch-indexer = { workspace = true }
rooch-da = { workspace = true }
rooch-framework = { workspace = true }
rooch-genesis = { workspace = true }
rooch-db = { workspace = true }
rooch-db = { workspace = true }
19 changes: 11 additions & 8 deletions crates/rooch-rpc-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ use crate::service::aggregate_service::AggregateService;
use crate::service::rpc_logger::RpcLogger;
use crate::service::rpc_service::RpcService;
use anyhow::{ensure, Error, Result};
use axum::http::{HeaderValue, Method};
use coerce::actor::scheduler::timer::Timer;
use coerce::actor::{system::ActorSystem, IntoActor};
use hyper::header::HeaderValue;
use hyper::Method;
use jsonrpsee::server::middleware::rpc::RpcServiceBuilder;
use jsonrpsee::server::ServerBuilder;
use jsonrpsee::RpcModule;
use raw_store::errors::RawStoreError;
Expand All @@ -34,6 +34,7 @@ use rooch_proposer::proxy::ProposerProxy;
use rooch_relayer::actor::messages::RelayTick;
use rooch_relayer::actor::relayer::RelayerActor;
use rooch_rpc_api::api::RoochRpcModule;
use rooch_rpc_api::RpcError;
use rooch_sequencer::actor::sequencer::SequencerActor;
use rooch_sequencer::proxy::SequencerProxy;
use rooch_types::address::RoochAddress;
Expand Down Expand Up @@ -327,18 +328,20 @@ pub async fn run_start_server(opt: RoochOpt, server_opt: ServerOpt) -> Result<Se
.allow_methods([Method::POST])
// Allow requests from any origin
.allow_origin(acl)
.allow_headers([hyper::header::CONTENT_TYPE]);
.allow_headers([axum::http::header::CONTENT_TYPE]);

let middleware = tower::ServiceBuilder::new()
.layer(TraceLayer::new_for_http())
.layer(cors);

let addr: SocketAddr = format!("{}:{}", config.host, config.port).parse()?;

let rpc_middleware = RpcServiceBuilder::new().layer_fn(RpcLogger);

// Build server
let server = ServerBuilder::default()
.set_logger(RpcLogger)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rpc logger 为啥也去掉了?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jsonrpcseed的logger转移到了middware,现在用的middware是tower库的

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

等我改一下

.set_middleware(middleware)
.set_http_middleware(middleware)
.set_rpc_middleware(rpc_middleware)
.build(&addr)
.await?;

Expand All @@ -352,7 +355,7 @@ pub async fn run_start_server(opt: RoochOpt, server_opt: ServerOpt) -> Result<Se

// let rpc_api = build_rpc_api(rpc_api);
let methods_names = rpc_module_builder.module.method_names().collect::<Vec<_>>();
let handle = server.start(rpc_module_builder.module)?;
let handle = server.start(rpc_module_builder.module);

info!("JSON-RPC HTTP Server start listening {:?}", addr);
info!("Available JSON-RPC methods : {:?}", methods_names);
Expand All @@ -369,8 +372,8 @@ fn _build_rpc_api<M: Send + Sync + 'static>(mut rpc_module: RpcModule<M>) -> Rpc
available_methods.sort();

rpc_module
.register_method("rpc_methods", move |_, _| {
Ok(json!({
.register_method("rpc_methods", move |_, _, _| {
Ok::<serde_json::Value, RpcError>(json!({
"methods": available_methods,
}))
})
Expand Down
6 changes: 2 additions & 4 deletions crates/rooch-rpc-server/src/server/btc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@

use crate::service::{aggregate_service::AggregateService, rpc_service::RpcService};
use anyhow::Result;
use jsonrpsee::{
core::{async_trait, RpcResult},
RpcModule,
};
use jsonrpsee::{core::async_trait, RpcModule};
use move_core_types::account_address::AccountAddress;
use rooch_rpc_api::api::btc_api::BtcAPIServer;
use rooch_rpc_api::api::{RoochRpcModule, DEFAULT_RESULT_LIMIT_USIZE, MAX_RESULT_LIMIT_USIZE};
use rooch_rpc_api::jsonrpc_types::btc::ord::{InscriptionFilterView, InscriptionStateView};
use rooch_rpc_api::jsonrpc_types::btc::utxo::{UTXOFilterView, UTXOStateView};
use rooch_rpc_api::jsonrpc_types::{InscriptionPageView, StrView, UTXOPageView};
use rooch_rpc_api::RpcResult;
use rooch_types::indexer::state::IndexerStateID;
use std::cmp::min;

Expand Down
23 changes: 10 additions & 13 deletions crates/rooch-rpc-server/src/server/rooch_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
use crate::service::aggregate_service::AggregateService;
use crate::service::rpc_service::RpcService;
use anyhow::Result;
use jsonrpsee::{
core::{async_trait, RpcResult},
RpcModule,
};
use jsonrpsee::{core::async_trait, RpcModule};
use moveos_types::{
access_path::AccessPath,
h256::H256,
Expand All @@ -33,6 +30,8 @@ use rooch_rpc_api::jsonrpc_types::{
ExecuteTransactionResponseView, FunctionCallView, H256View, StatePageView, StateView, StrView,
StructTagView, TransactionWithInfoPageView,
};
use rooch_rpc_api::RpcError;
use rooch_rpc_api::RpcResult;
use rooch_rpc_api::{api::rooch_api::RoochAPIServer, api::DEFAULT_RESULT_LIMIT};
use rooch_rpc_api::{
api::{RoochRpcModule, DEFAULT_RESULT_LIMIT_USIZE},
Expand Down Expand Up @@ -160,8 +159,7 @@ impl RoochAPIServer for RoochServer {

async fn send_raw_transaction(&self, payload: BytesView) -> RpcResult<H256View> {
info!("send_raw_transaction payload: {:?}", payload);
let mut tx =
bcs::from_bytes::<RoochTransaction>(&payload.0).map_err(anyhow::Error::from)?;
let mut tx = bcs::from_bytes::<RoochTransaction>(&payload.0)?;
info!("send_raw_transaction tx: {:?}", tx);

let hash = tx.tx_hash();
Expand All @@ -175,7 +173,7 @@ impl RoochAPIServer for RoochServer {
tx_options: Option<TxOptions>,
) -> RpcResult<ExecuteTransactionResponseView> {
let tx_options = tx_options.unwrap_or_default();
let tx = bcs::from_bytes::<RoochTransaction>(&payload.0).map_err(anyhow::Error::from)?;
let tx = bcs::from_bytes::<RoochTransaction>(&payload.0)?;
let tx_response = self.rpc_service.execute_tx(tx).await?;

let result = if tx_options.with_output {
Expand Down Expand Up @@ -553,12 +551,11 @@ impl RoochAPIServer for RoochServer {
(end..start).rev().collect::<Vec<_>>()
} else {
let start = cursor.unwrap_or(0);
let start_plus =
start
.checked_add(limit_of + 1)
.ok_or(jsonrpsee::core::Error::Custom(
"cursor value is overflow".to_string(),
))?;
let start_plus = start
.checked_add(limit_of + 1)
.ok_or(RpcError::UnexpectedError(
"cursor value is overflow".to_string(),
))?;
let end = min(start_plus, last_sequencer_order + 1);

(start..end).collect::<Vec<_>>()
Expand Down
Loading
Loading