Add BankClient support to bench-exchange (#3902)
This commit is contained in:
parent
320bd66c84
commit
afb00432d4
|
@ -2264,6 +2264,7 @@ dependencies = [
|
|||
"solana-logger 0.14.0",
|
||||
"solana-metrics 0.14.0",
|
||||
"solana-netutil 0.14.0",
|
||||
"solana-runtime 0.14.0",
|
||||
"solana-sdk 0.14.0",
|
||||
"untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ws 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
|
|
@ -29,6 +29,7 @@ solana-exchange-program = { path = "../programs/exchange_program", version = "0.
|
|||
solana-logger = { path = "../logger", version = "0.14.0" }
|
||||
solana-metrics = { path = "../metrics", version = "0.14.0" }
|
||||
solana-netutil = { path = "../netutil", version = "0.14.0" }
|
||||
solana-runtime = { path = "../runtime", version = "0.14.0" }
|
||||
solana-sdk = { path = "../sdk", version = "0.14.0" }
|
||||
ws = "0.8.0"
|
||||
untrusted = "0.6.2"
|
||||
|
|
|
@ -1017,6 +1017,10 @@ mod tests {
|
|||
use solana::local_cluster::{ClusterConfig, LocalCluster};
|
||||
use solana_client::thin_client::create_client;
|
||||
use solana_drone::drone::run_local_drone;
|
||||
use solana_exchange_api::exchange_processor::process_instruction;
|
||||
use solana_runtime::bank::Bank;
|
||||
use solana_runtime::bank_client::BankClient;
|
||||
use solana_sdk::genesis_block::GenesisBlock;
|
||||
use std::sync::mpsc::channel;
|
||||
|
||||
#[test]
|
||||
|
@ -1046,11 +1050,7 @@ mod tests {
|
|||
node_stakes: vec![100_000; NUM_NODES],
|
||||
cluster_lamports: 100_000_000_000_000,
|
||||
fullnode_config,
|
||||
native_instruction_processors: [(
|
||||
"solana_exchange_program".to_string(),
|
||||
solana_exchange_api::id(),
|
||||
)]
|
||||
.to_vec(),
|
||||
native_instruction_processors: [("solana_exchange_program".to_string(), id())].to_vec(),
|
||||
..ClusterConfig::default()
|
||||
});
|
||||
|
||||
|
@ -1105,4 +1105,24 @@ mod tests {
|
|||
|
||||
do_bench_exchange(clients, config);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_exchange_bank_client() {
|
||||
solana_logger::setup();
|
||||
let (genesis_block, identity) = GenesisBlock::new(100_000_000_000_000);
|
||||
let mut bank = Bank::new(&genesis_block);
|
||||
bank.add_instruction_processor(id(), process_instruction);
|
||||
let clients = vec![BankClient::new(bank)];
|
||||
|
||||
let mut config = Config::default();
|
||||
config.identity = identity;
|
||||
config.threads = 4;
|
||||
config.duration = Duration::from_secs(5);
|
||||
config.fund_amount = 100_000;
|
||||
config.trade_delay = 1;
|
||||
config.batch_size = 10;
|
||||
config.account_groups = 100;
|
||||
|
||||
do_bench_exchange(clients, config);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1013,7 +1013,7 @@ impl Bank {
|
|||
self.is_delta.load(Ordering::Relaxed) && self.tick_height() == max_tick_height
|
||||
}
|
||||
|
||||
/// Add an instruction processor to intercept intructions before the dynamic loader.
|
||||
/// Add an instruction processor to intercept instructions before the dynamic loader.
|
||||
pub fn add_instruction_processor(
|
||||
&mut self,
|
||||
program_id: Pubkey,
|
||||
|
|
|
@ -12,11 +12,12 @@ use solana_sdk::transport::Result;
|
|||
use std::io;
|
||||
use std::sync::mpsc::{channel, Receiver, Sender};
|
||||
use std::sync::Arc;
|
||||
use std::sync::Mutex;
|
||||
use std::thread::Builder;
|
||||
|
||||
pub struct BankClient {
|
||||
bank: Arc<Bank>,
|
||||
transaction_sender: Sender<Transaction>,
|
||||
transaction_sender: Mutex<Sender<Transaction>>,
|
||||
}
|
||||
|
||||
impl Client for BankClient {}
|
||||
|
@ -24,7 +25,8 @@ impl Client for BankClient {}
|
|||
impl AsyncClient for BankClient {
|
||||
fn async_send_transaction(&self, transaction: Transaction) -> io::Result<Signature> {
|
||||
let signature = transaction.signatures.get(0).cloned().unwrap_or_default();
|
||||
self.transaction_sender.send(transaction).unwrap();
|
||||
let transaction_sender = self.transaction_sender.lock().unwrap();
|
||||
transaction_sender.send(transaction).unwrap();
|
||||
Ok(signature)
|
||||
}
|
||||
|
||||
|
@ -122,6 +124,7 @@ impl BankClient {
|
|||
pub fn new(bank: Bank) -> Self {
|
||||
let bank = Arc::new(bank);
|
||||
let (transaction_sender, transaction_receiver) = channel();
|
||||
let transaction_sender = Mutex::new(transaction_sender);
|
||||
let thread_bank = bank.clone();
|
||||
let bank = bank.clone();
|
||||
Builder::new()
|
||||
|
|
Loading…
Reference in New Issue