Skip to content

Commit dae3892

Browse files
author
HaoranYi
committed
reorder load_account and program_cache replenish
1 parent f43cfc8 commit dae3892

File tree

9 files changed

+878
-414
lines changed

9 files changed

+878
-414
lines changed

runtime/src/bank.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6885,6 +6885,17 @@ impl TransactionProcessingCallback for Bank {
68856885
.ok()
68866886
}
68876887

6888+
fn load_account_with(
6889+
&self,
6890+
pubkey: &Pubkey,
6891+
callback: impl for<'a> Fn(&'a AccountSharedData) -> bool,
6892+
) -> Option<(AccountSharedData, Slot)> {
6893+
self.rc
6894+
.accounts
6895+
.accounts_db
6896+
.load_account_with(&self.ancestors, pubkey, callback)
6897+
}
6898+
68886899
fn get_account_shared_data(&self, pubkey: &Pubkey) -> Option<AccountSharedData> {
68896900
self.rc
68906901
.accounts

runtime/src/bank/builtins/core_bpf_migration/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ impl Bank {
249249
let source = SourceBuffer::new_checked(self, &config.source_buffer_address)?;
250250

251251
// Attempt serialization first before modifying the bank.
252-
let new_target_program_account = self.new_target_program_account(&target)?;
252+
let mut new_target_program_account = self.new_target_program_account(&target)?;
253253
let new_target_program_data_account =
254254
self.new_target_program_data_account(&source, config.upgrade_authority_address)?;
255255

@@ -275,6 +275,12 @@ impl Bank {
275275
new_target_program_data_account.data(),
276276
)?;
277277

278+
// After successfully deployed the `Builtin` program, we need to mark
279+
// the builtin program account as executable. This is required for
280+
// transaction account loading, when "fake program account" optimization
281+
// is disabled.
282+
new_target_program_account.set_executable(true);
283+
278284
// Calculate the lamports to burn.
279285
// The target program account will be replaced, so burn its lamports.
280286
// The source buffer account will be cleared, so burn its lamports.

runtime/src/bank/tests.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7212,12 +7212,10 @@ fn test_bpf_loader_upgradeable_deploy_with_max_len() {
72127212
invocation_message.clone(),
72137213
bank.last_blockhash(),
72147214
);
7215+
// See comments below for Test buffer invocation.
72157216
assert_eq!(
72167217
bank.process_transaction(&transaction),
7217-
Err(TransactionError::InstructionError(
7218-
0,
7219-
InstructionError::InvalidAccountData
7220-
)),
7218+
Err(TransactionError::InvalidProgramForExecution),
72217219
);
72227220
{
72237221
let program_cache = bank.transaction_processor.program_cache.read().unwrap();
@@ -7236,12 +7234,14 @@ fn test_bpf_loader_upgradeable_deploy_with_max_len() {
72367234
let instruction = Instruction::new_with_bytes(buffer_address, &[], Vec::new());
72377235
let message = Message::new(&[instruction], Some(&mint_keypair.pubkey()));
72387236
let transaction = Transaction::new(&[&binding], message, bank.last_blockhash());
7237+
// This is a slightly change of behavior for this PR. In the old code, we
7238+
// short-circuit buffer account to fake it and mark it executable. So it
7239+
// passed program execution check but failed with `Err(InstructionError(0, InvalidAccountData))`.
7240+
// With this PR, we don't do that. The buffer account will NOT be executable. A different error is throw `Err(InvalidProgramForExecution)`.
7241+
// This will NOT break consensus fortunately! Changing to `Err(InvalidProgramForExecution)` won't affect bank hash!
72397242
assert_eq!(
72407243
bank.process_transaction(&transaction),
7241-
Err(TransactionError::InstructionError(
7242-
0,
7243-
InstructionError::InvalidAccountData,
7244-
)),
7244+
Err(TransactionError::InvalidProgramForExecution),
72457245
);
72467246
{
72477247
let program_cache = bank.transaction_processor.program_cache.read().unwrap();

0 commit comments

Comments
 (0)