From b3f42cdd7e7bcb8ee064c19504caa07ee684bb58 Mon Sep 17 00:00:00 2001 From: Maciej Kulawik Date: Thu, 1 Feb 2024 23:04:36 +0000 Subject: [PATCH] set target only once --- cmd/staterecovery/staterecovery.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/cmd/staterecovery/staterecovery.go b/cmd/staterecovery/staterecovery.go index 97c570e9b0..bb67830354 100644 --- a/cmd/staterecovery/staterecovery.go +++ b/cmd/staterecovery/staterecovery.go @@ -15,6 +15,11 @@ import ( func RecreateMissingStates(chainDb ethdb.Database, bc *core.BlockChain, cacheConfig *core.CacheConfig, startBlock uint64) error { start := time.Now() + currentHeader := bc.CurrentBlock() + if currentHeader == nil { + return fmt.Errorf("current header is nil") + } + target := currentHeader.Number.Uint64() current := startBlock genesis := bc.Config().ArbitrumChainParams.GenesisBlockNum if current < genesis+1 { @@ -48,11 +53,7 @@ func RecreateMissingStates(chainDb ethdb.Database, bc *core.BlockChain, cacheCon break } if time.Since(logged) > 1*time.Minute { - var target uint64 - if h := bc.CurrentBlock(); h != nil { - target = h.Number.Uint64() - } - log.Info("Recreating missing states", "block", current, "target", target, "remaining", target-current, "elapsed", time.Since(start), "recreated", recreated) + log.Info("Recreating missing states", "block", current, "target", target, "remaining", int64(target)-int64(current), "elapsed", time.Since(start), "recreated", recreated) logged = time.Now() } currentState, err := state.New(currentBlock.Root(), database, nil)