Skip to content

Commit

Permalink
Add Avalanche Simulation (#2727)
Browse files Browse the repository at this point in the history
- No packet drops yet
- Optimistic retransmits without leader-id
  • Loading branch information
sagar-solana authored Feb 12, 2019
1 parent 144d321 commit 2e1dcd8
Show file tree
Hide file tree
Showing 6 changed files with 267 additions and 45 deletions.
23 changes: 19 additions & 4 deletions src/cluster_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ use solana_sdk::signature::{Keypair, KeypairUtil, Signable, Signature};
use solana_sdk::timing::{duration_as_ms, timestamp};
use solana_sdk::transaction::Transaction;
use std::cmp::min;
use std::fmt;
use std::io;
use std::net::{IpAddr, Ipv4Addr, SocketAddr, UdpSocket};
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
Expand Down Expand Up @@ -66,7 +67,7 @@ pub enum ClusterInfoError {
BadNodeInfo,
BadGossipAddress,
}

#[derive(Clone)]
pub struct ClusterInfo {
/// The network
pub gossip: CrdsGossip,
Expand All @@ -88,6 +89,16 @@ pub struct Locality {
pub child_layer_peers: Vec<usize>,
}

impl fmt::Debug for Locality {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"Packet {{ neighborhood_bounds: {:?}, current_layer: {:?}, child_layer_bounds: {:?} child_layer_peers: {:?} }}",
self.neighbor_bounds, self.layer_ix, self.child_layer_bounds, self.child_layer_peers
)
}
}

#[derive(Debug, Deserialize, Serialize)]
pub struct PruneData {
/// Pubkey of the node that sent this prune data
Expand Down Expand Up @@ -358,6 +369,7 @@ impl ClusterInfo {
.map(|c| (bank.get_balance(&c.id), c.clone()))
.collect();
peers_with_stakes.sort_unstable();
peers_with_stakes.reverse();
peers_with_stakes
}

Expand Down Expand Up @@ -655,11 +667,14 @@ impl ClusterInfo {
.collect()
}

fn create_broadcast_orders<'a>(
pub fn create_broadcast_orders<'a, T>(
contains_last_tick: bool,
blobs: &[SharedBlob],
blobs: &[T],
broadcast_table: &'a [NodeInfo],
) -> Vec<(SharedBlob, Vec<&'a NodeInfo>)> {
) -> Vec<(T, Vec<&'a NodeInfo>)>
where
T: Clone,
{
// enumerate all the blobs in the window, those are the indices
// transmit them to nodes, starting from a different node.
if blobs.is_empty() {
Expand Down
3 changes: 2 additions & 1 deletion src/crds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use solana_sdk::hash::{hash, Hash};
use solana_sdk::pubkey::Pubkey;
use std::cmp;

#[derive(Clone)]
pub struct Crds {
/// Stores the map of labels and values
pub table: IndexMap<CrdsValueLabel, VersionedCrdsValue>,
Expand All @@ -44,7 +45,7 @@ pub enum CrdsError {
/// This structure stores some local metadata associated with the CrdsValue
/// The implementation of PartialOrd ensures that the "highest" version is always picked to be
/// stored in the Crds
#[derive(PartialEq, Debug)]
#[derive(PartialEq, Debug, Clone)]
pub struct VersionedCrdsValue {
pub value: CrdsValue,
/// local time when inserted
Expand Down
1 change: 1 addition & 0 deletions src/crds_gossip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use solana_sdk::pubkey::Pubkey;
///The min size for bloom filters
pub const CRDS_GOSSIP_BLOOM_SIZE: usize = 1000;

#[derive(Clone)]
pub struct CrdsGossip {
pub crds: Crds,
pub id: Pubkey,
Expand Down
1 change: 1 addition & 0 deletions src/crds_gossip_pull.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use std::collections::VecDeque;

pub const CRDS_GOSSIP_PULL_CRDS_TIMEOUT_MS: u64 = 15000;

#[derive(Clone)]
pub struct CrdsGossipPull {
/// timestamp of last request
pub pull_request_time: HashMap<Pubkey, u64>,
Expand Down
1 change: 1 addition & 0 deletions src/crds_gossip_push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub const CRDS_GOSSIP_PUSH_FANOUT: usize = 6;
pub const CRDS_GOSSIP_PUSH_MSG_TIMEOUT_MS: u64 = 5000;
pub const CRDS_GOSSIP_PRUNE_MSG_TIMEOUT_MS: u64 = 500;

#[derive(Clone)]
pub struct CrdsGossipPush {
/// max bytes per message
pub max_bytes: usize,
Expand Down
Loading

0 comments on commit 2e1dcd8

Please sign in to comment.