@@ -27,8 +27,8 @@ import (
2727 "github.com/ethereum/go-ethereum/core/rawdb"
2828 "github.com/ethereum/go-ethereum/core/types"
2929 "github.com/ethereum/go-ethereum/crypto"
30+ "github.com/ethereum/go-ethereum/internal/testrand"
3031 "github.com/ethereum/go-ethereum/rlp"
31- "github.com/ethereum/go-ethereum/trie/testutil"
3232 "github.com/ethereum/go-ethereum/trie/trienode"
3333 "github.com/ethereum/go-ethereum/trie/triestate"
3434 "github.com/holiman/uint256"
@@ -46,15 +46,18 @@ func updateTrie(addrHash common.Hash, root common.Hash, dirties, cleans map[comm
4646 h .Update (key .Bytes (), val )
4747 }
4848 }
49- root , nodes , _ := h .Commit (false )
49+ root , nodes , err := h .Commit (false )
50+ if err != nil {
51+ panic (fmt .Errorf ("failed to commit hasher, err: %w" , err ))
52+ }
5053 return root , nodes
5154}
5255
5356func generateAccount (storageRoot common.Hash ) types.StateAccount {
5457 return types.StateAccount {
5558 Nonce : uint64 (rand .Intn (100 )),
5659 Balance : uint256 .NewInt (rand .Uint64 ()),
57- CodeHash : testutil . RandBytes (32 ),
60+ CodeHash : testrand . Bytes (32 ),
5861 Root : storageRoot ,
5962 }
6063}
@@ -101,8 +104,8 @@ func newTester(t *testing.T, historyLimit uint64) *tester {
101104 disk , _ = rawdb .NewDatabaseWithFreezer (rawdb .NewMemoryDatabase (), t .TempDir (), "" , false )
102105 db = New (disk , & Config {
103106 StateHistory : historyLimit ,
104- CleanCacheSize : 256 * 1024 ,
105- DirtyCacheSize : 256 * 1024 ,
107+ CleanCacheSize : 16 * 1024 ,
108+ DirtyCacheSize : 16 * 1024 ,
106109 })
107110 obj = & tester {
108111 db : db ,
@@ -113,7 +116,7 @@ func newTester(t *testing.T, historyLimit uint64) *tester {
113116 snapStorages : make (map [common.Hash ]map [common.Hash ]map [common.Hash ][]byte ),
114117 }
115118 )
116- for i := 0 ; i < 2 * 128 ; i ++ {
119+ for i := 0 ; i < 8 ; i ++ {
117120 var parent = types .EmptyRootHash
118121 if len (obj .roots ) != 0 {
119122 parent = obj .roots [len (obj .roots )- 1 ]
@@ -146,8 +149,8 @@ func (t *tester) generateStorage(ctx *genctx, addr common.Address) common.Hash {
146149 origin = make (map [common.Hash ][]byte )
147150 )
148151 for i := 0 ; i < 10 ; i ++ {
149- v , _ := rlp .EncodeToBytes (common .TrimLeftZeroes (testutil . RandBytes (32 )))
150- hash := testutil . RandomHash ()
152+ v , _ := rlp .EncodeToBytes (common .TrimLeftZeroes (testrand . Bytes (32 )))
153+ hash := testrand . Hash ()
151154
152155 storage [hash ] = v
153156 origin [hash ] = nil
@@ -175,8 +178,8 @@ func (t *tester) mutateStorage(ctx *genctx, addr common.Address, root common.Has
175178 }
176179 }
177180 for i := 0 ; i < 3 ; i ++ {
178- v , _ := rlp .EncodeToBytes (common .TrimLeftZeroes (testutil . RandBytes (32 )))
179- hash := testutil . RandomHash ()
181+ v , _ := rlp .EncodeToBytes (common .TrimLeftZeroes (testrand . Bytes (32 )))
182+ hash := testrand . Hash ()
180183
181184 storage [hash ] = v
182185 origin [hash ] = nil
@@ -218,7 +221,7 @@ func (t *tester) generate(parent common.Hash) (common.Hash, *trienode.MergedNode
218221 switch rand .Intn (opLen ) {
219222 case createAccountOp :
220223 // account creation
221- addr := testutil . RandomAddress ()
224+ addr := testrand . Address ()
222225 addrHash := crypto .Keccak256Hash (addr .Bytes ())
223226 if _ , ok := t .accounts [addrHash ]; ok {
224227 continue
@@ -320,14 +323,16 @@ func (t *tester) verifyState(root common.Hash) error {
320323 return errors .New ("root node is not available" )
321324 }
322325 for addrHash , account := range t .snapAccounts [root ] {
323- blob , err := reader .Node (common.Hash {}, addrHash .Bytes (), crypto .Keccak256Hash (account ))
326+ path := crypto .Keccak256 (addrHash .Bytes ())
327+ blob , err := reader .Node (common.Hash {}, path , crypto .Keccak256Hash (account ))
324328 if err != nil || ! bytes .Equal (blob , account ) {
325329 return fmt .Errorf ("account is mismatched: %w" , err )
326330 }
327331 }
328332 for addrHash , slots := range t .snapStorages [root ] {
329333 for hash , slot := range slots {
330- blob , err := reader .Node (addrHash , hash .Bytes (), crypto .Keccak256Hash (slot ))
334+ path := crypto .Keccak256 (hash .Bytes ())
335+ blob , err := reader .Node (addrHash , path , crypto .Keccak256Hash (slot ))
331336 if err != nil || ! bytes .Equal (blob , slot ) {
332337 return fmt .Errorf ("slot is mismatched: %w" , err )
333338 }
@@ -379,6 +384,12 @@ func (t *tester) bottomIndex() int {
379384}
380385
381386func TestDatabaseRollback (t * testing.T ) {
387+ // Redefine the diff layer depth allowance for faster testing.
388+ maxDiffLayers = 4
389+ defer func () {
390+ maxDiffLayers = 128
391+ }()
392+
382393 // Verify state histories
383394 tester := newTester (t , 0 )
384395 defer tester .release ()
@@ -409,6 +420,12 @@ func TestDatabaseRollback(t *testing.T) {
409420}
410421
411422func TestDatabaseRecoverable (t * testing.T ) {
423+ // Redefine the diff layer depth allowance for faster testing.
424+ maxDiffLayers = 4
425+ defer func () {
426+ maxDiffLayers = 128
427+ }()
428+
412429 var (
413430 tester = newTester (t , 0 )
414431 index = tester .bottomIndex ()
@@ -448,6 +465,12 @@ func TestDatabaseRecoverable(t *testing.T) {
448465}
449466
450467func TestDisable (t * testing.T ) {
468+ // Redefine the diff layer depth allowance for faster testing.
469+ maxDiffLayers = 4
470+ defer func () {
471+ maxDiffLayers = 128
472+ }()
473+
451474 tester := newTester (t , 0 )
452475 defer tester .release ()
453476
@@ -484,6 +507,12 @@ func TestDisable(t *testing.T) {
484507}
485508
486509func TestCommit (t * testing.T ) {
510+ // Redefine the diff layer depth allowance for faster testing.
511+ maxDiffLayers = 4
512+ defer func () {
513+ maxDiffLayers = 128
514+ }()
515+
487516 tester := newTester (t , 0 )
488517 defer tester .release ()
489518
@@ -508,6 +537,12 @@ func TestCommit(t *testing.T) {
508537}
509538
510539func TestJournal (t * testing.T ) {
540+ // Redefine the diff layer depth allowance for faster testing.
541+ maxDiffLayers = 4
542+ defer func () {
543+ maxDiffLayers = 128
544+ }()
545+
511546 tester := newTester (t , 0 )
512547 defer tester .release ()
513548
@@ -532,6 +567,12 @@ func TestJournal(t *testing.T) {
532567}
533568
534569func TestCorruptedJournal (t * testing.T ) {
570+ // Redefine the diff layer depth allowance for faster testing.
571+ maxDiffLayers = 4
572+ defer func () {
573+ maxDiffLayers = 128
574+ }()
575+
535576 tester := newTester (t , 0 )
536577 defer tester .release ()
537578
@@ -574,6 +615,12 @@ func TestCorruptedJournal(t *testing.T) {
574615// truncating the tail histories. This ensures that the ID of the persistent state
575616// always falls within the range of [oldest-history-id, latest-history-id].
576617func TestTailTruncateHistory (t * testing.T ) {
618+ // Redefine the diff layer depth allowance for faster testing.
619+ maxDiffLayers = 4
620+ defer func () {
621+ maxDiffLayers = 128
622+ }()
623+
577624 tester := newTester (t , 10 )
578625 defer tester .release ()
579626
0 commit comments