fix: make commit retry logic selective (#788)

This commit is contained in:
Ömer Faruk Irmak 2024-05-31 12:05:36 +03:00 committed by GitHub
parent ca1db84d75
commit 36d7325ea1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 29 additions and 13 deletions

View file

@ -592,18 +592,20 @@ func (w *worker) startNewPipeline(timestamp int64) {
} }
func (w *worker) handlePipelineResult(res *pipeline.Result) error { 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, // 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. // 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 { if res.FinalBlock != nil {
w.updateSnapshot(res.FinalBlock) w.updateSnapshot(res.FinalBlock)
} }
w.currentPipeline.Release()
w.currentPipeline = nil
return nil return nil
} }
if res != nil && res.OverflowingTx != nil { if res.OverflowingTx != nil {
if res.FinalBlock == nil { if res.FinalBlock == nil {
// first txn overflowed the circuit, skip // first txn overflowed the circuit, skip
log.Info("Circuit capacity limit reached for a single tx", "tx", res.OverflowingTx.Hash().String(), log.Info("Circuit capacity limit reached for a single tx", "tx", res.OverflowingTx.Hash().String(),
@ -615,10 +617,10 @@ func (w *worker) handlePipelineResult(res *pipeline.Result) error {
overflowingTrace = nil overflowingTrace = nil
} }
rawdb.WriteSkippedTransaction(w.eth.ChainDb(), res.OverflowingTx, overflowingTrace, res.CCCErr.Error(), 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 { 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 { } else {
w.prioritizedTx = nil w.prioritizedTx = nil
w.eth.TxPool().RemoveTx(res.OverflowingTx.Hash(), true) w.eth.TxPool().RemoveTx(res.OverflowingTx.Hash(), true)
@ -628,7 +630,7 @@ func (w *worker) handlePipelineResult(res *pipeline.Result) error {
// no need to prioritize L1 messages, they are fetched in order // no need to prioritize L1 messages, they are fetched in order
// and processed first in every block anyways // and processed first in every block anyways
w.prioritizedTx = &prioritizedTransaction{ w.prioritizedTx = &prioritizedTransaction{
blockNumber: w.currentPipeline.Header.Number.Uint64() + 1, blockNumber: startingHeader.Number.Uint64() + 1,
tx: res.OverflowingTx, tx: res.OverflowingTx,
} }
} }
@ -650,14 +652,30 @@ func (w *worker) handlePipelineResult(res *pipeline.Result) error {
} }
var commitError error var commitError error
if res != nil && res.FinalBlock != nil { if res.FinalBlock != nil {
if commitError = w.commit(res); commitError == nil { if commitError = w.commit(res); commitError == nil {
return nil return nil
} }
log.Error("Commit failed", "header", res.FinalBlock.Header, "reason", commitError) log.Error("Commit failed", "header", res.FinalBlock.Header, "reason", commitError)
if _, isRetryable := commitError.(retryableCommitError); !isRetryable {
return commitError
}
} }
w.startNewPipeline(time.Now().Unix()) 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 // commit runs any post-transaction state modifications, assembles the final block
@ -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 // 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 { if err = w.engine.VerifyHeader(w.chain, block.Header(), true); err != nil {
return err return retryableCommitError{inner: err}
} }
blockHash := block.Hash() blockHash := block.Hash()
@ -763,8 +781,6 @@ func (w *worker) commit(res *pipeline.Result) error {
// Broadcast the block and announce chain insertion event // Broadcast the block and announce chain insertion event
w.mux.Post(core.NewMinedBlockEvent{Block: block}) w.mux.Post(core.NewMinedBlockEvent{Block: block})
w.currentPipeline.Release()
w.currentPipeline = nil
return nil return nil
} }

View file

@ -24,7 +24,7 @@ import (
const ( const (
VersionMajor = 5 // Major version component of the current release VersionMajor = 5 // Major version component of the current release
VersionMinor = 3 // Minor 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 VersionMeta = "mainnet" // Version metadata to append to the version string
) )