implement From trait for CostTrackerError to TransactionError (#30267)
implement From trait for CostTrackerError to TransactionError
This commit is contained in:
parent
bcd7cf0821
commit
60bfc2524b
|
@ -10,7 +10,6 @@ use {
|
|||
solana_runtime::{
|
||||
bank::Bank,
|
||||
cost_model::{CostModel, TransactionCost},
|
||||
cost_tracker::CostTrackerError,
|
||||
},
|
||||
solana_sdk::{
|
||||
clock::Slot,
|
||||
|
@ -166,23 +165,7 @@ impl QosService {
|
|||
},
|
||||
Err(e) => {
|
||||
debug!("slot {:?}, transaction {:?}, cost {:?}, not fit into current block, '{:?}'", bank.slot(), tx, cost, e);
|
||||
match e {
|
||||
CostTrackerError::WouldExceedBlockMaxLimit => {
|
||||
Err(TransactionError::WouldExceedMaxBlockCostLimit)
|
||||
}
|
||||
CostTrackerError::WouldExceedVoteMaxLimit => {
|
||||
Err(TransactionError::WouldExceedMaxVoteCostLimit)
|
||||
}
|
||||
CostTrackerError::WouldExceedAccountMaxLimit => {
|
||||
Err(TransactionError::WouldExceedMaxAccountCostLimit)
|
||||
}
|
||||
CostTrackerError::WouldExceedAccountDataBlockLimit => {
|
||||
Err(TransactionError::WouldExceedAccountDataBlockLimit)
|
||||
}
|
||||
CostTrackerError::WouldExceedAccountDataTotalLimit => {
|
||||
Err(TransactionError::WouldExceedAccountDataTotalLimit)
|
||||
}
|
||||
}
|
||||
Err(TransactionError::from(e))
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
|
|
@ -5,7 +5,9 @@
|
|||
//!
|
||||
use {
|
||||
crate::{block_cost_limits::*, cost_model::TransactionCost},
|
||||
solana_sdk::{clock::Slot, pubkey::Pubkey, saturating_add_assign},
|
||||
solana_sdk::{
|
||||
clock::Slot, pubkey::Pubkey, saturating_add_assign, transaction::TransactionError,
|
||||
},
|
||||
std::{cmp::Ordering, collections::HashMap},
|
||||
};
|
||||
|
||||
|
@ -29,6 +31,22 @@ pub enum CostTrackerError {
|
|||
WouldExceedAccountDataTotalLimit,
|
||||
}
|
||||
|
||||
impl From<CostTrackerError> for TransactionError {
|
||||
fn from(err: CostTrackerError) -> Self {
|
||||
match err {
|
||||
CostTrackerError::WouldExceedBlockMaxLimit => Self::WouldExceedMaxBlockCostLimit,
|
||||
CostTrackerError::WouldExceedVoteMaxLimit => Self::WouldExceedMaxVoteCostLimit,
|
||||
CostTrackerError::WouldExceedAccountMaxLimit => Self::WouldExceedMaxAccountCostLimit,
|
||||
CostTrackerError::WouldExceedAccountDataBlockLimit => {
|
||||
Self::WouldExceedAccountDataBlockLimit
|
||||
}
|
||||
CostTrackerError::WouldExceedAccountDataTotalLimit => {
|
||||
Self::WouldExceedAccountDataTotalLimit
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(AbiExample, Debug)]
|
||||
pub struct CostTracker {
|
||||
account_cost_limit: u64,
|
||||
|
|
Loading…
Reference in New Issue