perf: only check pool if disk lookup came up empty (#2973)

This commit is contained in:
Matthias Seitz
2023-06-05 04:36:10 +02:00
committed by GitHub
parent 2d0e8162b8
commit 075fa59841

View File

@ -244,17 +244,15 @@ where
}
async fn transaction_by_hash(&self, hash: H256) -> EthResult<Option<TransactionSource>> {
if let Some(tx) = self.pool().get(&hash).map(|tx| tx.transaction.to_recovered_transaction())
{
return Ok(Some(TransactionSource::Pool(tx)))
}
self.on_blocking_task(|this| async move {
// Try to find the transaction on disk
let mut resp = self
.on_blocking_task(|this| async move {
match this.client().transaction_by_hash_with_meta(hash)? {
None => Ok(None),
Some((tx, meta)) => {
let transaction =
tx.into_ecrecovered().ok_or(EthApiError::InvalidTransactionSignature)?;
let transaction = tx
.into_ecrecovered()
.ok_or(EthApiError::InvalidTransactionSignature)?;
let tx = TransactionSource::Block {
transaction,
@ -267,7 +265,18 @@ where
}
}
})
.await
.await?;
if resp.is_none() {
// tx not found on disk, check pool
if let Some(tx) =
self.pool().get(&hash).map(|tx| tx.transaction.to_recovered_transaction())
{
resp = Some(TransactionSource::Pool(tx));
}
}
Ok(resp)
}
async fn transaction_by_hash_at(