Bigtable: Use index to filter address-signatures correctly (#11622)

* Use index to filter address-signatures correctly

* Pull additional keys to account for filtered records

* Clarify variable name
This commit is contained in:
Tyera Eulberg 2020-08-14 13:41:27 -06:00 committed by GitHub
parent 7c736f71fe
commit 820af533a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 6 deletions

View File

@ -371,25 +371,33 @@ impl LedgerStorage {
let address_prefix = format!("{}/", address); let address_prefix = format!("{}/", address);
// Figure out where to start listing from based on `before_signature` // Figure out where to start listing from based on `before_signature`
let (first_slot, mut first_transaction_index) = match before_signature { let (first_slot, mut before_transaction_index) = match before_signature {
None => (Slot::MAX, 0), None => (Slot::MAX, 0),
Some(before_signature) => { Some(before_signature) => {
let TransactionInfo { slot, index, .. } = bigtable let TransactionInfo { slot, index, .. } = bigtable
.get_bincode_cell("tx", before_signature.to_string()) .get_bincode_cell("tx", before_signature.to_string())
.await?; .await?;
(slot, index + 1) (slot, index)
} }
}; };
let mut infos = vec![]; let mut infos = vec![];
// Return the next `limit` tx-by-addr keys let starting_slot_tx_by_addr_infos = bigtable
.get_bincode_cell::<Vec<TransactionByAddrInfo>>(
"tx-by-addr",
format!("{}{}", address_prefix, slot_to_key(!first_slot)),
)
.await?;
// Return the next tx-by-addr keys of amount `limit` plus extra to account for the largest
// number that might be flitered out
let tx_by_addr_info_keys = bigtable let tx_by_addr_info_keys = bigtable
.get_row_keys( .get_row_keys(
"tx-by-addr", "tx-by-addr",
Some(format!("{}{}", address_prefix, slot_to_key(!first_slot))), Some(format!("{}{}", address_prefix, slot_to_key(!first_slot))),
limit as i64, limit as i64 + starting_slot_tx_by_addr_infos.len() as i64,
) )
.await?; .await?;
@ -413,7 +421,7 @@ impl LedgerStorage {
for tx_by_addr_info in tx_by_addr_infos for tx_by_addr_info in tx_by_addr_infos
.into_iter() .into_iter()
.skip(first_transaction_index as usize) .filter(|tx_by_addr_info| tx_by_addr_info.index < before_transaction_index)
{ {
infos.push(ConfirmedTransactionStatusWithSignature { infos.push(ConfirmedTransactionStatusWithSignature {
signature: tx_by_addr_info.signature, signature: tx_by_addr_info.signature,
@ -426,7 +434,7 @@ impl LedgerStorage {
} }
} }
first_transaction_index = 0; before_transaction_index = u32::MAX;
} }
Ok(infos) Ok(infos)
} }