Skip to content

Commit

Permalink
filters out offline nodes from pull options
Browse files Browse the repository at this point in the history
Inactive nodes are still observing incoming gossip traffic:
https://discord.com/channels/428295358100013066/670512312339398668/776140351291260968
likely because of pull-requests.

Previous related issues and commits:
solana-labs#12409
solana-labs#12620
solana-labs#12674

This commit implements same logic as
solana-labs#12674
to exclude inactive nodes from pull options, with the same periodic
retry logic for offline staked nodes in order to mitigate eclipse
attack.
  • Loading branch information
behzadnouri committed Nov 11, 2020
1 parent 38f15e4 commit 14a35dd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
34 changes: 26 additions & 8 deletions core/src/crds_gossip_pull.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ pub const CRDS_GOSSIP_PULL_CRDS_TIMEOUT_MS: u64 = 15000;
pub const CRDS_GOSSIP_PULL_MSG_TIMEOUT_MS: u64 = 60000;
// Retention period of hashes of received outdated values.
const FAILED_INSERTS_RETENTION_MS: u64 = 20_000;
// Do not pull from peers which have not been updated for this long.
const PULL_ACTIVE_TIMEOUT_MS: u64 = 60_000;
pub const FALSE_RATE: f64 = 0.1f64;
pub const KEYS: f64 = 8f64;

Expand Down Expand Up @@ -238,9 +240,23 @@ impl CrdsGossipPull {
gossip_validators: Option<&HashSet<Pubkey>>,
stakes: &HashMap<Pubkey, u64>,
) -> Vec<(f32, &'a ContactInfo)> {
let mut rng = rand::thread_rng();
let active_cutoff = now.saturating_sub(PULL_ACTIVE_TIMEOUT_MS);
crds.table
.values()
.filter_map(|v| v.value.contact_info())
.filter_map(|value| {
let info = value.value.contact_info()?;
// Stop pulling from nodes which have not been active recently.
if value.local_timestamp < active_cutoff {
// In order to mitigate eclipse attack, for staked nodes
// continue retrying periodically.
let stake = stakes.get(&info.id).unwrap_or(&0);
if *stake == 0 || !rng.gen_ratio(1, 16) {
return None;
}
}
Some(info)
})
.filter(|v| {
v.id != *self_id
&& ContactInfo::is_valid_address(&v.gossip)
Expand Down Expand Up @@ -949,6 +965,7 @@ mod test {

#[test]
fn test_new_mark_creation_time() {
let now: u64 = 1_605_127_770_789;
let thread_pool = ThreadPoolBuilder::new().build().unwrap();
let mut crds = Crds::default();
let entry = CrdsValue::new_unsigned(CrdsData::ContactInfo(ContactInfo::new_localhost(
Expand All @@ -957,29 +974,30 @@ mod test {
)));
let node_pubkey = entry.label().pubkey();
let mut node = CrdsGossipPull::default();
crds.insert(entry.clone(), 0).unwrap();
crds.insert(entry.clone(), now).unwrap();
let old = CrdsValue::new_unsigned(CrdsData::ContactInfo(ContactInfo::new_localhost(
&solana_sdk::pubkey::new_rand(),
0,
)));
crds.insert(old.clone(), 0).unwrap();
crds.insert(old.clone(), now).unwrap();
let new = CrdsValue::new_unsigned(CrdsData::ContactInfo(ContactInfo::new_localhost(
&solana_sdk::pubkey::new_rand(),
0,
)));
crds.insert(new.clone(), 0).unwrap();
crds.insert(new.clone(), now).unwrap();

// set request creation time to max_value
node.mark_pull_request_creation_time(&new.label().pubkey(), u64::max_value());
// set request creation time to now.
let now = now + PULL_ACTIVE_TIMEOUT_MS - 100;
node.mark_pull_request_creation_time(&new.label().pubkey(), now);

// odds of getting the other request should be 1 in u64::max_value()
// odds of getting the other request should be close to 1.
for _ in 0..10 {
let req = node.new_pull_request(
&thread_pool,
&crds,
&node_pubkey,
0,
u64::max_value(),
now,
None,
&HashMap::new(),
PACKET_DATA_SIZE,
Expand Down
2 changes: 1 addition & 1 deletion core/src/crds_gossip_push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ impl CrdsGossipPush {
// In order to mitigate eclipse attack, for staked nodes
// continue retrying periodically.
let stake = stakes.get(&info.id).unwrap_or(&0);
if *stake == 0 || rng.gen_ratio(7, 8) {
if *stake == 0 || !rng.gen_ratio(1, 16) {
return None;
}
}
Expand Down

0 comments on commit 14a35dd

Please sign in to comment.