feat: Add default gas regression limits for market and claim paths - #1423
Merged
greatest0fallt1me merged 1 commit intoAug 29, 2026
Conversation
Add compile-time gas regression limits for `create_market` (5M CPU) and `claim_winnings` (2M CPU) critical paths. These defaults are seeded during contract initialization and enforced in `end_tracking`, preventing silent gas regressions from shipping. Key changes: - Add DEFAULT_CREATE_MARKET_GAS_LIMIT and DEFAULT_CLAIM_WINNINGS_GAS_LIMIT constants - Add set_default_limits() to seed limits during initialize() - Modify end_tracking() to use default limits as fallback - Modify record_with_alert() to respect default limits - Add has_limit() and get_effective_cpu_limit() helpers - Wire gas tracking into claim_winnings (previously untracked) - Add 20 comprehensive unit tests for regression limit enforcement - Update CI gas.yml to run regression test suite Closes Predictify-org#1412 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
|
@sheyman546 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! 🚀 |
greatest0fallt1me
merged commit Aug 29, 2026
abb76ad
into
Predictify-org:master
0 of 3 checks passed
6 tasks
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.
Closes #1412
What it fixes
Adds default gas regression limits for the two highest-traffic critical paths in the Predictify Hybrid contract:
create_marketandclaim_winnings.Root cause
The existing
GasTrackerinfrastructure had hooks (start_tracking/end_tracking) and enforcement logic (panic_with_error!(GasBudgetExceeded)), but no limits were actually configured. Theperformance_benchmarks.rsfile defined threshold constants, but these were only used in benchmark tests — never wired into runtime enforcement.This meant:
create_marketorclaim_winningswithout any runtime or CI failureclaim_winningspath had no gas tracking at all (nostart_tracking/end_trackingcalls)record_with_alertlow-water alert system only checked admin-configured limits, not defaultsThe fix
Default regression limit constants in
gas.rs:DEFAULT_CREATE_MARKET_GAS_LIMIT = 5,000,000CPU instructionsDEFAULT_CLAIM_WINNINGS_GAS_LIMIT = 2,000,000CPU instructionsGasTracker::end_trackingnow falls back to default limits when no admin limit exists (admin override > default > unchecked)GasTracker::set_default_limits()seeds limits duringinitialize(), ensuring they're always activeclaim_winningsnow hasstart_tracking/end_trackingcalls (previously untracked)record_with_alertnow respects default limits for the 90% low-water alertHelper methods
has_limit()andget_effective_cpu_limit()for introspection20 unit tests covering enforcement, admin overrides, edge cases, and boundary conditions
CI workflow updated to run the regression test suite with real baseline values
How it was tested
gas_regression_tests.rscovering:end_tracking(within/at/exceeding limit)has_limitandget_effective_cpu_limitrecord_with_alertwith default limitsWhat could break
set_limit()API. The precedence is clear (admin > default), but admins should be aware defaults now exist.Follow-up (file separately)
voteandresolve_marketpathsstellar contract invoke --costp99 measurements