0

Trying to reinforce my understanding, so hoping you guys may help me out.

From reading the Ethereum wiki, I believe part of an Ethereum block header consist of the following:

stateRoot
transactionRoot
receiptsRoot

Which are the keccak hashes of the root node of the tries themselves.

My questions would be as follows......

Q1 - Where does geth stores these tries - I reckon within the block themselves, i.e. chaindata folder, within the ldb files? Or am I entirely off-base?

Q2 - (I am assuming the state trie is indeed kept in each block) Does the state trie of block N references the state trie of block N-1 (if no changes to an account's state is found, i.e. only log accounts with differences), or is the state trie duplicated across blocks?

Q3 - While state tree pruning, I reckon that the states are pruned off since if we have the stateRoot, this effectively verifies that the state trie nodes are OK, hence safe to discard the state trie themselves - Would this understanding be correct from high level perspective?

Q4 - What would the .\ethereum\nodes folder be for?

Thanks!

2

Firstly, you'll want to take a look at this picture from a previous question for reference.


Q1 - Where does geth stores these tries - I reckon within the block themselves, i.e. chaindata folder, within the ldb files? Or am I entirely off-base?

The chain data isn't actually part of the block proper - it's stored separately in a leveldb database. On your machine this is what's inside the chaindata folder. The block itself stores the hashes of the roots of the various tries, the state data (i.e. chain data) being one of these.

See:


Q2 - (I am assuming the state trie is indeed kept in each block) Does the state trie of block N references the state trie of block N-1 (if no changes to an account's state is found, i.e. only log accounts with differences), or is the state trie duplicated across blocks?

Your first assumption isn't correct, as per Q1, but yes, the state trie references backwards to prevent duplication. This picture from this previous answer helps visualise this:

![Ethereum Blockchain Architecture


Q3 - While state tree pruning, I reckon that the states are pruned off since if we have the stateRoot, this effectively verifies that the state trie nodes are OK, hence safe to discard the state trie themselves - Would this understanding be correct from high level perspective?

I'm not entirely sure, but this previous official blog post might help: https://blog.ethereum.org/2015/06/26/state-tree-pruning/


Q4 - What would the .\ethereum\nodes folder be for?

It's a database of nodes your node knows about. It's blobified in RLP format, so it's not readily readable. For further details, see Format of LevelDB files in nodes directory? Trouble pulling contents with python leveldb API

  • Sorry if I sound confused Richard (maybe because English isn't my first language), please bear with me. The chaindata folder stores a bunch of leveldb files, which are the block files (header + transaction list + ommer). Information from tries are used to produce hashes for the block header. In this case the tries are not stored persistently, and are simply data structures created to fill up the header hash requirements and used to verify a block? – John Doe Jul 22 '17 at 4:59
  • Thinking out loud - reading through the yellow paper Gavin mentioned under D.1. Trie Database - "no explicit assumptions are made concerning what data is stored and what is not, since that is an implementation-specific consideration"... Perhaps I should spend more time catching up on Geth's code... – John Doe Jul 22 '17 at 5:03
  • Where were my manners. @Richard - Thanks for helping out with my question. On a separate note, I've went through geth's code and see that tries are stored in a byte array database so I don't think it is stored on disk (caveat I am new with Go so I could be wrong with how interfaces work). Though I've seen a 2014 link mentioning states are stored in .\ethereum\state for cpp-ethereum so I'll check that next. Thanks again and feel free to correct if wrong. :) – John Doe Jul 24 '17 at 6:24
  • 1
    Hi @JohnDoe. The state data is stored as serialised RLP data within the .ldb database files. That data will be stored in the chaindata folder on disk. (In the C++ implementation that directory may well be called state.) github.com/ethereum/wiki/wiki/RLP – Richard Horrocks Jul 30 '17 at 15:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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