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:
@ -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());
|
||||
|
@ -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,
|
||||
}
|
||||
|
Reference in New Issue
Block a user