Reduce storage for Bonsai Tries
When using the Bonsai Tries data storage format,
--bonsai-limit-trie-logs-enabled
is
enabled by default.
When enabled, this feature can reduce database growth by more than 3 GB each week on Mainnet.
If --sync-mode=FULL
is set, the
--bonsai-limit-trie-logs-enabled
option is disallowed and must be set to false
.
Limit and prune trie logs
If you're running Besu without
--bonsai-limit-trie-logs-enabled
,
you might have a backlog of redundant trie logs.
You can prune these using the following instructions.
Ensure you are using Besu version 24.6.0 or later. If you are using an older version, upgrade Besu or refer to the older version of the documentation.
The following commands are examples. Before executing these example commands on your node, modify them to apply to your node's configuration.
- Stop Besu.
- (Optional) Run the Besu trie log prune command. Specify the Bonsai Trie data storage format and the data directory for your Besu database:
sudo /usr/local/bin/besu/bin/besu --data-storage-format=BONSAI --data-path=/var/lib/besu --sync-mode=SNAP storage trie-log prune
- Start Besu.
- Look for
Limit trie logs enabled: retention: 512; prune window: 30000
in your Besu configuration printout at startup.
Prune outdated trie logs
When you start Besu with
--bonsai-limit-trie-logs-enabled
, it
continuously prunes the unnecessary trie log data, removing it one block at a time.
This process begins after an initial reduction in the database size during startup.
Enabling --bonsai-limit-trie-logs-enabled
on a long-running node does not immediately clear your backlog of trie logs in the same way resyncing does.
Instead of resyncing, you can run an offline command to immediately prune old trie logs.
To run the offline command, you must shut down Besu for a minimal period.
If the --bonsai-limit-trie-logs-enabled
option is enabled, you do not need to run the offline command again after initially running it.
For minimal downtime, we recommend running the offline command before restarting Besu with --bonsai-limit-trie-logs-enabled
.
If you are following the guides by Somer Esat or CoinCashew, you have set the following options in your besu.service
or execution.service
systemd file:
...
ExecStart=/usr/local/bin/besu/bin/besu \
...
--sync-mode=SNAP \
--data-path="/var/lib/besu" \
--data-storage-format=BONSAI \
...
To prune trie logs, the command should look similar to the following:
sudo /usr/local/bin/besu/bin/besu --data-storage-format=BONSAI --data-path=/var/lib/besu --sync-mode=SNAP storage trie-log prune
The logs should look similar to the following:
2024-02-02 05:45:41.162+00:00 | main | INFO | KeyPairUtil | Attempting to load public key from /data/besu/key
...
2024-02-02 05:45:43.433+00:00 | main | INFO | TrieLogSubCommand | Estimating trie logs size before pruning...
2024-02-02 05:45:43.837+00:00 | main | INFO | TrieLogSubCommand | Estimated trie logs size before pruning: 9 GiB
2024-02-02 05:46:09.863+00:00 | main | INFO | TrieLogHelper | Starting pruning: retain 512 trie logs, processing in 1 batches...
2024-02-02 05:46:09.918+00:00 | main | INFO | TrieLogHelper | Saving trie logs to retain in file /data/besu/database/trieLogsToRetain-1 (batch 1)...
2024-02-02 05:46:09.926+00:00 | main | INFO | TrieLogHelper | Obtaining trielogs from db, this may take a few minutes...
2024-02-02 05:46:10.100+00:00 | main | INFO | TrieLogHelper | Clear trie logs...
2024-02-02 05:46:10.155+00:00 | main | INFO | TrieLogHelper | Restoring trie logs retained from batch 1...
2024-02-02 05:46:10.222+00:00 | main | INFO | TrieLogHelper | Key(0): 0xcd50706da7f6f2db7f9d54f3589122760900d9ab2508c20a4ca40b496d930368
...
2024-02-02 05:46:10.336+00:00 | main | INFO | TrieLogHelper | Key(511): 0x238f9649b59616430ad7e43b8f3cf65bc97cac4aa54a3eddf3ad6ee666ce733e
2024-02-02 05:46:10.441+00:00 | main | INFO | TrieLogHelper | Deleting files...
2024-02-02 05:46:10.446+00:00 | main | INFO | TrieLogSubCommand | Finished pruning. Re-estimating trie logs size...
2024-02-02 05:46:11.023+00:00 | main | INFO | TrieLogSubCommand | Estimated trie logs size after pruning: 0 B (0 B estimate is normal when using default settings)
2024-02-02 05:46:11.023+00:00 | main | INFO | TrieLogSubCommand | Prune ran successfully. We estimate you freed up 9 GiB!
Prune ran successfully. We estimate you freed up 9 GiB!
If you are using a TOML configuration file, you can run a command similar to the following:
sudo /usr/local/bin/besu/bin/besu --config-file=besu-config.toml storage trie-log prune
Troubleshoot
Troubleshoot common errors that can occur when using the trie log prune command to reduce your database size for Bonsai Tries. To minimize errors, ensure your command specifies the following: