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

v2.1: Fix builtin default cost dependents on migration (backport of #3768) #4415

Merged
merged 2 commits into from
Jan 15, 2025

Conversation

mergify[bot]
Copy link

@mergify mergify bot commented Jan 12, 2025

Problem

Some of builtin programs are being migrated to sbpf, while the rest is being planned for too. Once a builtin program is migrated in a cluster, it's "default cost" defined in BUILTIN_INSTRUCTION_COSTS should be changed to 0.

Summary of Changes

  • add public function to fetch correct default cost for builtin program, based on migration feature status
  • add BuiltinCost struct to track migration feature ID
  • add developer notes to remind to add migration feature ID whenever it becomes available.

Fixes #


This is an automatic backport of pull request #3768 done by [Mergify](https://mergify.com).

@mergify mergify bot added the conflicts label Jan 12, 2025
@mergify mergify bot requested a review from a team as a code owner January 12, 2025 18:57
Copy link
Author

mergify bot commented Jan 12, 2025

Cherry-pick of d791c9a has failed:

On branch mergify/bp/v2.1/pr-3768
Your branch is up to date with 'origin/v2.1'.

You are currently cherry-picking commit d791c9a76.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	modified:   builtins-default-costs/benches/builtin_instruction_costs.rs
	modified:   core/src/banking_stage/packet_filter.rs
	modified:   runtime/src/bank/builtins/mod.rs

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   builtins-default-costs/src/lib.rs
	both modified:   cost-model/src/cost_model.rs

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

@tao-stones
Copy link

tao-stones commented Jan 12, 2025

A prerequisite bp for backporting #3975 to 2.1 (#4091).

Details:

@jstarry
Copy link

jstarry commented Jan 13, 2025

For the record, I don't think the get_builtin_instruction_cost function is actually needed in v2.1. As far as I can tell, it's only used in packet filtering and in get_transaction_cost_without_minimal_builtin_cus both of which aren't important for replay consistency. But we do need the changes to the BUILTIN_INSTRUCTION_COSTS map which was also made "migration feature" aware in #3768

@tao-stones
Copy link

cost_model also calls get_builtin_instruction_cost function to get builtin cost with feature status. But yea, the main change is to the BUILTIN_INSTRUCTION_COSTS map and demoting its visibility to private, introducing get_builtin_instruction_cost function as public api.

tao-stones and others added 2 commits January 13, 2025 11:07
* Add public function to as placeholder to implement fetching default cost depends on feature_set;
Make AhashMap private

* Add BuiltinCost to help determine default cost based on migration status

* test

* fix - after migration feature activation, it should no longer be considered as builtin

* use lazy_static, avoid naked unwrap

* rename

* add comments to BUILINS

(cherry picked from commit d791c9a)

# Conflicts:
#	builtins-default-costs/src/lib.rs
#	cost-model/src/cost_model.rs
@jstarry
Copy link

jstarry commented Jan 14, 2025

cost_model also calls get_builtin_instruction_cost function to get builtin cost with feature status

Yeah, only in get_transaction_cost_without_minimal_builtin_cus right? That code path isn't really critical.

@tao-stones
Copy link

right, it's the execution path before feature reserve_minimal_cus_for_builtin_instructions is activated; after activation, it'd be obsoleted.

@t-nelson
Copy link

is #4091 not smuggling this change set? 4091 looks nothing like the master pr

Copy link

@t-nelson t-nelson left a comment

Choose a reason for hiding this comment

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

seems like an awfully roundabout way to get the job done 😭

(secp256k1_program::id(), 0),
(ed25519_program::id(), 0),
// DO NOT ADD MORE ENTRIES TO THIS MAP
static ref BUILTIN_INSTRUCTION_COSTS: AHashMap<Pubkey, BuiltinCost> = [

Choose a reason for hiding this comment

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

discarding pub breaks api here. probably what we eventually want, but not the way to do it

Choose a reason for hiding this comment

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

discarding pub breaks api here. probably what we eventually want, but not the way to do it

then again the signature is wrecked too, sigh. at least any brain dead consumers can adapt if it remains pub

Copy link

Choose a reason for hiding this comment

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

Why are you concerned with API compatibility in this crate?

lazy_static! {
// To calculate the static_builtin_cost_sum conservatively, an all-enabled dummy feature_set
// is used. It lowers required minimal compute_unit_limit, aligns with future versions.
static ref FEATURE_SET: FeatureSet = FeatureSet::all_enabled();

Choose a reason for hiding this comment

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

why can't we just resolve the feature gate status at a higher level and use a bool instead of some poorly named sentinel value?

Copy link

Choose a reason for hiding this comment

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

Is this important for backport review? Also can you explain the bool you're talking about? I'm not getting what you're suggesting

Choose a reason for hiding this comment

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

At the receiving & buffer part of Banking_stage, resolving feature gate status is always bit fuzzy since we have a 'working_bank' yet. There are certainly ways around it, but nothing is clean and easy afaik.

@tao-stones
Copy link

tao-stones commented Jan 15, 2025

is #4091 not smuggling this change set? 4091 looks nothing like the master pr

The urge to sneak it into #4091 was strong, but we decided to do it right: #4091 (comment). With this, 4091 looks pretty close to its original PR #3975

@tao-stones tao-stones merged commit f9d4939 into v2.1 Jan 15, 2025
28 checks passed
@tao-stones tao-stones deleted the mergify/bp/v2.1/pr-3768 branch January 15, 2025 04:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants