1

Based on the data structure of Ethereum blocks and transactions which is also represented here, we know the following sentences about the transactions receipts:

1- The transactions receipts are stored in the LevelDB.
2- The transactions receipts tire is created in RAM when there is a need for it.
3- The root hash of the trie is stored in the block header.

But if the receipts are neither stored inside the block body nor in the transactions data structure, then what is the link inside the block to the receipts in the LevelDB? And how do we know which receipt is related to which transaction?

2 Answers 2

0

The receipt is generated when executing the transaction. To validate a receipt that was generated by a transaction you have to execute the transaction.

6
  • But it is not possible to execute a transaction again after submitting it in a block, is it? It has some side effects such as spending ethers of a transaction undesirably. Could you please explain the process?
    – MHT
    Apr 25, 2019 at 19:30
  • Any execution is done on a world state root. If you execute a transaction in the same root when it was initially mined then every change should match the next state in case of error the block is invalid.
    – Ismael
    Apr 25, 2019 at 19:59
  • Then we need to spend some gas for executing the transaction again just for checking the receipts of an old transaction. Is it correct?
    – MHT
    Apr 26, 2019 at 14:50
  • No, you do not pay the execution again, it is paid only once when the block is mined. The execution is verified by every client that wants to validate a block or transaction.
    – Ismael
    Apr 26, 2019 at 15:22
  • Alright. Coming back again to my first question, if you need to run the transaction to check again its receipts, then why do we store the receipts in DB? Don't we have a more straightforward way of reaching to the receipts when we have them ready in the storage?
    – MHT
    Apr 26, 2019 at 15:47
0

In LevelDB the receipts are keyed by the block hash, stored as a list in the order the transactions were processed in the block.

So the link between the block and its receipts is pretty simple:

Block Hash -> Transaction Receipts

And we know which transaction relates to each receipt because the transaction and receipt share the same index in their respective lists.

There is no rpc endpoint to get the receipts for a block, so instead if you want to retrieve all receipts in a block you would need to call eth_getBlock and for each transaction in the block call eth_getTransactionReceipt with the hash of the transaction.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.