Summary
ledger_anchor.py:broadcast_anchor() is declared async def but calls subprocess.run() (synchronous) and time.sleep(5) in a polling loop. This blocks the entire event loop for up to 30 seconds during anchoring.
Current Code
async def broadcast_anchor(claim_rid: str, content_hash: str) -> dict:
# ...
tx_result = subprocess.run([regen_bin, ...], ...) # blocks event loop
# ...
for attempt in range(6):
time.sleep(5) # blocks event loop for 5s per attempt
query_result = subprocess.run(...) # blocks again
Proposed Fix
Option A (preferred): Use asyncio.create_subprocess_exec() + asyncio.sleep():
proc = await asyncio.create_subprocess_exec(
regen_bin, "tx", "data", "anchor", iri, ...,
stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
)
stdout, stderr = await proc.communicate()
Option B (simpler): Run blocking code in thread executor:
loop = asyncio.get_event_loop()
result = await loop.run_in_executor(None, _blocking_broadcast, ...)
Impact
Other API endpoints remain responsive during anchoring operations. No API contract change.
Summary
ledger_anchor.py:broadcast_anchor()is declaredasync defbut callssubprocess.run()(synchronous) andtime.sleep(5)in a polling loop. This blocks the entire event loop for up to 30 seconds during anchoring.Current Code
Proposed Fix
Option A (preferred): Use
asyncio.create_subprocess_exec()+asyncio.sleep():Option B (simpler): Run blocking code in thread executor:
Impact
Other API endpoints remain responsive during anchoring operations. No API contract change.