Skip to content

Commit

Permalink
Cost Model to limit transactions which are not parallelizeable (solan…
Browse files Browse the repository at this point in the history
…a-labs#16694)

* * Add following to banking_stage:
  1. CostModel as immutable ref shared between threads, to provide estimated cost for transactions.
  2. CostTracker which is shared between threads, tracks transaction costs for each block.

* replace hard coded program ID with id() calls

* Add Account Access Cost as part of TransactionCost. Account Access cost are weighted differently between read and write, signed and non-signed.

* Establish instruction_execution_cost_table, add function to update or insert instruction cost, unit tested. It is read-only for now; it allows Replay to insert realtime instruction execution costs to the table.

* add test for cost_tracker atomically try_add operation, serves as safety guard for future changes

* check cost against local copy of cost_tracker, return transactions that would exceed limit as unprocessed transaction to be buffered; only apply bank processed transactions cost to tracker;

* bencher to new banking_stage with max cost limit to allow cost model being hit consistently during bench iterations
  • Loading branch information
tao-stones committed Sep 30, 2021
1 parent 51593a8 commit d127164
Show file tree
Hide file tree
Showing 5 changed files with 1,094 additions and 25 deletions.
13 changes: 10 additions & 3 deletions core/benches/banking_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ use crossbeam_channel::unbounded;
use log::*;
use rand::{thread_rng, Rng};
use rayon::prelude::*;
use solana_core::banking_stage::{BankingStage, BankingStageStats};
use solana_core::banking_stage::{create_test_recorder, BankingStage, BankingStageStats};
use solana_core::cost_model::CostModel;
use solana_core::cost_tracker::CostTracker;
use solana_core::poh_recorder::WorkingBankEntry;
use solana_gossip::cluster_info::ClusterInfo;
use solana_gossip::cluster_info::Node;
use solana_ledger::blockstore_processor::process_entries;
Expand All @@ -33,7 +36,7 @@ use solana_streamer::socket::SocketAddrSpace;
use std::collections::VecDeque;
use std::sync::atomic::Ordering;
use std::sync::mpsc::Receiver;
use std::sync::Arc;
use std::sync::{Arc, Mutex};
use std::time::{Duration, Instant};
use test::Bencher;

Expand Down Expand Up @@ -92,6 +95,8 @@ fn bench_consume_buffered(bencher: &mut Bencher) {
None::<Box<dyn Fn()>>,
&BankingStageStats::default(),
&recorder,
&Arc::new(CostModel::default()),
&Arc::new(Mutex::new(CostTracker::new(std::u32::MAX, std::u32::MAX))),
);
});

Expand Down Expand Up @@ -210,14 +215,16 @@ fn bench_banking(bencher: &mut Bencher, tx_type: TransactionType) {
);
let cluster_info = Arc::new(cluster_info);
let (s, _r) = unbounded();
let _banking_stage = BankingStage::new(
let _banking_stage = BankingStage::new_with_cost_limit(
&cluster_info,
&poh_recorder,
verified_receiver,
tpu_vote_receiver,
vote_receiver,
None,
s,
std::u32::MAX,
std::u32::MAX,
);
poh_recorder.lock().unwrap().set_bank(&bank);

Expand Down
Loading

0 comments on commit d127164

Please sign in to comment.