Skip to content

Optimizer: cap chain reads of competitor quotes with chain_read_min_secs (optimizer.json, default 600s) - #735

Merged
anderdc merged 1 commit into
testfrom
optimizer-chain-read-cap
Sep 17, 2026
Merged

anderdc merged 1 commit into
testfrom
optimizer-chain-read-cap

Conversation

@anderdc

@anderdc anderdc commented Sep 17, 2026

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #734. That PR added a chain read of competitor quotes (getProgramAccounts per managed direction, 10 Helius credits each, about 21 credits per read) after every re-seed. Only the reads triggered by an API disagreement were rate-limited.

The risk: a re-seed can happen once per 60 s tick. If Helius drops the optimizer's websocket every minute (a throttled or flaky free key is exactly when that happens), the optimizer would do a chain read every minute: about 30k credits a day, over 1M a month from this read alone. That's the whole free tier, and the base miner's swap feed shares the same key.

The change:

  • Every chain read now goes through one limit: at most one per chain_read_min_secs. That covers reads after a re-seed, reads triggered by an API disagreement, and retries.
  • A read asked for sooner is marked due and taken by the first 5-minute reconcile once the limit allows it.
  • Failed attempts count toward the limit, so a failing read is capped too.
  • chain_read_min_secs is a new optimizer.json key, default 600, must be >= 0.
  • Worst case for this read is now 6 per hour, about 126 credits an hour, even with a feed that drops constantly.
  • Normal behaviour is unchanged: real drops are hours apart, so the read after a re-seed still happens immediately.

Tests

  • New: test_a_feed_that_drops_every_minute_reads_the_chain_once_per_limit. Reconnects every tick for 16 minutes read the chain twice (at 0 and 10 minutes); with a configured 300 s limit, they read every 5 minutes.
  • Updated: a failed read after a re-seed is retried by a reconcile once the limit has passed.
  • The config test covers loading chain_read_min_secs and rejecting a negative value.
  • pytest: full suite passes.

…d_min_secs (optimizer.json, default 600), so a flapping feed can't spend the Helius budget
@anderdc
anderdc merged commit a8c3d8d into test Sep 17, 2026
3 checks passed
@anderdc
anderdc deleted the optimizer-chain-read-cap branch September 17, 2026 16:27
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