Description
Context:
When --saveReceipts
is set, the client maintains in its DB a "transaction index". The "transaction index" is a key/value mapping of txHash
> [blockHash, txIndex]
.
To find a transaction by hash, we look up the txHash
to retrieve the blockHash
and index
(index
here meaning which tx
in the block.transactions
array). We then use the blockHash
to retrieve the block, and find the transaction
at the right index
in that block.
Problem:
This is only possible via the ReceiptsManager
, which only exists if --saveReceipts
is on. Transactions are not indexed otherwise. This does not feel like a necessary coupling. Additionally, in the process of looking up a transaction by hash (via eth_getTransactionByHash
), we currently also do an unnecessary retrieval of the receipt
from the DB.
Solution:
If we were to maintain the TxIndex
independently of Receipts
, we could enable Tx lookup by hash without also needing to have --saveReceipts
on.
- At a very minimum we should refactor
getTransactionByHash
to avoid the extra DB lookup.