@@ -62,7 +62,8 @@ func makeTestState() (Database, common.Hash, []*testAccount) {
62
62
}
63
63
if i % 5 == 0 {
64
64
for j := byte (0 ); j < 5 ; j ++ {
65
- obj .SetState (db , crypto .Keccak256Hash ([]byte {i , i , i , i , i , j , j }), crypto .Keccak256Hash ([]byte {i , i , i , i , i , j , j }))
65
+ hash := crypto .Keccak256Hash ([]byte {i , i , i , i , i , j , j })
66
+ obj .SetState (db , hash , hash )
66
67
}
67
68
}
68
69
state .updateStateObject (obj )
@@ -401,15 +402,14 @@ func TestIncompleteStateSync(t *testing.T) {
401
402
// Create a random state to copy
402
403
srcDb , srcRoot , srcAccounts := makeTestState ()
403
404
404
- // isCode reports whether the hash is contract code hash.
405
- isCode := func (hash common.Hash ) bool {
406
- for _ , acc := range srcAccounts {
407
- if hash == crypto .Keccak256Hash (acc .code ) {
408
- return true
409
- }
405
+ // isCodeLookup to save some hashing
406
+ var isCode = make (map [common.Hash ]struct {})
407
+ for _ , acc := range srcAccounts {
408
+ if len (acc .code ) > 0 {
409
+ isCode [crypto .Keccak256Hash (acc .code )] = struct {}{}
410
410
}
411
- return false
412
411
}
412
+ isCode [common .BytesToHash (emptyCodeHash )] = struct {}{}
413
413
checkTrieConsistency (srcDb .TrieDB ().DiskDB ().(ethdb.Database ), srcRoot )
414
414
415
415
// Create a destination state and sync with the scheduler
@@ -447,15 +447,13 @@ func TestIncompleteStateSync(t *testing.T) {
447
447
batch .Write ()
448
448
for _ , result := range results {
449
449
added = append (added , result .Hash )
450
- }
451
- // Check that all known sub-tries added so far are complete or missing entirely.
452
- for _ , hash := range added {
453
- if isCode (hash ) {
450
+ // Check that all known sub-tries added so far are complete or missing entirely.
451
+ if _ , ok := isCode [result .Hash ]; ok {
454
452
continue
455
453
}
456
454
// Can't use checkStateConsistency here because subtrie keys may have odd
457
455
// length and crash in LeafKey.
458
- if err := checkTrieConsistency (dstDb , hash ); err != nil {
456
+ if err := checkTrieConsistency (dstDb , result . Hash ); err != nil {
459
457
t .Fatalf ("state inconsistent: %v" , err )
460
458
}
461
459
}
@@ -466,9 +464,9 @@ func TestIncompleteStateSync(t *testing.T) {
466
464
// Sanity check that removing any node from the database is detected
467
465
for _ , node := range added [1 :] {
468
466
var (
469
- key = node .Bytes ()
470
- code = isCode ( node )
471
- val []byte
467
+ key = node .Bytes ()
468
+ _ , code = isCode [ node ]
469
+ val []byte
472
470
)
473
471
if code {
474
472
val = rawdb .ReadCode (dstDb , node )
0 commit comments