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

followup safety checks for #23295 (backport #23321) #23340

Merged
merged 1 commit into from
Feb 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 25 additions & 15 deletions runtime/src/builtins.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#[cfg(RUSTC_WITH_SPECIALIZATION)]
use solana_frozen_abi::abi_example::AbiExample;
#[cfg(debug_assertions)]
#[allow(deprecated)]
use solana_sdk::AutoTraitBreakSendSync;
use {
crate::system_instruction_processor,
solana_program_runtime::{
Expand Down Expand Up @@ -104,7 +107,7 @@ pub enum BuiltinAction {
/// State transition enum used for adding and removing builtin programs through
/// feature activations.
#[derive(Debug, Clone, AbiExample)]
pub enum BuiltinFeatureTransition {
enum InnerBuiltinFeatureTransition {
/// Add a builtin program if a feature is activated.
Add {
builtin: Builtin,
Expand All @@ -119,6 +122,13 @@ pub enum BuiltinFeatureTransition {
},
}

#[allow(deprecated)]
#[cfg(debug_assertions)]
impl AutoTraitBreakSendSync for InnerBuiltinFeatureTransition {}

#[derive(AbiExample, Clone, Debug)]
pub struct BuiltinFeatureTransition(InnerBuiltinFeatureTransition);

// https://github.com/solana-labs/solana/pull/23233 added `BuiltinFeatureTransition`
// to `Bank` which triggers https://github.com/rust-lang/rust/issues/92987 while
// attempting to resolve `Sync` on `BankRc` in `AccountsBackgroundService::new` ala,
Expand All @@ -142,21 +152,21 @@ impl BuiltinFeatureTransition {
&self,
should_apply_action_for_feature: &impl Fn(&Pubkey) -> bool,
) -> Option<BuiltinAction> {
match self {
Self::Add {
match &self.0 {
InnerBuiltinFeatureTransition::Add {
builtin,
feature_id,
ref feature_id,
} => {
if should_apply_action_for_feature(feature_id) {
Some(BuiltinAction::Add(builtin.clone()))
} else {
None
}
}
Self::RemoveOrRetain {
InnerBuiltinFeatureTransition::RemoveOrRetain {
previously_added_builtin,
addition_feature_id,
removal_feature_id,
ref addition_feature_id,
ref removal_feature_id,
} => {
if should_apply_action_for_feature(removal_feature_id) {
Some(BuiltinAction::Remove(previously_added_builtin.id))
Expand Down Expand Up @@ -209,40 +219,40 @@ fn dummy_process_instruction(
/// Dynamic feature transitions for builtin programs
fn builtin_feature_transitions() -> Vec<BuiltinFeatureTransition> {
vec![
BuiltinFeatureTransition::Add {
BuiltinFeatureTransition(InnerBuiltinFeatureTransition::Add {
builtin: Builtin::new(
"compute_budget_program",
solana_sdk::compute_budget::id(),
solana_compute_budget_program::process_instruction,
),
feature_id: feature_set::add_compute_budget_program::id(),
},
BuiltinFeatureTransition::RemoveOrRetain {
}),
BuiltinFeatureTransition(InnerBuiltinFeatureTransition::RemoveOrRetain {
previously_added_builtin: Builtin::new(
"secp256k1_program",
solana_sdk::secp256k1_program::id(),
dummy_process_instruction,
),
addition_feature_id: feature_set::secp256k1_program_enabled::id(),
removal_feature_id: feature_set::prevent_calling_precompiles_as_programs::id(),
},
BuiltinFeatureTransition::RemoveOrRetain {
}),
BuiltinFeatureTransition(InnerBuiltinFeatureTransition::RemoveOrRetain {
previously_added_builtin: Builtin::new(
"ed25519_program",
solana_sdk::ed25519_program::id(),
dummy_process_instruction,
),
addition_feature_id: feature_set::ed25519_program_enabled::id(),
removal_feature_id: feature_set::prevent_calling_precompiles_as_programs::id(),
},
BuiltinFeatureTransition::Add {
}),
BuiltinFeatureTransition(InnerBuiltinFeatureTransition::Add {
builtin: Builtin::new(
"address_lookup_table_program",
solana_address_lookup_table_program::id(),
solana_address_lookup_table_program::processor::process_instruction,
),
feature_id: feature_set::versioned_tx_message_enabled::id(),
},
}),
]
}

Expand Down
8 changes: 8 additions & 0 deletions sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ pub use solana_sdk_macro::pubkeys;
#[rustversion::since(1.46.0)]
pub use solana_sdk_macro::respan;

#[deprecated(
since = "1.9.0",
note = "use only to break https://github.com/rust-lang/rust/issues/92987. remove when we move to Rust 1.60.0"
)]
#[doc(hidden)]
#[cfg(debug_assertions)]
pub trait AutoTraitBreakSendSync: Send + Sync {}

// Unused `solana_sdk::program_stubs!()` macro retained for source backwards compatibility with older programs
#[macro_export]
#[deprecated(
Expand Down