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

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

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
builtin_cost.core_bpf_migration_feature.map(|id| {
MIGRATION_FEATURES_ID
.iter()
.position(|&x| x == id)
Copy link
Author

Choose a reason for hiding this comment

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

performance-wise: does same one lookup of AhashMap, then additional O(n) search, where n is 3.

Copy link

Choose a reason for hiding this comment

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

we could store a unique index in BuiltinCost. and we could have some tests to really simply verify the indexes are contiguous on (0..N) and unique.

byte per key in the BUILTIN_INSTRUCTION_COSTS, but then we don't need to do ~3 pubkey comparisons.

Thoughts?

Copy link
Author

Choose a reason for hiding this comment

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

We can do something like this:

pub const MIGRATING_BUILTINS_COSTS: &[(Pubkey, BuiltinCost)] = &[
    (
        solana_stake_program::id(),
        BuiltinCost {
            native_cost: solana_stake_program::stake_instruction::DEFAULT_COMPUTE_UNITS,
            core_bpf_migration_feature: Some(feature_set::migrate_stake_program_to_core_bpf::id()),
            index: 0,   <=== 
        },
    ),
    (
        solana_config_program::id(),
        BuiltinCost {
            native_cost: solana_config_program::config_processor::DEFAULT_COMPUTE_UNITS,
            core_bpf_migration_feature: Some(feature_set::migrate_config_program_to_core_bpf::id()),
            index: 1,   <====
        },
    ),
    ...
];

index correctness can be validated by tests during CI, or perhaps by asserts during compile-time. But need some push to be convinced this is Clean Code.

Copy link

Choose a reason for hiding this comment

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

Yeah, this is exactly what I would like 😄

"clean" be damned if it's faster and works. Tests can easily verify.

Probably best to put it inside the Option of core_bpf_migration_feature? That way it's effectively not set for non-migrating buitins.

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.

"clean" be damned if it's faster and works. Tests can easily verify.

respectively disagree.

Copy link
Author

Choose a reason for hiding this comment

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

b6c391b added explicit positional info to BuiltinCost, const function to validate position correctness at compile test. Also added unit test per suggestion.

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
@tao-stones tao-stones force-pushed the fix-support-migrating-builtins branch from e3ded01 to 28113aa Compare December 10, 2024 16:06
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!

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.

5 participants