In this topic, we are presenting an improvement mode for Incognito stateDB that would help Incognito fullnode saves at least 60% data storage.
What is state pruning?
Incognito node uses stateDB for storing state data such as pDEX, tokens, and transactions. And each time one leaf node changes value. New state trie will need to build a new path and new leaf node for the changed value. Therefore, with the purpose of decreasing the storage of stateDB, we will try to remove old paths and old nodes.
ETH state pruning
ETH uses a bloom filter to filter trie nodes that do not belong to a specific state root and genesis root. For more information check out this article:
https://blog.ethereum.org/2015/06/26/state-tree-pruning/
Incognito state pruning
Based on ETH state pruning, Incognito also uses a bloom filter to filter state trie nodes that do not belong to current final and best states.
How to prune data
We’ve supported the following two RPCs for triggering the pruning process and checking the pruning status. We will support a call to action button on the Incognito app’s Power tab so that you can trigger the process via a more user-friendly UI in the future.
Note that pruning is a CPU-intensive process so if you are running multiple nodes on the same server, please take CPU computation into account when triggering it.
For example, you are running 10 nodes on a single server but CPU capacity of the server can only handle pruning for a maximum of 4 nodes so if you trigger the pruning for more than 4 nodes, the server would likely be stressed and all 10 nodes on it would be affected.
Prune
Call the following RPC to activate the state pruning process in the background:
curl --location --request POST "node_IP:rpc_port" \
--header 'Content-Type: application/json' \
--data-raw '{
"id": 1,
"jsonrpc": "1.0",
"method": "pruneState",
"params": [
{
"Config": {
"0": {
"ShouldPruneByHash": false
},
"1": {
"ShouldPruneByHash": false
},
...
"7": {
"ShouldPruneByHash": false
}
}
}
]
}'
ShouldPruneByHash
is a boolean param. If it is true, the process would traverse by rootHash. Otherwise, If it is false, the process would traverse by height (default and recommended)
Get prune status
curl --location --request POST "node_IP:rpc_port" \
--header 'Content-Type: application/json' \
--data-raw '{
"id": 1,
"jsonrpc": "1.0",
"method": "getPruneState"
}'
Example response:
{
"Id": 1,
"Result": {
"0": {
"Status": 1,
"PrunedHeight": 2934
},
"1": {
"Status": 2,
"PrunedHeight": 1111
},
...
"7": {
"Status": 2,
"PrunedHeight": 3456
}
},
"Error": null,
"Params": null,
"Method": "getPruneState",
"Jsonrpc": "1.0"
}
Status:
)
0: IDLE
1: PRUNING
2: CHECKING
)