removed obsolete field from cost_tracker (#34762)
This commit is contained in:
parent
b222fdf3d7
commit
613f0ff226
|
@ -58,10 +58,6 @@ pub struct CostTracker {
|
|||
vote_cost: u64,
|
||||
transaction_count: u64,
|
||||
account_data_size: u64,
|
||||
|
||||
/// The amount of total account data size remaining. If `Some`, then do not add transactions
|
||||
/// that would cause `account_data_size` to exceed this limit.
|
||||
account_data_size_limit: Option<u64>,
|
||||
}
|
||||
|
||||
impl Default for CostTracker {
|
||||
|
@ -81,21 +77,11 @@ impl Default for CostTracker {
|
|||
vote_cost: 0,
|
||||
transaction_count: 0,
|
||||
account_data_size: 0,
|
||||
account_data_size_limit: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl CostTracker {
|
||||
/// Construct and new CostTracker and set the account data size limit.
|
||||
#[must_use]
|
||||
pub fn new_with_account_data_size_limit(account_data_size_limit: Option<u64>) -> Self {
|
||||
Self {
|
||||
account_data_size_limit,
|
||||
..Self::default()
|
||||
}
|
||||
}
|
||||
|
||||
/// allows to adjust limits initiated during construction
|
||||
pub fn set_limits(
|
||||
&mut self,
|
||||
|
@ -203,11 +189,6 @@ impl CostTracker {
|
|||
let account_data_size = self
|
||||
.account_data_size
|
||||
.saturating_add(tx_cost.account_data_size());
|
||||
if let Some(account_data_size_limit) = self.account_data_size_limit {
|
||||
if account_data_size > account_data_size_limit {
|
||||
return Err(CostTrackerError::WouldExceedAccountDataTotalLimit);
|
||||
}
|
||||
}
|
||||
|
||||
if account_data_size > MAX_BLOCK_ACCOUNTS_DATA_SIZE_DELTA {
|
||||
return Err(CostTrackerError::WouldExceedAccountDataBlockLimit);
|
||||
|
@ -302,19 +283,13 @@ mod tests {
|
|||
};
|
||||
|
||||
impl CostTracker {
|
||||
fn new(
|
||||
account_cost_limit: u64,
|
||||
block_cost_limit: u64,
|
||||
vote_cost_limit: u64,
|
||||
account_data_size_limit: Option<u64>,
|
||||
) -> Self {
|
||||
fn new(account_cost_limit: u64, block_cost_limit: u64, vote_cost_limit: u64) -> Self {
|
||||
assert!(account_cost_limit <= block_cost_limit);
|
||||
assert!(vote_cost_limit <= block_cost_limit);
|
||||
Self {
|
||||
account_cost_limit,
|
||||
block_cost_limit,
|
||||
vote_cost_limit,
|
||||
account_data_size_limit,
|
||||
..Self::default()
|
||||
}
|
||||
}
|
||||
|
@ -371,7 +346,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_cost_tracker_initialization() {
|
||||
let testee = CostTracker::new(10, 11, 8, None);
|
||||
let testee = CostTracker::new(10, 11, 8);
|
||||
assert_eq!(10, testee.account_cost_limit);
|
||||
assert_eq!(11, testee.block_cost_limit);
|
||||
assert_eq!(8, testee.vote_cost_limit);
|
||||
|
@ -386,7 +361,7 @@ mod tests {
|
|||
let cost = tx_cost.sum();
|
||||
|
||||
// build testee to have capacity for one simple transaction
|
||||
let mut testee = CostTracker::new(cost, cost, cost, None);
|
||||
let mut testee = CostTracker::new(cost, cost, cost);
|
||||
assert!(testee.would_fit(&tx_cost).is_ok());
|
||||
testee.add_transaction_cost(&tx_cost);
|
||||
assert_eq!(cost, testee.block_cost);
|
||||
|
@ -402,7 +377,7 @@ mod tests {
|
|||
let cost = tx_cost.sum();
|
||||
|
||||
// build testee to have capacity for one simple transaction
|
||||
let mut testee = CostTracker::new(cost, cost, cost, None);
|
||||
let mut testee = CostTracker::new(cost, cost, cost);
|
||||
assert!(testee.would_fit(&tx_cost).is_ok());
|
||||
testee.add_transaction_cost(&tx_cost);
|
||||
assert_eq!(cost, testee.block_cost);
|
||||
|
@ -423,7 +398,7 @@ mod tests {
|
|||
let cost = tx_cost.sum();
|
||||
|
||||
// build testee to have capacity for one simple transaction
|
||||
let mut testee = CostTracker::new(cost, cost, cost, None);
|
||||
let mut testee = CostTracker::new(cost, cost, cost);
|
||||
assert!(testee.would_fit(&tx_cost).is_ok());
|
||||
let old = testee.account_data_size;
|
||||
testee.add_transaction_cost(&tx_cost);
|
||||
|
@ -440,7 +415,7 @@ mod tests {
|
|||
let cost2 = tx_cost2.sum();
|
||||
|
||||
// build testee to have capacity for two simple transactions, with same accounts
|
||||
let mut testee = CostTracker::new(cost1 + cost2, cost1 + cost2, cost1 + cost2, None);
|
||||
let mut testee = CostTracker::new(cost1 + cost2, cost1 + cost2, cost1 + cost2);
|
||||
{
|
||||
assert!(testee.would_fit(&tx_cost1).is_ok());
|
||||
testee.add_transaction_cost(&tx_cost1);
|
||||
|
@ -466,8 +441,7 @@ mod tests {
|
|||
let cost2 = tx_cost2.sum();
|
||||
|
||||
// build testee to have capacity for two simple transactions, with same accounts
|
||||
let mut testee =
|
||||
CostTracker::new(cmp::max(cost1, cost2), cost1 + cost2, cost1 + cost2, None);
|
||||
let mut testee = CostTracker::new(cmp::max(cost1, cost2), cost1 + cost2, cost1 + cost2);
|
||||
{
|
||||
assert!(testee.would_fit(&tx_cost1).is_ok());
|
||||
testee.add_transaction_cost(&tx_cost1);
|
||||
|
@ -492,8 +466,7 @@ mod tests {
|
|||
let cost2 = tx_cost2.sum();
|
||||
|
||||
// build testee to have capacity for two simple transactions, but not for same accounts
|
||||
let mut testee =
|
||||
CostTracker::new(cmp::min(cost1, cost2), cost1 + cost2, cost1 + cost2, None);
|
||||
let mut testee = CostTracker::new(cmp::min(cost1, cost2), cost1 + cost2, cost1 + cost2);
|
||||
// should have room for first transaction
|
||||
{
|
||||
assert!(testee.would_fit(&tx_cost1).is_ok());
|
||||
|
@ -516,12 +489,8 @@ mod tests {
|
|||
let cost2 = tx_cost2.sum();
|
||||
|
||||
// build testee to have capacity for each chain, but not enough room for both transactions
|
||||
let mut testee = CostTracker::new(
|
||||
cmp::max(cost1, cost2),
|
||||
cost1 + cost2 - 1,
|
||||
cost1 + cost2 - 1,
|
||||
None,
|
||||
);
|
||||
let mut testee =
|
||||
CostTracker::new(cmp::max(cost1, cost2), cost1 + cost2 - 1, cost1 + cost2 - 1);
|
||||
// should have room for first transaction
|
||||
{
|
||||
assert!(testee.would_fit(&tx_cost1).is_ok());
|
||||
|
@ -544,12 +513,7 @@ mod tests {
|
|||
let cost2 = tx_cost2.sum();
|
||||
|
||||
// build testee to have capacity for each chain, but not enough room for both votes
|
||||
let mut testee = CostTracker::new(
|
||||
cmp::max(cost1, cost2),
|
||||
cost1 + cost2,
|
||||
cost1 + cost2 - 1,
|
||||
None,
|
||||
);
|
||||
let mut testee = CostTracker::new(cmp::max(cost1, cost2), cost1 + cost2, cost1 + cost2 - 1);
|
||||
// should have room for first vote
|
||||
{
|
||||
assert!(testee.would_fit(&tx_cost1).is_ok());
|
||||
|
@ -588,12 +552,7 @@ mod tests {
|
|||
let cost2 = tx_cost2.sum();
|
||||
|
||||
// build testee that passes
|
||||
let testee = CostTracker::new(
|
||||
cmp::max(cost1, cost2),
|
||||
cost1 + cost2 - 1,
|
||||
cost1 + cost2 - 1,
|
||||
None,
|
||||
);
|
||||
let testee = CostTracker::new(cmp::max(cost1, cost2), cost1 + cost2 - 1, cost1 + cost2 - 1);
|
||||
assert!(testee.would_fit(&tx_cost1).is_ok());
|
||||
// data is too big
|
||||
assert_eq!(
|
||||
|
@ -602,42 +561,6 @@ mod tests {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cost_tracker_reach_data_total_limit() {
|
||||
let (mint_keypair, start_hash) = test_setup();
|
||||
// build two transactions with diff accounts
|
||||
let second_account = Keypair::new();
|
||||
let (_tx1, mut tx_cost1) = build_simple_transaction(&mint_keypair, &start_hash);
|
||||
let (_tx2, mut tx_cost2) = build_simple_transaction(&second_account, &start_hash);
|
||||
let remaining_account_data_size = 1234;
|
||||
if let TransactionCost::Transaction(ref mut usage_cost) = tx_cost1 {
|
||||
usage_cost.account_data_size = remaining_account_data_size;
|
||||
} else {
|
||||
unreachable!();
|
||||
}
|
||||
if let TransactionCost::Transaction(ref mut usage_cost) = tx_cost2 {
|
||||
usage_cost.account_data_size = remaining_account_data_size + 1;
|
||||
} else {
|
||||
unreachable!();
|
||||
}
|
||||
let cost1 = tx_cost1.sum();
|
||||
let cost2 = tx_cost2.sum();
|
||||
|
||||
// build testee that passes
|
||||
let testee = CostTracker::new(
|
||||
cmp::max(cost1, cost2),
|
||||
cost1 + cost2 - 1,
|
||||
cost1 + cost2 - 1,
|
||||
Some(remaining_account_data_size),
|
||||
);
|
||||
assert!(testee.would_fit(&tx_cost1).is_ok());
|
||||
// data is too big
|
||||
assert_eq!(
|
||||
testee.would_fit(&tx_cost2),
|
||||
Err(CostTrackerError::WouldExceedAccountDataTotalLimit),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cost_tracker_remove() {
|
||||
let (mint_keypair, start_hash) = test_setup();
|
||||
|
@ -648,7 +571,7 @@ mod tests {
|
|||
let cost1 = tx_cost1.sum();
|
||||
let cost2 = tx_cost2.sum();
|
||||
// build testee
|
||||
let mut testee = CostTracker::new(cost1 + cost2, cost1 + cost2, cost1 + cost2, None);
|
||||
let mut testee = CostTracker::new(cost1 + cost2, cost1 + cost2, cost1 + cost2);
|
||||
|
||||
assert!(testee.try_add(&tx_cost1).is_ok());
|
||||
assert!(testee.try_add(&tx_cost2).is_ok());
|
||||
|
@ -675,7 +598,7 @@ mod tests {
|
|||
let account_max = cost * 2;
|
||||
let block_max = account_max * 3; // for three accts
|
||||
|
||||
let mut testee = CostTracker::new(account_max, block_max, block_max, None);
|
||||
let mut testee = CostTracker::new(account_max, block_max, block_max);
|
||||
|
||||
// case 1: a tx writes to 3 accounts, should success, we will have:
|
||||
// | acct1 | $cost |
|
||||
|
@ -744,7 +667,7 @@ mod tests {
|
|||
let account_max = cost * 2;
|
||||
let block_max = account_max * 3; // for three accts
|
||||
|
||||
let mut testee = CostTracker::new(account_max, block_max, block_max, None);
|
||||
let mut testee = CostTracker::new(account_max, block_max, block_max);
|
||||
let tx_cost = TransactionCost::Transaction(UsageCostDetails {
|
||||
writable_accounts: vec![acct1, acct2, acct3],
|
||||
bpf_execution_cost: cost,
|
||||
|
|
Loading…
Reference in New Issue