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

Accounting migrating builtin programs default Compute Unit Limit with feature status #3975

Merged
merged 5 commits into from
Dec 12, 2024

Conversation

tao-stones
Copy link

Problem

When a builtin program migrated into sbpf, it should no longer be considered as 'builtin', therefore its default Compute Budget Limit should change from 3K to 200K CU, per #3799. It is currently not supported by Compute Budget Instruction processing.

Summary of Changes

  • Add fixed-length (currently 3 entries) vector MigrationBuiltinFeatureCounter to transaction static meta;
  • Counts migrating builtin features gates during try_from()
  • Check feature_set to resolve if builtin has migrated during calculate_default_compute_unit_limit() if Compute Unit Limit was not requested.

Fixes #

@tao-stones tao-stones requested a review from a team as a code owner December 6, 2024 16:55
Copy link

@pgarg66 pgarg66 left a comment

Choose a reason for hiding this comment

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

Looks good from SVM side.

Comment on lines 175 to 187
/// Given a program pubkey, returns:
/// - None, if it is not in BUILTIN_INSTRUCTION_COSTS dictionary;
/// - Some<None>, is builtin, but no associated migration feature ID;
/// - Some<usize>, is builtin, and its associated migration feature ID
/// index in MIGRATION_FEATURES_ID.
pub fn get_builtin_migration_feature_index(program_id: &Pubkey) -> Option<Option<usize>> {
Copy link

Choose a reason for hiding this comment

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

would it make sense to have a simple enum:

pub enum BuiltinMigrationFeatureIndex {
    NotBuiltin,
    BuiltinNoMigrationFeature,
    BuiltinWithMigrationFeatureIndex(usize)
}

naming probably too long, but it's a bit more self-documenting than Option<Option>.

Copy link
Author

Choose a reason for hiding this comment

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

in b6c391b

@tao-stones tao-stones force-pushed the fix-support-migrating-builtins branch from b9a6fbe to 2c01afe Compare December 6, 2024 22:30
),
];

pub const NON_MIGRATING_BUILTINS_COSTS: &[(Pubkey, BuiltinCost)] = &[
Copy link

Choose a reason for hiding this comment

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

Can you add the developer warning to this const as well?

Copy link
Author

@tao-stones tao-stones Dec 9, 2024

Choose a reason for hiding this comment

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

in b6c391b, above

@tao-stones tao-stones force-pushed the fix-support-migrating-builtins branch 3 times, most recently from bde9c18 to b6c391b Compare December 9, 2024 23:46
@tao-stones tao-stones requested a review from apfitzge December 9, 2024 23:49
@tao-stones tao-stones force-pushed the fix-support-migrating-builtins branch from b6c391b to f522323 Compare December 10, 2024 00:13
Copy link

@buffalojoec buffalojoec left a comment

Choose a reason for hiding this comment

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

The changes look okay to me, but things are definitely getting pretty complex. I'm still an advocate for unifying & simplifying, but I'm not sure if I have a better solution or not.

Let me know what you guys think of #4039. I took a stab at integrating this PR in the last commit, but it's a little half-baked.

@tao-stones
Copy link
Author

tao-stones commented Dec 11, 2024

The changes look okay to me, but things are definitely getting pretty complex. I'm still an advocate for unifying & simplifying, but I'm not sure if I have a better solution or not.

Let me know what you guys think of #4039. I took a stab at integrating this PR in the last commit, but it's a little half-baked.

Thanks @buffalojoec for looking at it, as we chatted offline, I 100% support unifying builtin list; Like #4039 a lot (left few comments)

I appreciate the concern of complex. A part of that is to add positional info to avoid iter, and additional scaffolding for compile-time validation (0a747da).

Apart from that, the major difference between #4039 and this PR is unifying builtins. I'm leaning to land (and backport) this PR first to unblock SIMD-170 implementation, then work your PR to improve builtins list (at that time, there will only have small/cosmetic changes to compute-budget-instruction crate).

add explicit positional information to migrating builtin feature obj

update developer notes, added static_assertion to validate no new items are added, add enum type
@tao-stones tao-stones force-pushed the fix-support-migrating-builtins branch from 28113aa to 6331283 Compare December 11, 2024 18:47
@buffalojoec
Copy link

I'm leaning to land (and backport) this PR first to unblock SIMD-170 implementation, then work your PR to improve builtins list (at that time, there will only have small/cosmetic changes to compute-budget-instruction crate).

That sounds good to me, thanks!

@@ -31,6 +50,7 @@ pub struct ComputeBudgetInstructionDetails {
// Additional builtin program counters
num_builtin_instructions: u16,
Copy link

@apfitzge apfitzge Dec 12, 2024

Choose a reason for hiding this comment

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

can we add a comment on this field, or preferrably change the name, so that it's clear that this count is only for builtins that are not possibly migrated?

The math in calculate_default_compute_unit_limit makes a lot more sense if that is clearer 😄

Copy link
Author

Choose a reason for hiding this comment

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

s/num_builtin_instructions/num_non_migratable_builtin_instructions/g

Copy link

@apfitzge apfitzge left a comment

Choose a reason for hiding this comment

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

few minor comments, otherwise happy now!

@tao-stones tao-stones added the automerge automerge Merge this Pull Request automatically once CI passes label Dec 12, 2024
Copy link

@pgarg66 pgarg66 left a comment

Choose a reason for hiding this comment

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

Approving on behalf of SVM

@mergify mergify bot merged commit 9379fbc into anza-xyz:master Dec 12, 2024
52 checks passed
@tao-stones tao-stones deleted the fix-support-migrating-builtins branch December 12, 2024 18:29
@tao-stones tao-stones added the v2.1 Backport to v2.1 branch label Dec 12, 2024
Copy link

mergify bot commented Dec 12, 2024

Backports to the beta branch are to be avoided unless absolutely necessary for fixing bugs, security issues, and perf regressions. Changes intended for backport should be structured such that a minimum effective diff can be committed separately from any refactoring, plumbing, cleanup, etc that are not strictly necessary to achieve the goal. Any of the latter should go only into master and ride the normal stabilization schedule. Exceptions include CI/metrics changes, CLI improvements and documentation updates on a case by case basis.

mergify bot pushed a commit that referenced this pull request Dec 12, 2024
… feature status (#3975)

* Accounting migrating builtin programs default Compute Unit Limit with its feature gate status

* Declare Non/migrating buiiltins in const array, eleminates heap allocation (Vec<>) per transaction

* updates for review commients

add explicit positional information to migrating builtin feature obj

update developer notes, added static_assertion to validate no new items are added, add enum type

* use enum to separately define migrating and not-migrating builtins

* rename for clarity

(cherry picked from commit 9379fbc)

# Conflicts:
#	builtins-default-costs/src/lib.rs
#	compute-budget-instruction/Cargo.toml
#	compute-budget-instruction/src/builtin_programs_filter.rs
#	runtime-transaction/src/compute_budget_instruction_details.rs
tao-stones added a commit that referenced this pull request Dec 13, 2024
… feature status (#3975)

* Accounting migrating builtin programs default Compute Unit Limit with its feature gate status

* Declare Non/migrating buiiltins in const array, eleminates heap allocation (Vec<>) per transaction

* updates for review commients

add explicit positional information to migrating builtin feature obj

update developer notes, added static_assertion to validate no new items are added, add enum type

* use enum to separately define migrating and not-migrating builtins

* rename for clarity

(cherry picked from commit 9379fbc)
tao-stones added a commit that referenced this pull request Jan 9, 2025
… feature status (#3975)

* Accounting migrating builtin programs default Compute Unit Limit with its feature gate status

* Declare Non/migrating buiiltins in const array, eleminates heap allocation (Vec<>) per transaction

* updates for review commients

add explicit positional information to migrating builtin feature obj

update developer notes, added static_assertion to validate no new items are added, add enum type

* use enum to separately define migrating and not-migrating builtins

* rename for clarity

(cherry picked from commit 9379fbc)
tao-stones added a commit that referenced this pull request Jan 11, 2025
… feature status (#3975)

* Accounting migrating builtin programs default Compute Unit Limit with its feature gate status

* Declare Non/migrating buiiltins in const array, eleminates heap allocation (Vec<>) per transaction

* updates for review commients

add explicit positional information to migrating builtin feature obj

update developer notes, added static_assertion to validate no new items are added, add enum type

* use enum to separately define migrating and not-migrating builtins

* rename for clarity

(cherry picked from commit 9379fbc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge automerge Merge this Pull Request automatically once CI passes v2.1 Backport to v2.1 branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants