chore: use transaction_by_id_no_hash to avoid hash computation (#3718)

This commit is contained in:
joshieDo
2023-07-11 16:49:33 +01:00
committed by GitHub
parent fbdea30375
commit 65c7c1c4f9
2 changed files with 20 additions and 5 deletions

View File

@ -453,8 +453,14 @@ mod tests {
while let Some((_, body)) = body_cursor.next()? {
for tx_id in body.tx_num_range() {
let transaction: TransactionSigned =
provider.transaction_by_id(tx_id)?.expect("no transaction entry");
let transaction: TransactionSigned = provider
.transaction_by_id_no_hash(tx_id)?
.map(|tx| TransactionSigned {
hash: Default::default(), // we don't require the hash
signature: tx.signature,
transaction: tx.transaction,
})
.expect("no transaction entry");
let signer =
transaction.recover_signer().expect("failed to recover signer");
assert_eq!(Some(signer), provider.transaction_sender(tx_id)?)

View File

@ -935,12 +935,16 @@ impl<'this, TX: DbTx<'this>> TransactionsProvider for DatabaseProvider<'this, TX
}
fn transaction_by_id_no_hash(&self, id: TxNumber) -> Result<Option<TransactionSignedNoHash>> {
Ok(self.tx.get::<tables::Transactions>(id)?.map(Into::into))
Ok(self.tx.get::<tables::Transactions>(id)?)
}
fn transaction_by_hash(&self, hash: TxHash) -> Result<Option<TransactionSigned>> {
if let Some(id) = self.transaction_id(hash)? {
Ok(self.transaction_by_id(id)?)
Ok(self.transaction_by_id_no_hash(id)?.map(|tx| TransactionSigned {
hash,
signature: tx.signature,
transaction: tx.transaction,
}))
} else {
Ok(None)
}
@ -953,7 +957,12 @@ impl<'this, TX: DbTx<'this>> TransactionsProvider for DatabaseProvider<'this, TX
) -> Result<Option<(TransactionSigned, TransactionMeta)>> {
let mut transaction_cursor = self.tx.cursor_read::<tables::TransactionBlock>()?;
if let Some(transaction_id) = self.transaction_id(tx_hash)? {
if let Some(transaction) = self.transaction_by_id(transaction_id)? {
if let Some(tx) = self.transaction_by_id_no_hash(transaction_id)? {
let transaction = TransactionSigned {
hash: tx_hash,
signature: tx.signature,
transaction: tx.transaction,
};
if let Some(block_number) =
transaction_cursor.seek(transaction_id).map(|b| b.map(|(_, bn)| bn))?
{