Skip to content

Commit

Permalink
fix: make commit retry logic selective (#788)
Browse files Browse the repository at this point in the history
  • Loading branch information
omerfirmak authored May 31, 2024
1 parent ca1db84 commit 36d7325
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
40 changes: 28 additions & 12 deletions miner/scroll_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -592,18 +592,20 @@ func (w *worker) startNewPipeline(timestamp int64) {
}

func (w *worker) handlePipelineResult(res *pipeline.Result) error {
startingHeader := w.currentPipeline.Header
w.currentPipeline.Release()
w.currentPipeline = nil

// Rows being nil without an OverflowingTx means that block didn't go thru CCC,
// which means that we are not the sequencer. Do not attempt to commit.
if res != nil && res.Rows == nil && res.OverflowingTx == nil {
if res.Rows == nil && res.OverflowingTx == nil {
if res.FinalBlock != nil {
w.updateSnapshot(res.FinalBlock)
}
w.currentPipeline.Release()
w.currentPipeline = nil
return nil
}

if res != nil && res.OverflowingTx != nil {
if res.OverflowingTx != nil {
if res.FinalBlock == nil {
// first txn overflowed the circuit, skip
log.Info("Circuit capacity limit reached for a single tx", "tx", res.OverflowingTx.Hash().String(),
Expand All @@ -615,10 +617,10 @@ func (w *worker) handlePipelineResult(res *pipeline.Result) error {
overflowingTrace = nil
}
rawdb.WriteSkippedTransaction(w.eth.ChainDb(), res.OverflowingTx, overflowingTrace, res.CCCErr.Error(),
w.currentPipeline.Header.Number.Uint64(), nil)
startingHeader.Number.Uint64(), nil)

if overflowingL1MsgTx := res.OverflowingTx.AsL1MessageTx(); overflowingL1MsgTx != nil {
rawdb.WriteFirstQueueIndexNotInL2Block(w.eth.ChainDb(), w.currentPipeline.Header.ParentHash, overflowingL1MsgTx.QueueIndex+1)
rawdb.WriteFirstQueueIndexNotInL2Block(w.eth.ChainDb(), startingHeader.ParentHash, overflowingL1MsgTx.QueueIndex+1)
} else {
w.prioritizedTx = nil
w.eth.TxPool().RemoveTx(res.OverflowingTx.Hash(), true)
Expand All @@ -628,7 +630,7 @@ func (w *worker) handlePipelineResult(res *pipeline.Result) error {
// no need to prioritize L1 messages, they are fetched in order
// and processed first in every block anyways
w.prioritizedTx = &prioritizedTransaction{
blockNumber: w.currentPipeline.Header.Number.Uint64() + 1,
blockNumber: startingHeader.Number.Uint64() + 1,
tx: res.OverflowingTx,
}
}
Expand All @@ -650,14 +652,30 @@ func (w *worker) handlePipelineResult(res *pipeline.Result) error {
}

var commitError error
if res != nil && res.FinalBlock != nil {
if res.FinalBlock != nil {
if commitError = w.commit(res); commitError == nil {
return nil
}
log.Error("Commit failed", "header", res.FinalBlock.Header, "reason", commitError)
if _, isRetryable := commitError.(retryableCommitError); !isRetryable {
return commitError
}
}
w.startNewPipeline(time.Now().Unix())
return commitError
return nil
}

// retryableCommitError wraps an error that happened during commit phase and indicates that worker can retry to build a new block
type retryableCommitError struct {
inner error
}

func (e retryableCommitError) Error() string {
return e.inner.Error()
}

func (e retryableCommitError) Unwrap() error {
return e.inner
}

// commit runs any post-transaction state modifications, assembles the final block
Expand Down Expand Up @@ -699,7 +717,7 @@ func (w *worker) commit(res *pipeline.Result) error {

// verify the generated block with local consensus engine to make sure everything is as expected
if err = w.engine.VerifyHeader(w.chain, block.Header(), true); err != nil {
return err
return retryableCommitError{inner: err}
}

blockHash := block.Hash()
Expand Down Expand Up @@ -763,8 +781,6 @@ func (w *worker) commit(res *pipeline.Result) error {
// Broadcast the block and announce chain insertion event
w.mux.Post(core.NewMinedBlockEvent{Block: block})

w.currentPipeline.Release()
w.currentPipeline = nil
return nil
}

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 = 3 // Minor version component of the current release
VersionPatch = 31 // Patch version component of the current release
VersionPatch = 32 // Patch version component of the current release
VersionMeta = "mainnet" // Version metadata to append to the version string
)

Expand Down

0 comments on commit 36d7325

Please sign in to comment.