Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
Cost Model to limit transactions which are not parallelizeable (#16694)
Browse files Browse the repository at this point in the history
* * 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 authored Jun 1, 2021
1 parent 31ce6fa commit b000d49
Show file tree
Hide file tree
Showing 7 changed files with 1,087 additions and 21 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ solana-account-decoder = { path = "../account-decoder", version = "=1.8.0" }
solana-banks-server = { path = "../banks-server", version = "=1.8.0" }
solana-clap-utils = { path = "../clap-utils", version = "=1.8.0" }
solana-client = { path = "../client", version = "=1.8.0" }
solana-config-program = { path = "../programs/config", version = "=1.8.0" }
solana-faucet = { path = "../faucet", version = "=1.8.0" }
solana-gossip = { path = "../gossip", version = "=1.8.0" }
solana-ledger = { path = "../ledger", version = "=1.8.0" }
Expand Down
10 changes: 8 additions & 2 deletions core/benches/banking_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use log::*;
use rand::{thread_rng, Rng};
use rayon::prelude::*;
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;
Expand All @@ -32,7 +34,7 @@ use solana_sdk::transaction::Transaction;
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 @@ -91,6 +93,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 @@ -204,13 +208,15 @@ fn bench_banking(bencher: &mut Bencher, tx_type: TransactionType) {
let cluster_info = ClusterInfo::new_with_invalid_keypair(Node::new_localhost().info);
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,
vote_receiver,
None,
s,
std::u32::MAX,
std::u32::MAX,
);
poh_recorder.lock().unwrap().set_bank(&bank);

Expand Down
Loading

0 comments on commit b000d49

Please sign in to comment.