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
This commit is contained in:
parent
b7e34aea15
commit
90d9118048
|
@ -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<Vec<ConfirmedTransactionWithStatusMeta>> {
|
||||
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::<Vec<_>>();
|
||||
let cells = bigtable
|
||||
.get_bincode_cells::<TransactionInfo>("tx", &keys)
|
||||
.await?;
|
||||
|
||||
// Collect by slot
|
||||
let mut order: Vec<(Slot, u32, String)> = Vec::new();
|
||||
let mut slots: HashSet<Slot> = 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::<Vec<_>>())
|
||||
.await?
|
||||
.collect::<HashMap<_, _>>();
|
||||
|
||||
// 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::<Vec<_>>())
|
||||
}
|
||||
|
||||
/// Fetch a confirmed transaction
|
||||
pub async fn get_confirmed_transaction(
|
||||
&self,
|
||||
|
|
Loading…
Reference in New Issue