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: recover sender only for those txs that are included #1636

Merged
merged 1 commit into from
Jan 20, 2025
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
16 changes: 16 additions & 0 deletions zk/stages/stage_sequence_execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,22 @@ func sequencingBatchStep(
}

txHash := transaction.Hash()

if _, ok := transaction.GetSender(); !ok {
signer := types.MakeSigner(cfg.chainConfig, executionAt, 0)
sender, err := signer.Sender(transaction)
if err != nil {
log.Warn("[extractTransaction] Failed to recover sender from transaction, skipping and removing from pool",
"error", err,
"hash", transaction.Hash())
badTxHashes = append(badTxHashes, txHash)
batchState.blockState.transactionsToDiscard = append(batchState.blockState.transactionsToDiscard, batchState.blockState.transactionHashesToSlots[txHash])
continue
}

transaction.SetSender(sender)
}

effectiveGas := batchState.blockState.getL1EffectiveGases(cfg, i)

// The copying of this structure is intentional
Expand Down
16 changes: 2 additions & 14 deletions zk/stages/stage_sequence_execute_transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/ledgerwatch/erigon/core/vm/evmtypes"
"github.com/ledgerwatch/erigon/zk/utils"
"github.com/ledgerwatch/log/v3"
"github.com/ledgerwatch/secp256k1"
)

func getNextPoolTransactions(ctx context.Context, cfg SequenceBlockCfg, executionAt, forkId uint64, alreadyYielded mapset.Set[[32]byte]) ([]types.Transaction, []common.Hash, bool, error) {
Expand Down Expand Up @@ -89,8 +88,7 @@ func extractTransactionsFromSlot(slot *types2.TxsRlp, currentHeight uint64, cfg
ids := make([]common.Hash, 0, len(slot.TxIds))
transactions := make([]types.Transaction, 0, len(slot.Txs))
toRemove := make([]common.Hash, 0)
signer := types.MakeSigner(cfg.chainConfig, currentHeight, 0)
cryptoContext := secp256k1.ContextForThread(1)

for idx, txBytes := range slot.Txs {
transaction, err := types.DecodeTransaction(txBytes)
if err == io.EOF {
Expand All @@ -106,17 +104,7 @@ func extractTransactionsFromSlot(slot *types2.TxsRlp, currentHeight uint64, cfg
continue
}

// now attempt to recover the sender
sender, err := signer.SenderWithContext(cryptoContext, transaction)
if err != nil {
log.Warn("[extractTransaction] Failed to recover sender from transaction, skipping and removing from pool",
"error", err,
"hash", transaction.Hash())
toRemove = append(toRemove, slot.TxIds[idx])
continue
}

transaction.SetSender(sender)
// Recover sender later only for those transactions that are included in the block
transactions = append(transactions, transaction)
ids = append(ids, slot.TxIds[idx])
}
Expand Down
Loading