Skip to content

fix(node): use timezone-aware datetime in deploy_contract fallback - #1776

Open
Alicepoltora wants to merge 2 commits into
genlayerlabs:v0.123-devfrom
Alicepoltora:fix/deploy-contract-timezone
Open

Alicepoltora wants to merge 2 commits into
genlayerlabs:v0.123-devfrom
Alicepoltora:fix/deploy-contract-timezone

Conversation

@Alicepoltora

@Alicepoltora Alicepoltora commented Sep 26, 2026 •

Copy link
Copy Markdown

Problem

deploy_contract() in backend/node/base.py parses transaction_created_at via _date_from_str(). When that returns None (the common case when the caller does not supply a sim_config.genvm_datetime override), it falls back to datetime.datetime.now() — a naive datetime with no timezone.

_run_genvm() (called immediately after) asserts transaction_datetime.tzinfo is not None before sending the datetime to the GenVM host. The naive fallback therefore triggers an AssertionError on any eth_sendRawTransaction / deploy request that does not include a sim_config with a genvm_datetime override.

Fix

Replace datetime.datetime.now() with datetime.datetime.now(tz=datetime.timezone.utc) so the fallback always carries a +00:00 offset.

Tests

  • tests/unit/test_leader_llm_recovery.py: test_deploy_contract_fallback_is_timezone_aware — passes a tz-aware datetime into _run_genvm even when transaction_created_at is None. Regression fails on naive-datetime code path.

Summary by CodeRabbit

  • Bug Fixes
    • Fallback transaction timestamps and usage metric timestamps now include UTC timezone information, improving consistency when timestamps are missing.

…e-aware datetime.now(timezone.utc)

datetime.utcnow() was removed in Python 3.12 and returned a naive datetime
(no timezone). _format_created_at() should emit ISO 8601 strings that carry
timezone info (+00:00) so the upstream metrics API can parse the offset
consistently with the rest of Studio.

The change replaces:
    datetime.utcnow().isoformat()
with:
    datetime.now(timezone.utc).isoformat()

Regression tests verify the returned string contains a timezone offset.
_node.deploy_contract() uses _date_from_str(transaction_created_at)
to parse the override timestamp, and when that returns None falls back
to datetime.datetime.now().  datetime.datetime.now() returns a **naive**
datetime (no timezone).  _run_genvm() asserts
 before sending the datetime
to the GenVM host, so the naive fallback would trigger an AssertionError
as soon as any deploy request omits a sim_config.genvm_datetime
override.

Replace datetime.datetime.now() with datetime.datetime.now(tz=datetime.timezone.utc)
so the fallback always carries a +00:00 offset.

A regression test verifies the path passes a tz-aware datetime into
_run_genvm even when transaction_created_at is None.
@github-actions
github-actions Bot changed the base branch from main to v0.123-dev September 26, 2026 21:25
@github-actions

Copy link
Copy Markdown
Contributor

This PR targeted main, which is only the default/static branch.

I retargeted it to v0.123-dev, the active development branch. Pushes to v0.123-dev automatically fast-forward main.

@coderabbitai

coderabbitai Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 22b05702-c3dc-40e5-83dc-69a6b0bd440c

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant