reuse: serve the previous v5/v6 signature while the price is unchanged and unexpired - #72
Merged
Merged
Conversation
…d and unexpired The content cache (previous commit) removes duplicate signatures inside one price frame. A new frame every 5 seconds still meant a new signature per pair even when the price had not moved, because publish_time and expiry advance with the frame and are part of the signed bytes. This layer works across frames. For v5 and v6 the handler remembers the last response per (schema, symbol, direction) together with a fingerprint of everything signed except the two timestamps: price bytes, session tag and bounds, input and output token, and for v6 the NAV ratio. When a new frame arrives with the same fingerprint and the previous quote still has at least signing.reuse_min_remaining_secs (default 10) before its expiry, the previous response is returned as is. The taker sees the older publish_time and the original expiry in the signed bytes and judges freshness itself. A moving price, a session change or a NAV change always signs fresh. v1 and v4 never reuse: they sign no expiry, and the strategy's staleness rule on chain is not visible here. Pricing stamps expiry 20 to 30 seconds after the frame today, so a stable symbol now costs one signature per ~20s instead of one per 5s frame. Set reuse_min_remaining_secs = 0 in the [signing] table to sign every frame. oracle_signature_reuse_total counts the KMS calls avoided. LiveClient::seed lets the integration tests push new frames between requests; five new tests cover reuse, the expiry margin, v4 exclusion, the disabled setting and the v6 NAV ratio. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Collaborator
Author
|
Folded into #71 at Kais's request; same commits, one PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #71 (content cache within a frame). This one works across frames.
Problem
Pricing publishes a frame per symbol every ~5s. Even after #71, an unchanged price gets a new signature on every frame, because
publish_timeandexpirymove with the frame and are signed. For a stable symbol that is 12 signatures a minute saying the same price.Change
For v5 and v6 the handler keeps the last response per (schema, symbol, direction) with a fingerprint of everything signed except the two timestamps: price bytes, session tag and bounds, input and output token, and the v6 NAV ratio. A new frame with the same fingerprint, while the previous quote still has at least
signing.reuse_min_remaining_secs(default 10) before its expiry, gets the previous response back unchanged. The taker reads the older publish time and the original expiry in the signed bytes and judges freshness itself.[signing] reuse_min_remaining_secs = 0in the runtime TOML disables it. The t0.devops config-as-data file needs no change for the default.oracle_signature_reuse_totalon/metricscounts the KMS calls avoided.Effect
Expiry is stamped 20 to 30s after the frame today, so a stable pair costs one signature per ~20s instead of one per 5s frame, roughly a further 4x on quiet symbols and nothing on fast movers. Combined with #71 the KMS bill follows how often prices actually change, not how often anyone asks.
Tests
Five integration tests using a new
LiveClient::seedhelper to push frames between requests: reuse on unchanged price, no reuse under the expiry margin, v4 always fresh, disabled setting signs every frame, v6 requires the same NAV ratio.cargo test103 passed, clippy and fmt clean.🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.