From 90d9118048840872f184ee1665ae4556feb82bae Mon Sep 17 00:00:00 2001 From: Kirill Fomichev Date: Wed, 6 Jul 2022 02:52:11 +0400 Subject: [PATCH] Add `get_confirmed_transactions` to `storage-bigtable` (#25404) * Add get_confirmed_transactions to storage-bigtable * remove zip * HashMap::new instead of default * extract txs in order --- storage-bigtable/src/lib.rs | 62 +++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/storage-bigtable/src/lib.rs b/storage-bigtable/src/lib.rs index 69d3d95861..ba8e8c0e39 100644 --- a/storage-bigtable/src/lib.rs +++ b/storage-bigtable/src/lib.rs @@ -552,6 +552,68 @@ impl LedgerStorage { Ok(transaction_info.into()) } + // Fetches and gets a vector of confirmed transactions via a multirow fetch + pub async fn get_confirmed_transactions( + &self, + signatures: &[Signature], + ) -> Result> { + debug!( + "LedgerStorage::get_confirmed_transactions request received: {:?}", + signatures + ); + inc_new_counter_debug!("storage-bigtable-query", 1); + let mut bigtable = self.connection.client(); + + // Fetch transactions info + let keys = signatures.iter().map(|s| s.to_string()).collect::>(); + let cells = bigtable + .get_bincode_cells::("tx", &keys) + .await?; + + // Collect by slot + let mut order: Vec<(Slot, u32, String)> = Vec::new(); + let mut slots: HashSet = HashSet::new(); + for cell in cells { + if let (signature, Ok(TransactionInfo { slot, index, .. })) = cell { + order.push((slot, index, signature)); + slots.insert(slot); + } + } + + // Fetch blocks + let blocks = self + .get_confirmed_blocks_with_data(&slots.into_iter().collect::>()) + .await? + .collect::>(); + + // Extract transactions + Ok(order + .into_iter() + .filter_map(|(slot, index, signature)| { + blocks.get(&slot).and_then(|block| { + block + .transactions + .get(index as usize) + .and_then(|tx_with_meta| { + if tx_with_meta.transaction_signature().to_string() != *signature { + warn!( + "Transaction info or confirmed block for {} is corrupt", + signature + ); + None + } else { + Some(ConfirmedTransactionWithStatusMeta { + slot, + tx_with_meta: tx_with_meta.clone(), + block_time: block.block_time, + }) + } + }) + }) + }) + .collect::>()) + } + /// Fetch a confirmed transaction pub async fn get_confirmed_transaction( &self,