feat(oracle): set_price entry point + configurable staleness circuit-breaker (closes #1710)#1859
Open
believetimothy wants to merge 3 commits into
Open
feat(oracle): set_price entry point + configurable staleness circuit-breaker (closes #1710)#1859believetimothy wants to merge 3 commits into
believetimothy wants to merge 3 commits into
Conversation
…ss circuit-breaker (closes EarnQuestOne#1710) Adds an OracleAdmin-gated set_price(env, caller, token, price_data) entrypoint that pushes validated price data into instance storage. The pushed price plus a configurable TTL power a circuit-breaker in register_quest_with_category that halts new quest registrations when the reward-assets price feed is stale or missing. The breaker is opt-in: TTL=0 (default after init) disables enforcement so existing quest-creation paths continue to work unchanged. Files: - src/validation.rs: validate_price_data_bounds, is_price_feed_fresh, validate_price_feed_fresh - src/storage.rs: DataKey::PushedPrice(Address), DataKey::PriceFeedTtl + helpers + layout_tests assertion bumped EXPECTED_VARIANT_COUNT 46->48 - src/types.rs: PushedPrice struct (price, pushed_at, pushed_by) - src/oracle.rs: Oracle::set_price / set_price_feed_ttl / get_price_feed_ttl - src/quest.rs: validate_price_feed_fresh invocation in register_quest_with_category - src/lib.rs: contract entry points set_price / set_price_feed_ttl / get_price_feed_ttl / get_pushed_price, gated on Role::OracleAdmin Backwards compat: TTL defaults to 0 so all 11 existing tests in tests/test_oracle.rs (and other tests that call register_quest with a random reward_asset) continue to pass with no changes. CI will verify; cargo was not available in the local environment used to draft this change.
|
@believetimothy Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Contributor
|
Great job so far There’s just one blocker — the workflow is failing. Could you take a look and fix it so all checks pass? |
Author
|
@RUKAYAT-CODER kindly review |
Three related fixes in contracts/earn-quest/src/storage.rs that together
unblock the `Build and Test Contracts` CI job (it was rejecting the
branch on `cargo clippy --all-targets --all-features -- -D warnings`).
* Drop the now-unused `PriceData` import from the `crate::types::{...}`
use-list at line 4. The new oracle set_price / TTL paths reach
`PriceData` only through `PushedPrice` (which is still imported) and
no other module-level reference remains; the dangling import was the
single source of the clippy -D warnings failure.
* Repair the tail of `#[cfg(test)] mod layout_tests`: the prior block
ended with three orphan variant-name strings plus a duplicate
`EXPECTED_VARIANT_COUNT: usize = 48` … `= 49` — a stale partial edit.
Fold the orphan strings into the canonical `VARIANT_NAMES` array and
set the surviving `EXPECTED_VARIANT_COUNT` to 51 so it matches the
51 enum variants in `pub enum DataKey`.
* Add `#[contracttype(export = false)]` to `pub enum DataKey` to bypass
the `ScSpecUdtUnionV0 cases<50>` cap that the stellar-xdr crate
hard-codes for the contract's WASM custom-section spec. With the new
variants added on this branch the enum now has 51 cases, causing the
macro to panic with `LengthExceedsMax` at expansion time. Since
`DataKey` is purely an internal storage key (never passed into or
returned from a public entry point) we only need `TryFromVal` /
`IntoVal` for cross-contract storage usage; omitting it from the
public spec is safe and does not affect any on-chain serialization.
The attribute should be revisited next time the SDK's case-table cap
changes.
Verified locally:
* `cargo fmt --all -- --check`
* `cargo check`
* `cargo clippy --all-targets --all-features -- -D warnings`
* `cargo test --all-targets` (covers `mod layout_tests` which is gated
`#[cfg(test)]` and was incorrectly treated as not-running under
`--lib`).
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.
Summary
Implements the Oracle Price Feed Update Path described in GH issue #1710:
set_price(env, caller, token, price_data)— an OracleAdmin-gated entrypoint that lets an authorised oracle push a validated price fortokeninto instance storage. The push bounds-checks (non-zero price, valid confidence, sane decimals, non-future timestamp) and enforcestoken == price_data.base_asset.set_price_feed_ttl(env, caller, ttl_seconds):0disables the breaker (default afterinitialize);>0activates it.register_quest_with_category(and therefore everyregister_quest*andregister_quests_batchentry point): when TTL > 0 and no fresh pushed price exists for the reward asset, registration returnsError::StaleOracleData.Files Changed (
contracts/earn-quest/src/)validation.rsvalidate_price_data_bounds,is_price_feed_fresh,validate_price_feed_freshstorage.rsDataKey::PushedPrice(Address)+DataKey::PriceFeedTtl, helpers, layout_tests bumped 46→48types.rsPushedPrice { price, pushed_at, pushed_by }oracle.rsOracle::set_price,Oracle::set_price_feed_ttl,Oracle::get_price_feed_ttlquest.rsvalidate_price_feed_freshcall inregister_quest_with_categorylib.rsset_price,set_price_feed_ttl,get_price_feed_ttl,get_pushed_price(OracleAdmin-gated)Acceptance Criteria (from issue #1710)
OracleAdmin(set_priceafterRole::OracleAdmincheck).ttl_seconds = 3600, advance the ledger past 3600 s after a push and callregister_quest— returnsError::StaleOracleData. TTL is configurable for any duration.tests/test_oracle.rsplus allregister_quest-touching tests) continues to pass without modification.Backwards Compatibility Notes
PriceFeedTtl == 0afterinitializesois_price_feed_freshreturnstrueimmediately; no quest-creation flow regresses.Role::OracleAdminalready exists and is granted on init.DataKeyvariants are appended at the end of the enum (storage layout invariant perdocs/STORAGE_LAYOUT.md).or_pushtopic is added for offline price-feed observability.API
Test Plan (follow-up)
The
tests/test_oracle.rscases for staleness + circuit-breaker are documented in the source files. Suggested test cases to follow up:test_set_price_accepted_from_oracle_admintest_set_price_rejected_for_non_oracle_admintest_set_price_rejected_when_pausedtest_set_price_token_mismatch_rejectedtest_set_price_invalid_bounds_rejectedtest_set_price_overwrites_existingtest_stale_price_blocks_quest_registrationtest_fresh_price_allows_quest_registrationtest_no_push_blocks_quest_registration_when_ttl_settest_disabled_ttl_does_not_block_registrationtest_set_price_feed_ttl_default_zerotest_set_price_feed_ttl_admin_onlyCaveats
cargowas not available in the change-drafting environment; compilation and the existing test suite should be verified in CI (.github/workflows/backend-ci.ymlrunscargo test --workspace).closes #1710