Remove unwrap (#16652)
This commit is contained in:
parent
30c95d38a5
commit
01786f684e
|
@ -118,7 +118,7 @@ impl ExecuteTimings {
|
||||||
}
|
}
|
||||||
|
|
||||||
type BankStatusCache = StatusCache<Result<()>>;
|
type BankStatusCache = StatusCache<Result<()>>;
|
||||||
#[frozen_abi(digest = "3TYCJ7hSJ5ig2NmnwxSn1ggkzm6JCmMHoyRMBQQsLCa3")]
|
#[frozen_abi(digest = "F3Ubz2Sx973pKSYNHTEmj6LY3te1DKUo3fs3cgzQ1uqJ")]
|
||||||
pub type BankSlotDelta = SlotDelta<Result<()>>;
|
pub type BankSlotDelta = SlotDelta<Result<()>>;
|
||||||
type TransactionAccountRefCells = Vec<Rc<RefCell<AccountSharedData>>>;
|
type TransactionAccountRefCells = Vec<Rc<RefCell<AccountSharedData>>>;
|
||||||
type TransactionAccountDepRefCells = Vec<(Pubkey, Rc<RefCell<AccountSharedData>>)>;
|
type TransactionAccountDepRefCells = Vec<(Pubkey, Rc<RefCell<AccountSharedData>>)>;
|
||||||
|
@ -2798,18 +2798,26 @@ impl Bank {
|
||||||
loaders: &mut TransactionLoaders,
|
loaders: &mut TransactionLoaders,
|
||||||
mut account_refcells: TransactionAccountRefCells,
|
mut account_refcells: TransactionAccountRefCells,
|
||||||
loader_refcells: TransactionLoaderRefCells,
|
loader_refcells: TransactionLoaderRefCells,
|
||||||
) {
|
) -> std::result::Result<(), TransactionError> {
|
||||||
account_refcells.drain(..).for_each(|account_refcell| {
|
for account_refcell in account_refcells.drain(..) {
|
||||||
accounts.push(Rc::try_unwrap(account_refcell).unwrap().into_inner())
|
accounts.push(
|
||||||
});
|
Rc::try_unwrap(account_refcell)
|
||||||
loaders
|
.map_err(|_| TransactionError::AccountBorrowOutstanding)?
|
||||||
.iter_mut()
|
.into_inner(),
|
||||||
.zip(loader_refcells)
|
)
|
||||||
.for_each(|(ls, mut lrcs)| {
|
}
|
||||||
lrcs.drain(..).for_each(|(pubkey, lrc)| {
|
for (ls, mut lrcs) in loaders.iter_mut().zip(loader_refcells) {
|
||||||
ls.push((pubkey, Rc::try_unwrap(lrc).unwrap().into_inner()))
|
for (pubkey, lrc) in lrcs.drain(..) {
|
||||||
})
|
ls.push((
|
||||||
});
|
pubkey,
|
||||||
|
Rc::try_unwrap(lrc)
|
||||||
|
.map_err(|_| TransactionError::AccountBorrowOutstanding)?
|
||||||
|
.into_inner(),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compile_recorded_instructions(
|
fn compile_recorded_instructions(
|
||||||
|
@ -2974,7 +2982,7 @@ impl Bank {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
let process_result = self.message_processor.process_message(
|
let mut process_result = self.message_processor.process_message(
|
||||||
tx.message(),
|
tx.message(),
|
||||||
&loader_refcells,
|
&loader_refcells,
|
||||||
&account_refcells,
|
&account_refcells,
|
||||||
|
@ -3005,12 +3013,15 @@ impl Bank {
|
||||||
&tx.message,
|
&tx.message,
|
||||||
);
|
);
|
||||||
|
|
||||||
Self::refcells_to_accounts(
|
if let Err(e) = Self::refcells_to_accounts(
|
||||||
&mut loaded_transaction.accounts,
|
&mut loaded_transaction.accounts,
|
||||||
&mut loaded_transaction.loaders,
|
&mut loaded_transaction.loaders,
|
||||||
account_refcells,
|
account_refcells,
|
||||||
loader_refcells,
|
loader_refcells,
|
||||||
);
|
) {
|
||||||
|
warn!("Account lifetime mismanagement");
|
||||||
|
process_result = Err(e);
|
||||||
|
}
|
||||||
|
|
||||||
if process_result.is_ok() {
|
if process_result.is_ok() {
|
||||||
self.update_executors(executors);
|
self.update_executors(executors);
|
||||||
|
|
|
@ -108,7 +108,7 @@ pub enum InstructionError {
|
||||||
AccountBorrowFailed,
|
AccountBorrowFailed,
|
||||||
|
|
||||||
/// Account data has an outstanding reference after a program's execution
|
/// Account data has an outstanding reference after a program's execution
|
||||||
#[error("instruction left account with an outstanding reference borrowed")]
|
#[error("instruction left account with an outstanding borrowed reference")]
|
||||||
AccountBorrowOutstanding,
|
AccountBorrowOutstanding,
|
||||||
|
|
||||||
/// The same account was multiply passed to an on-chain program's entrypoint, but the program
|
/// The same account was multiply passed to an on-chain program's entrypoint, but the program
|
||||||
|
|
|
@ -94,6 +94,10 @@ pub enum TransactionError {
|
||||||
|
|
||||||
#[error("Transactions are currently disabled due to cluster maintenance")]
|
#[error("Transactions are currently disabled due to cluster maintenance")]
|
||||||
ClusterMaintenance,
|
ClusterMaintenance,
|
||||||
|
|
||||||
|
/// Transaction processing left an account with an outstanding borrowed reference
|
||||||
|
#[error("Transaction processing left an account with an outstanding borrowed reference")]
|
||||||
|
AccountBorrowOutstanding,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type Result<T> = result::Result<T, TransactionError>;
|
pub type Result<T> = result::Result<T, TransactionError>;
|
||||||
|
|
|
@ -66,6 +66,7 @@ pub enum TransactionErrorType {
|
||||||
InvalidProgramForExecution = 13,
|
InvalidProgramForExecution = 13,
|
||||||
SanitizeFailure = 14,
|
SanitizeFailure = 14,
|
||||||
ClusterMaintenance = 15,
|
ClusterMaintenance = 15,
|
||||||
|
AccountBorrowOutstanding = 16,
|
||||||
}
|
}
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
|
||||||
#[repr(i32)]
|
#[repr(i32)]
|
||||||
|
|
|
@ -529,6 +529,7 @@ impl TryFrom<tx_by_addr::TransactionError> for TransactionError {
|
||||||
13 => TransactionError::InvalidProgramForExecution,
|
13 => TransactionError::InvalidProgramForExecution,
|
||||||
14 => TransactionError::SanitizeFailure,
|
14 => TransactionError::SanitizeFailure,
|
||||||
15 => TransactionError::ClusterMaintenance,
|
15 => TransactionError::ClusterMaintenance,
|
||||||
|
16 => TransactionError::AccountBorrowOutstanding,
|
||||||
_ => return Err("Invalid TransactionError"),
|
_ => return Err("Invalid TransactionError"),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -584,6 +585,9 @@ impl From<TransactionError> for tx_by_addr::TransactionError {
|
||||||
TransactionError::InstructionError(_, _) => {
|
TransactionError::InstructionError(_, _) => {
|
||||||
tx_by_addr::TransactionErrorType::InstructionError
|
tx_by_addr::TransactionErrorType::InstructionError
|
||||||
}
|
}
|
||||||
|
TransactionError::AccountBorrowOutstanding => {
|
||||||
|
tx_by_addr::TransactionErrorType::AccountBorrowOutstanding
|
||||||
|
}
|
||||||
} as i32,
|
} as i32,
|
||||||
instruction_error: match transaction_error {
|
instruction_error: match transaction_error {
|
||||||
TransactionError::InstructionError(index, ref instruction_error) => {
|
TransactionError::InstructionError(index, ref instruction_error) => {
|
||||||
|
|
Loading…
Reference in New Issue