Skip to content

race condition in new headers subscription #18138

Description

@pata-eth

System information

Erigon version: 3.3.0

OS & Version: linux

Chain/Network: gnosis

Expected behaviour

calling any relevant endpoint with the block number from the event should not fail

Actual behaviour

occasionally, calls fail with error 'request beyond head block: requested X, head X-1

Steps to reproduce the behaviour

import asyncio

from web3 import AsyncWeb3, WebSocketProvider


async def main():
    rpc_url = "wss://rpc.gnosischain.com/wss"

    async with AsyncWeb3(WebSocketProvider(rpc_url)) as w3:
        _ = await w3.eth.subscribe("newHeads")

        async for block_header in w3.socket.process_subscriptions():
            block_number = block_header.get("result").get("number")
            print(f"Block {block_number} announced via subscription")

            # Immediately try to call eth_feeHistory with this block number
            try:
                _ = await w3.eth.fee_history(  
                    block_count=10,
                    newest_block=block_number,
                    reward_percentiles=[20],
                )
                print(f"✅ eth_feeHistory succeeded for block {block_number}")
            except Exception as e:
                error_msg = str(e)
                print(
                    f"❌ eth_feeHistory FAILED for block {block_number} {error_msg}"
                )


if __name__ == "__main__":
    asyncio.run(main())

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions