rename to MerkleDB

This commit is contained in:
Guillaume Ballet 2026-04-13 11:47:14 +02:00
parent 6dcb2f58f6
commit d649d93323

View file

@ -156,11 +156,11 @@ type Trie interface {
IsUBT() bool
}
// MPTDB is an implementation of Database interface for Merkle Patricia Tries.
// MerkleDB is an implementation of Database interface for Merkle Patricia Tries.
// It leverages both trie and state snapshot to provide functionalities for state
// access. It's meant to be a long-live object and has a few caches inside for
// sharing between blocks.
type MPTDB struct {
type MerkleDB struct {
triedb *triedb.Database
codedb *CodeDB
snap *snapshot.Tree
@ -177,7 +177,7 @@ func NewDatabase(tdb *triedb.Database, codedb *CodeDB) Database {
codedb: codedb,
}
}
return &MPTDB{
return &MerkleDB{
triedb: tdb,
codedb: codedb,
}
@ -192,13 +192,13 @@ func NewDatabaseForTesting() Database {
// WithSnapshot configures the provided contract code cache. Note that this
// registration must be performed before the MPTDB is used.
func (db *MPTDB) WithSnapshot(snapshot *snapshot.Tree) Database {
func (db *MerkleDB) WithSnapshot(snapshot *snapshot.Tree) Database {
db.snap = snapshot
return db
}
// StateReader returns a state reader associated with the specified state root.
func (db *MPTDB) StateReader(stateRoot common.Hash) (StateReader, error) {
func (db *MerkleDB) StateReader(stateRoot common.Hash) (StateReader, error) {
var readers []StateReader
// Configure the state reader using the standalone snapshot in hash mode.
@ -233,7 +233,7 @@ func (db *MPTDB) StateReader(stateRoot common.Hash) (StateReader, error) {
// Reader implements Database, returning a reader associated with the specified
// state root.
func (db *MPTDB) Reader(stateRoot common.Hash) (Reader, error) {
func (db *MerkleDB) Reader(stateRoot common.Hash) (Reader, error) {
sr, err := db.StateReader(stateRoot)
if err != nil {
return nil, err
@ -244,7 +244,7 @@ func (db *MPTDB) Reader(stateRoot common.Hash) (Reader, error) {
// ReadersWithCacheStats creates a pair of state readers that share the same
// underlying state reader and internal state cache, while maintaining separate
// statistics respectively.
func (db *MPTDB) ReadersWithCacheStats(stateRoot common.Hash) (Reader, Reader, error) {
func (db *MerkleDB) ReadersWithCacheStats(stateRoot common.Hash) (Reader, Reader, error) {
r, err := db.StateReader(stateRoot)
if err != nil {
return nil, nil, err
@ -256,7 +256,7 @@ func (db *MPTDB) ReadersWithCacheStats(stateRoot common.Hash) (Reader, Reader, e
}
// OpenTrie opens the main account trie at a specific root hash.
func (db *MPTDB) OpenTrie(root common.Hash) (Trie, error) {
func (db *MerkleDB) OpenTrie(root common.Hash) (Trie, error) {
tr, err := trie.NewStateTrie(trie.StateTrieID(root), db.triedb)
if err != nil {
return nil, err
@ -265,7 +265,7 @@ func (db *MPTDB) OpenTrie(root common.Hash) (Trie, error) {
}
// OpenStorageTrie opens the storage trie of an account.
func (db *MPTDB) OpenStorageTrie(stateRoot common.Hash, address common.Address, root common.Hash, self Trie) (Trie, error) {
func (db *MerkleDB) OpenStorageTrie(stateRoot common.Hash, address common.Address, root common.Hash, self Trie) (Trie, error) {
tr, err := trie.NewStateTrie(trie.StorageTrieID(stateRoot, crypto.Keccak256Hash(address.Bytes()), root), db.triedb)
if err != nil {
return nil, err
@ -274,19 +274,19 @@ func (db *MPTDB) OpenStorageTrie(stateRoot common.Hash, address common.Address,
}
// TrieDB retrieves any intermediate trie-node caching layer.
func (db *MPTDB) TrieDB() *triedb.Database {
func (db *MerkleDB) TrieDB() *triedb.Database {
return db.triedb
}
// Snapshot returns the underlying state snapshot.
func (db *MPTDB) Snapshot() *snapshot.Tree {
func (db *MerkleDB) Snapshot() *snapshot.Tree {
return db.snap
}
// Commit flushes all pending writes and finalizes the state transition,
// committing the changes to the underlying storage. It returns an error
// if the commit fails.
func (db *MPTDB) Commit(update *stateUpdate) error {
func (db *MerkleDB) Commit(update *stateUpdate) error {
// Short circuit if nothing to commit
if update.empty() {
return nil
@ -319,7 +319,7 @@ func (db *MPTDB) Commit(update *stateUpdate) error {
// Iteratee returns a state iteratee associated with the specified state root,
// through which the account iterator and storage iterator can be created.
func (db *MPTDB) Iteratee(root common.Hash) (Iteratee, error) {
func (db *MerkleDB) Iteratee(root common.Hash) (Iteratee, error) {
return newStateIteratee(true, root, db.triedb, db.snap)
}