3
3
from __future__ import annotations
4
4
5
5
import asyncio
6
+ import logging
6
7
import time
8
+ from itertools import chain
7
9
from pathlib import Path
8
10
from typing import Any , Optional
9
11
18
20
from chia .util .task_referencer import create_referenced_task
19
21
20
22
DEFAULT_PIPELINE_DEPTH : int = 10
23
+ log = logging .getLogger ("validate_rpcs" )
24
+ logging .basicConfig (level = logging .INFO , format = "%(asctime)s %(levelname)-8s %(message)s" )
21
25
22
26
23
27
def get_height_to_hash_filename (root_path : Path , config : dict [str , Any ]) -> Path :
@@ -154,9 +158,11 @@ async def node_spends_with_conditions(
154
158
height : int ,
155
159
) -> None :
156
160
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
158
164
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" )
160
166
raise e
161
167
162
168
@@ -166,9 +172,11 @@ async def node_block_spends(
166
172
height : int ,
167
173
) -> None :
168
174
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
170
178
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" )
172
180
raise e
173
181
174
182
@@ -178,9 +186,12 @@ async def node_additions_removals(
178
186
height : int ,
179
187
) -> None :
180
188
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
+
182
193
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" )
184
195
raise e
185
196
186
197
@@ -212,7 +223,7 @@ async def cli_async(
212
223
213
224
height_to_hash_bytes : bytes = await get_height_to_hash_bytes (root_path = root_path , config = config )
214
225
215
- print ("block header hashes loaded from height-to-hash file." )
226
+ log . info ("block header hashes loaded from height-to-hash file." )
216
227
217
228
# Set initial values for the loop
218
229
@@ -244,7 +255,7 @@ def add_tasks_for_height(height: int) -> None:
244
255
now = time .monotonic ()
245
256
if cycle_start + 5 < now :
246
257
time_taken = now - cycle_start
247
- print (
258
+ log . info (
248
259
f"Processed { completed_requests } RPCs in { time_taken :.2f} s, "
249
260
f"{ time_taken / completed_requests :.4f} s per RPC "
250
261
f"({ i - start_height } Blocks completed out of { end_height - start_height } )"
@@ -253,7 +264,7 @@ def add_tasks_for_height(height: int) -> None:
253
264
cycle_start = now
254
265
255
266
# 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..." )
257
268
if pipeline :
258
269
await asyncio .gather (* pipeline )
259
270
0 commit comments