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

default compute units per instruction #24899

Merged
merged 4 commits into from
May 3, 2022

Conversation

jackcmay
Copy link
Contributor

@jackcmay jackcmay commented May 2, 2022

Problem

Defaulting the tx-wide cap to the max overestimates what a transaction will need and later will skew transaction scheduling for transactions that don't explicitly request

Summary of Changes

Default the units to 200k per non-compute budget instruction in the transaction

Fixes #
Feature Gate Issue: #24898

@jackcmay jackcmay added the feature-gate Pull Request adds or modifies a runtime feature gate label May 2, 2022
@jackcmay jackcmay force-pushed the default-units-per-instruction branch from 5b52cae to 624f465 Compare May 2, 2022 17:22
program-runtime/src/compute_budget.rs Show resolved Hide resolved
program-runtime/src/compute_budget.rs Outdated Show resolved Hide resolved
program-runtime/src/compute_budget.rs Outdated Show resolved Hide resolved
sdk/src/feature_set.rs Outdated Show resolved Hide resolved
@jackcmay jackcmay requested a review from Lichtso May 2, 2022 18:17
@jackcmay jackcmay requested a review from aeyakovenko May 2, 2022 18:41
@codecov
Copy link

codecov bot commented May 2, 2022

Codecov Report

Merging #24899 (a5570b7) into master (8ba003a) will increase coverage by 0.1%.
The diff coverage is 88.7%.

@@            Coverage Diff            @@
##           master   #24899     +/-   ##
=========================================
+ Coverage    81.8%    82.0%   +0.1%     
=========================================
  Files         632      597     -35     
  Lines      167499   165739   -1760     
  Branches      322        0    -322     
=========================================
- Hits       137169   136047   -1122     
+ Misses      30217    29692    -525     
+ Partials      113        0    -113     

compute units used by each instruction in the transaction must not exceed that
value. The default number of maximum units allows is intentionally kept large to
avoid breaking existing client behavior.
default number of maximum units will calculated per instruction which means the
Copy link
Member

Choose a reason for hiding this comment

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

I don't really understand what this is trying to say

Copy link
Contributor

Choose a reason for hiding this comment

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

better? #24955

@jackcmay jackcmay requested a review from t-nelson May 3, 2022 16:15
@jackcmay jackcmay merged commit e070c5c into solana-labs:master May 3, 2022
@jackcmay jackcmay deleted the default-units-per-instruction branch May 3, 2022 16:50
mergify bot pushed a commit that referenced this pull request May 3, 2022
(cherry picked from commit e070c5c)

# Conflicts:
#	docs/src/developing/programming-model/runtime.md
#	sdk/src/feature_set.rs
mergify bot pushed a commit that referenced this pull request May 3, 2022
@arcticmatt
Copy link

jackcmay added a commit that referenced this pull request May 3, 2022
* default compute units per instruction (#24899)

(cherry picked from commit e070c5c)

# Conflicts:
#	docs/src/developing/programming-model/runtime.md
#	sdk/src/feature_set.rs

* fix merge

Co-authored-by: Jack May <[email protected]>
jackcmay added a commit that referenced this pull request May 3, 2022
* default compute units per instruction (#24899)

(cherry picked from commit e070c5c)

* update doc

Co-authored-by: Jack May <[email protected]>
Copy link
Contributor

@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.

gate lgtm. I thought we were going to swing a heavier hammer here, but I guess this is fine too.

// Compute budget instruction must be in the 1st 3 instructions (avoid
// nonce marker), otherwise ignored
if i < 3 {
match try_from_slice_unchecked(&instruction.data) {
Copy link
Contributor

Choose a reason for hiding this comment

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

OT, but should it be an error to specify any of these multiple times?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

eh, just take the last

Copy link
Member

Choose a reason for hiding this comment

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

To be fair, it's pretty confusing when looking at the explorer and some transactions have like 10 compute budget instructions and you have to know it's the 3rd one that was applied

requested_units
}
.unwrap_or(MAX_UNITS as u64)
.min(MAX_UNITS as u64);
Copy link
Contributor

Choose a reason for hiding this comment

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

should we really clamp here? failure is always an option

Copy link
Contributor Author

Choose a reason for hiding this comment

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

figure clamp and hope for best, max might change but in a way that would still allow the tx to succeed

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah, just thought it might be confusing DX


self.max_units = if default_units_per_instruction {
requested_units
.or_else(|| Some(num_instructions.saturating_mul(DEFAULT_UNITS as usize) as u64))
Copy link
Contributor

Choose a reason for hiding this comment

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

I thought we were just requesting DEFAULT_UNITS for the entire TX if unspecified, not retaining today's behavior. I guess this is OK, but I'd rather put some pressure on the offenders to change their ways

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the smoothest transition to tx-wide caps without breaking folks and the additional fee will schedule folks appropriately. I'm still a fan of charging a requested CU based fee to encourage low CU requests. @aeyakovenko using for additional fee based motivation, open market.

Copy link
Member

Choose a reason for hiding this comment

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

I think we should still cap the number of instructions for this calculation.. Like maybe 10 instructions? If you're doing more than that, you're a bot and can add the compute budget ix yourself.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's capped at a total maximum unit which should be sufficient, what does capping the ix's doing for us? Seems artificial to say that if there are 10 instructions it must be a bot

Copy link
Member

Choose a reason for hiding this comment

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

It's capped at a total maximum unit which should be sufficient

Ah ok, this works too! I clearly didn't read the PR 😅

Copy link
Contributor

Choose a reason for hiding this comment

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

This is the smoothest transition to tx-wide caps without breaking folks

Yep. I was just fully prepared to break the right folks 😉

jeffwashington pushed a commit to jeffwashington/solana that referenced this pull request Jun 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-gate Pull Request adds or modifies a runtime feature gate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants