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] Test hangs when mining many blocks #1983

Closed
jorgemmsilva opened this issue Jan 31, 2025 · 1 comment · Fixed by #1985
Closed

[Bug] Test hangs when mining many blocks #1983

jorgemmsilva opened this issue Jan 31, 2025 · 1 comment · Fixed by #1985
Labels
bug Something isn't working

Comments

@jorgemmsilva
Copy link
Contributor

jorgemmsilva commented Jan 31, 2025

Component

node-bindings

What version of Alloy are you on?

latest

Operating System

macOS (Apple Silicon)

Describe the bug

I found a regression when updating alloy from 0.9.2 to 0.11.0.

wrote a small test that reproduces the issue:

    #[tokio::test]
    async fn test_mine_many_blocks() {
        // 328 passes, 329 fails
        let blocks_to_mine = 329;

        let args =
            vec!["--base-fee", "0", "--gas-limit", "30000000", "--timestamp", "999", "--no-mining"];
        let anvil = alloy_node_bindings::Anvil::new().args(args).spawn();
        let provider = ProviderBuilder::new().on_http(anvil.endpoint_url());

        let head =
            provider.get_block(alloy_eips::BlockId::latest(), false.into()).await.unwrap().unwrap();
        assert_eq!(head.header.number, 0);
        let ts = head.header.timestamp;

        // Mine N blocks using anvil_mine_detailed
        for i in 0..blocks_to_mine {
            let mine_options =
                MineOptions::Options { timestamp: Some(ts + i + 1), blocks: Some(1) };
            provider.anvil_mine_detailed(Some(mine_options)).await.unwrap();
        }

        // Verify block number is at least 1000
        let final_block = provider.get_block_number().await.unwrap();
        assert!(
            final_block >= blocks_to_mine,
            "Expected at least {} blocks, got {}",
            blocks_to_mine,
            final_block
        );
    }

For some reason, on the latest version, that test will hang forever if I try to mine 329+ blocks. With less blocks, it passes.

I bissected this behavior and found the following:

70df381dd5ae09133137bd8c51b5c7f3530445c9 is the first bad commit
commit 70df381dd5ae09133137bd8c51b5c7f3530445c9 (HEAD)
Author: Yash Atreya <[email protected]>
Date:   Thu Jan 16 00:00:21 2025 +0530

    fix(`node-bindings`): reset `child.stdout` in `AnvilInstance` (#1920)
    
    * feat(`node-bindings`): expose `stdout` reader
    
    * remove reader and reset child.stdout
    
    * Update crates/node-bindings/src/nodes/anvil.rs
    
    ---------
    
    Co-authored-by: DaniPopes <[email protected]>

 crates/node-bindings/src/nodes/anvil.rs |  4 +++-
 crates/provider/src/provider/trait.rs   | 28 +++++++++++++++++++++++++++-
 2 files changed, 30 insertions(+), 2 deletions(-)

removing this line seems to fix the issue.

Please assist 🙏

@jorgemmsilva jorgemmsilva added the bug Something isn't working label Jan 31, 2025
@jorgemmsilva jorgemmsilva changed the title [Bug] Regression happens when mining many blocks fast [Bug] Regression happens when mining many blocks Jan 31, 2025
@jorgemmsilva jorgemmsilva changed the title [Bug] Regression happens when mining many blocks [Bug] Test hangs when mining many blocks Jan 31, 2025
@mattsse
Copy link
Member

mattsse commented Jan 31, 2025

yeah this pr doesn't look right

#1920

this will now fill the stdout buffer and blocks, checking

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.

2 participants