Skip to content

Commit

Permalink
discard transactions from the pool that error during execution (#1488)
Browse files Browse the repository at this point in the history
  • Loading branch information
hexoscott authored Nov 19, 2024
1 parent cfae08c commit 47b9d05
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
17 changes: 14 additions & 3 deletions zk/stages/stage_sequence_execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ func SpawnSequencingStage(
}
}

badTxIndexes := make([]int, 0)
for i, transaction := range batchState.blockState.transactionsForInclusion {
txHash := transaction.Hash()
effectiveGas := batchState.blockState.getL1EffectiveGases(cfg, i)
Expand All @@ -301,9 +302,12 @@ func SpawnSequencingStage(
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])
}

if anyOverflow {
Expand Down Expand Up @@ -351,6 +355,12 @@ func SpawnSequencingStage(
}
}

// 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 @@ -373,6 +383,7 @@ func SpawnSequencingStage(
}

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 @@ -225,6 +225,7 @@ type BlockState struct {
transactionHashesToSlots map[common.Hash]common.Hash
builtBlockElements BuiltBlockElements
blockL1RecoveryData *zktx.DecodedBatchL2Data
transactionsToDiscard []common.Hash
}

func newBlockState() *BlockState {
Expand Down

0 comments on commit 47b9d05

Please sign in to comment.