Skip to content

Commit 12712ea

Browse files
authored
improve validate_rpcs.py (#19873)
add validation to test
1 parent e4b6d42 commit 12712ea

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

tools/validate_rpcs.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
from __future__ import annotations
44

55
import asyncio
6+
import logging
67
import time
8+
from itertools import chain
79
from pathlib import Path
810
from typing import Any, Optional
911

@@ -18,6 +20,8 @@
1820
from chia.util.task_referencer import create_referenced_task
1921

2022
DEFAULT_PIPELINE_DEPTH: int = 10
23+
log = logging.getLogger("validate_rpcs")
24+
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)-8s %(message)s")
2125

2226

2327
def get_height_to_hash_filename(root_path: Path, config: dict[str, Any]) -> Path:
@@ -154,9 +158,11 @@ async def node_spends_with_conditions(
154158
height: int,
155159
) -> None:
156160
try:
157-
await node_client.get_block_spends_with_conditions(block_hash)
161+
res = await node_client.get_block_spends_with_conditions(block_hash)
162+
for c in res:
163+
c.coin_spend.get_hash() # Ensure CoinSpend is valid
158164
except Exception as e:
159-
print(f"ERROR: [{height}] get_block_spends_with_conditions returned invalid result")
165+
log.error(f"ERROR: [{height}] get_block_spends_with_conditions returned invalid result")
160166
raise e
161167

162168

@@ -166,9 +172,11 @@ async def node_block_spends(
166172
height: int,
167173
) -> None:
168174
try:
169-
await node_client.get_block_spends(block_hash)
175+
res = await node_client.get_block_spends(block_hash)
176+
for c in res:
177+
c.get_hash() # Ensure CoinSpend is valid
170178
except Exception as e:
171-
print(f"ERROR: [{height}] get_block_spends returned invalid result")
179+
log.error(f"ERROR: [{height}] get_block_spends returned invalid result")
172180
raise e
173181

174182

@@ -178,9 +186,12 @@ async def node_additions_removals(
178186
height: int,
179187
) -> None:
180188
try:
181-
await node_client.get_additions_and_removals(block_hash)
189+
add, rem = await node_client.get_additions_and_removals(block_hash)
190+
for coin in chain(add, rem):
191+
coin.get_hash()
192+
182193
except Exception as e:
183-
print(f"ERROR: [{height}] get_additions_and_removals returned invalid result")
194+
log.error(f"ERROR: [{height}] get_additions_and_removals returned invalid result")
184195
raise e
185196

186197

@@ -212,7 +223,7 @@ async def cli_async(
212223

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

215-
print("block header hashes loaded from height-to-hash file.")
226+
log.info("block header hashes loaded from height-to-hash file.")
216227

217228
# Set initial values for the loop
218229

@@ -244,7 +255,7 @@ def add_tasks_for_height(height: int) -> None:
244255
now = time.monotonic()
245256
if cycle_start + 5 < now:
246257
time_taken = now - cycle_start
247-
print(
258+
log.info(
248259
f"Processed {completed_requests} RPCs in {time_taken:.2f}s, "
249260
f"{time_taken / completed_requests:.4f}s per RPC "
250261
f"({i - start_height} Blocks completed out of {end_height - start_height})"
@@ -253,7 +264,7 @@ def add_tasks_for_height(height: int) -> None:
253264
cycle_start = now
254265

255266
# Wait for any remaining tasks to complete
256-
print(f"Waiting for {len(pipeline)} remaining tasks to complete...")
267+
log.info(f"Waiting for {len(pipeline)} remaining tasks to complete...")
257268
if pipeline:
258269
await asyncio.gather(*pipeline)
259270

0 commit comments

Comments
 (0)