3

If a variable is set to zero, is it removed from storage trie? If not, why not? Seems it would save a lot of storage space.

BipedalJoe
  • 151
  • 6

2 Answers2

1

You should find this discussion helpful:

How do gas refunds work?

Max.Koeg
  • 66
  • 6
  • thanks, not wondering so much from gas cost perspective, more about storage database size, but also good to know about the gas refunds – BipedalJoe Feb 02 '24 at 07:30
  • Yeah, I think zero values persist in storage but don't require funding for network commits. – Max.Koeg Feb 03 '24 at 06:39
0

As I understand, the functionality to remove data from the database when data in storage is cleared, garbage collection, is not widely implemented. Technically, it would rely on something like a reference counter. The reference counter keeps track of how many nodes in tries share the same preimage (thus the same hash, and the hash is the key in key-value database). And when a reference counter reaches zero, the node can be removed. This is a good article on the topic, https://blog.ethereum.org/2015/06/26/state-tree-pruning, and I recall reading in older documentation (cannot find it right now) that storage deletions were possible but that node implementations could decide themselves how to solve it.

BipedalJoe
  • 151
  • 6