-
Notifications
You must be signed in to change notification settings - Fork 238
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
base: master
Are you sure you want to change the base?
Accounting migrating builtin programs default Compute Unit Limit with feature status #3975
Conversation
builtins-default-costs/src/lib.rs
Outdated
builtin_cost.core_bpf_migration_feature.map(|id| { | ||
MIGRATION_FEATURES_ID | ||
.iter() | ||
.position(|&x| x == id) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
builtins-default-costs/src/lib.rs
Outdated
/// 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>> { |
There was a problem hiding this comment.
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>.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in b6c391b
b9a6fbe
to
2c01afe
Compare
), | ||
]; | ||
|
||
pub const NON_MIGRATING_BUILTINS_COSTS: &[(Pubkey, BuiltinCost)] = &[ |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in b6c391b, above
bde9c18
to
b6c391b
Compare
b6c391b
to
f522323
Compare
e3ded01
to
28113aa
Compare
There was a problem hiding this 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.
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 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 |
… its feature gate status
…ation (Vec<>) per transaction
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
28113aa
to
6331283
Compare
That sounds good to me, thanks! |
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
3
entries) vectorMigrationBuiltinFeatureCounter
to transaction static meta;try_from()
feature_set
to resolve if builtin has migrated duringcalculate_default_compute_unit_limit()
if Compute Unit Limit was not requested.Fixes #