implement From trait for CostTrackerError to TransactionError (#30267)

implement From trait for CostTrackerError to TransactionError
This commit is contained in:
Tao Zhu 2023-02-13 11:06:39 -06:00 committed by GitHub
parent bcd7cf0821
commit 60bfc2524b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 19 deletions

View File

@ -10,7 +10,6 @@ use {
solana_runtime::{ solana_runtime::{
bank::Bank, bank::Bank,
cost_model::{CostModel, TransactionCost}, cost_model::{CostModel, TransactionCost},
cost_tracker::CostTrackerError,
}, },
solana_sdk::{ solana_sdk::{
clock::Slot, clock::Slot,
@ -166,23 +165,7 @@ impl QosService {
}, },
Err(e) => { Err(e) => {
debug!("slot {:?}, transaction {:?}, cost {:?}, not fit into current block, '{:?}'", bank.slot(), tx, cost, e); debug!("slot {:?}, transaction {:?}, cost {:?}, not fit into current block, '{:?}'", bank.slot(), tx, cost, e);
match e { Err(TransactionError::from(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)
}
}
} }
}) })
.collect(); .collect();

View File

@ -5,7 +5,9 @@
//! //!
use { use {
crate::{block_cost_limits::*, cost_model::TransactionCost}, 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}, std::{cmp::Ordering, collections::HashMap},
}; };
@ -29,6 +31,22 @@ pub enum CostTrackerError {
WouldExceedAccountDataTotalLimit, 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)] #[derive(AbiExample, Debug)]
pub struct CostTracker { pub struct CostTracker {
account_cost_limit: u64, account_cost_limit: u64,