Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 24 additions & 18 deletions src/sindri/sindri.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,12 @@ def _get_circuit(self, circuit_id: str, include_verification_key: bool = False)
raise Sindri.APIError("Received unexpected type for circuit detail response.")
return response_json

def _get_circuit_status(
self,
circuit_id: str,
) -> str:
def _get_circuit_status(self, circuit_id: str) -> str:
Copy link
Member Author

@KPreisner KPreisner Jan 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The _get_circuit_status and _get_proof_status "private" methods already used the /status API endpoints. However, they did not return the finished_processing value from the response.

Instead of breaking the functionality of these existing methods, I created the _get_circuit_finished_status and _get_proof_finished_status methods, which are now used by the old _get_circuit_status and _get_proof_status methods.

"""Hit the circuit_status API endpoint and validate the response. Do not print anything.
This may raise `Sindri.APIError` if the response is invalid."""
return self._get_circuit_finished_status(circuit_id)[1]

def _get_circuit_finished_status(self, circuit_id: str) -> Tuple[bool, str]:
"""Hit the circuit_status API endpoint and validate the response. Do not print anything.
This may raise `Sindri.APIError` if the response is invalid."""
response_status_code, response_json = self._hit_api(
Expand All @@ -178,10 +180,11 @@ def _get_circuit_status(
)
if not isinstance(response_json, dict):
raise Sindri.APIError("Received unexpected type for circuit status response.")
finished_processing = response_json.get("finished_processing", False)
status = response_json.get("status", "")
if status == "":
raise Sindri.APIError("Received unexpected type for circuit status response.")
return status
return finished_processing, status

def _get_proof(
self,
Expand Down Expand Up @@ -212,10 +215,12 @@ def _get_proof(
raise Sindri.APIError("Received unexpected type for proof detail response.")
return response_json

def _get_proof_status(
self,
proof_id: str,
) -> str:
def _get_proof_status(self, proof_id: str) -> str:
"""Hit the proof_status API endpoint and validate the response. Do not print anything.
This may raise `Sindri.APIError` if the response is invalid."""
return self._get_proof_finished_status(proof_id)[1]

def _get_proof_finished_status(self, proof_id: str) -> Tuple[bool, str]:
"""Hit the proof_status API endpoint and validate the response. Do not print anything.
This may raise `Sindri.APIError` if the response is invalid."""
response_status_code, response_json = self._hit_api(
Expand All @@ -229,10 +234,11 @@ def _get_proof_status(
)
if not isinstance(response_json, dict):
raise Sindri.APIError("Received unexpected type for proof status response.")
finished_processing = response_json.get("finished_processing", False)
status = response_json.get("status", "")
if status == "":
raise Sindri.APIError("Received unexpected type for proof status response.")
return status
return finished_processing, status

def _get_verbose_1_circuit_detail(self, circuit_detail: dict) -> dict:
"""Return a slim circuit detail object for printing."""
Expand Down Expand Up @@ -437,12 +443,12 @@ def create_circuit(
print(f" circuit_id: {circuit_id}")

if wait:
# 2. Poll circuit detail until it has a status of Ready/Failed
# 2. Poll circuit detail until it is finished processing
if self.verbose_level > 0:
print("Circuit: Poll until Ready/Failed")
print("Circuit: Poll until Finished")
for _ in range(self.max_polling_iterations):
circuit_status = self._get_circuit_status(circuit_id)
if circuit_status in ["Ready", "Failed"]:
finished_processing, _ = self._get_circuit_finished_status(circuit_id)
if finished_processing:
break
time.sleep(self.polling_interval_sec)
else:
Expand Down Expand Up @@ -820,12 +826,12 @@ def prove_circuit(
print(f" proof_id: {proof_id}")

if wait:
# 2. Poll proof detail until it has a status of Ready/Failed
# 2. Poll proof detail until it is finished processing
if self.verbose_level > 0:
print("Proof: Poll until Ready/Failed")
print("Proof: Poll until Finished")
for _ in range(self.max_polling_iterations):
proof_status = self._get_proof_status(proof_id)
if proof_status in ["Ready", "Failed"]:
finished_processing, _ = self._get_proof_finished_status(proof_id)
if finished_processing:
break
time.sleep(self.polling_interval_sec)
else:
Expand Down
Loading