Skip to content

Commit af47f73

Browse files
gakonstampcode-commattsse
authored
chore: remove jsonrpsee dependencies (#3690)
* chore: remove jsonrpsee dependencies - Remove jsonrpsee and jsonrpsee-types workspace deps - Remove FilterId <-> jsonrpsee SubscriptionId conversions (rpc-types-eth) - Remove ForkchoiceUpdateError -> jsonrpsee ErrorObject conversion (rpc-types-engine) - Remove jsonrpsee-types feature from rpc-types, rpc-types-eth, rpc-types-engine - Remove rpc-types-json feature from alloy meta-crate - Rewrite test_subscription_race_condition to use tokio-tungstenite mock server - Rewrite serde_json_header test to use local deserialization structs Amp-Thread-ID: https://ampcode.com/threads/T-019c5c46-90c3-7619-9be3-555766617985 Co-authored-by: Amp <amp@ampcode.com> * fix: add dead_code allow on test-only deserialization structs Amp-Thread-ID: https://ampcode.com/threads/T-019c5c46-90c3-7619-9be3-555766617985 Co-authored-by: Amp <amp@ampcode.com> --------- Co-authored-by: Amp <amp@ampcode.com> Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
1 parent 01d1b22 commit af47f73

10 files changed

Lines changed: 56 additions & 95 deletions

File tree

Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,6 @@ semver = "1.0"
163163
strum = { version = "0.27", default-features = false }
164164
thiserror = { version = "2.0", default-features = false }
165165
url = "2.5"
166-
jsonrpsee = { version = "0.25", default-features = false }
167-
jsonrpsee-types = "0.25"
168166

169167
# misc-testing
170168
arbitrary = "1.3"

crates/alloy/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,6 @@ rpc-types-engine = [
251251
"alloy-provider?/engine-api",
252252
]
253253
rpc-types-eth = ["rpc-types", "alloy-rpc-types?/eth"]
254-
rpc-types-json = ["rpc-types", "alloy-rpc-types?/jsonrpsee-types"]
255254
rpc-types-mev = ["rpc-types", "alloy-rpc-types?/mev"]
256255
rpc-types-trace = [
257256
"rpc-types",

crates/provider/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ http.workspace = true
9999
alloy-rpc-types-engine = { workspace = true, features = ["jwt"] }
100100
ci_info.workspace = true
101101
similar-asserts.workspace = true
102-
jsonrpsee = { workspace = true, features = ["server"] }
102+
tokio-tungstenite.workspace = true
103103

104104
[features]
105105
default = ["reqwest", "reqwest-default-tls"]

crates/provider/tests/it/ws.rs

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -41,41 +41,48 @@ async fn ws_retry_pubsub() -> Result<(), Box<dyn std::error::Error>> {
4141
// <https://github.com/alloy-rs/alloy/issues/1601>
4242
#[tokio::test]
4343
async fn test_subscription_race_condition() -> Result<(), Box<dyn std::error::Error>> {
44-
async fn run_server() -> Result<std::net::SocketAddr, Box<dyn std::error::Error>> {
45-
use jsonrpsee::server::{RpcModule, Server, SubscriptionMessage};
46-
47-
let server = Server::builder().build("127.0.0.1:0").await?;
48-
let mut module = RpcModule::new(());
49-
module
50-
.register_subscription(
51-
"subscribe_hello",
52-
"s_hello",
53-
"unsubscribe_hello",
54-
|_, pending, _, _| async move {
55-
let sub = pending.accept().await.unwrap();
56-
57-
for i in 0..usize::MAX {
58-
let raw = serde_json::value::to_raw_value(&i).unwrap();
59-
let msg = SubscriptionMessage::from(raw);
60-
sub.send(msg).await.unwrap();
61-
tokio::time::sleep(std::time::Duration::from_millis(10)).await;
62-
}
63-
64-
Ok(())
65-
},
66-
)
67-
.unwrap();
68-
let addr = server.local_addr()?;
69-
70-
let handle = server.start(module);
71-
72-
tokio::spawn(handle.stopped());
73-
74-
Ok(addr)
75-
}
76-
use alloy_provider::{Provider, ProviderBuilder};
44+
use futures::{SinkExt, StreamExt};
45+
use tokio::net::TcpListener;
46+
use tokio_tungstenite::tungstenite::Message;
47+
48+
let listener = TcpListener::bind("127.0.0.1:0").await?;
49+
let addr = listener.local_addr()?;
50+
51+
tokio::spawn(async move {
52+
let (stream, _) = listener.accept().await.unwrap();
53+
let mut ws = tokio_tungstenite::accept_async(stream).await.unwrap();
54+
55+
// Read the subscribe request.
56+
let msg = ws.next().await.unwrap().unwrap();
57+
let req: serde_json::Value = serde_json::from_str(msg.to_text().unwrap()).unwrap();
58+
let id = req["id"].clone();
59+
60+
// Respond with a subscription ID.
61+
let resp = serde_json::json!({
62+
"jsonrpc": "2.0",
63+
"id": id,
64+
"result": "0x1"
65+
});
66+
ws.send(Message::Text(resp.to_string().into())).await.unwrap();
67+
68+
// Send subscription notifications.
69+
for i in 0..usize::MAX {
70+
let notif = serde_json::json!({
71+
"jsonrpc": "2.0",
72+
"method": "s_hello",
73+
"params": {
74+
"subscription": "0x1",
75+
"result": i
76+
}
77+
});
78+
if ws.send(Message::Text(notif.to_string().into())).await.is_err() {
79+
break;
80+
}
81+
tokio::time::sleep(std::time::Duration::from_millis(10)).await;
82+
}
83+
});
7784

78-
let addr = run_server().await?;
85+
use alloy_provider::{Provider, ProviderBuilder};
7986

8087
let ws_provider = ProviderBuilder::new().connect(format!("ws://{addr}").as_str()).await?;
8188
let mut request = ws_provider.client().request("subscribe_hello", ());

crates/rpc-types-engine/Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ serde = { workspace = true, features = ["derive"], optional = true }
4141
ethereum_ssz_derive = { workspace = true, optional = true }
4242
ethereum_ssz = { workspace = true, optional = true }
4343

44-
# jsonrpsee
45-
jsonrpsee-types = { workspace = true, optional = true }
46-
4744
# arbitrary
4845
arbitrary = { workspace = true, features = ["derive"], optional = true }
4946

@@ -72,7 +69,6 @@ serde = [
7269
"rand?/serde",
7370
]
7471
jwt = ["std", "dep:jsonwebtoken", "dep:rand"]
75-
jsonrpsee-types = ["dep:jsonrpsee-types"]
7672
ssz = ["std", "dep:ethereum_ssz", "dep:ethereum_ssz_derive", "alloy-eips/ssz"]
7773
kzg = ["alloy-consensus/kzg", "alloy-eips/kzg"]
7874
arbitrary = ["dep:arbitrary", "std", "alloy-primitives/arbitrary", "alloy-serde/arbitrary", "alloy-consensus/arbitrary", "alloy-eips/arbitrary"]

crates/rpc-types-engine/src/forkchoice.rs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -100,28 +100,6 @@ pub enum ForkchoiceUpdateError {
100100

101101
impl core::error::Error for ForkchoiceUpdateError {}
102102

103-
#[cfg(feature = "jsonrpsee-types")]
104-
impl From<ForkchoiceUpdateError> for jsonrpsee_types::error::ErrorObject<'static> {
105-
fn from(value: ForkchoiceUpdateError) -> Self {
106-
match value {
107-
ForkchoiceUpdateError::UpdatedInvalidPayloadAttributes => {
108-
jsonrpsee_types::error::ErrorObject::owned(
109-
INVALID_PAYLOAD_ATTRIBUTES_ERROR,
110-
INVALID_PAYLOAD_ATTRIBUTES_ERROR_MSG,
111-
None::<()>,
112-
)
113-
}
114-
ForkchoiceUpdateError::InvalidState | ForkchoiceUpdateError::UnknownFinalBlock => {
115-
jsonrpsee_types::error::ErrorObject::owned(
116-
INVALID_FORK_CHOICE_STATE_ERROR,
117-
INVALID_FORK_CHOICE_STATE_ERROR_MSG,
118-
None::<()>,
119-
)
120-
}
121-
}
122-
}
123-
}
124-
125103
/// Represents a successfully _processed_ forkchoice state update.
126104
///
127105
/// Note: this can still be INVALID if the provided payload was invalid.

crates/rpc-types-eth/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ serde_json = { workspace = true, optional = true }
4242
# arbitrary
4343
arbitrary = { version = "1.3", features = ["derive"], optional = true }
4444

45-
# jsonrpsee
46-
jsonrpsee-types = { workspace = true, optional = true }
4745
alloy-sol-types.workspace = true
4846

4947
[dev-dependencies]
@@ -99,6 +97,5 @@ arbitrary = [
9997
"alloy-consensus-any/arbitrary",
10098
"alloy-sol-types/arbitrary"
10199
]
102-
jsonrpsee-types = ["dep:jsonrpsee-types"]
103100
k256 = ["alloy-consensus/k256", "alloy-eips/k256"]
104101
serde-bincode-compat = ["serde", "dep:serde_with", "alloy-eips/serde-bincode-compat"]

crates/rpc-types-eth/src/block.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -831,14 +831,24 @@ mod tests {
831831
}
832832

833833
#[test]
834-
#[cfg(all(feature = "jsonrpsee-types", feature = "serde"))]
834+
#[cfg(feature = "serde")]
835835
fn serde_json_header() {
836-
use jsonrpsee_types::SubscriptionResponse;
836+
#[derive(serde::Deserialize)]
837+
#[allow(dead_code)]
838+
struct SubParams<T> {
839+
result: T,
840+
}
841+
#[derive(serde::Deserialize)]
842+
#[allow(dead_code)]
843+
struct SubNotification<T> {
844+
params: SubParams<T>,
845+
}
846+
837847
let resp = r#"{"jsonrpc":"2.0","method":"eth_subscribe","params":{"subscription":"0x7eef37ff35d471f8825b1c8f67a5d3c0","result":{"hash":"0x7a7ada12e140961a32395059597764416499f4178daf1917193fad7bd2cc6386","parentHash":"0xdedbd831f496e705e7f2ec3c8dcb79051040a360bf1455dbd7eb8ea6ad03b751","sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347","miner":"0x0000000000000000000000000000000000000000","stateRoot":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","receiptsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","number":"0x8","gasUsed":"0x0","gasLimit":"0x1c9c380","extraData":"0x","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","timestamp":"0x642aa48f","difficulty":"0x0","mixHash":"0x0000000000000000000000000000000000000000000000000000000000000000","nonce":"0x0000000000000000"}}}"#;
838-
let _header: SubscriptionResponse<'_, Header> = serde_json::from_str(resp).unwrap();
848+
let _header: SubNotification<Header> = serde_json::from_str(resp).unwrap();
839849

840850
let resp = r#"{"jsonrpc":"2.0","method":"eth_subscription","params":{"subscription":"0x1a14b6bdcf4542fabf71c4abee244e47","result":{"author":"0x000000568b9b5a365eaa767d42e74ed88915c204","difficulty":"0x1","extraData":"0x4e65746865726d696e6420312e392e32322d302d6463373666616366612d32308639ad8ff3d850a261f3b26bc2a55e0f3a718de0dd040a19a4ce37e7b473f2d7481448a1e1fd8fb69260825377c0478393e6055f471a5cf839467ce919a6ad2700","gasLimit":"0x7a1200","gasUsed":"0x0","hash":"0xa4856602944fdfd18c528ef93cc52a681b38d766a7e39c27a47488c8461adcb0","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","miner":"0x0000000000000000000000000000000000000000","mixHash":"0x0000000000000000000000000000000000000000000000000000000000000000","nonce":"0x0000000000000000","number":"0x434822","parentHash":"0x1a9bdc31fc785f8a95efeeb7ae58f40f6366b8e805f47447a52335c95f4ceb49","receiptsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347","size":"0x261","stateRoot":"0xf38c4bf2958e541ec6df148e54ce073dc6b610f8613147ede568cb7b5c2d81ee","totalDifficulty":"0x633ebd","timestamp":"0x604726b0","transactions":[],"transactionsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","uncles":[]}}}"#;
841-
let _header: SubscriptionResponse<'_, Header> = serde_json::from_str(resp).unwrap();
851+
let _header: SubNotification<Header> = serde_json::from_str(resp).unwrap();
842852
}
843853

844854
#[test]

crates/rpc-types-eth/src/filter.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,26 +1351,6 @@ impl From<String> for FilterId {
13511351
}
13521352
}
13531353

1354-
#[cfg(feature = "jsonrpsee-types")]
1355-
impl From<FilterId> for jsonrpsee_types::SubscriptionId<'_> {
1356-
fn from(value: FilterId) -> Self {
1357-
match value {
1358-
FilterId::Num(n) => jsonrpsee_types::SubscriptionId::Num(n),
1359-
FilterId::Str(s) => jsonrpsee_types::SubscriptionId::Str(s.into()),
1360-
}
1361-
}
1362-
}
1363-
1364-
#[cfg(feature = "jsonrpsee-types")]
1365-
impl From<jsonrpsee_types::SubscriptionId<'_>> for FilterId {
1366-
fn from(value: jsonrpsee_types::SubscriptionId<'_>) -> Self {
1367-
match value {
1368-
jsonrpsee_types::SubscriptionId::Num(n) => n.into(),
1369-
jsonrpsee_types::SubscriptionId::Str(s) => s.into_owned().into(),
1370-
}
1371-
}
1372-
}
1373-
13741354
/// Specifies the kind of information you wish to receive from the `eth_newPendingTransactionFilter`
13751355
/// RPC endpoint.
13761356
///

crates/rpc-types/Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,6 @@ arbitrary = [
6868
"alloy-primitives/arbitrary",
6969
"alloy-rpc-types-engine?/arbitrary"
7070
]
71-
jsonrpsee-types = [
72-
"alloy-rpc-types-eth?/jsonrpsee-types",
73-
"alloy-rpc-types-engine?/jsonrpsee-types",
74-
]
7571
ssz = ["alloy-rpc-types-beacon?/ssz", "alloy-rpc-types-engine?/ssz"]
7672
k256 = ["alloy-rpc-types-eth?/k256"]
7773
kzg = ["alloy-rpc-types-engine?/kzg"]

0 commit comments

Comments
 (0)