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] CacheProvider does not deserialize get_transaction_count to u64 #1940

Open
chain-lover opened this issue Jan 22, 2025 · 1 comment
Open
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

Node provider is Reth. Here is the code that encountred this bug:

use alloy_network::Ethereum;
use alloy_provider::{
    layers::{CacheLayer, CacheProvider},
    RootProvider,
};
use alloy_pubsub::PubSubFrontend;

pub use alloy_provider::Provider;

pub type NodeProvider = RootProvider<PubSubFrontend, Ethereum>;
pub type CacheNodeProvider = CacheProvider<NodeProvider, PubSubFrontend, Ethereum>;

pub fn create_cache_provider(
    provider: NodeProvider,
    cache_provider_limit: u32,
) -> CacheNodeProvider {
    let cache_layer = CacheLayer::new(cache_provider_limit);

    CacheNodeProvider::new(provider, cache_layer.cache())
}

#[cfg(test)]
mod test {
    use alloy_primitives::address;
    use alloy_provider::{Provider, ProviderBuilder, WsConnect};
    use anyhow::Result;

    use crate::node_provider::create_cache_provider;

    #[tokio::test]
    async fn should_get_nonce() -> Result<()> {
        let ws = todo!("add node ws");

        let provider = ProviderBuilder::new().on_ws(WsConnect::new(ws)).await?;

        let cache_provider = create_cache_provider(provider, 2000);

        let weth_address = address!("c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2");

        cache_provider.get_transaction_count(weth_address).await?;
        // Error: deserialization error: invalid type: string "0x1", expected u64 at line 1 column 5

        Ok(())
    }
}
@chain-lover chain-lover added the bug Something isn't working label Jan 22, 2025
@chain-lover chain-lover changed the title [Bug] CacheProvider does not deserialize get_transaction_count to u64 [Bug] CacheProvider does not deserialize get_transaction_count to u64 Jan 22, 2025
@mattsse
Copy link
Member

mattsse commented Jan 22, 2025

@yash-atreya I believe this is an issue with deserialization here

because this is picking the return type u64

if let Ok(Some(cached)) = $cache.get_deserialized(&hash) {

but we stored U64

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

No branches or pull requests

2 participants