3

I'm studying the block structure in several blockchains like Bitcoin or Ethereum. When I started to read about blockchain, many sites and books said that transactions are stored in blocks. Ok, I got it, I said to myself. But now I'm not sure to understand it because when I started to read about the block structure, I understood that there are no transactions in a block. In fact, a block contains a list of transaction hashes and the root Merkle tree/trie of all of these transactions, but the block doesn't contain the transactions themselves, just a reference to each of them. Is this true? If yes, where are the transactions stored if they are not in a block? Thank you!

16
  • 1
    What do you mean where? Physically or logically? Physically it's in a database but depends on client and how they implemented it. Logically it's just a list of tx with the hash as unique ID that the block can refer to. Sep 8, 2022 at 10:10
  • 1
    Yes it's correct Sep 8, 2022 at 10:45
  • 1
    I'm sorry, I can't tell you about this optimisation if it's a good idea or not. But I suggest that you discuss this on our Besu Discord: discord.gg/hyperledger If my answer is enough for the first part of your question, please approve it ;) Sep 8, 2022 at 13:19
  • 1
    I added an answer after our discussion in comments. Please let me know if that answers your initial question and if so please approve it. Thanks. Sep 9, 2022 at 8:08
  • 1
    No besu it totally mainnet client. You can do private chains but anyway we store data the same way. Sep 9, 2022 at 12:09

1 Answer 1

1

Maybe if you want to know more about Ethereum tries and storage, you can read https://medium.com/@eiki1212/ethereum-state-trie-architecture-explained-a30237009d4e

Otherwise, if it's just for transactions, for instance for Besu, we store transaction data in a key-value database (RocksDB) and the data is available to be retrieved by the TX hash as the key.

In Besu code, TX are retrieved through the block body storage.

When you ask Besu (for instance using RPC eth_getTransactionByHash) it will first look in a key/value table for the hash of the transaction.

This will return the location of the transaction data in the blockchain database.

The location is an object containing the hash of the block containing the transaction data (it also has the transaction position in the bloc for when you ask for eth_getTransactionByBlockNumberAndIndex for instance).

Once Besu has the location of the transaction data, which containes the block hash, it gets the block body from the key/value database where the body is also indexed by its hash.

The body contains the data in RLP format (RLP encoding is a space-efficient object serialization scheme used in Ethereum) and once it is retrieved, Besu decodes this RLP and returns the body as a BlockBody object containing a list of Transaction objects ( a Java List<Transaction> actually).

It finally returns the transaction matching the hash requested initially and processes the data either to return transaction info on RPC if you called an RPC method to have transaction info or use it to run the EVM and anything that requires the transaction as an input.

Your Answer

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

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