Skip to content

Feat: Implement faster cost tracker for default cost functions #5859

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 25, 2025

Conversation

kantai
Copy link
Contributor

@kantai kantai commented Feb 25, 2025

This PR adds a "fast path" for cost function evaluations when the cost functions are the default/boot costs (which they currently always are in mainnet and testnet). Rather than evaluating the clarity contracts, it evaluates the same cost function but in rust directly.

As has been pointed out in #5848 and #5813, the current cost tracker can be pretty slow in a lot of cases -- this PR should speed things up substantially.

It is important that the rust evaluations be identical to the evaluations that they replace. To this end, this PR adds strict cost assertions to the block replay commands (meaning that during block replays, the final cost of each block is checked against the expectation, allowing us to check that the change is safe on the entire history of the chain so far) and also a set of property-like tests which assert that the results of evaluation are identical between the rust code and the clarity contracts for given inputs. The unit tests cover a fixed range of values, but they can be evaluated for any input.

* add cost calculation checks to replay-block commands
* add prop testing to cost replacements
* apply lints to costs module
* add `CostValues` trait to reduce repetitive code in the default cost calculations.
* add artificial stall to force long-running tx in `tests::nakamoto_integrations::skip_mining_long_tx`
@kantai kantai requested a review from a team as a code owner February 25, 2025 16:16
@kantai kantai requested a review from a team as a code owner February 25, 2025 16:17
Copy link
Contributor

@obycode obycode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@jcnelson jcnelson self-requested a review February 25, 2025 17:40
@jcnelson jcnelson added this pull request to the merge queue Feb 25, 2025
Merged via the queue into develop with commit 60bcb5c Feb 25, 2025
184 checks passed
@jcnelson jcnelson deleted the feat/fast-default-cost-tracking branch February 25, 2025 18:03
@blockstack-devops
Copy link
Contributor

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@stacks-network stacks-network locked as resolved and limited conversation to collaborators Mar 5, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants