add get_confirmed_blocks_with_data and get_protobuf_or_bincode_cells

This commit is contained in:
Edgar Xi 2022-03-11 15:12:35 -05:00 committed by Trent Nelson
parent bc35e1c5f5
commit f3219fb695
2 changed files with 54 additions and 0 deletions

View File

@ -680,6 +680,29 @@ impl<F: FnMut(Request<()>) -> InterceptedRequestResult> BigTable<F> {
deserialize_protobuf_or_bincode_cell_data(&row_data, table, key)
}
pub async fn get_protobuf_or_bincode_cells<B, P>(
&mut self,
table: &str,
row_keys: Vec<RowKey>,
) -> Result<Vec<(RowKey, CellData<B, P>)>>
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<T>(
&mut self,
table: &str,

View File

@ -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<Slot>,
) -> Result<Vec<(Slot, ConfirmedBlock)>> {
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<RowKey> = slots.into_iter().map(|s| slot_to_blocks_key(s)).collect();
let data: Vec<(Slot, ConfirmedBlock)> = bigtable
.get_protobuf_or_bincode_cells::<StoredConfirmedBlock, generated::ConfirmedBlock>(
"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<ConfirmedBlock> {
debug!(