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

eth: explicit rpc error return #383

Merged
merged 2 commits into from
Jun 6, 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
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions kinode/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ alloy-contract = { git = "https://github.com/alloy-rs/alloy", rev = "6f8ebb4" }
alloy-consensus = { git = "https://github.com/alloy-rs/alloy", rev = "6f8ebb4" }
alloy-pubsub = { git = "https://github.com/alloy-rs/alloy", rev = "6f8ebb4" }
alloy-rpc-types = { git = "https://github.com/alloy-rs/alloy", rev = "6f8ebb4" }
alloy-json-rpc = { git = "https://github.com/alloy-rs/alloy", rev = "6f8ebb4" }
alloy-rpc-client = { git = "https://github.com/alloy-rs/alloy", rev = "6f8ebb4", features = ["ws"]}
alloy-transport-ws = { git = "https://github.com/alloy-rs/alloy", rev = "6f8ebb4" }
alloy-providers = { git = "https://github.com/alloy-rs/alloy", rev = "6f8ebb4" }
Expand Down
7 changes: 6 additions & 1 deletion kinode/src/eth/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use alloy_json_rpc::RpcError;
use alloy_providers::provider::Provider;
use alloy_pubsub::PubSubFrontend;
use alloy_rpc_client::ClientBuilder;
Expand Down Expand Up @@ -618,6 +619,10 @@ async fn fulfill_request(
return EthResponse::Response { value };
}
Err(rpc_error) => {
// if rpc_error is of type ErrResponse, return to user!
if let RpcError::ErrorResp(err) = rpc_error {
return EthResponse::Err(EthError::RpcError(err));
}
verbose_print(
print_tx,
&format!(
Expand Down Expand Up @@ -651,7 +656,7 @@ async fn fulfill_request(
)
.await;
if let EthResponse::Err(e) = response {
if e == EthError::RpcMalformedResponse {
if let EthError::RpcMalformedResponse = e {
node_provider.usable = false;
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion kinode/src/eth/subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ async fn build_subscription(
node_provider.usable = false;
}
EthResponse::Err(e) => {
if e == EthError::RpcMalformedResponse {
if let EthError::RpcMalformedResponse = e {
node_provider.usable = false;
}
}
Expand Down
1 change: 1 addition & 0 deletions lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ tokio = "1.28"

[dependencies]
alloy-rpc-types = { git = "https://github.com/alloy-rs/alloy", rev = "6f8ebb4" }
alloy-json-rpc = { git = "https://github.com/alloy-rs/alloy", rev = "6f8ebb4" }
lazy_static = "1.4.0"
rand = "0.8.4"
ring = "0.17.8"
Expand Down
5 changes: 4 additions & 1 deletion lib/src/eth.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use alloy_json_rpc::ErrorPayload;
use alloy_rpc_types::pubsub::{Params, SubscriptionKind, SubscriptionResult};
use serde::{Deserialize, Serialize};
use std::collections::{HashMap, HashSet};
Expand Down Expand Up @@ -59,8 +60,10 @@ pub enum EthResponse {
Err(EthError),
}

#[derive(Debug, Serialize, Deserialize, PartialEq)]
#[derive(Debug, Serialize, Deserialize)]
pub enum EthError {
/// RPC provider returned an error
RpcError(ErrorPayload),
/// provider module cannot parse message
MalformedRequest,
/// No RPC provider for the chain
Expand Down
Loading