Skip to content

Commit

Permalink
Refactoring: Unify account_deps and accounts (backport #17898) (#18486)
Browse files Browse the repository at this point in the history
* Refactoring: Unify account_deps and accounts (#17898)

* Changes ThisInvokeContext::get_account() to use accounts instead of pre_accounts.

* Adds explicit keys to accounts to make them symmetric to account_deps.

* Appends account_deps to accounts in transaction loading and removes account_deps everywhere else.

(cherry picked from commit 7462c27)

# Conflicts:
#	program-test/src/lib.rs
#	runtime/src/bank.rs
#	runtime/src/message_processor.rs

* fix conflicts

Co-authored-by: Alexander Meißner <[email protected]>
Co-authored-by: Justin Starry <[email protected]>
  • Loading branch information
3 people authored Jul 7, 2021
1 parent d668a76 commit 5321463
Show file tree
Hide file tree
Showing 7 changed files with 289 additions and 308 deletions.
8 changes: 3 additions & 5 deletions program-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ impl solana_sdk::program_stubs::SyscallStubs for SyscallStubs {
'outer: for key in &message.account_keys {
for account_info in account_infos {
if account_info.unsigned_key() == key {
accounts.push(Rc::new(RefCell::new(ai_to_a(account_info))));
accounts.push((*key, Rc::new(RefCell::new(ai_to_a(account_info)))));
continue 'outer;
}
}
Expand Down Expand Up @@ -333,14 +333,12 @@ impl solana_sdk::program_stubs::SyscallStubs for SyscallStubs {
.map_err(|err| ProgramError::try_from(err).unwrap_or_else(|err| panic!("{}", err)))?;

// Copy writeable account modifications back into the caller's AccountInfos
for (i, account_pubkey) in message.account_keys.iter().enumerate() {
for (i, (pubkey, account)) in accounts.iter().enumerate().take(message.account_keys.len()) {
if !message.is_writable(i) {
continue;
}

for account_info in account_infos {
if account_info.unsigned_key() == account_pubkey {
let account = &accounts[i];
if account_info.unsigned_key() == pubkey {
**account_info.try_borrow_mut_lamports().unwrap() = account.borrow().lamports();

let mut data = account_info.try_borrow_mut_data()?;
Expand Down
9 changes: 5 additions & 4 deletions programs/bpf_loader/src/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1343,7 +1343,7 @@ type TranslatedAccount<'a> = (
Option<AccountReferences<'a>>,
);
type TranslatedAccounts<'a> = (
Vec<Rc<RefCell<AccountSharedData>>>,
Vec<(Pubkey, Rc<RefCell<AccountSharedData>>)>,
Vec<Option<AccountReferences<'a>>>,
);

Expand Down Expand Up @@ -1988,7 +1988,7 @@ where

if i == program_account_index || account.borrow().executable() {
// Use the known account
accounts.push(account);
accounts.push((**account_key, account));
refs.push(None);
} else if let Some(account_info) =
account_info_keys
Expand All @@ -2003,7 +2003,7 @@ where
})
{
let (account, account_ref) = do_translate(account_info, invoke_context)?;
accounts.push(account);
accounts.push((**account_key, account));
refs.push(account_ref);
} else {
ic_msg!(
Expand Down Expand Up @@ -2188,6 +2188,7 @@ fn call<'a>(
ic_msg!(invoke_context, "Unknown program {}", callee_program_id,);
SyscallError::InstructionError(InstructionError::MissingAccount)
})?
.1
.clone();
let programdata_executable =
get_upgradeable_executable(&callee_program_id, &program_account, &invoke_context)?;
Expand Down Expand Up @@ -2228,7 +2229,7 @@ fn call<'a>(
// Copy results back to caller
{
let invoke_context = syscall.get_context()?;
for (i, (account, account_ref)) in accounts.iter().zip(account_refs).enumerate() {
for (i, ((_key, account), account_ref)) in accounts.iter().zip(account_refs).enumerate() {
let account = account.borrow();
if let Some(mut account_ref) = account_ref {
if message.is_writable(i) && !account.executable() {
Expand Down
24 changes: 15 additions & 9 deletions rpc/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3095,15 +3095,21 @@ pub mod rpc_full {
accounts.push(if result.is_err() {
None
} else {
transaction
.message
.account_keys
.iter()
.position(|pubkey| *pubkey == address)
.map(|i| post_simulation_accounts.get(i))
.flatten()
.map(|account| {
UiAccount::encode(&address, account, accounts_encoding, None, None)
(0..transaction.message.account_keys.len())
.position(|i| {
post_simulation_accounts
.get(i)
.map(|(key, _account)| *key == address)
.unwrap_or(false)
})
.map(|i| {
UiAccount::encode(
&address,
&post_simulation_accounts[i].1,
accounts_encoding,
None,
None,
)
})
});
}
Expand Down
Loading

0 comments on commit 5321463

Please sign in to comment.