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::{
|
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();
|
||||||
|
|
|
@ -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,
|
||||||
|
|
Loading…
Reference in New Issue