Skip to content

Commit ab59c52

Browse files
committed
core/state: fix broken test
1 parent bada592 commit ab59c52

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

core/bintrie_witness_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package core
1919
import (
2020
"encoding/binary"
2121
"fmt"
22+
"github.com/ethereum/go-ethereum/core/state/codedb"
2223
"math/big"
2324
"testing"
2425

@@ -220,7 +221,7 @@ func TestProcessParentBlockHash(t *testing.T) {
220221
cacheConfig := DefaultConfig().WithStateScheme(rawdb.PathScheme)
221222
cacheConfig.SnapshotLimit = 0
222223
triedb := triedb.NewDatabase(db, cacheConfig.triedbConfig(true))
223-
statedb, _ := state.New(types.EmptyVerkleHash, state.NewDatabase(triedb, nil))
224+
statedb, _ := state.New(types.EmptyVerkleHash, state.NewDatabase(triedb, codedb.New(db)))
224225
checkBlockHashes(statedb, true)
225226
})
226227
}

core/state/statedb.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,18 +1306,20 @@ func (s *StateDB) commit(deleteEmptyObjects bool, rawStorageKey bool, blockNumbe
13061306
// Clear all internal flags and update state root at the end.
13071307
s.mutations = make(map[common.Address]*mutation)
13081308
s.stateObjectsDestruct = make(map[common.Address]*stateObject)
1309-
s.reader, _ = s.db.Reader(root)
13101309

13111310
origin := s.originalRoot
13121311
s.originalRoot = root
13131312

1314-
update := newStateUpdate(rawStorageKey, origin, root, blockNumber, deletes, updates, nodes)
1315-
13161313
start = time.Now()
1314+
update := newStateUpdate(rawStorageKey, origin, root, blockNumber, deletes, updates, nodes)
13171315
if err := s.db.Commit(update); err != nil {
13181316
return nil, err
13191317
}
13201318
s.DatabaseCommits = time.Since(start)
1319+
1320+
// The reader update must be performed as the final step, otherwise,
1321+
// the new state would not be visible before db.commit.
1322+
s.reader, _ = s.db.Reader(root)
13211323
return update, nil
13221324
}
13231325

0 commit comments

Comments
 (0)