Skip to content

Investigate slow response time on fork tests #776

@amanusk

Description

@amanusk

Fetching information from a node is considerably faster that fetching it from Devent, using the same node + forking.

Test executed on a local node, so traffic time shouldn't be an issue.

Example script

from starknet_py.net.full_node_client import FullNodeClient
from starknet_py.hash.selector import get_selector_from_name
from starknet_py.hash.utils import pedersen_hash


# --- helper --------------------------------------------------------------
async def fetch_storage(client, contract_addr, selector, idx: int):
    """
    One concurrent task:
      • computes the key for slot idx
      • awaits the storage value
      • returns both so the caller can print / post‑process
    """
    key = pedersen_hash(selector, idx)
    storage = await client.get_storage_at(contract_addr, key)
    return key, storage


async def run():
    # Connect to Starknet testnet (Sepolia)
    # client = FullNodeClient("https://free-rpc.nethermind.io/sepolia-juno/rpc/v0_8")
    # client = FullNodeClient("https://starknet-sepolia.public.blastapi.io/rpc/v0_8")
    # client = FullNodeClient("http://192.168.1.45:9235")
    client = FullNodeClient("http://127.0.0.1:5050")

    contract_address = (
        "0x01ab144ed3433b3949b3116389d2730d77bbff5d0c4e61451b856d5903a2c970"
    )

    selector = get_selector_from_name("my_array")  # compute once
    tasks = [fetch_storage(client, contract_address, selector, i) for i in range(200)]

    # asyncio.as_completed yields tasks in the order they *finish*,
    # so we can print results immediately without waiting for the slowest one.
    for fut in asyncio.as_completed(tasks):
        key, storage = await fut
        print(f"Storage at {hex(key)} : {storage}")


if __name__ == "__main__":
    import asyncio

    contract = asyncio.run(run())

When running using the local node directly, execution 200 requests takes 700ms

real	0m0.702s

Runing the same script, where devnet is started with fork of the same node

starknet-devnet --fork-network http://192.168.1.45:9235/rpc/v0_8

Results in execution of ~17 seconds

real	0m16.664s

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    Status

    🆕 New

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions