changes Shred::parent return type to Option<Slot> (#21370)

Shred::parent can return garbage if the struct fields are invalid:
https://github.com/solana-labs/solana/blob/8a50b6302/ledger/src/shred.rs#L446-L453

The commit adds more sanity checks and changes the return type to Option<Slot>.
This commit is contained in:
behzad nouri
2021-11-23 14:45:26 +00:00
committed by GitHub
parent 22a2537aac
commit dd338b6c9f
4 changed files with 24 additions and 12 deletions

View File

@ -596,7 +596,7 @@ mod test {
.expect("Expected a shred that signals an interrupt");
// Validate the shred
assert_eq!(shred.parent(), parent);
assert_eq!(shred.parent(), Some(parent));
assert_eq!(shred.slot(), slot);
assert_eq!(shred.index(), next_shred_index);
assert!(shred.is_data());

View File

@ -164,7 +164,10 @@ impl ReceiveWindowStats {
fn verify_shred_slot(shred: &Shred, root: u64) -> bool {
match shred.shred_type() {
// Only data shreds have parent information
ShredType::Data => blockstore::verify_shred_slots(shred.slot(), shred.parent(), root),
ShredType::Data => match shred.parent() {
Some(parent) => blockstore::verify_shred_slots(shred.slot(), parent, root),
None => false,
},
// Filter out outdated coding shreds
ShredType::Code => shred.slot() >= root,
}