Feat: Implement faster cost tracker for default cost functions #5859
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.
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.