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(providers): connect_boxed api #342

Merged
merged 28 commits into from
Mar 26, 2024

Conversation

yash-atreya
Copy link
Member

@yash-atreya yash-atreya commented Mar 19, 2024

Motivation

Ref: #318

Solution

Implement a connect_boxed(&str) -> RootProvider<N, BoxTransport> method for RootProvider<N, T>.

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

crates/provider/src/utils.rs Outdated Show resolved Hide resolved
crates/provider/src/provider.rs Outdated Show resolved Hide resolved
crates/provider/src/provider.rs Outdated Show resolved Hide resolved
Cargo.toml Outdated Show resolved Hide resolved
crates/provider/src/utils.rs Outdated Show resolved Hide resolved
crates/provider/src/utils.rs Outdated Show resolved Hide resolved
@yash-atreya yash-atreya marked this pull request as ready for review March 21, 2024 20:13
crates/provider/src/utils.rs Outdated Show resolved Hide resolved
@@ -1,7 +1,7 @@
use alloy_node_bindings::Anvil;
use alloy_primitives::U64;
use alloy_rpc_client::{ClientBuilder, RpcCall};
use alloy_transport_ws::WsConnect;
use alloy_transport::WsConnect;
Copy link
Member

Choose a reason for hiding this comment

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

Failing in CI

crates/provider/src/provider.rs Outdated Show resolved Hide resolved
crates/provider/src/provider.rs Outdated Show resolved Hide resolved
crates/provider/src/provider.rs Outdated Show resolved Hide resolved
crates/provider/src/provider.rs Outdated Show resolved Hide resolved
crates/provider/src/utils.rs Outdated Show resolved Hide resolved
crates/provider/src/utils.rs Outdated Show resolved Hide resolved
@yash-atreya
Copy link
Member Author

Need some help with fixing ci. Not sure why it's failing.
WsConnect is to be imported from alloy_transport_ws.
That's how it is on main

use alloy_transport_ws::WsConnect;

@@ -14,12 +14,13 @@ exclude.workspace = true
[dependencies]
alloy-json-rpc.workspace = true
alloy-network.workspace = true
alloy-rpc-client = { workspace = true, features = ["reqwest"] }
alloy-rpc-client = { workspace = true, features = ["reqwest", "pubsub"] }
Copy link
Member

Choose a reason for hiding this comment

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

Need some help with fixing ci. Not sure why it's failing. WsConnect is to be imported from alloy_transport_ws. That's how it is on main

use alloy_transport_ws::WsConnect;

dep:alloy-transport-ws is under the ws feature, but the test is cfg(feature = "pubsub") so when the pubsub feature is active, but the ws feature is not, there's an error. This is triggered by this feature line here, I believe

Copy link
Member

Choose a reason for hiding this comment

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

basically, this feature activation causes the cargo resolver to activate ONLY pubsub on alloy-rpc-client, and not ws, which causes the alloy-transport-ws to be missing when the test runs. This feature should not be activated here, it should instead be activated under the pubsub feature n this crate

we should also change the cfg in rpc-client/tests/it/main.rs

Copy link
Member

@prestwich prestwich Mar 22, 2024

Choose a reason for hiding this comment

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

summary:

  • remove this pubsub feature activation
  • update cfgs in rpc-client/tests/it/main.rs

Copy link
Member

Choose a reason for hiding this comment

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

cc @mattsse @DaniPopes should ws and ipc be default features for the provider crate?

Copy link
Member Author

Choose a reason for hiding this comment

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

summary:

  • remove this pubsub feature activation
  • update cfgs in rpc-client/tests/it/main.rs

We need the pubsub feature enabled on alloy-rpc-client as it is required for connect_pubsub

Copy link
Member

Choose a reason for hiding this comment

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

that implies that connect_pubsub should be cfg gated behind the alloy-provider pubsub feature

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

and the WS/IPC components also need cfg gating

Copy link
Member Author

Choose a reason for hiding this comment

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

that implies that connect_pubsub should be cfg gated behind the alloy-provider pubsub feature

If I'm not mistaken, this means disabling the connect_boxed method as it uses connect_pubsub for ws and ipc.

Not seeing a way to gate connect_pubsub using the pubsub feature without sacrificing connect_boxed.

Copy link
Member

Choose a reason for hiding this comment

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

it means changing the behavior to produce ONLY enabled trandport types. eg. only http when pubsub is disabled

Copy link
Member

@prestwich prestwich left a comment

Choose a reason for hiding this comment

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

1 more feature:

The connect_boxed shortcut should also exist in the ProviderBuilder as fn connect_boxed(self, s: &str) -> Result<L::Provider>

crates/provider/src/utils.rs Outdated Show resolved Hide resolved
crates/provider/src/utils.rs Outdated Show resolved Hide resolved
crates/provider/src/utils.rs Outdated Show resolved Hide resolved
crates/provider/src/utils.rs Outdated Show resolved Hide resolved
@prestwich
Copy link
Member

did a significant cleanup here:

  • BuiltInConnectionString -> alloy-rpc-client
  • improve parsing
  • impl BoxTransportConnect for BuiltinConnectionString
  • passthrough features appropriately
  • ProviderBuilder::on_builtin to attempt to connect to a builting transport type via the connection string

Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

smol suggestion

crates/rpc-client/src/builtin.rs Outdated Show resolved Hide resolved
@prestwich prestwich linked an issue Mar 26, 2024 that may be closed by this pull request

# rpc
alloy-json-rpc = { workspace = true, default-features = false, optional = true }
alloy-rpc-client = { workspace = true, default-features = false, optional = true }
alloy-rpc-client = { workspace = true, optional = true }
Copy link
Member

Choose a reason for hiding this comment

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

this two lines now cause warnings as the root cargo toml doesn't set default-features

@prestwich prestwich merged commit 68952c0 into alloy-rs:main Mar 26, 2024
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] Provider::connect API
4 participants