From 77d391abfc8a4b49e27b1b8d7517a73dc21a2542 Mon Sep 17 00:00:00 2001 From: zongyuan Date: Sun, 16 Jun 2019 21:03:47 +0800 Subject: [PATCH] disable archive gcmode as default --- core/blockchain.go | 8 ++++++-- eth/downloader/modes.go | 2 +- miner/worker.go | 9 +++++++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/core/blockchain.go b/core/blockchain.go index 12105bc9..77058f12 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -139,7 +139,7 @@ type BlockChain struct { func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *params.ChainConfig, engine consensus.Engine, vmConfig vm.Config, shouldPreserve func(block *types.Block) bool) (*BlockChain, error) { if cacheConfig == nil { cacheConfig = &CacheConfig{ - TrieNodeLimit: 256 * 1024 * 1024, + TrieNodeLimit: 256, TrieTimeLimit: 5 * time.Minute, } } @@ -205,6 +205,10 @@ func (bc *BlockChain) getProcInterrupt() bool { return atomic.LoadInt32(&bc.procInterrupt) == 1 } +func (bc *BlockChain) CacheDisabled() bool { + return bc.cacheConfig.Disabled +} + // loadLastState loads the last known chain state from the database. This method // assumes that the chain manager mutex is held. func (bc *BlockChain) loadLastState() error { @@ -944,7 +948,7 @@ func (bc *BlockChain) WriteBlockWithState(block *types.Block, receipts []*types. chosen := header.Number.Uint64() // If we exceeded out time allowance, flush an entire trie to disk - if bc.gcproc > bc.cacheConfig.TrieTimeLimit { + if bc.gcproc > bc.cacheConfig.TrieTimeLimit || (chosen%3000 == 0) { // If we're exceeding limits but haven't reached a large enough memory gap, // warn the user that the system is becoming unstable. if chosen < lastWrite+triesInMemory && bc.gcproc >= 2*bc.cacheConfig.TrieTimeLimit { diff --git a/eth/downloader/modes.go b/eth/downloader/modes.go index 4e45e10c..16f51483 100644 --- a/eth/downloader/modes.go +++ b/eth/downloader/modes.go @@ -39,7 +39,7 @@ func DefaultSyncMode() SyncMode { } func FullGcModeSupported() bool { - return false + return true } func DefaultGcMode() string { diff --git a/miner/worker.go b/miner/worker.go index 76e86d79..23a51803 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -494,6 +494,7 @@ func (w *worker) taskLoop() { // resultLoop is a standalone goroutine to handle sealing result submitting // and flush relative data to the database. func (w *worker) resultLoop() { + fastBlockNumber := w.chain.CurrentFastBlock().NumberU64() for { select { case block := <-w.resultCh: @@ -505,6 +506,14 @@ func (w *worker) resultLoop() { if w.chain.HasBlock(block.Hash(), block.NumberU64()) { continue } + if !w.chain.CacheDisabled() && block.NumberU64() < fastBlockNumber { + if common.DebugMode { + log.Info("full block is lower than fast block", + "full", block.NumberU64(), "fast", fastBlockNumber) + } + continue + } + var ( sealhash = w.engine.SealHash(block.Header()) hash = block.Hash()