Skip to content

feat(provider): watch_full_blocks #2194

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

Merged
merged 17 commits into from
Mar 28, 2025
Merged

feat(provider): watch_full_blocks #2194

merged 17 commits into from
Mar 28, 2025

Conversation

yash-atreya
Copy link
Member

@yash-atreya yash-atreya commented Mar 13, 2025

Motivation

Partially addresses #325

Solution

  • Introduces WatchBlocks
  • WatchBlocks consumes the stream of block hashes from PollerBuilder and maps it to Stream<Item = TransportResult<BlockResponse>

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

@yash-atreya yash-atreya marked this pull request as ready for review March 17, 2025 08:13
@yash-atreya yash-atreya marked this pull request as draft March 17, 2025 08:13
@yash-atreya yash-atreya marked this pull request as ready for review March 17, 2025 08:18
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.

not immediately obvious why this needs an additional task.

I'm a bit confused by how the PollerBuilder stuff works, or why this appears to be so complex,

isn't this jus feature just mapped stream effectively?

@yash-atreya yash-atreya marked this pull request as draft March 17, 2025 15:13
@yash-atreya yash-atreya marked this pull request as ready for review March 18, 2025 11:23
@yash-atreya yash-atreya requested a review from mattsse March 18, 2025 11:23
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.

a few more questions


/// Consumes the stream of block hashes from the inner [`PollerBuilder`] and maps it to a stream
/// of [`BlockResponse`].
pub fn into_stream(self) -> impl Stream<Item = TransportResult<BlockResp>> + Unpin {
Copy link
Member

Choose a reason for hiding this comment

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

if we return anonymous types then this should also enforce Send because this can't be inferred on the callsite

but this is likely problematic for wasm compat

Copy link
Member

Choose a reason for hiding this comment

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

we don't do this anywhere for streams

Copy link
Member

Choose a reason for hiding this comment

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

this however means we can't send this stream, e.g. for background monitoring.

maybe this limitation is fine but doesn't sound ideal, we could roll our own stream type that this generic over the future so that Send is auto impl.

but this can also be a followup

Copy link
Member

Choose a reason for hiding this comment

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

you can call into_stream after sending, but yes ideally these are all named types...

@github-project-automation github-project-automation bot moved this to In Progress in Alloy Mar 19, 2025

/// Consumes the stream of block hashes from the inner [`PollerBuilder`] and maps it to a stream
/// of [`BlockResponse`].
pub fn into_stream(self) -> impl Stream<Item = TransportResult<BlockResp>> + Unpin {
Copy link
Member

Choose a reason for hiding this comment

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

we don't do this anywhere for streams

@yash-atreya yash-atreya enabled auto-merge (squash) March 21, 2025 10:26
@yash-atreya yash-atreya moved this from In Progress to Ready for Review in Alloy Mar 24, 2025

/// Consumes the stream of block hashes from the inner [`PollerBuilder`] and maps it to a stream
/// of [`BlockResponse`].
pub fn into_stream(self) -> impl Stream<Item = TransportResult<BlockResp>> + Unpin {
Copy link
Member

Choose a reason for hiding this comment

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

this however means we can't send this stream, e.g. for background monitoring.

maybe this limitation is fine but doesn't sound ideal, we could roll our own stream type that this generic over the future so that Send is auto impl.

but this can also be a followup

@@ -496,6 +496,36 @@ pub trait Provider<N: Network = Ethereum>: Send + Sync {
Ok(PollerBuilder::new(self.weak_client(), "eth_getFilterChanges", (id,)))
}

/// Watch for new blocks by polling the provider with
Copy link
Member

@DaniPopes DaniPopes Mar 25, 2025

Choose a reason for hiding this comment

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

shouldn't this be just watch_blocks().full() instead of a separate method?

Copy link
Member Author

@yash-atreya yash-atreya Mar 26, 2025

Choose a reason for hiding this comment

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

I'd like to keep it as a different method because if we want to get a block with full txns we'll have to do watch_blocks().await?.full().full_txns() vs watch_full_blocks().await?.full()

@github-project-automation github-project-automation bot moved this from Ready for Review to In Progress in Alloy Mar 25, 2025
@yash-atreya yash-atreya requested a review from DaniPopes March 27, 2025 08:43
@mattsse mattsse disabled auto-merge March 28, 2025 13:34
@mattsse mattsse merged commit 89af055 into main Mar 28, 2025
27 checks passed
@mattsse mattsse deleted the yash/watch-full-blocks branch March 28, 2025 13:35
@github-project-automation github-project-automation bot moved this from In Progress to Done in Alloy Mar 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[Feature] Add methods to retrieve full_blocks and full_blocks_with_txs in watch and subscribe methods.
3 participants