Skip to content

Commit

Permalink
feat: double check ancestor RowConsumption before committing (#1022)
Browse files Browse the repository at this point in the history
  • Loading branch information
omerfirmak committed Sep 5, 2024
1 parent 0573f6e commit e0203bf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
34 changes: 25 additions & 9 deletions miner/scroll_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,25 +331,29 @@ 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)
select {
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() {
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion params/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down

0 comments on commit e0203bf

Please sign in to comment.