fix: prune uses the latest block height as the target by default #46
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
After executing the pruning command
geth snapshot prune-state --datadir {the data dir of your node} --triesInMemory=32
on the current op-geth, the node may encounter a situation where the block height is stuck and unable to increase when restarted.When pruning, geth will by default select the block height corresponding to the bottom layer of diffLayer in the snapshot structure as the target block height. Since we have configured triesInMemory=32 , there are a total of 32 layers in diffLayer, and the target block height is the latest block height minus 31 blocks. After pruning, all block heights except for the target block height will have their state data cleared.
When geth is restarted, the code will automatically start rolling back the chain until a block height with state data is found, since the latest block height has lost state data. Therefore, the unsafe block height will roll back 31 block heights. It is worth noting that although the unsafe block height is rolled back, the header, body, receipts and other data are not deleted and still exist in the database.
At this time, op-node will also start, and it will use op-geth to obtain the new unsafe block height, and based on this, it will produce a block to advance the block height header.
At this time, if the node is a sequencer, we will encounter two situations:
Rationale
To solve the above problem, I changed the default target block of prune-state to the latest block, so there will be no rollback and all problems will be solved. In opBNB, we rarely encounter reOrg, so there is no need to roll back the chain.
I have another solution PR: #47
Both of these solutions can solve our problem, we can discuss choosing one or both.
Example
After this PR takes effect, the recommended pruning process is as follows:
geth snapshot prune-state --datadir {the data dir of your node} --triesInMemory=32
.Note: If you execute pruning while the target block height has not yet been finalized, and a chain reorganization occurs at this time, causing the head of the chain to be less than or equal to your target block height, your node will not be able to recover after pruning. Therefore, make sure that the latest block height at the time of shutdown has been finalized before executing the pruning command. If you find that a chain reorganization has occurred during this period, you should restart the node and then select an another appropriate time to perform pruning.
Changes
Notable changes: