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

Skip adding builtins if they will be removed #23233

Merged
merged 6 commits into from
Feb 19, 2022

Conversation

jstarry
Copy link
Member

@jstarry jstarry commented Feb 18, 2022

Problem

When loading from a snapshot, a validator adds and removes builtins and precompiles according to which runtime features are activated. Also, it's important to note that builtin additions are always processed before removals. So after a builtin has been turned into a precompile account on a cluster, the validator will still try to re-add it whenever it starts up from a snapshot. When the builtin is re-added while starting from a snapshot, the builtin account is checked to see whether it is owned by the native loader (precompiles are system-owned) and if not, the validator will hard exit because it thinks it booted from an incompatible snapshot.

Summary of Changes

  • Add additional types for feature activated transitions to the list of active builtin programs
  • Ensure that any removed builtin references an existing builtin that is retained if the removal feature hasn't been activated yet

Fixes #23231

@jstarry jstarry force-pushed the fix-builtin-deactivation branch from a525b16 to 9efe5c1 Compare February 18, 2022 12:56
@jstarry jstarry requested review from jackcmay and ryoqun February 18, 2022 12:56
@jstarry jstarry added the v1.9 label Feb 18, 2022
@@ -44,6 +44,8 @@ echo --- build environment
export RUST_BACKTRACE=1
export RUSTFLAGS="-D warnings -A incomplete_features"

_ "$cargo" stable clean
Copy link
Member

Choose a reason for hiding this comment

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

is this intended to be included in this pr? i think this increase the build time sometimes needlessly by removing the build cache too much?

Copy link
Member Author

Choose a reason for hiding this comment

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

It was my only way to get past a compiler issue on CI. I will remove before merging. I mentioned it in #devops on Discord as well

@jstarry
Copy link
Member Author

jstarry commented Feb 18, 2022

Oops I still need to fix the Abi changes. But the logic of the PR should still be reviewable in its current form

RemoveOrRetain {
previous_builtin: Builtin,
removal_feature_id: Pubkey,
},
Copy link
Member

Choose a reason for hiding this comment

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

nits: how about commenting about the lack of the obvious Remove like this?:

// historically, we had Remove to fully remove a builtin. however there's no use case for now. restore it if needed.

Copy link
Member Author

Choose a reason for hiding this comment

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

In case you didn't see this from the linked issue. This is why we need the remove and retain:

  • For v1.8 compatibility, we need to be able to keep adding a builtin until a feature is activated.
  • For v1.9 compatibility, we need to avoid adding a builtin if a feature is already activated.

Copy link
Member

Choose a reason for hiding this comment

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

also, I'm omitting Replace as it's really useless now. That's because builtins now has access to feature_set. Replace was relic before the widespread use of feature activation mechanism...

Copy link
Member

@ryoqun ryoqun Feb 18, 2022

Choose a reason for hiding this comment

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

lastly, i wonder when Remove would be needed in the (distant) future. so, I'm just saying leaving a comment would be just enough to work as a pointer to this pr in the future.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, that's exactly why I removed Replace. Relic of the past and not useful anymore.

Copy link
Member Author

Choose a reason for hiding this comment

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

Great yeah I will add a comment, I agree it probably won't be needed in the future

feature_id: Pubkey,
},
/// Remove a builtin program if a feature is activated or
/// retain a previously added builtin.
Copy link
Member

Choose a reason for hiding this comment

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

nit: /// Specifically, this is needed for rather the exceptional builtin -> precompile transition feature

};

#[test]
fn test_startup_from_snapshot_after_precompile_transition() {
Copy link
Member

Choose a reason for hiding this comment

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

thanks for writing this. yeah, feature activation needs more test coverage...

ryoqun
ryoqun previously approved these changes Feb 18, 2022
Copy link
Member

@ryoqun ryoqun left a comment

Choose a reason for hiding this comment

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

lgtm with nits and after ci passes. :)

ActivationType::NewProgram,
),
feature_id: feature_set::add_compute_budget_program::id(),
},
// TODO when feature `prevent_calling_precompiles_as_programs` is
Copy link
Contributor

Choose a reason for hiding this comment

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

These comments can be removed

@mergify mergify bot dismissed ryoqun’s stale review February 18, 2022 17:31

Pull request has been modified.

@jackcmay
Copy link
Contributor

Looks good @jstarry thanks!

On main and devnet all existing builtin and precompile accounts are owned by the native loader. I added a change to this pr to keep that consistency.

Also added a few nits

@jackcmay jackcmay force-pushed the fix-builtin-deactivation branch from 3578333 to 63d1c3e Compare February 18, 2022 18:00
t-nelson
t-nelson previously approved these changes Feb 18, 2022
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.

lgtm. thanks! third times the charm

@@ -51,63 +51,6 @@ macro_rules! with_program_logging {
};
}

/// State transition enum used for adding and removing builtin programs through
Copy link
Contributor

Choose a reason for hiding this comment

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

This block and the next are purely cosmetic, right? Hard to follow major cosmetics in a functional change set

@jstarry
Copy link
Member Author

jstarry commented Feb 18, 2022

Cool, I would prefer the owner fix to be separate but looks safe

@jackcmay jackcmay force-pushed the fix-builtin-deactivation branch from 63d1c3e to bd40fa4 Compare February 18, 2022 21:09
@mergify mergify bot dismissed t-nelson’s stale review February 18, 2022 21:09

Pull request has been modified.

@jackcmay jackcmay force-pushed the fix-builtin-deactivation branch from 8a93aea to 1a91f9e Compare February 18, 2022 22:49
@codecov
Copy link

codecov bot commented Feb 19, 2022

Codecov Report

Merging #23233 (1a91f9e) into master (c696944) will decrease coverage by 0.0%.
The diff coverage is 88.8%.

@@            Coverage Diff            @@
##           master   #23233     +/-   ##
=========================================
- Coverage    81.3%    81.3%   -0.1%     
=========================================
  Files         570      571      +1     
  Lines      155438   155451     +13     
=========================================
+ Hits       126452   126454      +2     
- Misses      28986    28997     +11     

@t-nelson
Copy link
Contributor

let's go?

@jackcmay jackcmay merged commit 1719d23 into solana-labs:master Feb 19, 2022
mergify bot pushed a commit that referenced this pull request Feb 19, 2022
* Add failing test for precompile transition

* Skip adding builtins if they will be removed

* cargo clean

* nits

* fix abi check

* remove workaround

Co-authored-by: Jack May <[email protected]>
(cherry picked from commit 1719d23)

# Conflicts:
#	runtime/src/bank.rs
#	runtime/src/builtins.rs
mergify bot added a commit that referenced this pull request Feb 19, 2022
* Skip adding builtins if they will be removed (#23233)

* Add failing test for precompile transition

* Skip adding builtins if they will be removed

* cargo clean

* nits

* fix abi check

* remove workaround

Co-authored-by: Jack May <[email protected]>
(cherry picked from commit 1719d23)

# Conflicts:
#	runtime/src/bank.rs
#	runtime/src/builtins.rs

* resolve conflicts

Co-authored-by: Justin Starry <[email protected]>
Co-authored-by: Jack May <[email protected]>
Comment on lines +147 to +150
} else {
// Retaining is no different from adding a new builtin.
Some(BuiltinAction::Add(previous_builtin.clone()))
}
Copy link
Member Author

Choose a reason for hiding this comment

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

I believe this branch introduced a new bug for epoch boundaries. On epoch boundaries, the should_apply_action_for_feature(removal_feature_id) condition will be false if the removal feature id wasn't newly activated. This causes the builtin to be re-added even if it was previously removed.

@jstarry jstarry deleted the fix-builtin-deactivation branch February 22, 2022 03:22
jeffwashington pushed a commit to jeffwashington/solana that referenced this pull request Mar 4, 2022
* Add failing test for precompile transition

* Skip adding builtins if they will be removed

* cargo clean

* nits

* fix abi check

* remove workaround

Co-authored-by: Jack May <[email protected]>
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.

Starting from snapshot fails when prevent_calling_precompiles_as_programs feature is activated
4 participants