From 09b9c27c83cabab2a07681f8f189a822c6f2308c Mon Sep 17 00:00:00 2001 From: Guillaume Ballet <3272758+gballet@users.noreply.github.com> Date: Wed, 28 Jan 2026 13:54:38 +0100 Subject: [PATCH] use the flat reader in LoadTransitionState --- core/overlay/state_transition.go | 40 -------------------------------- core/state/database.go | 38 ++++++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 42 deletions(-) diff --git a/core/overlay/state_transition.go b/core/overlay/state_transition.go index 099d68cca5..2fb7e9c3fd 100644 --- a/core/overlay/state_transition.go +++ b/core/overlay/state_transition.go @@ -17,12 +17,7 @@ package overlay import ( - "fmt" - "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/crypto" - "github.com/ethereum/go-ethereum/params" - "github.com/ethereum/go-ethereum/triedb/database" ) // TransitionState is a structure that holds the progress markers of the @@ -77,38 +72,3 @@ func (ts *TransitionState) Copy() *TransitionState { } return ret } - -var ( - conversionProgressAddressKey = common.Hash{1} - conversionProgressSlotKey = common.Hash{2} - conversionProgressStorageProcessed = common.Hash{3} -) - -// LoadTransitionState retrieves the Verkle transition state associated with -// the given state root hash from the database. -func LoadTransitionState(reader database.StateReader, root common.Hash) *TransitionState { - addrHash := crypto.Keccak256Hash(params.BinaryTransitionRegistryAddress[:]) - currentAccountBytes, err := reader.Storage(addrHash, conversionProgressAddressKey) - if err != nil { - panic(fmt.Errorf("error reading conversion account pointer: %w", err)) - } - currentAccount := common.BytesToAddress(currentAccountBytes[12:]) - - currentSlotBytes, err := reader.Storage(addrHash, conversionProgressSlotKey) - if err != nil { - panic(fmt.Errorf("error reading conversion slot pointer: %w", err)) - } - currentSlotHash := common.BytesToHash(currentSlotBytes) - - storageProcessedBytes, err := reader.Storage(addrHash, conversionProgressStorageProcessed) - if err != nil { - panic(fmt.Errorf("error reading conversion storage processing completion status: %w", err)) - } - storageProcessed := storageProcessedBytes[0] == 1 - - return &TransitionState{ - CurrentAccountAddress: ¤tAccount, - CurrentSlotHash: currentSlotHash, - StorageProcessed: storageProcessed, - } -} diff --git a/core/state/database.go b/core/state/database.go index c94e62ba54..763a73aa19 100644 --- a/core/state/database.go +++ b/core/state/database.go @@ -27,6 +27,7 @@ import ( "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethdb" + "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/trie" "github.com/ethereum/go-ethereum/trie/bintrie" "github.com/ethereum/go-ethereum/trie/transitiontrie" @@ -177,6 +178,39 @@ func NewDatabaseForTesting() *CachingDB { return NewDatabase(triedb.NewDatabase(rawdb.NewMemoryDatabase(), nil), nil) } +var ( + conversionProgressAddressKey = common.Hash{1} + conversionProgressSlotKey = common.Hash{2} + conversionProgressStorageProcessed = common.Hash{3} +) + +// LoadTransitionState retrieves the Verkle transition state associated with +// the given state root hash from the database. +func LoadTransitionState(reader StateReader, root common.Hash) *overlay.TransitionState { + currentAccountBytes, err := reader.Storage(params.BinaryTransitionRegistryAddress, conversionProgressAddressKey) + if err != nil { + panic(fmt.Errorf("error reading conversion account pointer: %w", err)) + } + currentAccount := common.BytesToAddress(currentAccountBytes[12:]) + + currentSlotHash, err := reader.Storage(params.BinaryTransitionRegistryAddress, conversionProgressSlotKey) + if err != nil { + panic(fmt.Errorf("error reading conversion slot pointer: %w", err)) + } + + storageProcessedBytes, err := reader.Storage(params.BinaryTransitionRegistryAddress, conversionProgressStorageProcessed) + if err != nil { + panic(fmt.Errorf("error reading conversion storage processing completion status: %w", err)) + } + storageProcessed := storageProcessedBytes[0] == 1 + + return &overlay.TransitionState{ + CurrentAccountAddress: ¤tAccount, + CurrentSlotHash: currentSlotHash, + StorageProcessed: storageProcessed, + } +} + // StateReader returns a state reader associated with the specified state root. func (db *CachingDB) StateReader(stateRoot common.Hash) (StateReader, error) { var readers []StateReader @@ -199,7 +233,7 @@ func (db *CachingDB) StateReader(stateRoot common.Hash) (StateReader, error) { reader, err := db.triedb.StateReader(stateRoot) if err == nil { readers = append(readers, newFlatReader(reader)) - ts = overlay.LoadTransitionState(reader, stateRoot) + ts = LoadTransitionState(readers[len(readers)-1], stateRoot) } } // Configure the trie reader, which is expected to be available as the @@ -252,7 +286,7 @@ func (db *CachingDB) OpenTrie(root common.Hash) (Trie, error) { if err != nil { return nil, fmt.Errorf("could not get reader for checking overlay status: %w", err) } - ts := overlay.LoadTransitionState(reader, root) + ts := LoadTransitionState(reader, root) if !ts.InTransition() { // Use BinaryTrie instead of VerkleTrie when IsVerkle is set // (IsVerkle actually means Binary Trie mode in this codebase)