diff --git a/storage-bigtable/src/bigtable.rs b/storage-bigtable/src/bigtable.rs index b8ca060617..6b60c66439 100644 --- a/storage-bigtable/src/bigtable.rs +++ b/storage-bigtable/src/bigtable.rs @@ -680,6 +680,29 @@ impl) -> InterceptedRequestResult> BigTable { deserialize_protobuf_or_bincode_cell_data(&row_data, table, key) } + pub async fn get_protobuf_or_bincode_cells( + &mut self, + table: &str, + row_keys: Vec, + ) -> Result)>> + where + B: serde::de::DeserializeOwned, + P: prost::Message + Default, + { + Ok(self + .get_multi_row_data(table, row_keys.as_slice()) + .await? + .into_iter() + .map(|(key, row_data)| { + let key_str = key.to_string(); + ( + key, + deserialize_protobuf_or_bincode_cell_data(&row_data, table, key_str).unwrap(), + ) + }) + .collect()) + } + pub async fn put_bincode_cells( &mut self, table: &str, diff --git a/storage-bigtable/src/lib.rs b/storage-bigtable/src/lib.rs index 7409536925..5086e9452c 100644 --- a/storage-bigtable/src/lib.rs +++ b/storage-bigtable/src/lib.rs @@ -1,5 +1,6 @@ #![allow(clippy::integer_arithmetic)] use { + crate::bigtable::RowKey, log::*, serde::{Deserialize, Serialize}, solana_metrics::inc_new_counter_debug, @@ -454,6 +455,36 @@ impl LedgerStorage { Ok(blocks.into_iter().filter_map(|s| key_to_slot(&s)).collect()) } + // Fetches and gets a vector of confirmed blocks via a multirow fetch + pub async fn get_confirmed_blocks_with_data( + &self, + slots: Vec, + ) -> Result> { + debug!( + "LedgerStorage::get_confirmed_blocks_with_data request received: {:?}", + slots + ); + inc_new_counter_debug!("storage-bigtable-query", 1); + let mut bigtable = self.connection.client(); + let row_keys: Vec = slots.into_iter().map(|s| slot_to_blocks_key(s)).collect(); + let data: Vec<(Slot, ConfirmedBlock)> = bigtable + .get_protobuf_or_bincode_cells::( + "blocks", + row_keys.clone(), + ) + .await? + .into_iter() + .filter_map(|(row_key, block_cell_data)| { + let block = match block_cell_data { + bigtable::CellData::Bincode(block) => block.into(), + bigtable::CellData::Protobuf(block) => block.try_into().ok()?, + }; + Some((key_to_slot(&(row_key.to_string())).unwrap(), block)) + }) + .collect(); + Ok(data) + } + /// Fetch the confirmed block from the desired slot pub async fn get_confirmed_block(&self, slot: Slot) -> Result { debug!(