github.com/unicornultrafoundation/go-u2u@v1.0.0-rc1.0.20240205080301-e74a83d3fadc/cmd/u2u/launcher/check.go (about) 1 package launcher 2 3 import ( 4 "time" 5 6 "github.com/unicornultrafoundation/go-helios/native/idx" 7 "github.com/unicornultrafoundation/go-u2u/cmd/utils" 8 "github.com/unicornultrafoundation/go-u2u/common" 9 "github.com/unicornultrafoundation/go-u2u/log" 10 "gopkg.in/urfave/cli.v1" 11 12 "github.com/unicornultrafoundation/go-u2u/native" 13 ) 14 15 func checkEvm(ctx *cli.Context) error { 16 if len(ctx.Args()) != 0 { 17 utils.Fatalf("This command doesn't require an argument.") 18 } 19 20 cfg := makeAllConfigs(ctx) 21 22 rawDbs := makeDirectDBsProducer(cfg) 23 gdb := makeGossipStore(rawDbs, cfg) 24 defer gdb.Close() 25 evms := gdb.EvmStore() 26 27 start, reported := time.Now(), time.Now() 28 29 var prevPoint idx.Block 30 var prevIndex idx.Block 31 checkBlocks := func(stateOK func(root common.Hash) (bool, error)) { 32 var ( 33 lastIdx = gdb.GetLatestBlockIndex() 34 prevPointRootExist bool 35 ) 36 gdb.ForEachBlock(func(index idx.Block, block *native.Block) { 37 prevIndex = index 38 found, err := stateOK(common.Hash(block.Root)) 39 if found != prevPointRootExist { 40 if index > 0 && found { 41 log.Warn("EVM history is pruned", "fromBlock", prevPoint, "toBlock", index-1) 42 } 43 prevPointRootExist = found 44 prevPoint = index 45 } 46 if index == lastIdx && !found { 47 log.Crit("State trie for the latest block is not found", "block", index) 48 } 49 if !found { 50 return 51 } 52 if err != nil { 53 log.Crit("State trie error", "err", err, "block", index) 54 } 55 if time.Since(reported) >= statsReportLimit { 56 log.Info("Checking presence of every node", "last", index, "pruned", !prevPointRootExist, "elapsed", common.PrettyDuration(time.Since(start))) 57 reported = time.Now() 58 } 59 }) 60 } 61 62 if err := evms.CheckEvm(checkBlocks, true); err != nil { 63 return err 64 } 65 log.Info("EVM storage is verified", "last", prevIndex, "elapsed", common.PrettyDuration(time.Since(start))) 66 return nil 67 }