triedb/pathdb: enable trienode history#32621
Conversation
d3caa37 to
86e494c
Compare
86e494c to
9cb5d6b
Compare
9cb5d6b to
6345086
Compare
a2d508a to
4119684
Compare
4119684 to
842047e
Compare
842047e to
de31359
Compare
MariusVanDerWijden
left a comment
There was a problem hiding this comment.
Added some comments, otherwise LGTM
| // Reset the both histories if the trie database is not initialized yet. | ||
| // This action is necessary because these histories are not expected | ||
| // to exist without an initialized trie database. | ||
| if stateID == 0 { |
There was a problem hiding this comment.
Wouldn't this also remove state history if we remove the current state (e.g. if we recommend someone to drop the current state and resync)
There was a problem hiding this comment.
It's exactly what the logic is handling of.
Once we remove the current state via geth removedb, keep the historical chain segment and run the snap sync on top, the state history and trienode history should all be wiped. The state history and trienode history should be consistent with the live state.
| if typ == typeStateHistory { | ||
| rawdb.DeleteStateHistoryIndexMetadata(batch) | ||
| rawdb.DeleteStateHistoryIndexes(batch) | ||
| } else { | ||
| rawdb.DeleteTrienodeHistoryIndexMetadata(batch) | ||
| rawdb.DeleteTrienodeHistoryIndexes(batch) | ||
| } |
There was a problem hiding this comment.
Won't these almost always error with ErrTooManyKeys?
There was a problem hiding this comment.
// DeleteTrienodeHistoryIndexes completely removes all trienode history indexing data.
func DeleteTrienodeHistoryIndexes(db ethdb.KeyValueRangeDeleter) {
DeleteHistoryByRange(db, TrienodeHistoryMetadataPrefix)
DeleteHistoryByRange(db, TrienodeHistoryBlockPrefix)
}
// DeleteHistoryByRange completely removes all database entries with the specific prefix.
// Note, this method assumes the space with the given prefix is exclusively occupied!
func DeleteHistoryByRange(db ethdb.KeyValueRangeDeleter, prefix []byte) {
start := prefix
limit := increaseKey(bytes.Clone(prefix))
// Try to remove the data in the range by a loop, as the leveldb
// doesn't support the native range deletion.
for {
err := db.DeleteRange(start, limit)
if err == nil {
return
}
if errors.Is(err, ethdb.ErrTooManyKeys) {
continue
}
log.Crit("Failed to delete history index range", "err", err)
}
}The deletion will be re-attempted once ErrTooManyKeys is encountered in terms of LevelDB.
de31359 to
3abbfde
Compare
|
@MariusVanDerWijden I have addressed the issue you found, please take another look. |
It's the part-4 for trienode history. The trienode history persistence has been enabled
with this PR by flag
history.trienode <non-negative-number>