2018-12-06 12:52:47 -08:00
|
|
|
//! The `broadcast_service` broadcasts data from a leader node to validators
|
2018-08-09 11:54:23 -07:00
|
|
|
//!
|
2019-02-11 17:56:52 -08:00
|
|
|
use crate::blocktree::Blocktree;
|
2019-01-02 00:46:15 -08:00
|
|
|
use crate::cluster_info::{ClusterInfo, ClusterInfoError, NodeInfo, DATA_PLANE_FANOUT};
|
2018-12-07 19:16:27 -08:00
|
|
|
use crate::entry::Entry;
|
2019-01-09 14:33:44 -08:00
|
|
|
use crate::entry::EntrySlice;
|
2018-08-09 11:54:23 -07:00
|
|
|
#[cfg(feature = "erasure")]
|
2019-01-15 10:51:53 -08:00
|
|
|
use crate::erasure::CodingGenerator;
|
|
|
|
use crate::packet::index_blobs;
|
2018-12-07 19:16:27 -08:00
|
|
|
use crate::result::{Error, Result};
|
|
|
|
use crate::service::Service;
|
2018-09-18 21:45:49 -07:00
|
|
|
use rayon::prelude::*;
|
2019-02-18 22:26:22 -08:00
|
|
|
use solana_metrics::counter::Counter;
|
2018-11-16 08:45:59 -08:00
|
|
|
use solana_metrics::{influxdb, submit};
|
2019-02-18 22:26:22 -08:00
|
|
|
use solana_runtime::bank::Bank;
|
2018-11-15 13:23:26 -08:00
|
|
|
use solana_sdk::pubkey::Pubkey;
|
2018-11-16 08:45:59 -08:00
|
|
|
use solana_sdk::timing::duration_as_ms;
|
2018-08-09 11:54:23 -07:00
|
|
|
use std::net::UdpSocket;
|
2019-02-13 20:04:20 -08:00
|
|
|
use std::sync::atomic::{AtomicBool, Ordering};
|
2018-09-18 13:49:10 -07:00
|
|
|
use std::sync::mpsc::{Receiver, RecvTimeoutError};
|
2018-08-09 11:54:23 -07:00
|
|
|
use std::sync::{Arc, RwLock};
|
2018-08-09 14:17:50 -07:00
|
|
|
use std::thread::{self, Builder, JoinHandle};
|
2018-09-18 21:45:49 -07:00
|
|
|
use std::time::{Duration, Instant};
|
2018-08-09 11:54:23 -07:00
|
|
|
|
2018-09-14 00:17:40 -07:00
|
|
|
#[derive(Debug, PartialEq, Eq, Clone)]
|
2018-12-06 12:52:47 -08:00
|
|
|
pub enum BroadcastServiceReturnType {
|
2018-09-14 00:17:40 -07:00
|
|
|
LeaderRotation,
|
|
|
|
ChannelDisconnected,
|
2018-12-12 15:58:29 -08:00
|
|
|
ExitSignal,
|
2018-09-14 00:17:40 -07:00
|
|
|
}
|
|
|
|
|
2019-01-15 10:51:53 -08:00
|
|
|
struct Broadcast {
|
|
|
|
id: Pubkey,
|
|
|
|
blob_index: u64,
|
2018-12-12 15:58:29 -08:00
|
|
|
|
2019-01-15 10:51:53 -08:00
|
|
|
#[cfg(feature = "erasure")]
|
|
|
|
coding_generator: CodingGenerator,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Broadcast {
|
|
|
|
fn run(
|
|
|
|
&mut self,
|
2019-02-25 16:15:53 -08:00
|
|
|
slot_height: u64,
|
|
|
|
max_tick_height: u64,
|
2019-01-15 10:51:53 -08:00
|
|
|
broadcast_table: &[NodeInfo],
|
2019-02-25 13:50:31 -08:00
|
|
|
receiver: &Receiver<Vec<(Entry, u64)>>,
|
2019-01-15 10:51:53 -08:00
|
|
|
sock: &UdpSocket,
|
2019-02-11 17:56:52 -08:00
|
|
|
blocktree: &Arc<Blocktree>,
|
2019-01-15 10:51:53 -08:00
|
|
|
) -> Result<()> {
|
|
|
|
let timer = Duration::new(1, 0);
|
|
|
|
let entries = receiver.recv_timeout(timer)?;
|
|
|
|
let now = Instant::now();
|
|
|
|
let mut num_entries = entries.len();
|
|
|
|
let mut ventries = Vec::new();
|
2019-02-25 13:50:31 -08:00
|
|
|
let mut last_tick = entries.last().map(|v| v.1).unwrap_or(0);
|
2019-01-15 10:51:53 -08:00
|
|
|
ventries.push(entries);
|
2018-08-09 11:54:23 -07:00
|
|
|
|
2019-01-15 10:51:53 -08:00
|
|
|
while let Ok(entries) = receiver.try_recv() {
|
|
|
|
num_entries += entries.len();
|
2019-02-25 13:50:31 -08:00
|
|
|
last_tick = entries.last().map(|v| v.1).unwrap_or(0);
|
2019-01-15 10:51:53 -08:00
|
|
|
ventries.push(entries);
|
|
|
|
}
|
2018-11-13 02:21:37 -08:00
|
|
|
|
2019-01-15 10:51:53 -08:00
|
|
|
inc_new_counter_info!("broadcast_service-entries_received", num_entries);
|
2018-09-18 21:45:49 -07:00
|
|
|
|
2019-01-15 10:51:53 -08:00
|
|
|
let to_blobs_start = Instant::now();
|
2018-09-18 21:45:49 -07:00
|
|
|
|
2019-01-15 10:51:53 -08:00
|
|
|
let blobs: Vec<_> = ventries
|
|
|
|
.into_par_iter()
|
2019-02-25 13:50:31 -08:00
|
|
|
.flat_map(|p| {
|
|
|
|
let entries: Vec<_> = p.into_iter().map(|e| e.0).collect();
|
|
|
|
entries.to_shared_blobs()
|
|
|
|
})
|
2019-01-15 10:51:53 -08:00
|
|
|
.collect();
|
2018-08-09 11:54:23 -07:00
|
|
|
|
2019-01-15 10:51:53 -08:00
|
|
|
// TODO: blob_index should be slot-relative...
|
2019-02-25 16:15:53 -08:00
|
|
|
index_blobs(&blobs, &mut self.blob_index, slot_height);
|
2019-02-13 19:46:36 -08:00
|
|
|
let parent = {
|
2019-02-25 16:15:53 -08:00
|
|
|
if slot_height == 0 {
|
2019-02-13 19:46:36 -08:00
|
|
|
0
|
|
|
|
} else {
|
2019-02-25 16:15:53 -08:00
|
|
|
slot_height - 1
|
2019-02-13 19:46:36 -08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
for b in blobs.iter() {
|
|
|
|
b.write().unwrap().set_parent(parent);
|
|
|
|
}
|
2018-08-09 11:54:23 -07:00
|
|
|
|
2019-01-15 10:51:53 -08:00
|
|
|
let to_blobs_elapsed = duration_as_ms(&to_blobs_start.elapsed());
|
2018-08-09 11:54:23 -07:00
|
|
|
|
2019-01-15 10:51:53 -08:00
|
|
|
let broadcast_start = Instant::now();
|
2018-08-09 11:54:23 -07:00
|
|
|
|
2019-01-14 15:11:18 -08:00
|
|
|
inc_new_counter_info!("streamer-broadcast-sent", blobs.len());
|
2018-12-19 16:11:47 -08:00
|
|
|
|
2019-02-25 16:15:53 -08:00
|
|
|
assert!(last_tick <= max_tick_height);
|
|
|
|
let contains_last_tick = last_tick == max_tick_height;
|
2019-02-19 21:29:11 -08:00
|
|
|
|
2019-02-11 17:30:46 -08:00
|
|
|
if contains_last_tick {
|
2019-02-12 14:45:16 -08:00
|
|
|
blobs.last().unwrap().write().unwrap().set_is_last_in_slot();
|
2019-02-11 17:30:46 -08:00
|
|
|
}
|
|
|
|
|
2019-02-11 18:09:58 -08:00
|
|
|
blocktree.write_shared_blobs(&blobs)?;
|
2019-01-31 13:43:22 -08:00
|
|
|
|
2019-01-15 10:51:53 -08:00
|
|
|
// Send out data
|
2019-02-11 17:30:46 -08:00
|
|
|
ClusterInfo::broadcast(&self.id, contains_last_tick, &broadcast_table, sock, &blobs)?;
|
2018-08-09 11:54:23 -07:00
|
|
|
|
|
|
|
// Fill in the coding blob data from the window data blobs
|
|
|
|
#[cfg(feature = "erasure")]
|
|
|
|
{
|
2019-01-15 10:51:53 -08:00
|
|
|
let coding = self.coding_generator.next(&blobs)?;
|
|
|
|
|
|
|
|
// send out erasures
|
|
|
|
ClusterInfo::broadcast(&self.id, false, &broadcast_table, sock, &coding)?;
|
2018-08-09 11:54:23 -07:00
|
|
|
}
|
|
|
|
|
2019-01-15 10:51:53 -08:00
|
|
|
let broadcast_elapsed = duration_as_ms(&broadcast_start.elapsed());
|
|
|
|
|
|
|
|
inc_new_counter_info!(
|
|
|
|
"broadcast_service-time_ms",
|
|
|
|
duration_as_ms(&now.elapsed()) as usize
|
|
|
|
);
|
|
|
|
info!(
|
|
|
|
"broadcast: {} entries, blob time {} broadcast time {}",
|
|
|
|
num_entries, to_blobs_elapsed, broadcast_elapsed
|
|
|
|
);
|
|
|
|
|
|
|
|
submit(
|
|
|
|
influxdb::Point::new("broadcast-service")
|
|
|
|
.add_field(
|
|
|
|
"transmit-index",
|
|
|
|
influxdb::Value::Integer(self.blob_index as i64),
|
|
|
|
)
|
|
|
|
.to_owned(),
|
|
|
|
);
|
|
|
|
|
|
|
|
Ok(())
|
2018-08-09 11:54:23 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-06 12:52:47 -08:00
|
|
|
// Implement a destructor for the BroadcastService3 thread to signal it exited
|
2018-09-14 14:34:32 -07:00
|
|
|
// even on panics
|
|
|
|
struct Finalizer {
|
|
|
|
exit_sender: Arc<AtomicBool>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Finalizer {
|
|
|
|
fn new(exit_sender: Arc<AtomicBool>) -> Self {
|
|
|
|
Finalizer { exit_sender }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Implement a destructor for Finalizer.
|
|
|
|
impl Drop for Finalizer {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
self.exit_sender.clone().store(true, Ordering::Relaxed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-06 12:52:47 -08:00
|
|
|
pub struct BroadcastService {
|
|
|
|
thread_hdl: JoinHandle<BroadcastServiceReturnType>,
|
2018-08-09 14:17:50 -07:00
|
|
|
}
|
|
|
|
|
2018-12-06 12:52:47 -08:00
|
|
|
impl BroadcastService {
|
2019-02-07 15:10:54 -08:00
|
|
|
#[allow(clippy::too_many_arguments)]
|
2018-08-09 14:17:50 -07:00
|
|
|
fn run(
|
2019-02-25 16:15:53 -08:00
|
|
|
slot_height: u64,
|
2019-01-02 00:46:15 -08:00
|
|
|
bank: &Arc<Bank>,
|
2018-08-09 15:20:13 -07:00
|
|
|
sock: &UdpSocket,
|
2018-10-08 19:55:54 -07:00
|
|
|
cluster_info: &Arc<RwLock<ClusterInfo>>,
|
2019-02-07 15:10:54 -08:00
|
|
|
blob_index: u64,
|
2019-02-25 13:50:31 -08:00
|
|
|
receiver: &Receiver<Vec<(Entry, u64)>>,
|
2018-12-12 15:58:29 -08:00
|
|
|
exit_signal: &Arc<AtomicBool>,
|
2019-02-11 17:56:52 -08:00
|
|
|
blocktree: &Arc<Blocktree>,
|
2018-12-06 12:52:47 -08:00
|
|
|
) -> BroadcastServiceReturnType {
|
2019-01-14 15:11:18 -08:00
|
|
|
let me = cluster_info.read().unwrap().my_data().clone();
|
2019-01-15 10:51:53 -08:00
|
|
|
|
|
|
|
let mut broadcast = Broadcast {
|
|
|
|
id: me.id,
|
2019-02-07 15:10:54 -08:00
|
|
|
blob_index,
|
2019-01-15 10:51:53 -08:00
|
|
|
#[cfg(feature = "erasure")]
|
|
|
|
coding_generator: CodingGenerator::new(),
|
|
|
|
};
|
|
|
|
|
2019-02-25 16:15:53 -08:00
|
|
|
let max_tick_height = (slot_height + 1) * bank.ticks_per_slot() - 1;
|
|
|
|
|
2018-08-09 14:17:50 -07:00
|
|
|
loop {
|
2018-12-12 15:58:29 -08:00
|
|
|
if exit_signal.load(Ordering::Relaxed) {
|
|
|
|
return BroadcastServiceReturnType::ExitSignal;
|
|
|
|
}
|
2019-02-20 21:38:16 -08:00
|
|
|
let mut broadcast_table = cluster_info
|
|
|
|
.read()
|
|
|
|
.unwrap()
|
|
|
|
.sorted_tvu_peers(&bank.staked_nodes());
|
2019-01-15 10:51:53 -08:00
|
|
|
// Layer 1, leader nodes are limited to the fanout size.
|
2019-01-02 00:46:15 -08:00
|
|
|
broadcast_table.truncate(DATA_PLANE_FANOUT);
|
2018-12-10 14:24:32 -08:00
|
|
|
inc_new_counter_info!("broadcast_service-num_peers", broadcast_table.len() + 1);
|
2019-01-31 13:43:22 -08:00
|
|
|
if let Err(e) = broadcast.run(
|
2019-02-25 16:15:53 -08:00
|
|
|
slot_height,
|
|
|
|
max_tick_height,
|
2019-01-31 13:43:22 -08:00
|
|
|
&broadcast_table,
|
|
|
|
receiver,
|
|
|
|
sock,
|
2019-02-11 17:56:52 -08:00
|
|
|
blocktree,
|
2019-01-31 13:43:22 -08:00
|
|
|
) {
|
2018-08-09 14:17:50 -07:00
|
|
|
match e {
|
2019-02-01 12:03:14 -08:00
|
|
|
Error::RecvTimeoutError(RecvTimeoutError::Disconnected) | Error::SendError => {
|
2019-01-28 12:42:23 -08:00
|
|
|
return BroadcastServiceReturnType::ChannelDisconnected;
|
2018-09-14 00:17:40 -07:00
|
|
|
}
|
2018-08-09 14:17:50 -07:00
|
|
|
Error::RecvTimeoutError(RecvTimeoutError::Timeout) => (),
|
2018-10-08 19:55:54 -07:00
|
|
|
Error::ClusterInfoError(ClusterInfoError::NoPeers) => (), // TODO: Why are the unit-tests throwing hundreds of these?
|
2018-08-09 14:17:50 -07:00
|
|
|
_ => {
|
|
|
|
inc_new_counter_info!("streamer-broadcaster-error", 1, 1);
|
|
|
|
error!("broadcaster error: {:?}", e);
|
2018-08-09 11:54:23 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-08-09 14:17:50 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Service to broadcast messages from the leader to layer 1 nodes.
|
2018-10-08 19:55:54 -07:00
|
|
|
/// See `cluster_info` for network layer definitions.
|
2018-08-09 14:17:50 -07:00
|
|
|
/// # Arguments
|
|
|
|
/// * `sock` - Socket to send from.
|
|
|
|
/// * `exit` - Boolean to signal system exit.
|
2018-10-08 19:55:54 -07:00
|
|
|
/// * `cluster_info` - ClusterInfo structure
|
2018-08-09 14:17:50 -07:00
|
|
|
/// * `window` - Cache of blobs that we have broadcast
|
|
|
|
/// * `receiver` - Receive channel for blobs to be retransmitted to all the layer 1 nodes.
|
2018-12-06 12:52:47 -08:00
|
|
|
/// * `exit_sender` - Set to true when this service exits, allows rest of Tpu to exit cleanly.
|
|
|
|
/// Otherwise, when a Tpu closes, it only closes the stages that come after it. The stages
|
2018-09-14 14:34:32 -07:00
|
|
|
/// that come before could be blocked on a receive, and never notice that they need to
|
|
|
|
/// exit. Now, if any stage of the Tpu closes, it will lead to closing the WriteStage (b/c
|
2018-12-06 12:52:47 -08:00
|
|
|
/// WriteStage is the last stage in the pipeline), which will then close Broadcast service,
|
2018-09-14 14:34:32 -07:00
|
|
|
/// which will then close FetchStage in the Tpu, and then the rest of the Tpu,
|
|
|
|
/// completing the cycle.
|
2019-02-07 15:10:54 -08:00
|
|
|
#[allow(clippy::too_many_arguments)]
|
2018-08-09 14:17:50 -07:00
|
|
|
pub fn new(
|
2019-02-25 16:15:53 -08:00
|
|
|
slot_height: u64,
|
2019-01-02 00:46:15 -08:00
|
|
|
bank: Arc<Bank>,
|
2018-08-09 14:17:50 -07:00
|
|
|
sock: UdpSocket,
|
2018-10-08 19:55:54 -07:00
|
|
|
cluster_info: Arc<RwLock<ClusterInfo>>,
|
2019-02-07 15:10:54 -08:00
|
|
|
blob_index: u64,
|
2019-02-25 13:50:31 -08:00
|
|
|
receiver: Receiver<Vec<(Entry, u64)>>,
|
2018-09-14 14:34:32 -07:00
|
|
|
exit_sender: Arc<AtomicBool>,
|
2019-02-11 17:56:52 -08:00
|
|
|
blocktree: &Arc<Blocktree>,
|
2019-01-08 20:11:04 -08:00
|
|
|
) -> Self {
|
2018-12-12 15:58:29 -08:00
|
|
|
let exit_signal = Arc::new(AtomicBool::new(false));
|
2019-02-11 17:56:52 -08:00
|
|
|
let blocktree = blocktree.clone();
|
2018-08-09 14:17:50 -07:00
|
|
|
let thread_hdl = Builder::new()
|
|
|
|
.name("solana-broadcaster".to_string())
|
2018-09-14 14:34:32 -07:00
|
|
|
.spawn(move || {
|
|
|
|
let _exit = Finalizer::new(exit_sender);
|
2018-11-07 13:18:14 -08:00
|
|
|
Self::run(
|
2019-02-25 16:15:53 -08:00
|
|
|
slot_height,
|
2019-01-02 00:46:15 -08:00
|
|
|
&bank,
|
2018-11-07 13:18:14 -08:00
|
|
|
&sock,
|
|
|
|
&cluster_info,
|
2019-02-07 15:10:54 -08:00
|
|
|
blob_index,
|
2018-11-07 13:18:14 -08:00
|
|
|
&receiver,
|
2019-01-08 20:11:04 -08:00
|
|
|
&exit_signal,
|
2019-02-11 17:56:52 -08:00
|
|
|
&blocktree,
|
2018-11-07 13:18:14 -08:00
|
|
|
)
|
2018-12-07 19:01:28 -08:00
|
|
|
})
|
|
|
|
.unwrap();
|
2018-08-09 14:17:50 -07:00
|
|
|
|
2019-01-08 20:11:04 -08:00
|
|
|
Self { thread_hdl }
|
2018-08-09 14:17:50 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-06 12:52:47 -08:00
|
|
|
impl Service for BroadcastService {
|
|
|
|
type JoinReturnType = BroadcastServiceReturnType;
|
2018-08-09 14:17:50 -07:00
|
|
|
|
2018-12-06 12:52:47 -08:00
|
|
|
fn join(self) -> thread::Result<BroadcastServiceReturnType> {
|
2018-09-14 00:17:40 -07:00
|
|
|
self.thread_hdl.join()
|
2018-08-09 14:17:50 -07:00
|
|
|
}
|
2018-08-09 11:54:23 -07:00
|
|
|
}
|
2018-12-12 15:58:29 -08:00
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod test {
|
|
|
|
use super::*;
|
2019-02-26 17:11:26 -08:00
|
|
|
use crate::blocktree::{get_tmp_ledger_path, Blocktree};
|
2018-12-12 15:58:29 -08:00
|
|
|
use crate::cluster_info::{ClusterInfo, Node};
|
2019-01-09 14:33:44 -08:00
|
|
|
use crate::entry::create_ticks;
|
2019-02-25 16:15:53 -08:00
|
|
|
use crate::leader_scheduler::LeaderScheduler;
|
2018-12-12 15:58:29 -08:00
|
|
|
use crate::service::Service;
|
|
|
|
use solana_sdk::hash::Hash;
|
|
|
|
use solana_sdk::signature::{Keypair, KeypairUtil};
|
2019-02-22 19:50:59 -08:00
|
|
|
use solana_sdk::timing::DEFAULT_TICKS_PER_SLOT;
|
2018-12-12 15:58:29 -08:00
|
|
|
use std::sync::atomic::AtomicBool;
|
|
|
|
use std::sync::mpsc::channel;
|
|
|
|
use std::sync::{Arc, RwLock};
|
|
|
|
use std::thread::sleep;
|
|
|
|
use std::time::Duration;
|
|
|
|
|
2019-01-08 20:11:04 -08:00
|
|
|
struct MockBroadcastService {
|
2019-02-07 20:52:39 -08:00
|
|
|
blocktree: Arc<Blocktree>,
|
2018-12-12 15:58:29 -08:00
|
|
|
broadcast_service: BroadcastService,
|
|
|
|
}
|
|
|
|
|
|
|
|
fn setup_dummy_broadcast_service(
|
2019-02-25 16:15:53 -08:00
|
|
|
slot_height: u64,
|
2018-12-12 15:58:29 -08:00
|
|
|
leader_pubkey: Pubkey,
|
|
|
|
ledger_path: &str,
|
2019-02-25 13:50:31 -08:00
|
|
|
entry_receiver: Receiver<Vec<(Entry, u64)>>,
|
2019-02-07 15:10:54 -08:00
|
|
|
blob_index: u64,
|
2019-01-08 20:11:04 -08:00
|
|
|
) -> MockBroadcastService {
|
2018-12-12 15:58:29 -08:00
|
|
|
// Make the database ledger
|
2019-02-07 20:52:39 -08:00
|
|
|
let blocktree = Arc::new(Blocktree::open(ledger_path).unwrap());
|
2018-12-12 15:58:29 -08:00
|
|
|
|
|
|
|
// Make the leader node and scheduler
|
|
|
|
let leader_info = Node::new_localhost_with_pubkey(leader_pubkey);
|
|
|
|
|
|
|
|
// Make a node to broadcast to
|
|
|
|
let buddy_keypair = Keypair::new();
|
|
|
|
let broadcast_buddy = Node::new_localhost_with_pubkey(buddy_keypair.pubkey());
|
|
|
|
|
|
|
|
// Fill the cluster_info with the buddy's info
|
|
|
|
let mut cluster_info = ClusterInfo::new(leader_info.info.clone());
|
|
|
|
cluster_info.insert_info(broadcast_buddy.info);
|
|
|
|
let cluster_info = Arc::new(RwLock::new(cluster_info));
|
|
|
|
|
|
|
|
let exit_sender = Arc::new(AtomicBool::new(false));
|
2019-01-02 00:46:15 -08:00
|
|
|
let bank = Arc::new(Bank::default());
|
2018-12-12 15:58:29 -08:00
|
|
|
|
|
|
|
// Start up the broadcast stage
|
2019-01-08 20:11:04 -08:00
|
|
|
let broadcast_service = BroadcastService::new(
|
2019-02-25 16:15:53 -08:00
|
|
|
slot_height,
|
2019-01-02 00:46:15 -08:00
|
|
|
bank.clone(),
|
2018-12-12 15:58:29 -08:00
|
|
|
leader_info.sockets.broadcast,
|
|
|
|
cluster_info,
|
2019-02-07 15:10:54 -08:00
|
|
|
blob_index,
|
2018-12-12 15:58:29 -08:00
|
|
|
entry_receiver,
|
|
|
|
exit_sender,
|
2019-02-11 17:56:52 -08:00
|
|
|
&blocktree,
|
2018-12-12 15:58:29 -08:00
|
|
|
);
|
|
|
|
|
2019-01-08 20:11:04 -08:00
|
|
|
MockBroadcastService {
|
2019-02-07 20:52:39 -08:00
|
|
|
blocktree,
|
2018-12-12 15:58:29 -08:00
|
|
|
broadcast_service,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2019-01-26 00:28:08 -08:00
|
|
|
#[ignore]
|
|
|
|
//TODO this test won't work since broadcast stage no longer edits the ledger
|
2018-12-12 15:58:29 -08:00
|
|
|
fn test_broadcast_ledger() {
|
2019-02-07 15:10:54 -08:00
|
|
|
let ledger_path = get_tmp_ledger_path("test_broadcast_ledger");
|
2018-12-12 15:58:29 -08:00
|
|
|
{
|
|
|
|
// Create the leader scheduler
|
|
|
|
let leader_keypair = Keypair::new();
|
2019-02-05 08:03:52 -08:00
|
|
|
let mut leader_scheduler = LeaderScheduler::default();
|
2018-12-12 15:58:29 -08:00
|
|
|
|
|
|
|
// Mock the tick height to look like the tick height right after a leader transition
|
|
|
|
leader_scheduler.set_leader_schedule(vec![leader_keypair.pubkey()]);
|
2019-02-05 08:03:52 -08:00
|
|
|
let start_tick_height = 0;
|
2019-02-22 19:50:59 -08:00
|
|
|
let max_tick_height = start_tick_height + DEFAULT_TICKS_PER_SLOT;
|
2018-12-12 15:58:29 -08:00
|
|
|
|
2019-01-08 20:11:04 -08:00
|
|
|
let (entry_sender, entry_receiver) = channel();
|
2018-12-12 15:58:29 -08:00
|
|
|
let broadcast_service = setup_dummy_broadcast_service(
|
2019-02-25 16:15:53 -08:00
|
|
|
0,
|
2018-12-12 15:58:29 -08:00
|
|
|
leader_keypair.pubkey(),
|
|
|
|
&ledger_path,
|
2019-01-08 20:11:04 -08:00
|
|
|
entry_receiver,
|
2019-02-07 15:10:54 -08:00
|
|
|
0,
|
2018-12-12 15:58:29 -08:00
|
|
|
);
|
|
|
|
|
2019-01-28 10:29:42 -08:00
|
|
|
let ticks = create_ticks(max_tick_height - start_tick_height, Hash::default());
|
2019-02-25 13:50:31 -08:00
|
|
|
for (i, tick) in ticks.into_iter().enumerate() {
|
2019-01-08 20:11:04 -08:00
|
|
|
entry_sender
|
2019-02-25 13:50:31 -08:00
|
|
|
.send(vec![(tick, i as u64 + 1)])
|
2018-12-12 15:58:29 -08:00
|
|
|
.expect("Expect successful send to broadcast service");
|
|
|
|
}
|
|
|
|
|
|
|
|
sleep(Duration::from_millis(2000));
|
2019-02-07 20:52:39 -08:00
|
|
|
let blocktree = broadcast_service.blocktree;
|
2019-02-07 15:10:54 -08:00
|
|
|
let mut blob_index = 0;
|
2018-12-12 15:58:29 -08:00
|
|
|
for i in 0..max_tick_height - start_tick_height {
|
2019-02-25 16:15:53 -08:00
|
|
|
let slot = leader_scheduler.tick_height_to_slot(start_tick_height + i + 1);
|
2018-12-12 15:58:29 -08:00
|
|
|
|
2019-02-07 20:52:39 -08:00
|
|
|
let result = blocktree.get_data_blob(slot, blob_index).unwrap();
|
2019-02-07 15:10:54 -08:00
|
|
|
|
|
|
|
blob_index += 1;
|
2018-12-12 15:58:29 -08:00
|
|
|
assert!(result.is_some());
|
|
|
|
}
|
|
|
|
|
2019-01-08 20:11:04 -08:00
|
|
|
drop(entry_sender);
|
2018-12-12 15:58:29 -08:00
|
|
|
broadcast_service
|
|
|
|
.broadcast_service
|
|
|
|
.join()
|
|
|
|
.expect("Expect successful join of broadcast service");
|
|
|
|
}
|
|
|
|
|
2019-02-07 20:52:39 -08:00
|
|
|
Blocktree::destroy(&ledger_path).expect("Expected successful database destruction");
|
2018-12-12 15:58:29 -08:00
|
|
|
}
|
|
|
|
}
|