From d7ffab50dc5a3ebec1a23e0006cb053a01a999d1 Mon Sep 17 00:00:00 2001 From: Ashwin Sekar Date: Mon, 11 Dec 2023 16:03:51 +0000 Subject: [PATCH] pr feedback: reuse fn, remove redundant clones --- core/src/window_service.rs | 32 ++++++++++---------------------- turbine/src/cluster_nodes.rs | 2 +- 2 files changed, 11 insertions(+), 23 deletions(-) diff --git a/core/src/window_service.rs b/core/src/window_service.rs index 0fe9c70367be29..a36692cc7ef3ab 100644 --- a/core/src/window_service.rs +++ b/core/src/window_service.rs @@ -1,6 +1,7 @@ //! `window_service` handles the data plane incoming shreds, storing them in //! blockstore and retransmitting where required //! + use { crate::{ cluster_info_vote_listener::VerifiedVoteReceiver, @@ -28,11 +29,12 @@ use { solana_metrics::inc_new_counter_error, solana_perf::packet::{Packet, PacketBatch}, solana_rayon_threadlimit::get_thread_count, - solana_runtime::{bank::Bank, bank_forks::BankForks}, + solana_runtime::bank_forks::BankForks, solana_sdk::{ clock::{Slot, DEFAULT_MS_PER_SLOT}, feature_set, }, + solana_turbine::cluster_nodes, std::{ cmp::Reverse, collections::{HashMap, HashSet}, @@ -141,23 +143,6 @@ impl WindowServiceMetrics { } } -fn should_send_index_and_erasure_conflicts(shred_slot: Slot, root_bank: &Arc) -> bool { - match root_bank - .feature_set - .activated_slot(&feature_set::index_erasure_conflict_duplicate_proofs::id()) - { - None => false, - Some(feature_slot) => { - let epoch_schedule = root_bank.epoch_schedule(); - let feature_epoch = epoch_schedule.get_epoch(feature_slot); - let shred_epoch = epoch_schedule.get_epoch(shred_slot); - // Has a 1 epoch delay, as we don't have enough information - // on the epoch boundary of the feature activation - feature_epoch < shred_epoch - } - } -} - fn run_check_duplicate( cluster_info: &ClusterInfo, blockstore: &Blockstore, @@ -165,17 +150,20 @@ fn run_check_duplicate( duplicate_slots_sender: &DuplicateSlotSender, bank_forks: &RwLock, ) -> Result<()> { - let mut root_bank = bank_forks.read().unwrap().root_bank().clone(); + let mut root_bank = bank_forks.read().unwrap().root_bank(); let mut last_updated = Instant::now(); let check_duplicate = |shred: PossibleDuplicateShred| -> Result<()> { if last_updated.elapsed().as_millis() as u64 > DEFAULT_MS_PER_SLOT { // Grabs bank forks lock once a slot last_updated = Instant::now(); - root_bank = bank_forks.read().unwrap().root_bank().clone(); + root_bank = bank_forks.read().unwrap().root_bank(); } let shred_slot = shred.slot(); - let send_index_and_erasure_conflicts = - should_send_index_and_erasure_conflicts(shred_slot, &root_bank); + let send_index_and_erasure_conflicts = cluster_nodes::check_feature_activation( + &feature_set::index_erasure_conflict_duplicate_proofs::id(), + shred_slot, + &root_bank, + ); let (shred1, shred2) = match shred { PossibleDuplicateShred::LastIndexConflict(shred, conflict) | PossibleDuplicateShred::ErasureConflict(shred, conflict) => { diff --git a/turbine/src/cluster_nodes.rs b/turbine/src/cluster_nodes.rs index 57676a34b75eff..124d6d8c99cca1 100644 --- a/turbine/src/cluster_nodes.rs +++ b/turbine/src/cluster_nodes.rs @@ -513,7 +513,7 @@ fn enable_turbine_fanout_experiments(shred_slot: Slot, root_bank: &Bank) -> bool // Returns true if the feature is effective for the shred slot. #[must_use] -fn check_feature_activation(feature: &Pubkey, shred_slot: Slot, root_bank: &Bank) -> bool { +pub fn check_feature_activation(feature: &Pubkey, shred_slot: Slot, root_bank: &Bank) -> bool { match root_bank.feature_set.activated_slot(feature) { None => false, Some(feature_slot) => {