- make cost_tracker a member of bank, remove shared instance from TPU; (#20627)

- decouple cost_model from cost_tracker; allowing one cost_model
  instance being shared within a validator;
- update cost_model api to calculate_cost(&self...)->transaction_cost
This commit is contained in:
Tao Zhu
2021-10-19 14:37:33 -05:00
committed by GitHub
parent 27d1850c3d
commit 7496b5784b
8 changed files with 152 additions and 296 deletions

View File

@ -775,13 +775,11 @@ fn compute_slot_cost(blockstore: &Blockstore, slot: Slot) -> Result<(), String>
let mut program_ids = HashMap::new();
let mut cost_model = CostModel::default();
cost_model.initialize_cost_table(&blockstore.read_program_costs().unwrap());
let cost_model = Arc::new(RwLock::new(cost_model));
let mut cost_tracker = CostTracker::new(cost_model.clone());
let mut cost_tracker = CostTracker::default();
let mut cost_tracker_stats = CostTrackerStats::default();
for entry in entries {
num_transactions += entry.transactions.len();
let mut cost_model = cost_model.write().unwrap();
entry
.transactions
.into_iter()
@ -802,7 +800,7 @@ fn compute_slot_cost(blockstore: &Blockstore, slot: Slot) -> Result<(), String>
true, // demote_program_write_locks
);
if cost_tracker
.try_add(tx_cost, &mut cost_tracker_stats)
.try_add(&transaction, &tx_cost, &mut cost_tracker_stats)
.is_err()
{
println!(