Refactor: Removes Rc
from Refcell<AccountSharedData>
in the program-runtime (#21927)
* Removes Rc from Rc<RefCell<AccountSharedData>> in the program-runtime. * Adjusts tests in bpf_loader, system_instruction_processor, config_processor, vote_instruction and stake_instruction
This commit is contained in:
committed by
GitHub
parent
56ec5245cc
commit
66fa8f9667
@ -3403,11 +3403,10 @@ impl Bank {
|
||||
/// Converts Accounts into RefCell<AccountSharedData>, this involves moving
|
||||
/// ownership by draining the source
|
||||
fn accounts_to_refcells(accounts: &mut TransactionAccounts) -> TransactionAccountRefCells {
|
||||
let account_refcells: Vec<_> = accounts
|
||||
accounts
|
||||
.drain(..)
|
||||
.map(|(pubkey, account)| (pubkey, Rc::new(RefCell::new(account))))
|
||||
.collect();
|
||||
account_refcells
|
||||
.map(|(pubkey, account)| (pubkey, RefCell::new(account)))
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Converts back from RefCell<AccountSharedData> to AccountSharedData, this involves moving
|
||||
@ -3415,17 +3414,10 @@ impl Bank {
|
||||
fn refcells_to_accounts(
|
||||
accounts: &mut TransactionAccounts,
|
||||
mut account_refcells: TransactionAccountRefCells,
|
||||
) -> std::result::Result<(), TransactionError> {
|
||||
) {
|
||||
for (pubkey, account_refcell) in account_refcells.drain(..) {
|
||||
accounts.push((
|
||||
pubkey,
|
||||
Rc::try_unwrap(account_refcell)
|
||||
.map_err(|_| TransactionError::AccountBorrowOutstanding)?
|
||||
.into_inner(),
|
||||
))
|
||||
accounts.push((pubkey, account_refcell.into_inner()))
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Get any cached executors needed by the transaction
|
||||
@ -3641,13 +3633,10 @@ impl Bank {
|
||||
});
|
||||
inner_instructions.push(inner_instruction_list);
|
||||
|
||||
if let Err(e) = Self::refcells_to_accounts(
|
||||
Self::refcells_to_accounts(
|
||||
&mut loaded_transaction.accounts,
|
||||
account_refcells,
|
||||
) {
|
||||
warn!("Account lifetime mismanagement");
|
||||
process_result = Err(e);
|
||||
}
|
||||
);
|
||||
|
||||
if process_result.is_ok() {
|
||||
self.update_executors(executors);
|
||||
|
@ -202,19 +202,19 @@ mod tests {
|
||||
process_instruction: mock_system_process_instruction,
|
||||
}];
|
||||
|
||||
let program_account = Rc::new(RefCell::new(create_loadable_account_for_test(
|
||||
"mock_system_program",
|
||||
)));
|
||||
let accounts = vec![
|
||||
(
|
||||
solana_sdk::pubkey::new_rand(),
|
||||
AccountSharedData::new_ref(100, 1, &mock_system_program_id),
|
||||
RefCell::new(AccountSharedData::new(100, 1, &mock_system_program_id)),
|
||||
),
|
||||
(
|
||||
solana_sdk::pubkey::new_rand(),
|
||||
AccountSharedData::new_ref(0, 1, &mock_system_program_id),
|
||||
RefCell::new(AccountSharedData::new(0, 1, &mock_system_program_id)),
|
||||
),
|
||||
(
|
||||
mock_system_program_id,
|
||||
RefCell::new(create_loadable_account_for_test("mock_system_program")),
|
||||
),
|
||||
(mock_system_program_id, program_account),
|
||||
];
|
||||
let program_indices = vec![vec![2]];
|
||||
|
||||
@ -406,19 +406,19 @@ mod tests {
|
||||
process_instruction: mock_system_process_instruction,
|
||||
}];
|
||||
|
||||
let program_account = Rc::new(RefCell::new(create_loadable_account_for_test(
|
||||
"mock_system_program",
|
||||
)));
|
||||
let accounts = vec![
|
||||
(
|
||||
solana_sdk::pubkey::new_rand(),
|
||||
AccountSharedData::new_ref(100, 1, &mock_program_id),
|
||||
RefCell::new(AccountSharedData::new(100, 1, &mock_program_id)),
|
||||
),
|
||||
(
|
||||
solana_sdk::pubkey::new_rand(),
|
||||
AccountSharedData::new_ref(0, 1, &mock_program_id),
|
||||
RefCell::new(AccountSharedData::new(0, 1, &mock_program_id)),
|
||||
),
|
||||
(
|
||||
mock_program_id,
|
||||
RefCell::new(create_loadable_account_for_test("mock_system_program")),
|
||||
),
|
||||
(mock_program_id, program_account),
|
||||
];
|
||||
let program_indices = vec![vec![2]];
|
||||
|
||||
@ -539,13 +539,13 @@ mod tests {
|
||||
process_instruction: mock_process_instruction,
|
||||
}];
|
||||
|
||||
let secp256k1_account = AccountSharedData::new_ref(1, 0, &native_loader::id());
|
||||
secp256k1_account.borrow_mut().set_executable(true);
|
||||
let mock_program_account = AccountSharedData::new_ref(1, 0, &native_loader::id());
|
||||
mock_program_account.borrow_mut().set_executable(true);
|
||||
let mut secp256k1_account = AccountSharedData::new(1, 0, &native_loader::id());
|
||||
secp256k1_account.set_executable(true);
|
||||
let mut mock_program_account = AccountSharedData::new(1, 0, &native_loader::id());
|
||||
mock_program_account.set_executable(true);
|
||||
let accounts = vec![
|
||||
(secp256k1_program::id(), secp256k1_account),
|
||||
(mock_program_id, mock_program_account),
|
||||
(secp256k1_program::id(), RefCell::new(secp256k1_account)),
|
||||
(mock_program_id, RefCell::new(mock_program_account)),
|
||||
];
|
||||
|
||||
let message = Message::new(
|
||||
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user