Skip to content

Commit

Permalink
feat(api): remove jsonrpc backend (#693)
Browse files Browse the repository at this point in the history
## What ❔

The new release of `jsonrpsee` removes all known blockers for removing
`jsonrpc` backend.


## Checklist

<!-- Check your PR fulfills the following items. -->
<!-- For draft PRs check the boxes as you complete them. -->

- [ ] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [ ] Tests for the changes have been added / updated.
- [ ] Documentation comments have been added / updated.
- [ ] Code has been formatted via `zk fmt` and `zk lint`.
- [ ] Spellcheck has been run via `cargo spellcheck
--cfg=./spellcheck/era.cfg --code 1`.
  • Loading branch information
montekki authored Dec 21, 2023
1 parent 7661558 commit b3f0417
Show file tree
Hide file tree
Showing 39 changed files with 814 additions and 1,962 deletions.
773 changes: 266 additions & 507 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions core/bin/external_node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ async fn init_tasks(
};

let http_server_handles =
ApiBuilder::jsonrpc_backend(config.clone().into(), connection_pool.clone())
ApiBuilder::jsonrpsee_backend(config.clone().into(), connection_pool.clone())
.http(config.required.http_port)
.with_filter_limit(config.optional.filters_limit)
.with_batch_request_size_limit(config.optional.max_batch_request_size)
Expand All @@ -284,7 +284,7 @@ async fn init_tasks(
.context("Failed initializing HTTP JSON-RPC server")?;

let ws_server_handles =
ApiBuilder::jsonrpc_backend(config.clone().into(), connection_pool.clone())
ApiBuilder::jsonrpsee_backend(config.clone().into(), connection_pool.clone())
.ws(config.required.ws_port)
.with_filter_limit(config.optional.filters_limit)
.with_subscriptions_limit(config.optional.subscriptions_limit)
Expand Down
9 changes: 5 additions & 4 deletions core/lib/config/src/configs/api.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{net::SocketAddr, time::Duration};
use std::{net::SocketAddr, num::NonZeroU32, time::Duration};

use serde::Deserialize;
use zksync_basic_types::H256;
Expand Down Expand Up @@ -86,7 +86,7 @@ pub struct Web3JsonRpcConfig {
/// Maximum number of requests per minute for the WebSocket server.
/// The value is per active connection.
/// Note: For HTTP, rate limiting is expected to be configured on the infra level.
pub websocket_requests_per_minute_limit: Option<u32>,
pub websocket_requests_per_minute_limit: Option<NonZeroU32>,
/// Tree API url, currently used to proxy `getProof` calls to the tree
pub tree_api_url: Option<String>,
}
Expand Down Expand Up @@ -204,9 +204,10 @@ impl Web3JsonRpcConfig {
self.max_response_body_size_mb.unwrap_or(10) * super::BYTES_IN_MEGABYTE
}

pub fn websocket_requests_per_minute_limit(&self) -> u32 {
pub fn websocket_requests_per_minute_limit(&self) -> NonZeroU32 {
// The default limit is chosen to be reasonably permissive.
self.websocket_requests_per_minute_limit.unwrap_or(6000)
self.websocket_requests_per_minute_limit
.unwrap_or(NonZeroU32::new(6000).unwrap())
}

pub fn tree_api_url(&self) -> Option<String> {
Expand Down
4 changes: 3 additions & 1 deletion core/lib/env_config/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ impl FromEnv for MerkleTreeApiConfig {

#[cfg(test)]
mod tests {
use std::num::NonZeroU32;

use super::*;
use crate::test_utils::{hash, EnvMutex};

Expand Down Expand Up @@ -86,7 +88,7 @@ mod tests {
fee_history_limit: Some(100),
max_batch_request_size: Some(200),
max_response_body_size_mb: Some(10),
websocket_requests_per_minute_limit: Some(10),
websocket_requests_per_minute_limit: Some(NonZeroU32::new(10).unwrap()),
tree_api_url: None,
},
contract_verification: ContractVerificationApiConfig {
Expand Down
2 changes: 1 addition & 1 deletion core/lib/web3_decl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ serde_json = "1.0"
rlp = "0.5.0"
thiserror = "1.0"
bigdecimal = { version = "0.2.2", features = ["serde"] }
jsonrpsee = { version = "0.19.0", default-features = false, features = [
jsonrpsee = { version = "0.21.0", default-features = false, features = [
"macros",
] }
chrono = "0.4"
Expand Down
4 changes: 2 additions & 2 deletions core/lib/web3_decl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ pub mod namespaces;
pub mod types;

pub use jsonrpsee;
use jsonrpsee::core::Error;
use jsonrpsee::core::ClientError;

pub type RpcResult<T> = Result<T, Error>;
pub type RpcResult<T> = Result<T, ClientError>;
16 changes: 13 additions & 3 deletions core/lib/web3_decl/src/namespaces/eth.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
use jsonrpsee::{core::RpcResult, proc_macros::rpc};
use jsonrpsee::{
core::{RpcResult, SubscriptionResult},
proc_macros::rpc,
};
use zksync_types::{
api::{BlockIdVariant, BlockNumber, Transaction, TransactionVariant},
transaction_request::CallRequest,
Address, H256,
};

use crate::types::{
Block, Bytes, FeeHistory, Filter, FilterChanges, Index, Log, SyncState, TransactionReceipt,
U256, U64,
Block, Bytes, FeeHistory, Filter, FilterChanges, Index, Log, PubSubFilter, SyncState,
TransactionReceipt, U256, U64,
};

#[cfg_attr(
Expand Down Expand Up @@ -166,3 +169,10 @@ pub trait EthNamespace {
reward_percentiles: Vec<f32>,
) -> RpcResult<FeeHistory>;
}

#[rpc(server, namespace = "eth")]
pub trait EthPubSub {
#[subscription(name = "subscribe" => "subscription", unsubscribe = "unsubscribe", item = PubSubResult)]
async fn subscribe(&self, sub_type: String, filter: Option<PubSubFilter>)
-> SubscriptionResult;
}
4 changes: 2 additions & 2 deletions core/lib/web3_decl/src/namespaces/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ pub use self::{
#[cfg(feature = "server")]
pub use self::{
debug::DebugNamespaceServer, en::EnNamespaceServer, eth::EthNamespaceServer,
net::NetNamespaceServer, snapshots::SnapshotsNamespaceClient, web3::Web3NamespaceServer,
zks::ZksNamespaceServer,
eth::EthPubSubServer, net::NetNamespaceServer, snapshots::SnapshotsNamespaceClient,
web3::Web3NamespaceServer, zks::ZksNamespaceServer,
};
8 changes: 1 addition & 7 deletions core/lib/zksync_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,6 @@ thiserror = "1.0"
async-trait = "0.1"
bitflags = "1.3.2"

# API dependencies
jsonrpc-core = { git = "https://github.com/matter-labs/jsonrpc.git", branch = "master" }
jsonrpc-core-client = { git = "https://github.com/matter-labs/jsonrpc.git", branch = "master" } # Required for the RPC trait
jsonrpc-http-server = { git = "https://github.com/matter-labs/jsonrpc.git", branch = "master" }
jsonrpc-ws-server = { git = "https://github.com/matter-labs/jsonrpc.git", branch = "master" }
jsonrpc-derive = { git = "https://github.com/matter-labs/jsonrpc.git", branch = "master" }
jsonrpc-pubsub = { git = "https://github.com/matter-labs/jsonrpc.git", branch = "master" }
num = { version = "0.3.1", features = ["serde"] }
bigdecimal = { version = "0.2.2", features = ["serde"] }
reqwest = { version = "0.11", features = ["blocking", "json"] }
Expand All @@ -96,6 +89,7 @@ tracing = "0.1.26"
zksync_test_account = { path = "../test_account" }

assert_matches = "1.5"
jsonrpsee = "0.21.0"
tempfile = "3.0.2"
test-casing = "0.1.2"

Expand Down
2 changes: 1 addition & 1 deletion core/lib/zksync_core/src/api_server/tx_sender/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub enum SubmitTxError {
IntrinsicGas,
/// Error returned from main node
#[error("{0}")]
ProxyError(#[from] zksync_web3_decl::jsonrpsee::core::Error),
ProxyError(#[from] zksync_web3_decl::jsonrpsee::core::ClientError),
}

impl SubmitTxError {
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit b3f0417

Please sign in to comment.