Skip to content
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

Add a test-only mechanism for metering most of the relevant resources per-invocation #1482

Merged
merged 5 commits into from
Nov 7, 2024

Conversation

dmkozh
Copy link
Contributor

@dmkozh dmkozh commented Oct 29, 2024

What

This is an opt-in feature that will reset the budget and take a storage snapshot for every 'logical' invocation (such as call or a lifecycle operation). Then when the invocation is done we use the snapshot and current budget to produce the estimate for the resources consumed by the invocation (budget-related, IO-related and rent bumps).

This also provides a rough estimation for the respective fee breakdown given a fee config.

Why

Make unit tests more useful for rough performance evaluation. This is the initial env-side implementation for stellar/rs-soroban-sdk#1319

Known limitations

Some of the resources are tricky to model. Specifically, this omits:

  • transaction size
  • return value size
  • some XDR roundtrips that always happen for production scenarios

These shouldn't be too significant though and are likely better addressed via e2e runs (like simulation or some e2e_invoke-based mechanism)

… per-invocation.

This is an opt-in feature that will reset the budget and take a storage snapshot for every 'logical' invocation (such as `call` or a lifecycle operation). Then when the invocation is done we use the snapshot and current budget to produce the estimate for the resources consumed by the invocation (budget-related, IO-related and rent bumps).

This also provides a rough estimation for the respective fee breakdown given a fee config.
Copy link
Member

@leighmcculloch leighmcculloch left a comment

Choose a reason for hiding this comment

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

Will the idea be in the SDK to call budget.reset() before each top-level invocation? That sounds like a great idea.

I think we should move to that approach env wide, except for types that are in memory and storage, treat everything else like a reset. One thing we need to start doing that for is logs. Right now you can output diagnostic logs for many invocations, which is quite confusing. In short, yeah, this approach of resetting 👍🏻, and it should just be mandated in the SDK and always happen.

If someone needs to test calls together they can always wrap their calls in a single .as_contract.

@dmkozh
Copy link
Contributor Author

dmkozh commented Oct 30, 2024

Will the idea be in the SDK to call budget.reset() before each top-level invocation?

SDK just needs to enable invocation metering, env will take care of the resets.

I think we should move to that approach env wide, except for types that are in memory and storage, treat everything else like a reset. One thing we need to start doing that for is logs.

Yeah, we're getting this automatically by clearing the events. I'm resetting the budget, footprint, and events. I think that should be everything, but we can reset more if necessary.

If someone needs to test calls together they can always wrap their calls in a single .as_contract.

Good point, this actually hasn't been covered by the metering scope.

Copy link
Contributor

@sisuresh sisuresh left a comment

Choose a reason for hiding this comment

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

Nice work!

@sisuresh sisuresh added this pull request to the merge queue Nov 7, 2024
Merged via the queue into stellar:main with commit 05219cf Nov 7, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants