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

Unify builtin lists wip #4039

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

buffalojoec
Copy link

No description provided.

Copy link

@tao-stones tao-stones left a comment

Choose a reason for hiding this comment

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

Awesome to have the single source of truth here. Can you take a look at #3975, there two BUILTINS arrays were created - one for migrating one for not-migrating. The motivation is each transaction can have a fixed-length array in meta data, avoiding Vec allocation, by

struct MigrationBuiltinFeatureCounter {
    // The vector of counters, matching the size of the static vector MIGRATION_FEATURE_IDS,
    // each counter representing the number of times its corresponding feature ID is
    // referenced in this transaction.
    migrating_builtin: [u16; MIGRATING_BUILTINS_COSTS.len()],
}

Do you think if that's a reasonable approach? If so, could this PR rebase on top of that one?

pub struct CostModelingConfig {
/// The default cost of the builtin program.
/// If None, this builtin program is not cost modeled.
pub default_cost: Option<u64>,

Choose a reason for hiding this comment

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

Nice, this solves ZK stuff. We could use enum instead of Option to make it even more distinguished.

Copy link
Author

Choose a reason for hiding this comment

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

I refactored to use an enum! I think that's a smoother approach. Good tip.

.chain(
[
(
secp256k1_program::id(),

Choose a reason for hiding this comment

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

+1 for not forgetting these 2.

the new secp256r1 probably will never be added to this list

lazy_static! {
static ref BUILTIN_INSTRUCTION_COSTS: AHashMap<Pubkey, BuiltinCost> = BUILTINS
.iter()
.map(|builtin| {

Choose a reason for hiding this comment

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

maybe can filter out those default_cost.is_none() so the BUILTIN_INSTRUCTION_COSTS itself is identical to before-version?

Copy link
Author

Choose a reason for hiding this comment

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

I didn't filter out default_cost.is_none() only because this allows get_builtin_instruction_cost to query the new_default_cost field based on feature set.

Copy link
Author

Choose a reason for hiding this comment

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

I believe my refactor does this now!

@buffalojoec
Copy link
Author

@tao-stones thanks for taking a look! I refactored this a bit and re-wrote my commits (I had to rebase anyway from some other changes that went in).

With this approach, we can eliminate the footgun of having to update two lists with a new migration feature ID. The only "secondary" area that needs to get updated now is the NUM_COST_MODELED_BUILTINS_WITH_MIGRATIONS in the cost_modeling module. However, I've added a test that will barf if someone forgets to adjust the constant. The feature IDs are always sourced from BUILTINS, which should eliminate the footgun.

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.

2 participants