Properly handle block_height in Bigtable bincode deserialization (#17990) (#17994)

* Default block_height on eof

* Add comment to prevent future errors

(cherry picked from commit c57d1b44ef)

Co-authored-by: Tyera Eulberg <teulberg@gmail.com>
This commit is contained in:
mergify[bot]
2021-06-16 05:41:38 +00:00
committed by GitHub
parent 61573756f8
commit 4ee366edfa

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>,
}