solana/src/tpu.rs

93 lines
2.5 KiB
Rust
Raw Normal View History

2018-05-14 16:36:19 -07:00
//! The `tpu` module implements the Transaction Processing Unit, a
//! multi-stage transaction processing pipeline in software.
2018-05-14 16:36:19 -07:00
2018-12-07 19:16:27 -08:00
use crate::bank::Bank;
use crate::banking_stage::{BankingStage, BankingStageReturnType};
use crate::entry::Entry;
use crate::fetch_stage::FetchStage;
use crate::poh_service::Config;
use crate::service::Service;
use crate::sigverify_stage::SigVerifyStage;
2018-11-16 08:04:46 -08:00
use solana_sdk::hash::Hash;
use solana_sdk::pubkey::Pubkey;
2018-05-14 16:36:19 -07:00
use std::net::UdpSocket;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::mpsc::Receiver;
use std::sync::Arc;
use std::thread;
pub enum TpuReturnType {
LeaderRotation,
}
2018-05-14 16:36:19 -07:00
pub struct Tpu {
fetch_stage: FetchStage,
sigverify_stage: SigVerifyStage,
banking_stage: BankingStage,
exit: Arc<AtomicBool>,
2018-05-14 16:36:19 -07:00
}
impl Tpu {
#[allow(clippy::new_ret_no_self)]
pub fn new(
2018-07-11 13:40:46 -07:00
bank: &Arc<Bank>,
tick_duration: Config,
transactions_sockets: Vec<UdpSocket>,
sigverify_disabled: bool,
max_tick_height: Option<u64>,
last_entry_id: &Hash,
leader_id: Pubkey,
) -> (Self, Receiver<Vec<Entry>>, Arc<AtomicBool>) {
let exit = Arc::new(AtomicBool::new(false));
2018-05-29 10:18:12 -07:00
let (fetch_stage, packet_receiver) = FetchStage::new(transactions_sockets, exit.clone());
2018-05-14 16:36:19 -07:00
let (sigverify_stage, verified_receiver) =
SigVerifyStage::new(packet_receiver, sigverify_disabled);
2018-05-14 16:36:19 -07:00
let (banking_stage, entry_receiver) = BankingStage::new(
&bank,
verified_receiver,
tick_duration,
last_entry_id,
max_tick_height,
leader_id,
);
2018-05-14 16:36:19 -07:00
let tpu = Self {
fetch_stage,
sigverify_stage,
banking_stage,
exit: exit.clone(),
};
(tpu, entry_receiver, exit)
}
pub fn exit(&self) {
self.exit.store(true, Ordering::Relaxed);
}
2018-07-09 13:53:18 -07:00
Leader scheduler plumbing (#1440) * Added LeaderScheduler module and tests * plumbing for LeaderScheduler in Fullnode + tests. Add vote processing for active set to ReplicateStage and WriteStage * Add LeaderScheduler plumbing for Tvu, window, and tests * Fix bank and switch tests to use new LeaderScheduler * move leader rotation check from window service to replicate stage * Add replicate_stage leader rotation exit test * removed leader scheduler from the window service and associated modules/tests * Corrected is_leader calculation in repair() function in window.rs * Integrate LeaderScheduler with write_stage for leader to validator transitions * Integrated LeaderScheduler with BroadcastStage * Removed gossip leader rotation from crdt * Add multi validator, leader test * Comments and cleanup * Remove unneeded checks from broadcast stage * Fix case where a validator/leader need to immediately transition on startup after reading ledger and seeing they are not in the correct role * Set new leader in validator -> validator transitions * Clean up for PR comments, refactor LeaderScheduler from process_entry/process_ledger_tail * Cleaned out LeaderScheduler options, implemented LeaderScheduler strategy that only picks the bootstrap leader to support existing tests, drone/airdrops * Ignore test_full_leader_validator_network test due to bug where the next leader in line fails to get the last entry before rotation (b/c it hasn't started up yet). Added a test test_dropped_handoff_recovery go track this bug
2018-10-10 16:49:41 -07:00
pub fn is_exited(&self) -> bool {
self.exit.load(Ordering::Relaxed)
}
pub fn close(self) -> thread::Result<Option<TpuReturnType>> {
2018-07-09 13:53:18 -07:00
self.fetch_stage.close();
self.join()
}
}
impl Service for Tpu {
type JoinReturnType = Option<TpuReturnType>;
fn join(self) -> thread::Result<(Option<TpuReturnType>)> {
self.fetch_stage.join()?;
self.sigverify_stage.join()?;
match self.banking_stage.join()? {
Some(BankingStageReturnType::LeaderRotation) => Ok(Some(TpuReturnType::LeaderRotation)),
_ => Ok(None),
}
2018-05-14 16:36:19 -07:00
}
}