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: set poll interval based on connected chain #767

Merged
merged 5 commits into from
May 24, 2024
Merged

feat: set poll interval based on connected chain #767

merged 5 commits into from
May 24, 2024

Conversation

RexCloud
Copy link
Contributor

@RexCloud RexCloud commented May 21, 2024

Motivation

Closes #604

Solution

Add with_chain() method to ProviderBuilder. The ChainLayer will fetch the average block time for the chain and set client's poll interval

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

@RexCloud RexCloud changed the title Main feat: set poll interval based on connected chain May 21, 2024
@RexCloud RexCloud marked this pull request as ready for review May 21, 2024 18:45
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.

imo this makes sense, and isn't very complex

crates/provider/Cargo.toml Outdated Show resolved Hide resolved
crates/provider/src/provider/trait.rs Outdated Show resolved Hide resolved
crates/rpc-client/src/client.rs Outdated Show resolved Hide resolved
crates/rpc-client/src/client.rs Outdated Show resolved Hide resolved
crates/rpc-client/src/client.rs Outdated Show resolved Hide resolved
crates/rpc-client/src/client.rs Outdated Show resolved Hide resolved
crates/provider/src/provider/trait.rs Outdated Show resolved Hide resolved
crates/rpc-client/src/client.rs Outdated Show resolved Hide resolved
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.

Approach is a hard NACK from me

  • Behavior is non-obvious. Users would not expect that calling an RPC method would change provider behavior
  • Not all users will call get_chain_id, leading to different behavior in a hard-to-diagnose setting
  • The same program may not call get_chain_id on different runs, leading to inconsistent configuration for the same code

This could be done idiomatically by adding ProviderBuilder methods to provide or fetch this at instantiation time

fn with_chain()
async fn fetch_chain()

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.

i like the approach, thanks :) couple quick questions in the review comments

crates/rpc-client/src/client.rs Show resolved Hide resolved
crates/provider/src/layers/chain.rs Show resolved Hide resolved
@RexCloud RexCloud requested a review from mattsse May 24, 2024 12:02
@prestwich prestwich merged commit fbd84f8 into alloy-rs:main May 24, 2024
24 checks passed
ben186 pushed a commit to ben186/alloy that referenced this pull request Jul 27, 2024
* feat: set poll interval based on connected chain

* Revert changes

* feat: `ChainLayer` to set poll interval based on chain

* use const fn
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] Set default poll interval based on connected chain
4 participants