Skip to content

shred_fetch: enforce fixed fec sets#7728

Merged
AshwinSekar merged 5 commits intoanza-xyz:masterfrom
AshwinSekar:fixed-fec-set
Aug 29, 2025
Merged

shred_fetch: enforce fixed fec sets#7728
AshwinSekar merged 5 commits intoanza-xyz:masterfrom
AshwinSekar:fixed-fec-set

Conversation

@AshwinSekar
Copy link
Copy Markdown

@AshwinSekar AshwinSekar commented Aug 26, 2025

Problem

See solana-foundation/solana-improvement-documents#317 for more details.
We wish to enforce that each FEC set has exactly 32 data and 32 coding shreds.

Summary of Changes

As outlined in the SIMD, we ignore any shreds that do not meet the index/fec_set_index requirements on ingest.
Specifically ensure that:

  • fec_set_index is a multiple of 32
  • fec_set_index <= index < fec_set_index + 32
  • The LAST_SHRED_IN_SLOT data shred index must be == 31 (mod 32)
  • The ErasureConfig on all coding shreds must specify 32:32

Note: this is a shred feature flag so it takes effect 1 epoch after normal feature activation

An alternate approach considered was performing the verification after ingest and marking the block as dead:

  • This approach avoids adding extra repair overhead in case of malicious voters
  • However it's add more cost to sigverify and then insert these malicious shreds into blockstore
  • and more code complexity to do this at the blockstore level
  • FD does not mark block as dead

Some follow up work after FF activation:

  • In the next shred version we can consider removing fec_set_index, ErasureConfig, and proof_size from shred headers.
  • Blockstore can be reworked to use 32 offsets instead of the ErasureConfig/searching
  • We could recover FEC sets in cases where there are 32 data shreds but 0 coding shreds (need to store some state so that we don't do this repeatedly for the same FEC set)
  • ErasureMeta column / data types and related consistency checks can be removed
  • Remove check_last_fec_set, we're guaranteed that the last fec set has 32 data shreds

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Aug 27, 2025

Codecov Report

❌ Patch coverage is 84.90566% with 40 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.0%. Comparing base (996570b) to head (1b8fe3f).
⚠️ Report is 4 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff            @@
##           master    #7728    +/-   ##
========================================
  Coverage    83.0%    83.0%            
========================================
  Files         812      812            
  Lines      356934   357178   +244     
========================================
+ Hits       296535   296814   +279     
+ Misses      60399    60364    -35     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@AshwinSekar AshwinSekar force-pushed the fixed-fec-set branch 3 times, most recently from 3f06a5d to a55bcca Compare August 27, 2025 02:43
recvr_stats: Option<Arc<StreamerReceiveStats>>,
sendr: EvictingSender<PacketBatch>,
bank_forks: &RwLock<BankForks>,
sharable_banks: &SharableBanks,
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was here anyway 🪓

Comment thread ledger/src/shred.rs
return true;
};
let Some(fec_set_index) = layout::get_fec_set_index(shred) else {
stats.fec_set_index_bad_deserialize += 1;
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these deserialize failures are already thrown out when we parse the shred in sigverify, this just moves it up - shouldn't be a consensus altering change no need to feature flag.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds reasonable

Comment thread ledger/src/shred/wire.rs
Comment thread ledger/src/blockstore_meta.rs Outdated
/// all erasure sets contain exactly `DATA_SHREDS_PER_FEC_BLOCK` data and coding shreds:
/// - `index` is between `fec_set_index` and `fec_set_index + DATA_SHREDS_PER_FEC_BLOCK`
/// - `fec_set_index` is a multiple of `DATA_SHREDS_PER_FEC_BLOCK`
pub fn check_fixed_fec_set(index: u32, fec_set_index: u32) -> bool {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we not have this together with basic shred format validation outside of blockstore code?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah good call 8622835

Comment thread ledger/src/blockstore_meta.rs Outdated
/// Note: this check is critical to verify that the last fec set is sufficiently sized.
/// This currently is checked post insert in `Blockstore::check_last_fec_set`, but in the
/// future it can be solely checked during ingest
pub fn check_last_data_shred_index(index: u32) -> bool {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this also might be better suited inside shred.rs or similar.

@alexpyattaev
Copy link
Copy Markdown

Thank you, this looks great, left a couple of small nits

Comment thread core/src/shred_fetch_stage.rs Outdated
Comment thread core/src/shred_fetch_stage.rs
Comment thread ledger/src/shred.rs
Comment thread ledger/src/shred.rs Outdated
Copy link
Copy Markdown

@alexpyattaev alexpyattaev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but please let @bw-solana also take a second look before merging.

Copy link
Copy Markdown

@bw-solana bw-solana left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@AshwinSekar AshwinSekar merged commit 77f600b into anza-xyz:master Aug 29, 2025
43 checks passed
@AshwinSekar AshwinSekar deleted the fixed-fec-set branch August 29, 2025 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants