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): event, polling and streaming methods #274

Merged
merged 46 commits into from
Mar 13, 2024

Conversation

DaniPopes
Copy link
Member

@DaniPopes DaniPopes commented Mar 11, 2024

  • better pending transaction API, with config
  • added boxed to root provider and rpc clients
  • watch*, subscribe (TODO), filter* provider methods and related structs
  • Event API from ethers, including event *filter methods in sol! (feat(sol-macro): add event filters to contracts core#563)
    • subscribe and subscribe_with_meta have been merged into one, watch, which is a flattened stream over the Vec<Log> responses of eth_getFilterChanges. The stream returns (E: SolEvent, Log)
  • bump MSRV to 1.76 for Arc::unwrap_or_clone

Closes #264
Ref #270 (no rename, but doc alias)
Closes #293

crates/providers/src/heart.rs Outdated Show resolved Hide resolved
crates/providers/src/heart.rs Outdated Show resolved Hide resolved
crates/providers/src/new.rs Outdated Show resolved Hide resolved
crates/providers/src/new.rs Outdated Show resolved Hide resolved
///
/// The return value depends on what stream `id` corresponds to.
/// See [`FilterChanges`] for all possible return values.
#[auto_impl(keep_default_for(&, &mut, Rc, Arc, Box))]
Copy link
Member Author

Choose a reason for hiding this comment

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

TIL this is necessary for dyn Provider to work, because otherwise auto_impl puts U: Provider + Sized bounds on the generic implementations if Self: Sized methods are not marked with keep_default_for. I added a test for this in this file

crates/providers/src/new.rs Outdated Show resolved Hide resolved
crates/providers/src/new.rs Outdated Show resolved Hide resolved
crates/providers/src/new.rs Outdated Show resolved Hide resolved
crates/providers/src/new.rs Outdated Show resolved Hide resolved
crates/providers/src/new.rs Outdated Show resolved Hide resolved
crates/providers/src/new.rs Outdated Show resolved Hide resolved
crates/providers/src/heart.rs Outdated Show resolved Hide resolved
crates/providers/src/heart.rs Outdated Show resolved Hide resolved
crates/node-bindings/src/anvil.rs Show resolved Hide resolved
crates/contract/src/instance.rs Show resolved Hide resolved
@onbjerg
Copy link
Member

onbjerg commented Mar 12, 2024

looks ossome

Copy link
Member

@gakonst gakonst left a comment

Choose a reason for hiding this comment

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

gg so far so good

crates/contract/src/call.rs Outdated Show resolved Hide resolved
crates/contract/src/call.rs Show resolved Hide resolved
crates/contract/src/call.rs Outdated Show resolved Hide resolved
crates/contract/src/event.rs Show resolved Hide resolved
crates/contract/src/event.rs Show resolved Hide resolved
crates/providers/src/new.rs Outdated Show resolved Hide resolved
self.client().prepare("eth_getTransactionCount", (address, tag.unwrap_or_default())).await
}

/// Get a block by its number.
///
/// TODO: Network associate
// TODO: Network associate
Copy link
Member

Choose a reason for hiding this comment

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

not a blocker

Copy link
Member Author

@DaniPopes DaniPopes Mar 12, 2024

Choose a reason for hiding this comment

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

There is no network block RPC type, not really related to this PR

Copy link
Member Author

Choose a reason for hiding this comment

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

crates/providers/src/new.rs Outdated Show resolved Hide resolved
crates/providers/src/new.rs Outdated Show resolved Hide resolved
crates/providers/src/new.rs Outdated Show resolved Hide resolved
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.

I think the pending tx type should take a clone

crates/provider/src/new.rs Show resolved Hide resolved
@DaniPopes DaniPopes marked this pull request as ready for review March 12, 2024 17:24
@DaniPopes DaniPopes requested a review from Evalir as a code owner March 12, 2024 17:24
@gakonst gakonst requested review from mattsse and onbjerg March 12, 2024 17:42
Copy link
Member

@onbjerg onbjerg left a comment

Choose a reason for hiding this comment

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

generally like this, although we need to figure out a way to make transport layering work again. i think let's get this in, think on it, and if it's not possible, maybe we can move most use cases into provider layers? (retry logic etc)

crates/provider/src/new.rs Show resolved Hide resolved
crates/provider/src/new.rs Show resolved Hide resolved
Copy link
Member

@gakonst gakonst left a comment

Choose a reason for hiding this comment

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

Great!!! I am comfortable moving forward with this, let's get all the ethers examples ported now @yash-atreya @zerosnacks and please flag missing pieces to Dani as needed.

Comment on lines +48 to +49
/// .watch()
/// .await?;
Copy link
Member

Choose a reason for hiding this comment

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

OK I am fine with this API -- let's open issue for potentially auto-registering if possible, but we can move forward.

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure what this means

Comment on lines +92 to +99
let t = self.transport() as &dyn std::any::Any;
t.downcast_ref::<PubSubFrontend>()
.or_else(|| {
t.downcast_ref::<BoxTransport>()
.and_then(|t| t.as_any().downcast_ref::<PubSubFrontend>())
})
.ok_or_else(TransportErrorKind::pubsub_unavailable)
}
Copy link
Member

Choose a reason for hiding this comment

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

I am OK with this -- @mattsse @onbjerg any objections?

Copy link
Member

Choose a reason for hiding this comment

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

we can probably improve this, but for now this seems fine

crates/provider/src/new.rs Show resolved Hide resolved
Comment on lines +255 to +257
/// let poller = provider.watch_blocks().await?;
/// let mut stream = poller.into_stream().flat_map(futures::stream::iter).take(5);
/// while let Some(block_hash) = stream.next().await {
Copy link
Member

Choose a reason for hiding this comment

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

Can we get rid of the into_stream().flat_map(futures::stream::iter)? When do we want to use the stream vs the iter? https://docs.rs/futures/latest/futures/stream/fn.iter.html

Copy link
Member Author

@DaniPopes DaniPopes Mar 12, 2024

Choose a reason for hiding this comment

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

flat_map(futures::stream::iter) is .flatten() for streams of vecs (turns the vec into a stream, then flattens it), as discussed eth_getFilterChanges returns a Vec when we poll it

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.

progress 💪

@DaniPopes DaniPopes merged commit c65fd8a into main Mar 13, 2024
15 checks passed
@DaniPopes DaniPopes deleted the dani/provider-streams branch March 13, 2024 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants