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

Code before:
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 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 = blockchain_state["peak"]["height"]

        print("Connected to Full Node")

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

        print("block header hashes loaded 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

        while end_segment <= end_height:
            # Create an initial list to hold pending tasks
            pending_tasks: list[Coroutine[Any, Any, Any]] = []

            for i in range(start_segment, end_segment):
                block_header_hash: bytes32 = get_block_hash_from_height(i, height_to_hash_bytes)

Review comment (suggestion):
```suggestion
            end_height = blockchain_state["peak"].height
```

Code after:
    node_client: FullNodeRpcClient,
    block_hash: bytes32,
    height: int,
) -> None:
    result = await node_client.get_block_spends_with_conditions(block_hash)
    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: