From f275e1f5cc3c13f57eaafa78df6843ae76268653 Mon Sep 17 00:00:00 2001 From: Alexey Akhunov Date: Tue, 10 Jul 2018 21:20:14 +0100 Subject: [PATCH] Disable block processing --- core/block_validator.go | 4 +- core/blockchain.go | 92 ++---------------------------------- core/tx_pool.go | 2 +- eth/downloader/downloader.go | 4 +- miner/worker.go | 4 +- 5 files changed, 10 insertions(+), 96 deletions(-) diff --git a/core/block_validator.go b/core/block_validator.go index 98958809b7..787798d712 100644 --- a/core/block_validator.go +++ b/core/block_validator.go @@ -50,10 +50,10 @@ func NewBlockValidator(config *params.ChainConfig, blockchain *BlockChain, engin // validated at this point. func (v *BlockValidator) ValidateBody(block *types.Block) error { // Check whether the block's known, and if not, that it's linkable - if v.bc.HasBlockAndState(block.Hash(), block.NumberU64()) { + if v.bc.HasBlock(block.Hash(), block.NumberU64()) { return ErrKnownBlock } - if !v.bc.HasBlockAndState(block.ParentHash(), block.NumberU64()-1) { + if !v.bc.HasBlock(block.ParentHash(), block.NumberU64()-1) { if !v.bc.HasBlock(block.ParentHash(), block.NumberU64()-1) { return consensus.ErrUnknownAncestor } diff --git a/core/blockchain.go b/core/blockchain.go index 2f1e78423e..0cdfd1d09e 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -216,14 +216,6 @@ func (bc *BlockChain) loadLastState() error { log.Warn("Head block missing, resetting chain", "hash", head) return bc.Reset() } - // Make sure the state associated with the block is available - if _, err := state.New(currentBlock.Root(), bc.stateCache); err != nil { - // Dangling block without a state associated, init from scratch - log.Warn("Head state missing, repairing chain", "number", currentBlock.Number(), "hash", currentBlock.Hash()) - if err := bc.repair(¤tBlock); err != nil { - return err - } - } // Everything seems to be fine, set as the head block bc.currentBlock.Store(currentBlock) @@ -874,7 +866,7 @@ func (bc *BlockChain) WriteBlockWithoutState(block *types.Block, td *big.Int) (e } // WriteBlockWithState writes the block and all associated state to the database. -func (bc *BlockChain) WriteBlockWithState(block *types.Block, receipts []*types.Receipt, state *state.StateDB) (status WriteStatus, err error) { +func (bc *BlockChain) WriteBlockWithState(block *types.Block) (status WriteStatus, err error) { bc.wg.Add(1) defer bc.wg.Done() @@ -899,59 +891,6 @@ func (bc *BlockChain) WriteBlockWithState(block *types.Block, receipts []*types. batch := bc.db.NewBatch() rawdb.WriteBlock(batch, block) - root, err := state.Commit(bc.chainConfig.IsEIP158(block.Number())) - if err != nil { - return NonStatTy, err - } - triedb := bc.stateCache.TrieDB() - - // If we're running an archive node, always flush - if bc.cacheConfig.Disabled { - if err := triedb.Commit(root, false); err != nil { - return NonStatTy, err - } - } else { - // Full but not archive node, do proper garbage collection - triedb.Reference(root, common.Hash{}) // metadata reference to keep trie alive - bc.triegc.Push(root, -float32(block.NumberU64())) - - if current := block.NumberU64(); current > triesInMemory { - // If we exceeded our memory allowance, flush matured singleton nodes to disk - var ( - nodes, imgs = triedb.Size() - limit = common.StorageSize(bc.cacheConfig.TrieNodeLimit) * 1024 * 1024 - ) - if nodes > limit || imgs > 4*1024*1024 { - triedb.Cap(limit - ethdb.IdealBatchSize) - } - // Find the next state trie we need to commit - header := bc.GetHeaderByNumber(current - triesInMemory) - chosen := header.Number.Uint64() - - // If we exceeded out time allowance, flush an entire trie to disk - if bc.gcproc > bc.cacheConfig.TrieTimeLimit { - // 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 { - log.Info("State in memory for too long, committing", "time", bc.gcproc, "allowance", bc.cacheConfig.TrieTimeLimit, "optimum", float64(chosen-lastWrite)/triesInMemory) - } - // Flush an entire trie and restart the counters - triedb.Commit(header.Root, true) - lastWrite = chosen - bc.gcproc = 0 - } - // Garbage collect anything below our required write retention - for !bc.triegc.Empty() { - root, number := bc.triegc.Pop() - if uint64(-number) > chosen { - bc.triegc.Push(root, number) - break - } - triedb.Dereference(root.(common.Hash)) - } - } - } - rawdb.WriteReceipts(batch, block.Hash(), block.NumberU64(), receipts) // If the total difficulty is higher than our known, add it to the canonical chain // Second clause in the if statement reduces the vulnerability to selfish mining. @@ -971,7 +910,6 @@ func (bc *BlockChain) WriteBlockWithState(block *types.Block, receipts []*types. } // Write the positional metadata for transaction/receipt lookups and preimages rawdb.WriteTxLookupEntries(batch, block) - rawdb.WritePreimages(batch, block.NumberU64(), state.Preimages()) status = CanonStatTy } else { @@ -1133,32 +1071,10 @@ func (bc *BlockChain) insertChain(chain types.Blocks) (int, []interface{}, []*ty } // Create a new statedb using the parent block and report an // error if it fails. - var parent *types.Block - if i == 0 { - parent = bc.GetBlock(block.ParentHash(), block.NumberU64()-1) - } else { - parent = chain[i-1] - } - state, err := state.New(parent.Root(), bc.stateCache) - if err != nil { - return i, events, coalescedLogs, err - } - // Process block using the parent state as reference point. - receipts, logs, usedGas, err := bc.processor.Process(block, state, bc.vmConfig) - if err != nil { - bc.reportBlock(block, receipts, err) - return i, events, coalescedLogs, err - } - // Validate the state using the default validator - err = bc.Validator().ValidateState(block, parent, state, receipts, usedGas) - if err != nil { - bc.reportBlock(block, receipts, err) - return i, events, coalescedLogs, err - } proctime := time.Since(bstart) // Write the block to the chain and get the status. - status, err := bc.WriteBlockWithState(block, receipts, state) + status, err := bc.WriteBlockWithState(block) if err != nil { return i, events, coalescedLogs, err } @@ -1167,9 +1083,8 @@ func (bc *BlockChain) insertChain(chain types.Blocks) (int, []interface{}, []*ty log.Debug("Inserted new block", "number", block.Number(), "hash", block.Hash(), "uncles", len(block.Uncles()), "txs", len(block.Transactions()), "gas", block.GasUsed(), "elapsed", common.PrettyDuration(time.Since(bstart))) - coalescedLogs = append(coalescedLogs, logs...) blockInsertTimer.UpdateSince(bstart) - events = append(events, ChainEvent{block, block.Hash(), logs}) + events = append(events, ChainEvent{block, block.Hash(), []*types.Log{}}) lastCanon = block // Only count canonical blocks for GC processing time @@ -1183,7 +1098,6 @@ func (bc *BlockChain) insertChain(chain types.Blocks) (int, []interface{}, []*ty events = append(events, ChainSideEvent{block}) } stats.processed++ - stats.usedGas += usedGas cache, _ := bc.stateCache.TrieDB().Size() stats.report(chain, i, cache) diff --git a/core/tx_pool.go b/core/tx_pool.go index 9c958e3b6f..76f37621df 100644 --- a/core/tx_pool.go +++ b/core/tx_pool.go @@ -402,7 +402,7 @@ func (pool *TxPool) reset(oldHead, newHead *types.Header) { } statedb, err := pool.chain.StateAt(newHead.Root) if err != nil { - log.Error("Failed to reset txpool state", "err", err) + //log.Error("Failed to reset txpool state", "err", err) return } pool.currentState = statedb diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go index fbde9c6caa..b67a1bb219 100644 --- a/eth/downloader/downloader.go +++ b/eth/downloader/downloader.go @@ -57,8 +57,8 @@ var ( qosTuningImpact = 0.25 // Impact that a new tuning target has on the previous value maxQueuedHeaders = 32 * 1024 // [eth/62] Maximum number of headers to queue for import (DOS protection) - maxHeadersProcess = 2048 // Number of header download results to import at once into the chain - maxResultsProcess = 2048 // Number of content download results to import at once into the chain + maxHeadersProcess = 8192 // Number of header download results to import at once into the chain + maxResultsProcess = 8192 // Number of content download results to import at once into the chain fsHeaderCheckFrequency = 100 // Verification frequency of the downloaded headers during fast sync fsHeaderSafetyNet = 2048 // Number of headers to discard in case a chain violation is detected diff --git a/miner/worker.go b/miner/worker.go index ee7506d70f..4c60843c59 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -317,7 +317,7 @@ func (self *worker) wait() { log.BlockHash = block.Hash() } self.currentMu.Lock() - stat, err := self.chain.WriteBlockWithState(block, work.receipts, work.state) + stat, err := self.chain.WriteBlockWithState(block) self.currentMu.Unlock() if err != nil { log.Error("Failed writing block to chain", "err", err) @@ -440,7 +440,7 @@ func (self *worker) commitNewWork() { // Could potentially happen if starting to mine in an odd state. err := self.makeCurrent(parent, header) if err != nil { - log.Error("Failed to create mining context", "err", err) + //log.Error("Failed to create mining context", "err", err) return } // Create the current work task and check any fork transitions needed