Skip to content

Commit

Permalink
Revert "- move cost tracker into bank, so each bank has its own cost …
Browse files Browse the repository at this point in the history
…tracker; (solana-labs#20527)"

This reverts commit d0e055f.
  • Loading branch information
frits-metalogix authored Nov 24, 2021
1 parent c420db5 commit dc22ac6
Show file tree
Hide file tree
Showing 20 changed files with 39 additions and 60 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions banking-bench/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crossbeam_channel::unbounded;
use log::*;
use rand::{thread_rng, Rng};
use rayon::prelude::*;
use solana_core::banking_stage::BankingStage;
use solana_core::{banking_stage::BankingStage, cost_model::CostModel, cost_tracker::CostTracker};
use solana_gossip::{cluster_info::ClusterInfo, cluster_info::Node};
use solana_ledger::{
blockstore::Blockstore,
Expand All @@ -16,7 +16,6 @@ use solana_perf::packet::to_packets_chunked;
use solana_poh::poh_recorder::{create_test_recorder, PohRecorder, WorkingBankEntry};
use solana_runtime::{
accounts_background_service::AbsRequestSender, bank::Bank, bank_forks::BankForks,
cost_model::CostModel, cost_tracker::CostTracker,
};
use solana_sdk::{
hash::Hash,
Expand Down
6 changes: 3 additions & 3 deletions core/benches/banking_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ use log::*;
use rand::{thread_rng, Rng};
use rayon::prelude::*;
use solana_core::banking_stage::{BankingStage, BankingStageStats};
use solana_core::cost_model::CostModel;
use solana_core::cost_tracker::CostTracker;
use solana_core::cost_tracker_stats::CostTrackerStats;
use solana_entry::entry::{next_hash, Entry};
use solana_gossip::cluster_info::ClusterInfo;
use solana_gossip::cluster_info::Node;
Expand All @@ -18,9 +21,6 @@ use solana_perf::packet::to_packets_chunked;
use solana_perf::test_tx::test_tx;
use solana_poh::poh_recorder::{create_test_recorder, WorkingBankEntry};
use solana_runtime::bank::Bank;
use solana_runtime::cost_model::CostModel;
use solana_runtime::cost_tracker::CostTracker;
use solana_runtime::cost_tracker_stats::CostTrackerStats;
use solana_sdk::genesis_config::GenesisConfig;
use solana_sdk::hash::Hash;
use solana_sdk::message::Message;
Expand Down
8 changes: 4 additions & 4 deletions core/src/banking_stage.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
//! The `banking_stage` processes Transaction messages. It is intended to be used
//! to contruct a software pipeline. The stage uses all available CPU cores and
//! can do its processing in parallel with signature verification on the GPU.
use crate::packet_hasher::PacketHasher;
use crate::{
cost_tracker::CostTracker, cost_tracker_stats::CostTrackerStats, packet_hasher::PacketHasher,
};
use crossbeam_channel::{Receiver as CrossbeamReceiver, RecvTimeoutError};
use itertools::Itertools;
use lru::LruCache;
Expand All @@ -25,8 +27,6 @@ use solana_runtime::{
TransactionExecutionResult,
},
bank_utils,
cost_tracker::CostTracker,
cost_tracker_stats::CostTrackerStats,
transaction_batch::TransactionBatch,
vote_sender_types::ReplayVoteSender,
};
Expand Down Expand Up @@ -1697,6 +1697,7 @@ where
#[cfg(test)]
mod tests {
use super::*;
use crate::cost_model::CostModel;
use crossbeam_channel::unbounded;
use itertools::Itertools;
use solana_entry::entry::{next_entry, Entry, EntrySlice};
Expand All @@ -1713,7 +1714,6 @@ mod tests {
poh_service::PohService,
};
use solana_rpc::transaction_status_service::TransactionStatusService;
use solana_runtime::cost_model::CostModel;
use solana_sdk::{
hash::Hash,
instruction::InstructionError,
Expand Down
9 changes: 5 additions & 4 deletions runtime/src/cost_model.rs → core/src/cost_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
//!
//! The main function is `calculate_cost` which returns &TransactionCost.
//!
use crate::{block_cost_limits::*, execute_cost_table::ExecuteCostTable};
use crate::execute_cost_table::ExecuteCostTable;
use log::*;
use solana_ledger::block_cost_limits::*;
use solana_sdk::{pubkey::Pubkey, transaction::SanitizedTransaction};
use std::collections::HashMap;

Expand All @@ -24,7 +25,7 @@ pub enum CostModelError {
WouldExceedAccountMaxLimit,
}

#[derive(AbiExample, Default, Debug)]
#[derive(Default, Debug)]
pub struct TransactionCost {
pub writable_accounts: Vec<Pubkey>,
pub signature_cost: u64,
Expand Down Expand Up @@ -54,7 +55,7 @@ impl TransactionCost {
}
}

#[derive(AbiExample, Debug)]
#[derive(Debug)]
pub struct CostModel {
account_cost_limit: u64,
block_cost_limit: u64,
Expand Down Expand Up @@ -218,7 +219,7 @@ impl CostModel {
#[cfg(test)]
mod tests {
use super::*;
use crate::{
use solana_runtime::{
bank::Bank,
genesis_utils::{create_genesis_config, GenesisConfigInfo},
};
Expand Down
10 changes: 2 additions & 8 deletions runtime/src/cost_tracker.rs → core/src/cost_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::{

const WRITABLE_ACCOUNTS_PER_BLOCK: usize = 512;

#[derive(AbiExample, Debug)]
#[derive(Debug)]
pub struct CostTracker {
cost_model: Arc<RwLock<CostModel>>,
account_cost_limit: u64,
Expand All @@ -24,12 +24,6 @@ pub struct CostTracker {
block_cost: u64,
}

impl Default for CostTracker {
fn default() -> Self {
CostTracker::new(Arc::new(RwLock::new(CostModel::default())))
}
}

impl CostTracker {
pub fn new(cost_model: Arc<RwLock<CostModel>>) -> Self {
let (account_cost_limit, block_cost_limit) = {
Expand Down Expand Up @@ -197,7 +191,7 @@ impl CostTracker {
#[cfg(test)]
mod tests {
use super::*;
use crate::{
use solana_runtime::{
bank::Bank,
genesis_utils::{create_genesis_config, GenesisConfigInfo},
};
Expand Down
File renamed without changes.
3 changes: 2 additions & 1 deletion core/src/cost_update_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
//! packing transactions into block; it also triggers persisting cost
//! table to blockstore.
use crate::cost_model::CostModel;
use solana_ledger::blockstore::Blockstore;
use solana_measure::measure::Measure;
use solana_runtime::{bank::ExecuteTimings, cost_model::CostModel};
use solana_runtime::bank::ExecuteTimings;
use solana_sdk::timing::timestamp;
use std::{
sync::{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/// to make room for new ones.
use log::*;
use solana_sdk::pubkey::Pubkey;
use std::collections::HashMap;
use std::{collections::HashMap, time::SystemTime};

// prune is rather expensive op, free up bulk space in each operation
// would be more efficient. PRUNE_RATIO defines the after prune table
Expand All @@ -16,11 +16,11 @@ const OCCURRENCES_WEIGHT: i64 = 100;

const DEFAULT_CAPACITY: usize = 1024;

#[derive(AbiExample, Debug)]
#[derive(Debug)]
pub struct ExecuteCostTable {
capacity: usize,
table: HashMap<Pubkey, u64>,
occurrences: HashMap<Pubkey, (usize, u128)>,
occurrences: HashMap<Pubkey, (usize, SystemTime)>,
}

impl Default for ExecuteCostTable {
Expand Down Expand Up @@ -91,9 +91,9 @@ impl ExecuteCostTable {
let (count, timestamp) = self
.occurrences
.entry(*key)
.or_insert((0, Self::micros_since_epoch()));
.or_insert((0, SystemTime::now()));
*count += 1;
*timestamp = Self::micros_since_epoch();
*timestamp = SystemTime::now();

Some(*program_cost)
}
Expand All @@ -120,12 +120,12 @@ impl ExecuteCostTable {
return;
}

let now = Self::micros_since_epoch();
let now = SystemTime::now();
let mut sorted_by_weighted_age: Vec<_> = self
.occurrences
.iter()
.map(|(key, (count, timestamp))| {
let age = now - timestamp;
let age = now.duration_since(*timestamp).unwrap().as_micros();
let weighted_age = *count as i64 * OCCURRENCES_WEIGHT + -(age as i64);
(weighted_age, *key)
})
Expand All @@ -140,13 +140,6 @@ impl ExecuteCostTable {
}
}
}

fn micros_since_epoch() -> u128 {
std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap()
.as_micros()
}
}

#[cfg(test)]
Expand Down
4 changes: 4 additions & 0 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ pub mod cluster_slots_service;
pub mod commitment_service;
pub mod completed_data_sets_service;
pub mod consensus;
pub mod cost_model;
pub mod cost_tracker;
pub mod cost_tracker_stats;
pub mod cost_update_service;
pub mod duplicate_repair_status;
pub mod execute_cost_table;
pub mod fetch_stage;
pub mod fork_choice;
pub mod gen_keys;
Expand Down
4 changes: 2 additions & 2 deletions core/src/tpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use crate::{
ClusterInfoVoteListener, GossipDuplicateConfirmedSlotsSender, GossipVerifiedVoteHashSender,
VerifiedVoteSender, VoteTracker,
},
cost_model::CostModel,
cost_tracker::CostTracker,
fetch_stage::FetchStage,
sigverify::TransactionSigVerifier,
sigverify_stage::SigVerifyStage,
Expand All @@ -22,8 +24,6 @@ use solana_rpc::{
};
use solana_runtime::{
bank_forks::BankForks,
cost_model::CostModel,
cost_tracker::CostTracker,
vote_sender_types::{ReplayVoteReceiver, ReplayVoteSender},
};
use std::{
Expand Down
2 changes: 1 addition & 1 deletion core/src/tvu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::{
cluster_slots::ClusterSlots,
completed_data_sets_service::CompletedDataSetsSender,
consensus::Tower,
cost_model::CostModel,
cost_update_service::CostUpdateService,
ledger_cleanup_service::LedgerCleanupService,
replay_stage::{ReplayStage, ReplayStageConfig},
Expand Down Expand Up @@ -42,7 +43,6 @@ use solana_runtime::{
bank::ExecuteTimings,
bank_forks::BankForks,
commitment::BlockCommitmentCache,
cost_model::CostModel,
snapshot_config::SnapshotConfig,
snapshot_package::{AccountsPackageReceiver, AccountsPackageSender, PendingSnapshotPackage},
vote_sender_types::ReplayVoteSender,
Expand Down
2 changes: 1 addition & 1 deletion core/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use {
cluster_info_vote_listener::VoteTracker,
completed_data_sets_service::CompletedDataSetsService,
consensus::{reconcile_blockstore_roots_with_tower, Tower},
cost_model::CostModel,
rewards_recorder_service::{RewardsRecorderSender, RewardsRecorderService},
sample_performance_service::SamplePerformanceService,
serve_repair::ServeRepair,
Expand Down Expand Up @@ -68,7 +69,6 @@ use {
bank::Bank,
bank_forks::BankForks,
commitment::BlockCommitmentCache,
cost_model::CostModel,
hardened_unpack::{open_genesis_config, MAX_GENESIS_ARCHIVE_UNPACKED_SIZE},
snapshot_archive_info::SnapshotArchiveInfoGetter,
snapshot_config::SnapshotConfig,
Expand Down
6 changes: 3 additions & 3 deletions ledger-tool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ use solana_clap_utils::{
is_bin, is_parsable, is_pubkey, is_pubkey_or_keypair, is_slot, is_valid_percentage,
},
};
use solana_core::cost_model::CostModel;
use solana_core::cost_tracker::CostTracker;
use solana_core::cost_tracker_stats::CostTrackerStats;
use solana_entry::entry::Entry;
use solana_ledger::{
ancestor_iterator::AncestorIterator,
Expand All @@ -29,9 +32,6 @@ use solana_runtime::{
accounts_index::AccountsIndexConfig,
bank::{Bank, RewardCalculationEvent},
bank_forks::BankForks,
cost_model::CostModel,
cost_tracker::CostTracker,
cost_tracker_stats::CostTrackerStats,
hardened_unpack::{open_genesis_config, MAX_GENESIS_ARCHIVE_UNPACKED_SIZE},
snapshot_archive_info::SnapshotArchiveInfoGetter,
snapshot_config::SnapshotConfig,
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions ledger/src/blockstore_processor.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::{
block_error::BlockError, blockstore::Blockstore, blockstore_db::BlockstoreError,
blockstore_meta::SlotMeta, leader_schedule_cache::LeaderScheduleCache,
block_cost_limits::*, block_error::BlockError, blockstore::Blockstore,
blockstore_db::BlockstoreError, blockstore_meta::SlotMeta,
leader_schedule_cache::LeaderScheduleCache,
};
use chrono_humanize::{Accuracy, HumanTime, Tense};
use crossbeam_channel::Sender;
Expand All @@ -24,7 +25,6 @@ use solana_runtime::{
},
bank_forks::BankForks,
bank_utils,
block_cost_limits::*,
commitment::VOTE_THRESHOLD_SIZE,
snapshot_config::SnapshotConfig,
snapshot_package::{AccountsPackageSender, SnapshotType},
Expand Down
1 change: 1 addition & 0 deletions ledger/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub mod block_error;
#[macro_use]
pub mod blockstore;
pub mod ancestor_iterator;
pub mod block_cost_limits;
pub mod blockstore_db;
pub mod blockstore_meta;
pub mod blockstore_processor;
Expand Down
7 changes: 0 additions & 7 deletions programs/bpf/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ crossbeam-channel = "0.5"
dir-diff = "0.3.2"
flate2 = "1.0.22"
fnv = "1.0.7"
histogram = "0.6.9"
itertools = "0.10.1"
lazy_static = "1.4.0"
log = "0.4.14"
Expand Down
5 changes: 0 additions & 5 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ pub mod bank;
pub mod bank_client;
pub mod bank_forks;
pub mod bank_utils;
pub mod block_cost_limits;
pub mod blockhash_queue;
pub mod bloom;
pub mod bucket_map_holder;
Expand All @@ -24,11 +23,7 @@ pub mod cache_hash_data;
pub mod cache_hash_data_stats;
pub mod commitment;
pub mod contains;
pub mod cost_model;
pub mod cost_tracker;
pub mod cost_tracker_stats;
pub mod epoch_stakes;
pub mod execute_cost_table;
pub mod genesis_utils;
pub mod hardened_unpack;
pub mod in_mem_accounts_index;
Expand Down

0 comments on commit dc22ac6

Please sign in to comment.