Aggregate cost_model into cost_tracker (#18374)

* * aggregate cost_model into cost_tracker, decouple it from banking_stage to prevent accidental deadlock. * Simplified code, removed unused functions

* review fixes
This commit is contained in:
Tao Zhu
2021-07-06 10:41:25 -05:00
committed by GitHub
parent 660788d227
commit 0e039b4094
7 changed files with 168 additions and 310 deletions

View File

@@ -60,7 +60,7 @@ use std::{
path::{Path, PathBuf},
process::{exit, Command, Stdio},
str::FromStr,
sync::Arc,
sync::{Arc, RwLock},
};
mod bigtable;
@@ -737,14 +737,15 @@ fn compute_slot_cost(blockstore: &Blockstore, slot: Slot) -> Result<(), String>
let mut transactions = 0;
let mut programs = 0;
let mut program_ids = HashMap::new();
let cost_model = CostModel::new(ACCOUNT_MAX_COST, BLOCK_MAX_COST);
let mut cost_tracker = CostTracker::new(
cost_model.get_account_cost_limit(),
cost_model.get_block_cost_limit(),
);
let cost_model = Arc::new(RwLock::new(CostModel::new(
ACCOUNT_MAX_COST,
BLOCK_MAX_COST,
)));
let mut cost_tracker = CostTracker::new(cost_model.clone());
for entry in &entries {
transactions += entry.transactions.len();
let mut cost_model = cost_model.write().unwrap();
for transaction in &entry.transactions {
programs += transaction.message().instructions.len();
let tx_cost = cost_model.calculate_cost(transaction);