Repository: Chia-Network/chia-blockchain
File: tools/validate_rpcs.py (Python)

Code before:
            end_height=end_height,
            concurrent_requests=concurrent_requests,
        )
    )


async def cli_async(
    root_path: Path,
    rpc_port: Optional[int],
    spends_with_conditions: bool,
    block_spends: bool,
    additions_and_removals: bool,
    concurrent_requests: int,
    start_height: int,
    end_height: Optional[int] = None,
) -> None:
    blocks_per_status: int = 3000
    last_status_height: int = 0

    async with get_any_service_client(FullNodeRpcClient, root_path, rpc_port) as (
        node_client,
        config,
    ):
        blockchain_state: dict[str, Any] = await node_client.get_blockchain_state()
        if blockchain_state is None or blockchain_state["peak"] is None:
            # Peak height is required for thep cache.
            print("No blockchain found. Exiting.")
            return
        peak_height = blockchain_state["peak"].height
        assert peak_height is not None, "Blockchain peak height is None"
        if end_height is None:
            end_height = blockchain_state["peak"]["height"]

        print("Connected to Full Node")

        block_cache_bytearray: bytearray = await get_block_cache_bytearray(
            root_path=root_path,
            config=config,
            peak=peak_height,
        )

        print("Bytearray loaded with block header hashes from height-to-hash file.")

        # set initial segment heights
        start_segment: int = start_height
        end_segment: int = start_height + concurrent_requests
        # measure time for performance measurement per segment
        cycle_start: float = time.time()
        # also measure time for the whole process
        start_time: float = cycle_start


Review comment (performance):
```suggestion
            # Peak height is required for the cache.
```

Code after:
    if result is None:
        print(f"ERROR: [{height}] get_block_spends_with_conditions returned invalid result")


async def node_block_spends(
    node_client: FullNodeRpcClient,
    block_hash: bytes32,
    height: int,
) -> None:
    result = await node_client.get_block_spends(block_hash)
    if result is None:
        print(f"ERROR: [{height}] get_block_spends returned invalid result")


async def node_additions_removals(
    node_client: FullNodeRpcClient,
    block_hash: bytes32,
    height: int,
) -> None:
    response = await node_client.get_additions_and_removals(block_hash)
    if response is None:
        print(f"ERROR: [{height}] get_additions_and_removals returned invalid result")


async def cli_async(
    root_path: Path,
    rpc_port: Optional[int],
    spends_with_conditions: bool,
    block_spends: bool,
    additions_and_removals: bool,
    pipeline_depth: int,
    start_height: int,
    end_height: Optional[int] = None,
) -> None:
    async with get_any_service_client(FullNodeRpcClient, root_path, rpc_port) as (
        node_client,
        config,
    ):
        blockchain_state: dict[str, Any] = await node_client.get_blockchain_state()
        if blockchain_state is None or blockchain_state["peak"] is None:
            # Peak height is required for the cache.
            print("No blockchain found. Exiting.")
            return
        peak_height = blockchain_state["peak"].height
        assert peak_height is not None, "Blockchain peak height is None"
        if end_height is None:
            end_height = peak_height

        print("Connected to Full Node")

        height_to_hash_bytes: bytes = await get_height_to_hash_bytes(root_path=root_path, config=config)