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.
This commit is contained in:
Alexander Meißner
2021-07-05 13:49:37 +02:00
committed by GitHub
parent ffb1f3932a
commit 7462c27d07
7 changed files with 289 additions and 308 deletions

View File

@ -290,7 +290,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;
}
}
@ -336,14 +336,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, true) {
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()?;