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

feat(eth-client): Generalize RPC client #1898

Merged
merged 17 commits into from
May 14, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix web3_decl features
slowli committed May 9, 2024

Verified

This commit was signed with the committer’s verified signature.
joshcooper Josh Cooper
commit 9b0abfc236bd0a12a4fa7bd15a38653b2e0da26d
1 change: 1 addition & 0 deletions core/lib/web3_decl/Cargo.toml
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@ rlp.workspace = true
thiserror.workspace = true
jsonrpsee = { workspace = true, features = [
"macros",
"client-core",
] }
pin-project-lite.workspace = true
zksync_types.workspace = true
15 changes: 10 additions & 5 deletions core/lib/web3_decl/src/namespaces/debug.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
use jsonrpsee::{core::RpcResult, proc_macros::rpc};
#[cfg_attr(not(feature = "server"), allow(unused_imports))]
use jsonrpsee::core::RpcResult;
use jsonrpsee::proc_macros::rpc;
use zksync_types::{
api::{BlockId, BlockNumber, DebugCall, ResultDebugCall, TracerConfig},
debug_flat_call::DebugCallFlat,
transaction_request::CallRequest,
};

use crate::{
client::{ForNetwork, L2},
types::H256,
};
#[cfg(feature = "client")]
use crate::client::{ForNetwork, L2};
use crate::types::H256;

#[cfg_attr(
all(feature = "client", feature = "server"),
@@ -29,25 +30,29 @@ pub trait DebugNamespace {
block: BlockNumber,
options: Option<TracerConfig>,
) -> RpcResult<Vec<ResultDebugCall>>;

#[method(name = "traceBlockByNumber.callFlatTracer")]
async fn trace_block_by_number_flat(
&self,
block: BlockNumber,
options: Option<TracerConfig>,
) -> RpcResult<Vec<DebugCallFlat>>;

#[method(name = "traceBlockByHash")]
async fn trace_block_by_hash(
&self,
hash: H256,
options: Option<TracerConfig>,
) -> RpcResult<Vec<ResultDebugCall>>;

#[method(name = "traceCall")]
async fn trace_call(
&self,
request: CallRequest,
block: Option<BlockId>,
options: Option<TracerConfig>,
) -> RpcResult<DebugCall>;

#[method(name = "traceTransaction")]
async fn trace_transaction(
&self,
5 changes: 4 additions & 1 deletion core/lib/web3_decl/src/namespaces/en.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use jsonrpsee::{core::RpcResult, proc_macros::rpc};
#[cfg_attr(not(feature = "server"), allow(unused_imports))]
use jsonrpsee::core::RpcResult;
use jsonrpsee::proc_macros::rpc;
use zksync_config::{configs::EcosystemContracts, GenesisConfig};
use zksync_types::{api::en, tokens::TokenInfo, Address, L2BlockNumber};

#[cfg(feature = "client")]
use crate::client::{ForNetwork, L2};

#[cfg_attr(
41 changes: 26 additions & 15 deletions core/lib/web3_decl/src/namespaces/eth.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
use jsonrpsee::{
core::{RpcResult, SubscriptionResult},
proc_macros::rpc,
};
#[cfg_attr(not(feature = "server"), allow(unused_imports))]
use jsonrpsee::core::RpcResult;
slowli marked this conversation as resolved.
Show resolved Hide resolved
use jsonrpsee::proc_macros::rpc;
use zksync_types::{
api::{BlockId, BlockIdVariant, BlockNumber, Transaction, TransactionVariant},
transaction_request::CallRequest,
Address, H256,
};

use crate::{
client::{ForNetwork, L2},
types::{
Block, Bytes, FeeHistory, Filter, FilterChanges, Index, Log, PubSubFilter, SyncState,
TransactionReceipt, U256, U64,
},
#[cfg(feature = "client")]
use crate::client::{ForNetwork, L2};
use crate::types::{
Block, Bytes, FeeHistory, Filter, FilterChanges, Index, Log, SyncState, TransactionReceipt,
U256, U64,
};

#[cfg_attr(
@@ -179,9 +177,22 @@ pub trait EthNamespace {
) -> 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;
#[cfg(feature = "server")]
mod pub_sub {
use jsonrpsee::{core::SubscriptionResult, proc_macros::rpc};

use crate::types::PubSubFilter;

#[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;
}
}

#[cfg(feature = "server")]
pub use self::pub_sub::EthPubSubServer;
4 changes: 2 additions & 2 deletions core/lib/web3_decl/src/namespaces/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#[cfg(feature = "client")]
pub use self::{
debug::DebugNamespaceClient, en::EnNamespaceClient, eth::EthNamespaceClient,
net::NetNamespaceClient, snapshots::SnapshotsNamespaceServer, web3::Web3NamespaceClient,
net::NetNamespaceClient, snapshots::SnapshotsNamespaceClient, web3::Web3NamespaceClient,
zks::ZksNamespaceClient,
};
#[cfg(feature = "server")]
pub use self::{
debug::DebugNamespaceServer, en::EnNamespaceServer, eth::EthNamespaceServer,
eth::EthPubSubServer, net::NetNamespaceServer, snapshots::SnapshotsNamespaceClient,
eth::EthPubSubServer, net::NetNamespaceServer, snapshots::SnapshotsNamespaceServer,
web3::Web3NamespaceServer, zks::ZksNamespaceServer,
};

5 changes: 4 additions & 1 deletion core/lib/web3_decl/src/namespaces/net.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use jsonrpsee::{core::RpcResult, proc_macros::rpc};
#[cfg_attr(not(feature = "server"), allow(unused_imports))]
use jsonrpsee::core::RpcResult;
use jsonrpsee::proc_macros::rpc;
use zksync_types::U256;

#[cfg(feature = "client")]
use crate::client::{ForNetwork, L2};

#[cfg_attr(
5 changes: 4 additions & 1 deletion core/lib/web3_decl/src/namespaces/snapshots.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use jsonrpsee::{core::RpcResult, proc_macros::rpc};
#[cfg_attr(not(feature = "server"), allow(unused_imports))]
use jsonrpsee::core::RpcResult;
use jsonrpsee::proc_macros::rpc;
use zksync_types::{
snapshots::{AllSnapshots, SnapshotHeader},
L1BatchNumber,
};

#[cfg(feature = "client")]
use crate::client::{ForNetwork, L2};

#[cfg_attr(
5 changes: 4 additions & 1 deletion core/lib/web3_decl/src/namespaces/web3.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use jsonrpsee::{core::RpcResult, proc_macros::rpc};
#[cfg_attr(not(feature = "server"), allow(unused_imports))]
use jsonrpsee::core::RpcResult;
use jsonrpsee::proc_macros::rpc;

#[cfg(feature = "client")]
use crate::client::{ForNetwork, L2};

#[cfg_attr(
11 changes: 6 additions & 5 deletions core/lib/web3_decl/src/namespaces/zks.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::collections::HashMap;

use jsonrpsee::{core::RpcResult, proc_macros::rpc};
#[cfg_attr(not(feature = "server"), allow(unused_imports))]
use jsonrpsee::core::RpcResult;
use jsonrpsee::proc_macros::rpc;
use zksync_types::{
api::{
BlockDetails, BridgeAddresses, L1BatchDetails, L2ToL1LogProof, Proof, ProtocolVersion,
@@ -12,10 +14,9 @@ use zksync_types::{
Address, L1BatchNumber, L2BlockNumber, H256, U256, U64,
};

use crate::{
client::{ForNetwork, L2},
types::{Bytes, Token},
};
#[cfg(feature = "client")]
use crate::client::{ForNetwork, L2};
use crate::types::{Bytes, Token};

#[cfg_attr(
all(feature = "client", feature = "server"),
2 changes: 1 addition & 1 deletion prover/prover_cli/src/commands/status/l1.rs
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ pub(crate) async fn run() -> anyhow::Result<()> {
let postgres_config = PostgresConfig::from_env().context("PostgresConfig::from_env")?;
let contracts_config = ContractsConfig::from_env().context("ContractsConfig::from_env()")?;
let eth_config = EthConfig::from_env().context("EthConfig::from_env")?;
let query_client = Client::<L1, _>::http(eth_config.web3_url)?.build();
let query_client = Client::<L1>::http(eth_config.web3_url)?.build();

let total_batches_committed: U256 = CallFunctionArgs::new("getTotalBatchesCommitted", ())
.for_contract(