Skip to content

Commit

Permalink
- move cost tracker into bank, so each bank has its own cost tracker;
Browse files Browse the repository at this point in the history
- move related modules to runtime
  • Loading branch information
tao-stones committed Oct 12, 2021
1 parent 005d686 commit 02952e5
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ use crate::{
ancestors::{Ancestors, AncestorsForSerialization},
blockhash_queue::BlockhashQueue,
builtins::{self, ActivationType, Builtin, Builtins},
cost_tracker::CostTracker,
epoch_stakes::{EpochStakes, NodeVoteAccounts},
inline_spl_token_v2_0,
instruction_recorder::InstructionRecorder,
Expand Down Expand Up @@ -994,6 +995,8 @@ pub struct Bank {
pub freeze_started: AtomicBool,

vote_only_bank: bool,

pub cost_tracker: RwLock<CostTracker>,
}

impl Default for BlockhashQueue {
Expand Down Expand Up @@ -1132,6 +1135,7 @@ impl Bank {
drop_callback: RwLock::<OptionalDropCallback>::default(),
freeze_started: AtomicBool::default(),
vote_only_bank: false,
cost_tracker: RwLock::<CostTracker>::default(),
}
}

Expand Down Expand Up @@ -1382,6 +1386,7 @@ impl Bank {
.map(|drop_callback| drop_callback.clone_box()),
)),
freeze_started: AtomicBool::new(false),
cost_tracker: RwLock::new(CostTracker::default()),
};

datapoint_info!(
Expand Down Expand Up @@ -1568,6 +1573,7 @@ impl Bank {
drop_callback: RwLock::new(OptionalDropCallback(None)),
freeze_started: AtomicBool::new(fields.hash != Hash::default()),
vote_only_bank: false,
cost_tracker: RwLock::new(CostTracker::default()),
};
bank.finish_init(
genesis_config,
Expand Down Expand Up @@ -5945,6 +5951,14 @@ impl Bank {
.is_active(&feature_set::send_to_tpu_vote_port::id())
}

pub fn read_current_cost(&self) -> LockResult<RwLockReadGuard<CostTracker>> {
self.cost_tracker.read()
}

pub fn write_current_cost(&self) -> LockResult<RwLockWriteGuard<CostTracker>> {
self.cost_tracker.write()
}

// Check if the wallclock time from bank creation to now has exceeded the allotted
// time for transaction processing
pub fn should_bank_still_be_processing_txs(
Expand Down

0 comments on commit 02952e5

Please sign in to comment.