triedb/pathdb: address comments from guillaume

This commit is contained in:
Gary Rong 2025-12-30 22:11:21 +08:00
parent 5379bdf8a8
commit 4b196ac530
2 changed files with 10 additions and 16 deletions

View file

@ -164,8 +164,8 @@ type indexWriter struct {
}
// newIndexWriter constructs the index writer for the specified state. Additionally,
// it takes an element ID and prunes all existing elements above that ID. It's
// essential as the recovery mechanism after unclean shutdown during the history
// it takes an integer as the limit and prunes all existing elements above that ID.
// It's essential as the recovery mechanism after unclean shutdown during the history
// indexing.
func newIndexWriter(db ethdb.KeyValueReader, state stateIdent, limit uint64) (*indexWriter, error) {
blob := readStateIndex(state, db)
@ -184,10 +184,7 @@ func newIndexWriter(db ethdb.KeyValueReader, state stateIdent, limit uint64) (*i
return nil, err
}
// Trim trailing blocks whose elements all exceed the limit.
for i := len(descList) - 1; i > 0; i-- {
if descList[i].max <= limit {
break
}
for i := len(descList) - 1; i > 0 && descList[i].max > limit; i-- {
// The previous block has the elements that exceed the limit,
// therefore the current block can be entirely dropped.
if descList[i-1].max >= limit {
@ -308,10 +305,7 @@ func newIndexDeleter(db ethdb.KeyValueReader, state stateIdent, limit uint64) (*
return nil, err
}
// Trim trailing blocks whose elements all exceed the limit.
for i := len(descList) - 1; i > 0; i-- {
if descList[i].max <= limit {
break
}
for i := len(descList) - 1; i > 0 && descList[i].max > limit; i-- {
// The previous block has the elements that exceed the limit,
// therefore the current block can be entirely dropped.
if descList[i-1].max >= limit {
@ -337,7 +331,7 @@ func newIndexDeleter(db ethdb.KeyValueReader, state stateIdent, limit uint64) (*
}, nil
}
// empty returns a flag indicating whether the state index is empty.
// empty returns whether the state index is empty.
func (d *indexDeleter) empty() bool {
return d.bw.empty() && len(d.descList) == 1
}

View file

@ -121,11 +121,11 @@ func deleteIndexMetadata(db ethdb.KeyValueWriter, typ historyType) {
// of historical data (e.g., state or trie node changes) atomically.
type batchIndexer struct {
index map[stateIdent][]uint64 // List of history IDs for tracked state entry
pending int // Number of entries processed in the current batch
delete bool // Operation mode: true for unindex, false for index
lastID uint64 // ID of the most recently processed history
typ historyType // Type of history being processed (e.g., state or trienode)
db ethdb.KeyValueStore // Key-value database used to store or delete index data
pending int // Number of entries processed in the current batch.
delete bool // Operation mode: true for unindex, false for index.
lastID uint64 // ID of the most recently processed history.
typ historyType // Type of history being processed (e.g., state or trienode).
db ethdb.KeyValueStore // Key-value database used to store or delete index data.
}
// newBatchIndexer constructs the batch indexer with the supplied mode.