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

[Bug] subscribe_blocks could not downcast to pubsub when creating provider using RetryBackoffLayer #1972

Closed
chain-lover opened this issue Jan 30, 2025 · 0 comments · Fixed by #1977
Labels
bug Something isn't working

Comments

@chain-lover
Copy link

Component

provider, pubsub

What version of Alloy are you on?

0.9.2

Operating System

Linux

Describe the bug

I'm trying to build provider using RetryBackoffLayer as it was in the example below but adding IpcConnect:
https://github.com/alloy-rs/examples/blob/9db483f94af1fb23141baa8e574f3c2ae12b90e6/examples/layers/examples/retry_layer.rs#L29

It doesn't downcast to pubsub when running subscribe_blocks method.

struct ProviderConfig {
    ipc: String,
    max_rate_limit_retries: u32,
    initial_backoff: u64,
    compute_units_per_second: u64,
}

#[cfg(test)]
mod test {
    use alloy_provider::{IpcConnect, Provider, ProviderBuilder};
    use alloy_rpc_client::RpcClient;
    use alloy_transport::layers::RetryBackoffLayer;
    use anyhow::Result;

    use crate::aggregate::ProviderConfig;

    #[tokio::test]
    async fn should_stream_block() -> Result<()> {
        let provider_config = ProviderConfig {
            ipc: "/tmp/reth.ipc".to_string(),
            max_rate_limit_retries: 1,
            initial_backoff: 50,
            compute_units_per_second: 1600,
        };

        let ipc_connect = IpcConnect::new(provider_config.ipc);
        let retry_layer = RetryBackoffLayer::new(
            provider_config.max_rate_limit_retries,
            provider_config.initial_backoff,
            provider_config.compute_units_per_second,
        );

        let rpc_client = RpcClient::builder()
            .layer(retry_layer)
            .ipc(ipc_connect)
            .await?;

        let provider = ProviderBuilder::new()
            .disable_recommended_fillers()
            .on_client(rpc_client);

       let block_stream = provider.subscribe_blocks().await?;
        // Error: subscriptions are not available on this provider

        Ok(())
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant