I was researching how contract storage works. I know that the world state is a Merkle Patricia Trie, containing all active Ethereum adresses with their storageRoot
(and their nonce
, balance
, and codeHash
).
I have gained a better understanding of how a Merkle Patricia Trie works, and the fact that if you store all the key-values in the form of a Merkle Patricia Trie, all you need is the root hash (stored in storageRoot
) to verify all the key-values.
I understand that each client has its own implementation. Go Ethereum uses levelDB (Google's key-value database), for instance.
The thing is that if a key-value is modified (because of contract execution), it creates a new node but doesn't delete the old one.
But I guess there are a lot of keys-values unique to each contract. And if every time a state variable is modified, a new node is created, but the old one isn't deleted, that's a crazy waste of space, isn't it? Is there something I'm missing here?
Thanks 🙏