Skip to content

Commit

Permalink
Adds a feature gate.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lichtso committed Feb 9, 2023
1 parent d2dddf6 commit 45bb601
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 16 deletions.
16 changes: 14 additions & 2 deletions program-runtime/src/executor_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,21 @@ impl TransactionExecutorCache {
self.visible.get(key).cloned()
}

pub fn set(&mut self, key: Pubkey, executor: Arc<dyn Executor>, upgrade: bool) {
pub fn set(
&mut self,
key: Pubkey,
executor: Arc<dyn Executor>,
upgrade: bool,
delay_visibility_of_program_deployment: bool,
) {
if upgrade {
self.visible.insert(key, Some(executor.clone()));
if delay_visibility_of_program_deployment {
// Place a tomb stone in the cache so that
// we don't load the new version from the database as it should remain invisible
self.visible.insert(key, None);
} else {
self.visible.insert(key, Some(executor.clone()));
}
self.deployments.insert(key, executor);
} else {
self.visible.insert(key, Some(executor.clone()));
Expand Down
28 changes: 20 additions & 8 deletions programs/bpf_loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ use {
entrypoint::{HEAP_LENGTH, SUCCESS},
feature_set::{
cap_accounts_data_allocations_per_transaction, cap_bpf_program_instruction_accounts,
check_slice_translation_size, disable_deploy_of_alloc_free_syscall,
enable_bpf_loader_extend_program_ix, enable_bpf_loader_set_authority_checked_ix,
enable_program_redeployment_cooldown, limit_max_instruction_trace_length, FeatureSet,
check_slice_translation_size, delay_visibility_of_program_deployment,
disable_deploy_of_alloc_free_syscall, enable_bpf_loader_extend_program_ix,
enable_bpf_loader_set_authority_checked_ix, enable_program_redeployment_cooldown,
limit_max_instruction_trace_length, FeatureSet,
},
instruction::{AccountMeta, InstructionError},
loader_instruction::LoaderInstruction,
Expand Down Expand Up @@ -232,6 +233,7 @@ pub fn create_executor_from_account(
// Executor exists and is cached, use it
Some(Some(executor)) => return Ok((executor, None)),
// We cached that the Executor does not exist, abort
// This case can only happen once delay_visibility_of_program_deployment is active.
Some(None) => return Err(InstructionError::InvalidAccountData),
// Nothing cached, try to load from account instead
None => {}
Expand All @@ -255,14 +257,22 @@ pub fn create_executor_from_account(
false, /* reject_deployment_of_broken_elfs */
)?;
if let Some(mut tx_executor_cache) = tx_executor_cache {
tx_executor_cache.set(*program.get_key(), executor.clone(), false);
tx_executor_cache.set(
*program.get_key(),
executor.clone(),
false,
feature_set.is_active(&delay_visibility_of_program_deployment::id()),
);
}
Ok((executor, Some(create_executor_metrics)))
}

macro_rules! deploy_program {
($invoke_context:expr, $use_jit:expr, $program_id:expr,
$drop:expr, $new_programdata:expr $(,)?) => {{
let delay_visibility_of_program_deployment = $invoke_context
.feature_set
.is_active(&delay_visibility_of_program_deployment::id());
let mut create_executor_metrics = CreateMetrics::default();
let executor = create_executor_from_bytes(
&$invoke_context.feature_set,
Expand All @@ -276,10 +286,12 @@ macro_rules! deploy_program {
$drop
create_executor_metrics.program_id = $program_id.to_string();
create_executor_metrics.submit_datapoint(&mut $invoke_context.timings);
$invoke_context
.tx_executor_cache
.borrow_mut()
.set($program_id, executor, true);
$invoke_context.tx_executor_cache.borrow_mut().set(
$program_id,
executor,
true,
delay_visibility_of_program_deployment,
);
}};
}

Expand Down
12 changes: 6 additions & 6 deletions runtime/src/bank/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7716,10 +7716,10 @@ fn test_bank_executor_cache() {
// do work
let mut executors =
TransactionExecutorCache::new((2..3).map(|i| (accounts[i].0, executor.clone())));
executors.set(key1, executor.clone(), false);
executors.set(key2, executor.clone(), false);
executors.set(key3, executor.clone(), true);
executors.set(key4, executor.clone(), false);
executors.set(key1, executor.clone(), false, true);
executors.set(key2, executor.clone(), false, true);
executors.set(key3, executor.clone(), true, true);
executors.set(key4, executor.clone(), false, true);
let executors = Rc::new(RefCell::new(executors));

// store Missing
Expand Down Expand Up @@ -7810,7 +7810,7 @@ fn test_bank_executor_cow() {

// add one to root bank
let mut executors = TransactionExecutorCache::default();
executors.set(key1, executor.clone(), false);
executors.set(key1, executor.clone(), false, true);
let executors = Rc::new(RefCell::new(executors));
root.store_executors_which_added_to_the_cache(&executors);
let executors = root.get_tx_executor_cache(accounts);
Expand All @@ -7825,7 +7825,7 @@ fn test_bank_executor_cow() {
assert_eq!(executors.borrow().visible.len(), 1);

let mut executors = TransactionExecutorCache::default();
executors.set(key2, executor.clone(), false);
executors.set(key2, executor.clone(), false, true);
let executors = Rc::new(RefCell::new(executors));
fork1.store_executors_which_added_to_the_cache(&executors);

Expand Down
5 changes: 5 additions & 0 deletions sdk/src/feature_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,10 @@ pub mod prevent_rent_paying_rent_recipients {
solana_sdk::declare_id!("Fab5oP3DmsLYCiQZXdjyqT3ukFFPrsmqhXU4WU1AWVVF");
}

pub mod delay_visibility_of_program_deployment {
solana_sdk::declare_id!("GmuBvtFb2aHfSfMXpuFeWZGHyDeCLPS79s48fmCWCfM5");
}

lazy_static! {
/// Map of feature identifiers to user-visible description
pub static ref FEATURE_NAMES: HashMap<Pubkey, &'static str> = [
Expand Down Expand Up @@ -757,6 +761,7 @@ lazy_static! {
(remove_congestion_multiplier_from_fee_calculation::id(), "Remove congestion multiplier from transaction fee calculation #29881"),
(enable_request_heap_frame_ix::id(), "Enable transaction to request heap frame using compute budget instruction #30076"),
(prevent_rent_paying_rent_recipients::id(), "prevent recipients of rent rewards from ending in rent-paying state #30???"),
(delay_visibility_of_program_deployment::id(), "delay visibility of program upgrades #30085"),
/*************** ADD NEW FEATURES HERE ***************/
]
.iter()
Expand Down

0 comments on commit 45bb601

Please sign in to comment.