harmony icon indicating copy to clipboard operation
harmony copied to clipboard

Prune state trie in run-time

Open peekpi opened this issue 3 years ago • 8 comments
trafficstars

Description

This pr is designed to prune the state-trie in run-time. The goal is to slow down the growth of disk usage for non-archival nodes. When a new state-trie is written to disk, it compares the old state-trie with the new state-trie, and deletes data exists in old state-trie but not in the new state-trie.

Enable state pruning

cmd line

harmony --pruning

config

[General]
  StatePruneEnable = true

TODO

  • [x] 1. add more complex unit tests.
  • [x] 2. make this feature optional
  • [x] 3. prune in async
  • [x] 4. allow pruning to be interrupted and aborted.
  • [x] 5. waiting prune finished when node exit
  • [ ] 6. test it on a mainnet non-archival node

peekpi avatar Oct 29 '22 12:10 peekpi

@peekpi do we know why state trie was intentionally dumped to disk at the end of each epoch?

MaxMustermann2 avatar Nov 01 '22 10:11 MaxMustermann2

@peekpi do we know why state trie was intentionally dumped to disk at the end of each epoch?

I don't know, but I don't see where this feature is needed. do you know about this? @rlan35

peekpi avatar Nov 01 '22 14:11 peekpi

I don't know, but I don't see where this feature is needed.

Let's retain it for now. According to RJ, it is "convenient for fast state sync where only state is synced".

MaxMustermann2 avatar Nov 04 '22 17:11 MaxMustermann2

I don't know, but I don't see where this feature is needed.

Let's retain it for now. According to RJ, it is "convenient for fast state sync where only state is synced".

How about make it to optional? And the default is to keep it.

peekpi avatar Nov 08 '22 14:11 peekpi

How about make it to optional? And the default is to keep it.

Let's keep the last block in epoch please.

MaxMustermann2 avatar Nov 11 '22 06:11 MaxMustermann2

@peekpi , is there anyway we can get an update on this PR and possibly fix the conflicts on the following files:

cmd/harmony/config_migrations.go cmd/harmony/default.go core/blockchain_impl.go internal/shardchain/shardchains.go

ONECasey avatar Jan 06 '23 19:01 ONECasey

@peekpi , is there anyway we can get an update on this PR and possibly fix the conflicts on the following files:

cmd/harmony/config_migrations.go

cmd/harmony/default.go

core/blockchain_impl.go

internal/shardchain/shardchains.go

yeah, I can fix it. But there is a problem with this pr that is difficult to solve... If two contracts have the same state, they share the same state tire. If the data of one contract changes, we cannot prune it, otherwise the data of the other contract will be missing.

So I don't think this pr can be merged unless the problem is solved.

peekpi avatar Jan 12 '23 03:01 peekpi

If two contracts have the same state, they share the same state tire. If the data of one contract changes, we cannot prune it, otherwise the data of the other contract will be missing.

Is there no reference counting for these states that can be used to assess whether it can be deleted? In other words, if there is a state with two references, it should not be deleted.

MaxMustermann2 avatar Apr 04 '23 09:04 MaxMustermann2