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

Fix reserve minimal compute units for builtins #3799

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

tao-stones
Copy link

Problem

Implementing solana-foundation/solana-improvement-documents#170 by defining MAX_BUILTIN_ALLOCATION_COMPUTE_UNIT_LIMIT to 3K CUs, then use it to allocate builtin instructions' CU Meters for VM and cost tracking for leaders.

Summary of Changes

  • Resolve if builtin program has been migrated to core bpf by check feature status
  • When calculates default tx cu limits, use MAX_BUILTIN_ALLOCATION_COMPUTE_UNIT_LIMIT per builtin instruction, including compute-budget program instructions.
  • Cost model reads cu limits from RuntimeTransaction's static_meta, replacing a localized implementation that isn't consistent with compute-budget.
  • Changes are behind Feature gate
  • updated existing tests to allow additional feature_set parameters (touch many files)
  • add final tests to verify new behavior

Feature Gate Issue: #2562

@tao-stones tao-stones added the feature-gate Pull Request adds or modifies a runtime feature gate label Nov 26, 2024
@tao-stones tao-stones force-pushed the fix-reserve-minimal-cus-for-builtins-less-api-change branch from e416a8f to 6bbd650 Compare November 26, 2024 18:27
Comment on lines +28 to +30
num_compute_budget_instructions: u32,
num_builtin_instructions: u32,
num_non_builtin_instructions: u32,

Choose a reason for hiding this comment

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

these can be u16

Copy link
Author

Choose a reason for hiding this comment

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

It could, made them u32 mainly because they are used to calculate cu-limits, which is u32, saves a bunch of try_into(). Honestly I don't see it, but is changing them into u16 necessary?

num_builtin_instructions: u32,
num_non_builtin_instructions: u32,
// A list of migration feature IDs for builtin instructions
maybe_builtin: Vec<Pubkey>,
Copy link

@apfitzge apfitzge Nov 26, 2024

Choose a reason for hiding this comment

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

we shouldn't allocate like this per transaction

Copy link
Author

@tao-stones tao-stones Nov 27, 2024

Choose a reason for hiding this comment

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

This is sort of proof of concept - it implements the function, but not great for allocation.

To improve performance, maybe need @buffalojoec PR, then Vec<pubkey> can be replaced with maybe_builtin: [u12; 10] - a fixed array that maps BUILTINS, each u12 counts number of builtin instructions. That way sanitize can refer to BUILTINS for migration feature id.

@tao-stones tao-stones force-pushed the fix-reserve-minimal-cus-for-builtins-less-api-change branch 2 times, most recently from 77381a1 to 8faee07 Compare November 27, 2024 20:18
@tao-stones tao-stones marked this pull request as ready for review November 27, 2024 20:18
@tao-stones tao-stones requested a review from a team as a code owner November 27, 2024 20:18
@tao-stones tao-stones force-pushed the fix-reserve-minimal-cus-for-builtins-less-api-change branch from 8faee07 to c181481 Compare November 27, 2024 20:20
@@ -27,6 +27,7 @@ name = "solana_runtime_transaction"
bincode = { workspace = true }
criterion = { workspace = true }
rand = { workspace = true }
solana-stake-program = { workspace = true }
Copy link

Choose a reason for hiding this comment

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

This dependency is added specifically for a test. Can the test be reworked to move this dependency out of SVM related crates? We are trying to keep the deps to a minimum so that SVM can be moved to its own Github repo.

Copy link
Author

Choose a reason for hiding this comment

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

thanks for pointing this out, change in 34f497d

@tao-stones tao-stones force-pushed the fix-reserve-minimal-cus-for-builtins-less-api-change branch from 8711a52 to 59a7305 Compare November 30, 2024 21:44
@tao-stones tao-stones force-pushed the fix-reserve-minimal-cus-for-builtins-less-api-change branch from 59a7305 to 4f13a31 Compare November 30, 2024 22:05
@tao-stones tao-stones force-pushed the fix-reserve-minimal-cus-for-builtins-less-api-change branch from 4f13a31 to 0e8a348 Compare December 1, 2024 00:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-gate Pull Request adds or modifies a runtime feature gate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants