Skip to content

fix(cli): implement CHARON_PRICE_MAX_AGE_SECS env override (closes #413)#416

Merged
obchain merged 2 commits intomainfrom
fix/413-price-max-age-env
May 3, 2026
Merged

fix(cli): implement CHARON_PRICE_MAX_AGE_SECS env override (closes #413)#416
obchain merged 2 commits intomainfrom
fix/413-price-max-age-env

Conversation

@obchain
Copy link
Copy Markdown
Owner

@obchain obchain commented May 3, 2026

Summary

The docstring on `BotConfig::chainlink_max_age_secs` and the operator-facing comment in `scripts/anvil_fork.sh` both reference `CHARON_PRICE_MAX_AGE_SECS` as a documented escape hatch for the Chainlink freshness gate. The env var was never implemented — `grep -rn CHARON_PRICE_MAX_AGE_SECS crates/` returned only the docstring. Both `PriceCache::with_per_symbol_max_age` call sites in charon-cli (listen + replay) hardcoded `DEFAULT_MAX_AGE`. Operators following the documented recovery flow on a stale fork hit `feed 'BNB' missing or stale ... max_age 3600 s` regardless of the env var.

Fix

  • Add `resolve_default_price_max_age()` helper in charon-cli that reads `CHARON_PRICE_MAX_AGE_SECS` (u64 seconds), logs once on success, warns on parse failure, and falls back to `DEFAULT_MAX_AGE`.
  • Use the helper at both `PriceCache::with_per_symbol_max_age` call sites (`listen` path and `replay` path).
  • Per-symbol overrides in `[chainlink_max_age_secs.]` continue to win over the env-resolved global default.
  • Update the `BotConfig` docstring to describe the actual behaviour so the docs stop misrepresenting the wiring.

Test plan

  • `cargo check --bin charon` clean (verified locally).
  • `CHARON_PRICE_MAX_AGE_SECS=86400 charon listen` accepts a feed that was rejected at the 600s default.
  • `CHARON_PRICE_MAX_AGE_SECS=abc charon listen` warns and falls back without aborting startup.
  • `CHARON_PRICE_MAX_AGE_SECS` unset behaves identically to current main.

Do NOT merge until #412 + #414 land and the local fork-test passes end-to-end.

obchain added 2 commits May 3, 2026 18:35
The docstring on `BotConfig::chainlink_max_age_secs` and the
operator-facing comment in scripts/anvil_fork.sh both reference
`CHARON_PRICE_MAX_AGE_SECS` as a global staleness override, but no
call site ever read the env var — both `PriceCache::with_per_symbol_max_age`
sites in charon-cli (listen + replay) hardcoded `DEFAULT_MAX_AGE`.

Fix: add `resolve_default_price_max_age` helper that reads
`CHARON_PRICE_MAX_AGE_SECS` (u64 seconds), logs once on success,
warns on parse failure, and falls back to `DEFAULT_MAX_AGE`. Use it
in place of the hardcoded constant at both call sites. Per-symbol
overrides in `[chainlink_max_age_secs.<chain>]` continue to win.

Updated the BotConfig docstring to describe the actual behaviour
(env var anchors the floor for symbols without per-symbol overrides,
not the headline value) so the docs stop misrepresenting the wiring.
@obchain obchain merged commit 0bc9fdf into main May 3, 2026
4 checks passed
@obchain obchain deleted the fix/413-price-max-age-env branch May 3, 2026 14:39
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