Skip to content

Commit

Permalink
better handling of errors bubbling up from the txpool (#1306)
Browse files Browse the repository at this point in the history
  • Loading branch information
hexoscott authored Oct 10, 2024
1 parent 34b78f3 commit 7d2ba1a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
20 changes: 15 additions & 5 deletions zk/stages/stage_sequence_execute_transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@ func getNextPoolTransactions(ctx context.Context, cfg SequenceBlockCfg, executio
if allConditionsOk, _, err = cfg.txPool.YieldBest(cfg.yieldSize, &slots, poolTx, executionAt, gasLimit, 0, alreadyYielded); err != nil {
return err
}
yieldedTxs, err := extractTransactionsFromSlot(&slots)
yieldedTxs, toRemove, err := extractTransactionsFromSlot(&slots)
if err != nil {
return err
}
for _, txId := range toRemove {
cfg.txPool.MarkForDiscardFromPendingBest(txId)
}
transactions = append(transactions, yieldedTxs...)
return nil
}); err != nil {
Expand All @@ -63,7 +66,9 @@ func getLimboTransaction(ctx context.Context, cfg SequenceBlockCfg, txHash *comm
}

if slots != nil {
transactions, err = extractTransactionsFromSlot(slots)
// ignore the toRemove value here, we know the RLP will be sound as we had to read it from the pool
// in the first place to get it into limbo
transactions, _, err = extractTransactionsFromSlot(slots)
if err != nil {
return err
}
Expand All @@ -77,22 +82,27 @@ func getLimboTransaction(ctx context.Context, cfg SequenceBlockCfg, txHash *comm
return transactions, nil
}

func extractTransactionsFromSlot(slot *types2.TxsRlp) ([]types.Transaction, error) {
func extractTransactionsFromSlot(slot *types2.TxsRlp) ([]types.Transaction, []common.Hash, error) {
transactions := make([]types.Transaction, 0, len(slot.Txs))
toRemove := make([]common.Hash, 0)
for idx, txBytes := range slot.Txs {
transaction, err := types.DecodeTransaction(txBytes)
if err == io.EOF {
continue
}
if err != nil {
return nil, err
// we have a transaction that cannot be decoded or a similar issue. We don't want to handle
// this tx so just WARN about it and remove it from the pool and continue
log.Warn("Failed to decode transaction from pool, skipping and removing from pool", "error", err)
toRemove = append(toRemove, slot.TxIds[idx])
continue
}
var sender common.Address
copy(sender[:], slot.Senders.At(idx))
transaction.SetSender(sender)
transactions = append(transactions, transaction)
}
return transactions, nil
return transactions, toRemove, nil
}

type overflowType uint8
Expand Down
1 change: 1 addition & 0 deletions zk/txpool/pool_zk.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ func (p *TxPool) best(n uint16, txs *types.TxsRlp, tx kv.Tx, onTopOf, availableG
}

txs.Txs[count] = rlpTx
txs.TxIds[count] = mt.Tx.IDHash
copy(txs.Senders.At(count), sender.Bytes())
txs.IsLocal[count] = isLocal
toSkip.Add(mt.Tx.IDHash)
Expand Down
1 change: 1 addition & 0 deletions zk/txpool/pool_zk_limbo.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ func (p *TxPool) GetLimboTxRplsByHash(tx kv.Tx, txHash *common.Hash) (*types.Txs
for i := uint32(0); i < txSize; i++ {
limboTx := limboBlock.Transactions[i]
txsRlps.Txs[i] = limboTx.Rlp
txsRlps.TxIds[i] = limboTx.Hash
copy(txsRlps.Senders.At(int(i)), limboTx.Sender[:])
txsRlps.IsLocal[i] = true // all limbo tx are considered local //TODO: explain better about local
}
Expand Down

0 comments on commit 7d2ba1a

Please sign in to comment.