Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: improve sidecar logs #1109

Merged
merged 2 commits into from
Dec 12, 2024
Merged
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
13 changes: 9 additions & 4 deletions emily_sidecar/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class Meta:
url = os.getenv("EMILY_CHAINSTATE_URL", "http://host.docker.internal:3031/chainstate")
deployer_address = os.getenv("DEPLOYER_ADDRESS", "SN3R84XZYA63QS28932XQF3G1J8R9PC3W76P9CSQS")

logger.info("Using chainstate URL: %s", url)
logger.info("Using deployer address: %s", deployer_address)

headers = {
"Content-Type": "application/json",
"x-api-key": api_key
Expand All @@ -37,22 +40,24 @@ def validate_json(schema, data):
try:
return schema.load(data)
except ValidationError as err:
logger.warning(f"Validation error: {err.messages}")
logger.warning("Validation error: %s", err.messages)
raise ValueError({"error": "Invalid data", "messages": err.messages})

@app.route("/new_block", methods=["POST"])
def handle_new_block():
logger.debug(f"Received new_block event")
if not request.is_json:
logger.error("Request was not JSON")
return jsonify({"error": "Request must be JSON"}), 400

data = request.get_json()
logger.debug(f"Received new-block event: {data}")

schema = NewBlockEventSchema()

try:
validated_data = validate_json(schema, data)
except ValueError as e:
logger.error("Failed to validate new block event: %s", e)
return jsonify(str(e)), 400

chainstate = {
Expand All @@ -64,11 +69,11 @@ def handle_new_block():
resp = requests.post(url, headers=headers, json=chainstate)
resp.raise_for_status() # This will raise an HTTPError if the response was an error
except requests.RequestException as e:
logger.error(f"Failed to send chainstate to {url}: {e}")
logger.error("Failed to send chainstate %s to %s: %s", chainstate, url, e)
# lets return an error so that the node will retry
return jsonify({"error": "Failed to send chainstate"}), 500

logger.info(f"Successfully processed new block: {validated_data}")
logger.info("Successfully processed new block for chainstate: %s", chainstate)
return jsonify({}), 200


Expand Down
Loading