2018-05-14 17:36:19 -06:00
|
|
|
//! The `tpu` module implements the Transaction Processing Unit, a
|
|
|
|
//! 5-stage transaction processing pipeline in software.
|
|
|
|
|
|
|
|
use bank::Bank;
|
|
|
|
use banking_stage::BankingStage;
|
2018-05-29 11:18:12 -06:00
|
|
|
use fetch_stage::FetchStage;
|
2018-05-14 17:36:19 -06:00
|
|
|
use hash::Hash;
|
2018-05-29 11:18:12 -06:00
|
|
|
use packet::{BlobRecycler, PacketRecycler};
|
2018-05-14 17:36:19 -06:00
|
|
|
use record_stage::RecordStage;
|
2018-05-25 16:52:17 -06:00
|
|
|
use sigverify_stage::SigVerifyStage;
|
2018-05-14 17:36:19 -06:00
|
|
|
use std::io::Write;
|
|
|
|
use std::net::UdpSocket;
|
|
|
|
use std::sync::atomic::AtomicBool;
|
2018-05-29 11:02:58 -06:00
|
|
|
use std::sync::{Arc, Mutex};
|
2018-05-14 17:36:19 -06:00
|
|
|
use std::thread::JoinHandle;
|
|
|
|
use std::time::Duration;
|
2018-05-29 11:18:12 -06:00
|
|
|
use streamer::BlobReceiver;
|
2018-05-14 17:36:19 -06:00
|
|
|
use write_stage::WriteStage;
|
|
|
|
|
|
|
|
pub struct Tpu {
|
2018-05-29 11:18:12 -06:00
|
|
|
pub blob_receiver: BlobReceiver,
|
2018-05-15 10:27:18 -06:00
|
|
|
pub thread_hdls: Vec<JoinHandle<()>>,
|
2018-05-14 17:36:19 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Tpu {
|
2018-05-15 10:45:33 -06:00
|
|
|
pub fn new<W: Write + Send + 'static>(
|
2018-05-15 11:21:40 -06:00
|
|
|
bank: Arc<Bank>,
|
2018-05-15 10:27:18 -06:00
|
|
|
start_hash: Hash,
|
|
|
|
tick_duration: Option<Duration>,
|
2018-05-25 15:51:41 -06:00
|
|
|
transactions_socket: UdpSocket,
|
2018-05-29 11:18:12 -06:00
|
|
|
blob_recycler: BlobRecycler,
|
2018-05-15 10:27:18 -06:00
|
|
|
exit: Arc<AtomicBool>,
|
|
|
|
writer: W,
|
|
|
|
) -> Self {
|
2018-05-29 11:18:12 -06:00
|
|
|
let packet_recycler = PacketRecycler::default();
|
|
|
|
|
|
|
|
let fetch_stage =
|
|
|
|
FetchStage::new(transactions_socket, exit.clone(), packet_recycler.clone());
|
2018-05-14 17:36:19 -06:00
|
|
|
|
2018-05-29 11:18:12 -06:00
|
|
|
let sigverify_stage = SigVerifyStage::new(exit.clone(), fetch_stage.packet_receiver);
|
2018-05-14 17:36:19 -06:00
|
|
|
|
|
|
|
let banking_stage = BankingStage::new(
|
2018-05-15 10:44:47 -06:00
|
|
|
bank.clone(),
|
2018-05-14 17:36:19 -06:00
|
|
|
exit.clone(),
|
2018-05-25 16:52:17 -06:00
|
|
|
sigverify_stage.verified_receiver,
|
2018-05-14 17:36:19 -06:00
|
|
|
packet_recycler.clone(),
|
|
|
|
);
|
|
|
|
|
2018-05-30 15:37:12 -06:00
|
|
|
let record_stage = match tick_duration {
|
|
|
|
Some(tick_duration) => RecordStage::new_with_clock(
|
|
|
|
banking_stage.signal_receiver,
|
|
|
|
&start_hash,
|
|
|
|
tick_duration,
|
|
|
|
),
|
|
|
|
None => RecordStage::new(banking_stage.signal_receiver, &start_hash),
|
|
|
|
};
|
2018-05-14 17:36:19 -06:00
|
|
|
|
|
|
|
let write_stage = WriteStage::new(
|
2018-05-15 10:44:47 -06:00
|
|
|
bank.clone(),
|
2018-05-14 17:36:19 -06:00
|
|
|
exit.clone(),
|
|
|
|
blob_recycler.clone(),
|
|
|
|
Mutex::new(writer),
|
|
|
|
record_stage.entry_receiver,
|
|
|
|
);
|
2018-05-15 10:44:47 -06:00
|
|
|
let mut thread_hdls = vec![
|
2018-05-29 11:18:12 -06:00
|
|
|
fetch_stage.thread_hdl,
|
2018-05-14 17:36:19 -06:00
|
|
|
banking_stage.thread_hdl,
|
2018-05-24 10:03:17 -06:00
|
|
|
record_stage.thread_hdl,
|
2018-05-14 17:36:19 -06:00
|
|
|
write_stage.thread_hdl,
|
|
|
|
];
|
2018-05-25 16:52:17 -06:00
|
|
|
thread_hdls.extend(sigverify_stage.thread_hdls.into_iter());
|
2018-05-29 11:02:58 -06:00
|
|
|
Tpu {
|
2018-05-29 11:18:12 -06:00
|
|
|
blob_receiver: write_stage.blob_receiver,
|
2018-05-29 11:02:58 -06:00
|
|
|
thread_hdls,
|
|
|
|
}
|
2018-05-14 17:36:19 -06:00
|
|
|
}
|
|
|
|
}
|