diff --git a/miner/scroll_worker.go b/miner/scroll_worker.go index ce290a08fd26..ce5a9b4151b0 100644 --- a/miner/scroll_worker.go +++ b/miner/scroll_worker.go @@ -331,15 +331,6 @@ func (w *worker) mainLoop() { var err error for { - if _, isRetryable := err.(retryableCommitError); isRetryable { - if _, err = w.tryCommitNewWork(time.Now(), w.current.header.ParentHash, w.current.reorgReason); err != nil { - continue - } - } else if err != nil { - log.Error("failed to mine block", "err", err) - w.current = nil - } - // check for reorgs first to lower the chances of trying to handle another // event eventhough a reorg is pending (due to Go `select` pseudo-randomly picking a case // to execute if multiple of them are ready) @@ -347,9 +338,22 @@ func (w *worker) mainLoop() { case trigger := <-w.reorgCh: err = w.handleReorg(&trigger) continue + // System stopped + case <-w.exitCh: + return default: } + if _, isRetryable := err.(retryableCommitError); isRetryable { + log.Warn("failed to commit to a block, retrying", "err", err) + if _, err = w.tryCommitNewWork(time.Now(), w.current.header.ParentHash, w.current.reorgReason); err != nil { + continue + } + } else if err != nil { + log.Error("failed to mine block", "err", err) + w.current = nil + } + select { case <-w.startCh: if w.isRunning() { @@ -845,6 +849,18 @@ func (w *worker) commit(force bool) (common.Hash, error) { ) } + currentHeight := w.current.header.Number.Uint64() + maxReorgDepth := uint64(w.config.CCCMaxWorkers + 1) + if currentHeight > maxReorgDepth { + ancestorHeight := currentHeight - maxReorgDepth + ancestorHash := w.chain.GetHeaderByNumber(ancestorHeight).Hash() + if rawdb.ReadBlockRowConsumption(w.chain.Database(), ancestorHash) == nil { + // reject committing to a block if its ancestor doesn't have its RC stored in DB yet. + // which may either mean that it failed CCC or it is still in the process of being checked + return common.Hash{}, retryableCommitError{inner: errors.New("ancestor doesn't have RC yet")} + } + } + // A new block event will trigger a reorg in the txpool, pause reorgs to defer this until we fetch txns for next block. // We may end up trying to process txns that we already included in the previous block, but they will all fail the nonce check w.eth.TxPool().PauseReorgs() diff --git a/params/version.go b/params/version.go index d591d70b2955..0a2531d42bdf 100644 --- a/params/version.go +++ b/params/version.go @@ -24,7 +24,7 @@ import ( const ( VersionMajor = 5 // Major version component of the current release VersionMinor = 7 // Minor version component of the current release - VersionPatch = 7 // Patch version component of the current release + VersionPatch = 8 // Patch version component of the current release VersionMeta = "mainnet" // Version metadata to append to the version string )