-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Stop loading program accounts if program exists in cache #30703
Changes from all commits
7e02074
744f126
d043eb7
e54f706
84b2873
6626a9c
a46c1f5
01efbc3
bf12204
179b103
17daeb9
7df97de
b367a5a
208c1d8
5d722cf
f552413
b4c11e4
8066628
6054727
df0bd1d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -135,7 +135,7 @@ pub fn load_program_from_bytes( | |
Ok(loaded_program) | ||
} | ||
|
||
fn get_programdata_offset_and_depoyment_offset( | ||
fn get_programdata_offset_and_deployment_offset( | ||
log_collector: &Option<Rc<RefCell<LogCollector>>>, | ||
program: &BorrowedAccount, | ||
programdata: &BorrowedAccount, | ||
|
@@ -181,21 +181,20 @@ pub fn load_program_from_account( | |
return Err(InstructionError::IncorrectProgramId); | ||
} | ||
|
||
let (programdata_offset, deployment_slot) = | ||
get_programdata_offset_and_depoyment_offset(&log_collector, program, programdata)?; | ||
|
||
if let Some(ref tx_executor_cache) = tx_executor_cache { | ||
if let Some(loaded_program) = tx_executor_cache.get(program.get_key()) { | ||
if loaded_program.is_tombstone() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can have tombstone in the TX batch cache now, even if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, in case the program fails to compile/verify. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was referring to the comment below which is incorrect now. |
||
// We cached that the Executor does not exist, abort | ||
// This case can only happen once delay_visibility_of_program_deployment is active. | ||
return Err(InstructionError::InvalidAccountData); | ||
} | ||
// Executor exists and is cached, use it | ||
return Ok((loaded_program, None)); | ||
} | ||
} | ||
|
||
let (programdata_offset, deployment_slot) = | ||
get_programdata_offset_and_deployment_offset(&log_collector, program, programdata)?; | ||
|
||
let programdata_size = if programdata_offset != 0 { | ||
programdata.get_data().len() | ||
} else { | ||
|
@@ -556,14 +555,16 @@ fn process_instruction_common( | |
ic_logger_msg!(log_collector, "Program is not executable"); | ||
return Err(InstructionError::IncorrectProgramId); | ||
} | ||
|
||
let programdata_account = if bpf_loader_upgradeable::check_id(program_account.get_owner()) { | ||
let programdata_account = instruction_context.try_borrow_program_account( | ||
transaction_context, | ||
instruction_context | ||
.get_number_of_program_accounts() | ||
.saturating_sub(2), | ||
)?; | ||
Some(programdata_account) | ||
instruction_context | ||
.try_borrow_program_account( | ||
transaction_context, | ||
instruction_context | ||
.get_number_of_program_accounts() | ||
.saturating_sub(2), | ||
) | ||
.ok() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As this is only an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Would you prefer if the code deletion/refactor was done in this PR itself. It was causing some changes to tests in other parts of the code which are unrelated to this PR. |
||
} else { | ||
None | ||
}; | ||
|
@@ -591,7 +592,9 @@ fn process_instruction_common( | |
|
||
executor.usage_counter.fetch_add(1, Ordering::Relaxed); | ||
match &executor.program { | ||
LoadedProgramType::Invalid => Err(InstructionError::InvalidAccountData), | ||
LoadedProgramType::FailedVerification | ||
| LoadedProgramType::Closed | ||
| LoadedProgramType::DelayVisibility => Err(InstructionError::InvalidAccountData), | ||
LoadedProgramType::LegacyV0(executable) => execute(executable, invoke_context), | ||
LoadedProgramType::LegacyV1(executable) => execute(executable, invoke_context), | ||
_ => Err(InstructionError::IncorrectProgramId), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this code movement necessary?
Bit concerned about error priorities here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, since we don't load the actual program account, the
get_programdata_offset_and_depoyment_offset
returns an error, sincestate()
is not valid.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking through the code,
get_programdata_offset_and_depoyment_offset()
returnsInvalidAccountData
in all error scenarios. So, moving the code after cache lookup should not change the error codes (as the cache lookup failure returns the same error code).