uses enum for shred type

Current code is using u8 which does not have any type-safety and can
contain invalid values:
https://github.com/solana-labs/solana/blob/66fa062f1/ledger/src/shred.rs#L167

Checks for invalid shred-types are scattered through the code:
https://github.com/solana-labs/solana/blob/66fa062f1/ledger/src/blockstore.rs#L849-L851
https://github.com/solana-labs/solana/blob/66fa062f1/ledger/src/shred.rs#L346-L348

The commit uses enum for shred type with #[repr(u8)]. Backward
compatibility is maintained by implementing Serialize and Deserialize
compatible with u8, and adding a test to assert that.
This commit is contained in:
behzad nouri
2021-11-16 12:50:56 -05:00
parent bae5dae61d
commit 57057f8d39
8 changed files with 183 additions and 127 deletions

2
Cargo.lock generated
View File

@@ -5084,6 +5084,8 @@ dependencies = [
"libc",
"log 0.4.14",
"matches",
"num-derive",
"num-traits",
"num_cpus",
"prost 0.9.0",
"rand 0.7.3",