diff options
Diffstat (limited to 'core/blockchain.go')
-rw-r--r-- | core/blockchain.go | 43 |
1 files changed, 6 insertions, 37 deletions
diff --git a/core/blockchain.go b/core/blockchain.go index 60707281c..711959692 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -220,47 +220,16 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par } // Initialize the chain with ancient data if it isn't empty. if bc.empty() { - if frozen, err := bc.db.Ancients(); err == nil && frozen > 0 { - var ( - start = time.Now() - logged time.Time - ) - for i := uint64(0); i < frozen; i++ { - // Inject hash<->number mapping. - hash := rawdb.ReadCanonicalHash(bc.db, i) - if hash == (common.Hash{}) { - return nil, errors.New("broken ancient database") - } - rawdb.WriteHeaderNumber(bc.db, hash, i) - - // Inject txlookup indexes. - block := rawdb.ReadBlock(bc.db, hash, i) - if block == nil { - return nil, errors.New("broken ancient database") - } - rawdb.WriteTxLookupEntries(bc.db, block) - - // If we've spent too much time already, notify the user of what we're doing - if time.Since(logged) > 8*time.Second { - log.Info("Initializing chain from ancient data", "number", i, "hash", hash, "total", frozen-1, "elapsed", common.PrettyDuration(time.Since(start))) - logged = time.Now() - } - } - hash := rawdb.ReadCanonicalHash(bc.db, frozen-1) - rawdb.WriteHeadHeaderHash(bc.db, hash) - rawdb.WriteHeadFastBlockHash(bc.db, hash) - - // The first thing the node will do is reconstruct the verification data for - // the head block (ethash cache or clique voting snapshot). Might as well do - // it in advance. - bc.engine.VerifyHeader(bc, rawdb.ReadHeader(bc.db, hash, frozen-1), true) - - log.Info("Initialized chain from ancient data", "number", frozen-1, "hash", hash, "elapsed", common.PrettyDuration(time.Since(start))) - } + rawdb.InitDatabaseFromFreezer(bc.db) } if err := bc.loadLastState(); err != nil { return nil, err } + // The first thing the node will do is reconstruct the verification data for + // the head block (ethash cache or clique voting snapshot). Might as well do + // it in advance. + bc.engine.VerifyHeader(bc, bc.CurrentHeader(), true) + if frozen, err := bc.db.Ancients(); err == nil && frozen > 0 { var ( needRewind bool |