Ethereum – Understanding Block Structure, Roots, and Tries Concept

blocksstate-trie

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!

Best Answer

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

Related Topic