Plug getConfirmedSignaturesForAddress2 into bigtable storage
This commit is contained in:
parent
8d1400d3d6
commit
4222932e08
|
@ -839,8 +839,8 @@ impl JsonRpcRequestProcessor {
|
||||||
pub fn get_confirmed_signatures_for_address2(
|
pub fn get_confirmed_signatures_for_address2(
|
||||||
&self,
|
&self,
|
||||||
address: Pubkey,
|
address: Pubkey,
|
||||||
before: Option<Signature>,
|
mut before: Option<Signature>,
|
||||||
limit: usize,
|
mut limit: usize,
|
||||||
) -> Result<Vec<RpcConfirmedTransactionStatusWithSignature>> {
|
) -> Result<Vec<RpcConfirmedTransactionStatusWithSignature>> {
|
||||||
if self.config.enable_rpc_transaction_history {
|
if self.config.enable_rpc_transaction_history {
|
||||||
let highest_confirmed_root = self
|
let highest_confirmed_root = self
|
||||||
|
@ -849,7 +849,7 @@ impl JsonRpcRequestProcessor {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.highest_confirmed_root();
|
.highest_confirmed_root();
|
||||||
|
|
||||||
let results = self
|
let mut results = self
|
||||||
.blockstore
|
.blockstore
|
||||||
.get_confirmed_signatures_for_address2(
|
.get_confirmed_signatures_for_address2(
|
||||||
address,
|
address,
|
||||||
|
@ -859,6 +859,27 @@ impl JsonRpcRequestProcessor {
|
||||||
)
|
)
|
||||||
.map_err(|err| Error::invalid_params(format!("{}", err)))?;
|
.map_err(|err| Error::invalid_params(format!("{}", err)))?;
|
||||||
|
|
||||||
|
if results.len() < limit {
|
||||||
|
if let Some(bigtable_ledger_storage) = &self.bigtable_ledger_storage {
|
||||||
|
if !results.is_empty() {
|
||||||
|
limit -= results.len();
|
||||||
|
before = results.last().map(|x| x.signature);
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut bigtable_results = self
|
||||||
|
.runtime_handle
|
||||||
|
.block_on(
|
||||||
|
bigtable_ledger_storage.get_confirmed_signatures_for_address(
|
||||||
|
&address,
|
||||||
|
before.as_ref(),
|
||||||
|
limit,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.map_err(|err| Error::invalid_params(format!("{}", err)))?;
|
||||||
|
results.append(&mut bigtable_results)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(results.into_iter().map(|x| x.into()).collect())
|
Ok(results.into_iter().map(|x| x.into()).collect())
|
||||||
} else {
|
} else {
|
||||||
Ok(vec![])
|
Ok(vec![])
|
||||||
|
|
|
@ -308,30 +308,39 @@ async fn confirm(signature: &Signature, verbose: bool) -> Result<(), Box<dyn std
|
||||||
|
|
||||||
pub async fn transaction_history(
|
pub async fn transaction_history(
|
||||||
address: &Pubkey,
|
address: &Pubkey,
|
||||||
limit: usize,
|
mut limit: usize,
|
||||||
before: Option<&Signature>,
|
mut before: Option<Signature>,
|
||||||
verbose: bool,
|
verbose: bool,
|
||||||
) -> Result<(), Box<dyn std::error::Error>> {
|
) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let bigtable = solana_storage_bigtable::LedgerStorage::new(true).await?;
|
let bigtable = solana_storage_bigtable::LedgerStorage::new(true).await?;
|
||||||
|
|
||||||
let results = bigtable
|
while limit > 0 {
|
||||||
.get_confirmed_signatures_for_address(address, before, limit)
|
let results = bigtable
|
||||||
.await?;
|
.get_confirmed_signatures_for_address(address, before.as_ref(), limit.min(1000))
|
||||||
|
.await?;
|
||||||
|
|
||||||
for (signature, slot, memo, err) in results {
|
if results.is_empty() {
|
||||||
if verbose {
|
break;
|
||||||
println!(
|
}
|
||||||
"{}, slot={}, memo=\"{}\", status={}",
|
before = Some(results.last().unwrap().signature);
|
||||||
signature,
|
assert!(limit >= results.len());
|
||||||
slot,
|
limit = limit.saturating_sub(results.len());
|
||||||
memo.unwrap_or_else(|| "".to_string()),
|
|
||||||
match err {
|
for result in results {
|
||||||
None => "Confirmed".to_string(),
|
if verbose {
|
||||||
Some(err) => format!("Failed: {:?}", err),
|
println!(
|
||||||
}
|
"{}, slot={}, memo=\"{}\", status={}",
|
||||||
);
|
result.signature,
|
||||||
} else {
|
result.slot,
|
||||||
println!("{}", signature);
|
result.memo.unwrap_or_else(|| "".to_string()),
|
||||||
|
match result.err {
|
||||||
|
None => "Confirmed".to_string(),
|
||||||
|
Some(err) => format!("Failed: {:?}", err),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
println!("{}", result.signature);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -462,7 +471,7 @@ impl BigTableSubCommand for App<'_, '_> {
|
||||||
.value_name("LIMIT")
|
.value_name("LIMIT")
|
||||||
.validator(is_slot)
|
.validator(is_slot)
|
||||||
.index(2)
|
.index(2)
|
||||||
.default_value("1000")
|
.default_value("18446744073709551615")
|
||||||
.help("Maximum number of transaction signatures to return"),
|
.help("Maximum number of transaction signatures to return"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
|
@ -531,12 +540,7 @@ pub fn bigtable_process_command(ledger_path: &Path, matches: &ArgMatches<'_>) {
|
||||||
.map(|signature| signature.parse().expect("Invalid signature"));
|
.map(|signature| signature.parse().expect("Invalid signature"));
|
||||||
let verbose = arg_matches.is_present("verbose");
|
let verbose = arg_matches.is_present("verbose");
|
||||||
|
|
||||||
runtime.block_on(transaction_history(
|
runtime.block_on(transaction_history(&address, limit, before, verbose))
|
||||||
&address,
|
|
||||||
limit,
|
|
||||||
before.as_ref(),
|
|
||||||
verbose,
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,8 +8,9 @@ use solana_sdk::{
|
||||||
transaction::{Transaction, TransactionError},
|
transaction::{Transaction, TransactionError},
|
||||||
};
|
};
|
||||||
use solana_transaction_status::{
|
use solana_transaction_status::{
|
||||||
ConfirmedBlock, ConfirmedTransaction, EncodedTransaction, Rewards, TransactionStatus,
|
ConfirmedBlock, ConfirmedTransaction, ConfirmedTransactionStatusWithSignature,
|
||||||
TransactionWithStatusMeta, UiTransactionEncoding, UiTransactionStatusMeta,
|
EncodedTransaction, Rewards, TransactionStatus, TransactionWithStatusMeta,
|
||||||
|
UiTransactionEncoding, UiTransactionStatusMeta,
|
||||||
};
|
};
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
|
@ -365,7 +366,7 @@ impl LedgerStorage {
|
||||||
address: &Pubkey,
|
address: &Pubkey,
|
||||||
before_signature: Option<&Signature>,
|
before_signature: Option<&Signature>,
|
||||||
limit: usize,
|
limit: usize,
|
||||||
) -> Result<Vec<(Signature, Slot, Option<String>, Option<TransactionError>)>> {
|
) -> Result<Vec<ConfirmedTransactionStatusWithSignature>> {
|
||||||
let mut bigtable = self.connection.client();
|
let mut bigtable = self.connection.client();
|
||||||
let address_prefix = format!("{}/", address);
|
let address_prefix = format!("{}/", address);
|
||||||
|
|
||||||
|
@ -414,12 +415,12 @@ impl LedgerStorage {
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.skip(first_transaction_index as usize)
|
.skip(first_transaction_index as usize)
|
||||||
{
|
{
|
||||||
infos.push((
|
infos.push(ConfirmedTransactionStatusWithSignature {
|
||||||
tx_by_addr_info.signature,
|
signature: tx_by_addr_info.signature,
|
||||||
slot,
|
slot,
|
||||||
tx_by_addr_info.memo,
|
err: tx_by_addr_info.err,
|
||||||
tx_by_addr_info.err,
|
memo: tx_by_addr_info.memo,
|
||||||
));
|
});
|
||||||
if infos.len() >= limit {
|
if infos.len() >= limit {
|
||||||
break 'outer;
|
break 'outer;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue