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

Code before:
    help="Number of concurrent requests to make to the RPC endpoints",
    type=int,
    default=DEFAULT_REQUESTS_PER_BATCH,
)
def cli(
    root_path: str,
    rpc_port: Optional[int],
    spends_with_conditions: bool,
    block_spends: bool,
    additions_and_removals: bool,
    concurrent_requests: int,
    start_height: Optional[int] = None,
    end_height: Optional[int] = None,
) -> None:
    root_path_path = Path(root_path)
    requests_per_batch = 0
    if spends_with_conditions:
        requests_per_batch += 1
    if block_spends:
        requests_per_batch += 1
    if additions_and_removals:
        requests_per_batch += 1
    if requests_per_batch == 0:
        print("No RPC calls selected. Exiting.")
        return
    concurrent_requests = max(1, concurrent_requests // requests_per_batch)
    if start_height is None:
        start_height = 0
    asyncio.run(
        cli_async(
            root_path=root_path_path,
            rpc_port=rpc_port,
            spends_with_conditions=spends_with_conditions,
            block_spends=block_spends,
            additions_and_removals=additions_and_removals,
            start_height=start_height,
            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,

Review comment (performance):
```suggestion
    concurrent_requests = max(concurrent_requests, requests_per_batch)
```
I'm not sure what you intended by this division, but I imagine you'd want a lower cap on the batch-size

Code after:
    help="Set the number of concurrent RPC calls to make.",
    type=int,
    default=DEFAULT_PIPELINE_DEPTH,
)
def cli(
    root_path: str,
    rpc_port: Optional[int],
    spends_with_conditions: bool,
    block_spends: bool,
    additions_and_removals: bool,
    pipeline_depth: int,
    start_height: Optional[int] = None,
    end_height: Optional[int] = None,
) -> None:
    root_path_path = Path(root_path)
    requests_per_batch = 0
    if spends_with_conditions:
        requests_per_batch += 1
    if block_spends:
        requests_per_batch += 1
    if additions_and_removals:
        requests_per_batch += 1
    if requests_per_batch == 0:
        print("No RPC calls selected. Exiting.")
        return
    if start_height is None:
        start_height = 0
    asyncio.run(
        cli_async(
            root_path=root_path_path,
            rpc_port=rpc_port,
            spends_with_conditions=spends_with_conditions,
            block_spends=block_spends,
            additions_and_removals=additions_and_removals,
            start_height=start_height,
            end_height=end_height,
            pipeline_depth=pipeline_depth,
        )
    )


async def node_spends_with_conditions(
    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")