Skip to content

Commit

Permalink
Load previous version before deploying the new one.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lichtso committed Feb 3, 2023
1 parent a02558b commit cfccefc
Showing 1 changed file with 57 additions and 6 deletions.
63 changes: 57 additions & 6 deletions programs/bpf_loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,37 @@ pub fn create_executor_from_account(

macro_rules! deploy_program {
($invoke_context:expr, $use_jit:expr, $program_id:expr,
$buffer_account:expr, $new_programdata:expr $(,)?) => {{
$program_account:expr, $programdata_account:expr, $new_programdata:expr,
$first_drop:expr, $second_drop:expr $(,)?) => {{
let delay_visibility_of_program_deployment = $invoke_context
.feature_set
.is_active(&delay_visibility_of_program_deployment::id());

if delay_visibility_of_program_deployment {
// Make sure the old version is in the cache so that we don't
// load the new version from the database while the old one is still active
let mut get_or_create_executor_time = Measure::start("get_or_create_executor_time");
let result = create_executor_from_account(
&$invoke_context.feature_set,
$invoke_context.get_compute_budget(),
$invoke_context.get_log_collector(),
Some($invoke_context.tx_executor_cache.borrow_mut()),
&$program_account,
&$programdata_account,
$use_jit,
);
$first_drop
get_or_create_executor_time.stop();
saturating_add_assign!(
$invoke_context.timings.get_or_create_executor_us,
get_or_create_executor_time.as_us()
);
if let Ok((_executor, Some(create_executor_metrics))) = result {
create_executor_metrics.submit_datapoint(&mut $invoke_context.timings);
}
}

// Create the new version which will be deployed later
let mut create_executor_metrics = CreateMetrics::default();
let executor = create_executor_from_bytes(
&$invoke_context.feature_set,
Expand All @@ -276,7 +303,7 @@ macro_rules! deploy_program {
$use_jit,
true,
)?;
drop($buffer_account);
$second_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(
Expand Down Expand Up @@ -673,17 +700,29 @@ fn process_loader_upgradeable_instruction(
// Load and verify the program bits
let transaction_context = &invoke_context.transaction_context;
let instruction_context = transaction_context.get_current_instruction_context()?;
let programdata =
instruction_context.try_borrow_instruction_account(transaction_context, 1)?;
let program =
instruction_context.try_borrow_instruction_account(transaction_context, 2)?;
let buffer =
instruction_context.try_borrow_instruction_account(transaction_context, 3)?;
deploy_program!(
invoke_context,
use_jit,
new_program_id,
buffer,
program,
programdata,
buffer
.get_data()
.get(buffer_data_offset..)
.ok_or(InstructionError::AccountDataTooSmall)?,
{
drop(program);
drop(programdata);
},
{
drop(buffer);
},
);

let transaction_context = &invoke_context.transaction_context;
Expand Down Expand Up @@ -853,20 +892,29 @@ fn process_loader_upgradeable_instruction(
ic_logger_msg!(log_collector, "Invalid ProgramData account");
return Err(InstructionError::InvalidAccountData);
}
drop(programdata);

// Load and verify the program bits
let program =
instruction_context.try_borrow_instruction_account(transaction_context, 1)?;
let buffer =
instruction_context.try_borrow_instruction_account(transaction_context, 2)?;
deploy_program!(
invoke_context,
use_jit,
new_program_id,
buffer,
program,
programdata,
buffer
.get_data()
.get(buffer_data_offset..)
.ok_or(InstructionError::AccountDataTooSmall)?,
{
drop(program);
drop(programdata);
},
{
drop(buffer);
},
);

let transaction_context = &invoke_context.transaction_context;
Expand Down Expand Up @@ -1375,8 +1423,11 @@ fn process_loader_instruction(
invoke_context,
use_jit,
*program.get_key(),
(),
program,
program,
program.get_data(),
{},
{},
);
program.set_executable(true)?;
ic_msg!(invoke_context, "Finalized account {:?}", program.get_key());
Expand Down

0 comments on commit cfccefc

Please sign in to comment.