Speeding up `eth_getTransactionReceipt`
Here's an idea for speeding up RPC method eth_getTransactionReceipt, i.e. the operation that
loads a single receipt by txhash. Right now, this operation is very slow because it has to:
- load inclusion block from the txhash -> block index
- load the full block from the database
- find the tx in the block
- verify tx signature and derive the sender
- load/parse all receipts in the block
- derive non-consensus fields for all receipts
- return receipt n
Some of these steps should be avoidable. I propose that, in the tx inclusion index (txhash -> block) we should also store the tx sender, as well as other information required to derive receipt fields. If this information was available, the steps for resolving a single receipts would be:
- load the inclusion block, sender, etc. from the txhash -> block index
- load the full block from the database
- find the tx in the block
- load all receipts in the block
- find receipt n
- derive fields of receipt n
- return it
This doesn't look very different, but there is another advantage: we wouldn't need to actually parse the receipts just to load the nth one. Decoding receipts is slow, and a bit of time can be saved by not doing it. Unrelated derivation of receipt fields is also avoided.
More about the additional content of the txhash -> number index. In order to derive the non-persistent fields of a single receipt, we require these new fields in the index:
txIndex: the index of the transaction in the block.blockLogCount: the count of logs in the block up to this receipt. This is needed to assign the index of logs corrrectly.gasUsed: the gas used by a tx is not stored in the receipt. Instead, we store the cumulative amount of used block gas at the end of the transaction. In the index, we could simply storegasUseddirectly. This might also be helpful for other use cases of the index.txType: the type byte of the transaction
@fjl is this still open for collaboration?
Yeah sure, nobody has worked on this. I just posted it as an idea.
Cool, thanks! Will start working on this
https://github.com/ethereum/go-ethereum/pull/32063#issuecomment-2990298842