Skip to content

Commit

Permalink
v1.16: removes outdated check for merkle shreds (backport of #33088) (#…
Browse files Browse the repository at this point in the history
…33136)

* removes outdated check for merkle shreds (#33088)
* Add back deleted features to keep feature set id unchaged
* Use root_bank.slot() to update last_root to avoid unused variable

(cherry picked from commit 1431275)

# Conflicts:
#	core/src/cluster_nodes.rs
#	core/src/shred_fetch_stage.rs

---------

Co-authored-by: behzad nouri <[email protected]>
Co-authored-by: Steven Czabaniuk <[email protected]>
  • Loading branch information
3 people authored Sep 5, 2023
1 parent 6b8f836 commit ea03d6c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 66 deletions.
6 changes: 1 addition & 5 deletions core/src/cluster_nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -576,11 +576,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]
pub(crate) fn check_feature_activation(
feature: &Pubkey,
shred_slot: Slot,
root_bank: &Bank,
) -> bool {
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) => {
Expand Down
49 changes: 6 additions & 43 deletions core/src/shred_fetch_stage.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
//! The `shred_fetch_stage` pulls shreds from UDP sockets and sends it to a channel.
use {
crate::{cluster_nodes::check_feature_activation, serve_repair::ServeRepair},
crate::serve_repair::ServeRepair,
crossbeam_channel::{unbounded, Sender},
solana_gossip::cluster_info::ClusterInfo,
solana_ledger::shred::{should_discard_shred, ShredFetchStats},
solana_perf::packet::{PacketBatch, PacketBatchRecycler, PacketFlags},
solana_runtime::{bank::Bank, bank_forks::BankForks},
solana_sdk::{
clock::{Slot, DEFAULT_MS_PER_SLOT},
feature_set,
},
solana_runtime::bank_forks::BankForks,
solana_sdk::clock::DEFAULT_MS_PER_SLOT,
solana_streamer::streamer::{self, PacketBatchReceiver, StreamerReceiveStats},
std::{
net::UdpSocket,
Expand Down Expand Up @@ -47,7 +44,7 @@ impl ShredFetchStage {

// In the case of bank_forks=None, setup to accept any slot range
let mut root_bank = bank_forks.read().unwrap().root_bank();
let mut last_root = 0;
let mut last_root = root_bank.slot();
let mut last_slot = std::u64::MAX;
let mut slots_per_epoch = 0;

Expand Down Expand Up @@ -85,19 +82,10 @@ impl ShredFetchStage {

// Limit shreds to 2 epochs away.
let max_slot = last_slot + 2 * slots_per_epoch;
let should_drop_merkle_shreds =
|shred_slot| should_drop_merkle_shreds(shred_slot, &root_bank);
let turbine_disabled = turbine_disabled.load(Ordering::Relaxed);
for packet in packet_batch.iter_mut().filter(|p| !p.meta().discard()) {
if turbine_disabled
|| should_discard_shred(
packet,
last_root,
max_slot,
shred_version,
should_drop_merkle_shreds,
&mut stats,
)
|| should_discard_shred(packet, last_root, max_slot, shred_version, &mut stats)
{
packet.meta_mut().set_discard(true);
} else {
Expand Down Expand Up @@ -232,19 +220,6 @@ impl ShredFetchStage {
}
}

#[must_use]
fn should_drop_merkle_shreds(shred_slot: Slot, root_bank: &Bank) -> bool {
check_feature_activation(
&feature_set::keep_merkle_shreds::id(),
shred_slot,
root_bank,
) && !check_feature_activation(
&feature_set::drop_merkle_shreds::id(),
shred_slot,
root_bank,
)
}

#[cfg(test)]
mod tests {
use {
Expand Down Expand Up @@ -285,7 +260,6 @@ mod tests {
last_root,
max_slot,
shred_version,
|_| false, // should_drop_merkle_shreds
&mut stats,
));
let coding = solana_ledger::shred::Shredder::generate_coding_shreds(
Expand All @@ -299,7 +273,6 @@ mod tests {
last_root,
max_slot,
shred_version,
|_| false, // should_drop_merkle_shreds
&mut stats,
));
}
Expand All @@ -321,7 +294,6 @@ mod tests {
last_root,
max_slot,
shred_version,
|_| false, // should_drop_merkle_shreds
&mut stats,
));
assert_eq!(stats.index_overrun, 1);
Expand All @@ -343,18 +315,12 @@ mod tests {
3,
max_slot,
shred_version,
|_| false, // should_drop_merkle_shreds
&mut stats,
));
assert_eq!(stats.slot_out_of_range, 1);

assert!(should_discard_shred(
&packet,
last_root,
max_slot,
345, // shred_version
|_| false, // should_drop_merkle_shreds
&mut stats,
&packet, last_root, max_slot, /*shred_version:*/ 345, &mut stats,
));
assert_eq!(stats.shred_version_mismatch, 1);

Expand All @@ -364,7 +330,6 @@ mod tests {
last_root,
max_slot,
shred_version,
|_| false, // should_drop_merkle_shreds
&mut stats,
));

Expand All @@ -386,7 +351,6 @@ mod tests {
last_root,
max_slot,
shred_version,
|_| false, // should_drop_merkle_shreds
&mut stats,
));

Expand All @@ -398,7 +362,6 @@ mod tests {
last_root,
max_slot,
shred_version,
|_| false, // should_drop_merkle_shreds
&mut stats,
));
}
Expand Down
18 changes: 0 additions & 18 deletions ledger/src/shred.rs
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,6 @@ pub fn should_discard_shred(
root: Slot,
max_slot: Slot,
shred_version: u16,
should_drop_merkle_shreds: impl Fn(Slot) -> bool,
stats: &mut ShredFetchStats,
) -> bool {
debug_assert!(root < max_slot);
Expand Down Expand Up @@ -984,15 +983,9 @@ pub fn should_discard_shred(
match shred_variant {
ShredVariant::LegacyCode | ShredVariant::LegacyData => (),
ShredVariant::MerkleCode(_) => {
if should_drop_merkle_shreds(slot) {
return true;
}
stats.num_shreds_merkle_code = stats.num_shreds_merkle_code.saturating_add(1);
}
ShredVariant::MerkleData(_) => {
if should_drop_merkle_shreds(slot) {
return true;
}
stats.num_shreds_merkle_data = stats.num_shreds_merkle_data.saturating_add(1);
}
}
Expand Down Expand Up @@ -1192,7 +1185,6 @@ mod tests {
root,
max_slot,
shred_version,
|_| false, // should_drop_merkle_shreds
&mut stats
));
assert_eq!(stats, ShredFetchStats::default());
Expand All @@ -1203,7 +1195,6 @@ mod tests {
root,
max_slot,
shred_version,
|_| false, // should_drop_merkle_shreds
&mut stats
));
assert_eq!(stats.index_overrun, 1);
Expand All @@ -1214,7 +1205,6 @@ mod tests {
root,
max_slot,
shred_version,
|_| false, // should_drop_merkle_shreds
&mut stats
));
assert_eq!(stats.index_overrun, 2);
Expand All @@ -1225,7 +1215,6 @@ mod tests {
root,
max_slot,
shred_version,
|_| false, // should_drop_merkle_shreds
&mut stats
));
assert_eq!(stats.index_overrun, 3);
Expand All @@ -1236,7 +1225,6 @@ mod tests {
root,
max_slot,
shred_version,
|_| false, // should_drop_merkle_shreds
&mut stats
));
assert_eq!(stats.index_overrun, 4);
Expand All @@ -1247,7 +1235,6 @@ mod tests {
root,
max_slot,
shred_version,
|_| false, // should_drop_merkle_shreds
&mut stats
));
assert_eq!(stats.bad_parent_offset, 1);
Expand All @@ -1268,7 +1255,6 @@ mod tests {
root,
max_slot,
shred_version,
|_| false, // should_drop_merkle_shreds
&mut stats
));

Expand All @@ -1288,7 +1274,6 @@ mod tests {
root,
max_slot,
shred_version,
|_| false, // should_drop_merkle_shreds
&mut stats
));
assert_eq!(1, stats.index_out_of_bounds);
Expand All @@ -1309,7 +1294,6 @@ mod tests {
root,
max_slot,
shred_version,
|_| false, // should_drop_merkle_shreds
&mut stats
));
packet.buffer_mut()[OFFSET_OF_SHRED_VARIANT] = u8::MAX;
Expand All @@ -1319,7 +1303,6 @@ mod tests {
root,
max_slot,
shred_version,
|_| false, // should_drop_merkle_shreds
&mut stats
));
assert_eq!(1, stats.bad_shred_type);
Expand All @@ -1331,7 +1314,6 @@ mod tests {
root,
max_slot,
shred_version,
|_| false, // should_drop_merkle_shreds
&mut stats
));
assert_eq!(1, stats.bad_shred_type);
Expand Down

0 comments on commit ea03d6c

Please sign in to comment.