Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make commit retry logic selective #788

Merged
merged 2 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
colinlyguo marked this conversation as resolved.
Show resolved Hide resolved
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 {
Thegaram marked this conversation as resolved.
Show resolved Hide resolved
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 {
Thegaram marked this conversation as resolved.
Show resolved Hide resolved
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
omerfirmak marked this conversation as resolved.
Show resolved Hide resolved
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
Loading