aboutsummaryrefslogtreecommitdiffstats
path: root/core/blockchain.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2019-05-27 20:48:30 +0800
committerGitHub <noreply@github.com>2019-05-27 20:48:30 +0800
commitfc85777a219acd12620fe9b76a3b7e585800300c (patch)
tree9f09877de3f1800460e35bf4c3ac1e8bccf5a06d /core/blockchain.go
parenta184ab7a61884409a4deea2419c5307a0dc7c49d (diff)
downloadgo-tangerine-fc85777a219acd12620fe9b76a3b7e585800300c.tar
go-tangerine-fc85777a219acd12620fe9b76a3b7e585800300c.tar.gz
go-tangerine-fc85777a219acd12620fe9b76a3b7e585800300c.tar.bz2
go-tangerine-fc85777a219acd12620fe9b76a3b7e585800300c.tar.lz
go-tangerine-fc85777a219acd12620fe9b76a3b7e585800300c.tar.xz
go-tangerine-fc85777a219acd12620fe9b76a3b7e585800300c.tar.zst
go-tangerine-fc85777a219acd12620fe9b76a3b7e585800300c.zip
core: concurrent database reinit from freezer dump
* core: reinit chain from freezer in batches * core/rawdb: concurrent database reinit from freezer dump * core/rawdb: reinit from freezer in sequential order
Diffstat (limited to 'core/blockchain.go')
-rw-r--r--core/blockchain.go43
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