Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions src/choose_gossip_peer_strategy.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crdt::ReplicatedData;
use rand::distributions::{IndependentSample, Weighted, WeightedChoice};
use rand::distributions::{Distribution, Weighted, WeightedChoice};
use rand::thread_rng;
use result::{Error, Result};
use signature::PublicKey;
Expand Down Expand Up @@ -37,26 +37,26 @@ impl<'a> ChooseGossipPeerStrategy for ChooseRandomPeerStrategy<'a> {
}
}

// This strategy uses rumors accumulated from the rest of the network to weight
// the importance of communicating with a particular validator based on cumulative network
// This strategy uses rumors accumulated from the rest of the network to weight
// the importance of communicating with a particular validator based on cumulative network
// perceiption of the number of updates the validator has to offer. A validator is randomly
// picked based on a weighted sample from the pool of viable choices. The "weight", w, of a
// particular validator "v" is calculated as follows:
//
// w = [Sum for all i in I_v: (rumor_v(i) - observed(v)) * stake(i)] /
//
// w = [Sum for all i in I_v: (rumor_v(i) - observed(v)) * stake(i)] /
// [Sum for all i in I_v: Sum(stake(i))]
//
// where I_v is the set of all validators that returned a rumor about the update_index of
// validator "v", stake(i) is the size of the stake of validator "i", observed(v) is the
// observed update_index from the last direct communication validator "v", and
// observed update_index from the last direct communication validator "v", and
// rumor_v(i) is the rumored update_index of validator "v" propagated by fellow validator "i".

// This could be a problem if there are validators with large stakes lying about their
// observed updates. There could also be a problem in network partitions, or even just
// observed updates. There could also be a problem in network partitions, or even just
// when certain validators are disproportionately active, where we hear more rumors about
// certain clusters of nodes that then propagate more rumros about each other. Hopefully
// this can be resolved with a good baseline DEFAULT_WEIGHT, or by implementing lockout
// periods for very active validators in the future.
// this can be resolved with a good baseline DEFAULT_WEIGHT, or by implementing lockout
// periods for very active validators in the future.

pub struct ChooseWeightedPeerStrategy<'a> {
// The map of last directly observed update_index for each active validator.
Expand Down Expand Up @@ -184,7 +184,7 @@ impl<'a> ChooseGossipPeerStrategy for ChooseWeightedPeerStrategy<'a> {
}

let mut rng = thread_rng();
Ok(WeightedChoice::new(&mut weighted_peers).ind_sample(&mut rng))
Ok(WeightedChoice::new(&mut weighted_peers).sample(&mut rng))
}
}

Expand All @@ -196,8 +196,8 @@ mod tests {
use std;
use std::collections::HashMap;

fn get_stake(id: PublicKey) -> f64 {
return 1.0;
fn get_stake(_id: PublicKey) -> f64 {
1.0
}

#[test]
Expand Down Expand Up @@ -315,7 +315,7 @@ mod tests {

remote.insert(key1, old_index);

for i in 0..num_peers {
for _i in 0..num_peers {
let pk = KeyPair::new().pubkey();
rumors.insert(pk, old_index);
}
Expand Down
6 changes: 2 additions & 4 deletions src/crdt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@

use bincode::{deserialize, serialize};
use byteorder::{LittleEndian, ReadBytesExt};
use choose_gossip_peer_strategy::{
ChooseGossipPeerStrategy, ChooseRandomPeerStrategy, ChooseWeightedPeerStrategy,
};
use choose_gossip_peer_strategy::{ChooseGossipPeerStrategy, ChooseWeightedPeerStrategy};
use hash::Hash;
use packet::{to_blob, Blob, BlobRecycler, SharedBlob, BLOB_SIZE};
use pnet_datalink as datalink;
Expand Down Expand Up @@ -491,7 +489,7 @@ impl Crdt {
}

// TODO: fill in with real implmentation once staking is implemented
fn get_stake(id: PublicKey) -> f64 {
fn get_stake(_id: PublicKey) -> f64 {
1.0
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub mod bank;
pub mod banking_stage;
pub mod blob_fetch_stage;
pub mod budget;
mod choose_gossip_peer_strategy;
pub mod choose_gossip_peer_strategy;
pub mod crdt;
pub mod drone;
pub mod entry;
Expand Down