@@ -105,7 +105,7 @@ data, and verifies that all snapshot storage data has a corresponding account.
105
105
},
106
106
{
107
107
Name : "traverse-state" ,
108
- Usage : "Traverse the state with given root hash for verification" ,
108
+ Usage : "Traverse the state with given root hash and perform quick verification" ,
109
109
ArgsUsage : "<root>" ,
110
110
Action : utils .MigrateFlags (traverseState ),
111
111
Category : "MISCELLANEOUS COMMANDS" ,
@@ -121,7 +121,7 @@ It's also usable without snapshot enabled.
121
121
},
122
122
{
123
123
Name : "traverse-rawstate" ,
124
- Usage : "Traverse the state with given root hash for verification" ,
124
+ Usage : "Traverse the state with given root hash and perform detailed verification" ,
125
125
ArgsUsage : "<root>" ,
126
126
Action : utils .MigrateFlags (traverseRawState ),
127
127
Category : "MISCELLANEOUS COMMANDS" ,
@@ -367,6 +367,8 @@ func traverseRawState(ctx *cli.Context) error {
367
367
codes int
368
368
lastReport time.Time
369
369
start = time .Now ()
370
+ hasher = crypto .NewKeccakState ()
371
+ got = make ([]byte , 32 )
370
372
)
371
373
accIter := t .NodeIterator (nil )
372
374
for accIter .Next (true ) {
@@ -376,10 +378,18 @@ func traverseRawState(ctx *cli.Context) error {
376
378
// Check the present for non-empty hash node(embedded node doesn't
377
379
// have their own hash).
378
380
if node != (common.Hash {}) {
379
- if ! rawdb .HasTrieNode (chaindb , node ) {
381
+ blob := rawdb .ReadTrieNode (chaindb , node )
382
+ if len (blob ) == 0 {
380
383
log .Error ("Missing trie node(account)" , "hash" , node )
381
384
return errors .New ("missing account" )
382
385
}
386
+ hasher .Reset ()
387
+ hasher .Write (blob )
388
+ hasher .Read (got )
389
+ if ! bytes .Equal (got , node .Bytes ()) {
390
+ log .Error ("Invalid trie node(account)" , "hash" , node .Hex (), "value" , blob )
391
+ return errors .New ("invalid account node" )
392
+ }
383
393
}
384
394
// If it's a leaf node, yes we are touching an account,
385
395
// dig into the storage trie further.
@@ -404,10 +414,18 @@ func traverseRawState(ctx *cli.Context) error {
404
414
// Check the present for non-empty hash node(embedded node doesn't
405
415
// have their own hash).
406
416
if node != (common.Hash {}) {
407
- if ! rawdb .HasTrieNode (chaindb , node ) {
417
+ blob := rawdb .ReadTrieNode (chaindb , node )
418
+ if len (blob ) == 0 {
408
419
log .Error ("Missing trie node(storage)" , "hash" , node )
409
420
return errors .New ("missing storage" )
410
421
}
422
+ hasher .Reset ()
423
+ hasher .Write (blob )
424
+ hasher .Read (got )
425
+ if ! bytes .Equal (got , node .Bytes ()) {
426
+ log .Error ("Invalid trie node(storage)" , "hash" , node .Hex (), "value" , blob )
427
+ return errors .New ("invalid storage node" )
428
+ }
411
429
}
412
430
// Bump the counter if it's leaf node.
413
431
if storageIter .Leaf () {
0 commit comments