Skip to content

Commit

Permalink
Makes undeployment visible immediately.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lichtso committed Feb 10, 2023
1 parent cbe0cb2 commit 9a469fe
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
6 changes: 5 additions & 1 deletion program-runtime/src/executor_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ impl TransactionExecutorCache {
self.visible.get(key).cloned()
}

pub fn set_tombstone(&mut self, key: Pubkey) {
self.visible.insert(key, None);
}

pub fn set(
&mut self,
key: Pubkey,
Expand All @@ -54,7 +58,7 @@ impl TransactionExecutorCache {
if delay_visibility_of_program_deployment {
// Place a tombstone 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);
self.set_tombstone(key);
} else {
self.visible.insert(key, Some(executor.clone()));
}
Expand Down
9 changes: 9 additions & 0 deletions programs/bpf_loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1166,6 +1166,15 @@ fn process_loader_upgradeable_instruction(
instruction_context,
&log_collector,
)?;
if invoke_context
.feature_set
.is_active(&delay_visibility_of_program_deployment::id())
{
invoke_context
.tx_executor_cache
.borrow_mut()
.set_tombstone(program_key);
}
}
_ => {
ic_logger_msg!(log_collector, "Invalid Program account");
Expand Down
10 changes: 3 additions & 7 deletions programs/sbf/tests/programs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2031,7 +2031,7 @@ fn test_program_sbf_invoke_in_same_tx_as_undeployment() {
Some(&program_id),
);

// Undeployment is invisible to both top-level-instructions and CPI instructions
// Undeployment is visible to both top-level-instructions and CPI instructions
for invoke_instruction in [invoke_instruction, indirect_invoke_instruction] {
// Call upgradeable program
let result =
Expand All @@ -2040,11 +2040,7 @@ fn test_program_sbf_invoke_in_same_tx_as_undeployment() {

// Upgrade the program and invoke in same tx
let message = Message::new(
&[
undeployment_instruction.clone(),
invoke_instruction,
panic_instruction.clone(), // Make sure the TX fails, so we don't have to deploy another program
],
&[undeployment_instruction.clone(), invoke_instruction],
Some(&mint_keypair.pubkey()),
);
let tx = Transaction::new(
Expand All @@ -2055,7 +2051,7 @@ fn test_program_sbf_invoke_in_same_tx_as_undeployment() {
let (result, _, _) = process_transaction_and_record_inner(&bank, tx);
assert_eq!(
result.unwrap_err(),
TransactionError::InstructionError(2, InstructionError::ProgramFailedToComplete),
TransactionError::InstructionError(1, InstructionError::InvalidAccountData),
);
}
}
Expand Down

0 comments on commit 9a469fe

Please sign in to comment.