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

discard transactions from the pool that error during execution #1490

Merged
merged 1 commit into from
Nov 20, 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
17 changes: 14 additions & 3 deletions zk/stages/stage_sequence_execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ func sequencingBatchStep(
log.Trace(fmt.Sprintf("[%s] Yielded transactions from the pool", logPrefix), "txCount", len(batchState.blockState.transactionsForInclusion))
}

badTxIndexes := make([]int, 0)
for i, transaction := range batchState.blockState.transactionsForInclusion {
txHash := transaction.Hash()
effectiveGas := batchState.blockState.getL1EffectiveGases(cfg, i)
Expand Down Expand Up @@ -412,9 +413,12 @@ func sequencingBatchStep(
continue
}

// if running in normal operation mode and error != nil then just allow the code to continue
// It is safe because this approach ensures that the problematic transaction (the one that caused err != nil to be returned) is kept in yielded
// Each transaction in yielded will be reevaluated at the end of each batch
// if we have an error at this point something has gone wrong, either in the pool or otherwise
// to stop the pool growing and hampering further processing of good transactions here
// we mark it for being discarded
log.Warn(fmt.Sprintf("[%s] error adding transaction to batch, discarding from pool", logPrefix), "hash", txHash, "err", err)
badTxIndexes = append(badTxIndexes, i)
batchState.blockState.transactionsToDiscard = append(batchState.blockState.transactionsToDiscard, batchState.blockState.transactionHashesToSlots[txHash])
}

switch anyOverflow {
Expand Down Expand Up @@ -501,6 +505,12 @@ func sequencingBatchStep(
}
}

// remove transactions that have been marked for removal
for i := len(badTxIndexes) - 1; i >= 0; i-- {
idx := badTxIndexes[i]
batchState.blockState.transactionsForInclusion = append(batchState.blockState.transactionsForInclusion[:idx], batchState.blockState.transactionsForInclusion[idx+1:]...)
}

if batchState.isL1Recovery() {
// just go into the normal loop waiting for new transactions to signal that the recovery
// has finished as far as it can go
Expand All @@ -523,6 +533,7 @@ func sequencingBatchStep(
}

cfg.txPool.RemoveMinedTransactions(batchState.blockState.builtBlockElements.txSlots)
cfg.txPool.RemoveMinedTransactions(batchState.blockState.transactionsToDiscard)

if batchState.isLimboRecovery() {
stateRoot := block.Root()
Expand Down
1 change: 1 addition & 0 deletions zk/stages/stage_sequence_execute_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ type BlockState struct {
transactionHashesToSlots map[common.Hash]common.Hash
builtBlockElements BuiltBlockElements
blockL1RecoveryData *zktx.DecodedBatchL2Data
transactionsToDiscard []common.Hash
}

func newBlockState() *BlockState {
Expand Down
Loading