Properly handle block_height in Bigtable bincode deserialization (#17990)

* Default block_height on eof

* Add comment to prevent future errors
This commit is contained in:
Tyera Eulberg 2021-06-15 17:34:07 -06:00 committed by GitHub
parent dbd4dc04b0
commit c57d1b44ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 0 deletions

View File

@ -3,6 +3,7 @@ use log::*;
use serde::{Deserialize, Serialize};
use solana_sdk::{
clock::{Slot, UnixTimestamp},
deserialize_utils::default_on_eof,
pubkey::Pubkey,
signature::Signature,
sysvar::is_sysvar_id,
@ -81,6 +82,9 @@ fn key_to_slot(key: &str) -> Option<Slot> {
// StoredConfirmedBlock holds the same contents as ConfirmedBlock, but is slightly compressed and avoids
// some serde JSON directives that cause issues with bincode
//
// Note: in order to continue to support old bincode-serialized bigtable entries, if new fields are
// added to ConfirmedBlock, they must either be excluded or set to `default_on_eof` here
//
#[derive(Serialize, Deserialize)]
struct StoredConfirmedBlock {
previous_blockhash: String,
@ -89,6 +93,7 @@ struct StoredConfirmedBlock {
transactions: Vec<StoredConfirmedBlockTransaction>,
rewards: StoredConfirmedBlockRewards,
block_time: Option<UnixTimestamp>,
#[serde(deserialize_with = "default_on_eof")]
block_height: Option<u64>,
}