Skip to content

triedb/pathdb: enable trienode history#32621

Merged
rjl493456442 merged 2 commits intoethereum:masterfrom
rjl493456442:trie-archive-p4
Jan 17, 2026
Merged

triedb/pathdb: enable trienode history#32621
rjl493456442 merged 2 commits intoethereum:masterfrom
rjl493456442:trie-archive-p4

Conversation

@rjl493456442
Copy link
Copy Markdown
Member

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>

@rjl493456442 rjl493456442 force-pushed the trie-archive-p4 branch 5 times, most recently from d3caa37 to 86e494c Compare September 22, 2025 06:20
@ethereumorg092-arch ethereumorg092-arch mentioned this pull request Oct 10, 2025
@rjl493456442 rjl493456442 force-pushed the trie-archive-p4 branch 2 times, most recently from a2d508a to 4119684 Compare October 25, 2025 15:03
@fjl fjl added this to the 1.17.0 milestone Jan 15, 2026
Copy link
Copy Markdown
Member

@MariusVanDerWijden MariusVanDerWijden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some comments, otherwise LGTM

Comment thread triedb/pathdb/history.go
// 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 {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread triedb/pathdb/history.go Outdated
Comment thread triedb/pathdb/history.go
Comment on lines +281 to +287
if typ == typeStateHistory {
rawdb.DeleteStateHistoryIndexMetadata(batch)
rawdb.DeleteStateHistoryIndexes(batch)
} else {
rawdb.DeleteTrienodeHistoryIndexMetadata(batch)
rawdb.DeleteTrienodeHistoryIndexes(batch)
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't these almost always error with ErrTooManyKeys?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// 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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah sorry

@rjl493456442
Copy link
Copy Markdown
Member Author

@MariusVanDerWijden I have addressed the issue you found, please take another look.

Copy link
Copy Markdown
Member

@MariusVanDerWijden MariusVanDerWijden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@rjl493456442 rjl493456442 merged commit add1890 into ethereum:master Jan 17, 2026
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants