Skip to content

Commit 34a91cf

Browse files
committed
merged code from 0xPolygonHermez/pull/1636
1 parent d61c69f commit 34a91cf

3 files changed

+26
-40
lines changed

zk/stages/stage_sequence_execute.go

+24-14
Original file line numberDiff line numberDiff line change
@@ -369,26 +369,15 @@ func sequencingBatchStep(
369369
return err
370370
}
371371
} else if !batchState.isL1Recovery() {
372-
373-
var allConditionsOK bool
374372
var newTransactions []types.Transaction
375373
var newIds []common.Hash
376374

377-
newTransactions, newIds, allConditionsOK, err = getNextPoolTransactions(ctx, cfg, executionAt, batchState.forkId, batchState.yieldedTransactions)
375+
newTransactions, newIds, _, err = getNextPoolTransactions(ctx, cfg, executionAt, batchState.forkId, batchState.yieldedTransactions)
378376
if err != nil {
379377
return err
380378
}
381379

382-
if len(newTransactions) == 0 {
383-
if allConditionsOK {
384-
log.Info(fmt.Sprintf("[%s] Sleep for %v ms", logPrefix, batchContext.cfg.zk.SequencerTimeoutOnEmptyTxPool.Milliseconds()))
385-
time.Sleep(batchContext.cfg.zk.SequencerTimeoutOnEmptyTxPool)
386-
387-
} else {
388-
log.Info(fmt.Sprintf("[%s] Sleep for %v ms", logPrefix, batchContext.cfg.zk.SequencerTimeoutOnEmptyTxPool.Milliseconds()/5))
389-
time.Sleep(batchContext.cfg.zk.SequencerTimeoutOnEmptyTxPool / 5) // we do not need to sleep too long for txpool not ready
390-
}
391-
} else {
380+
if len(newTransactions) > 0 {
392381
hashResults := make([]common.Hash, len(newTransactions))
393382
var wg sync.WaitGroup
394383

@@ -412,7 +401,12 @@ func sequencingBatchStep(
412401
}
413402

414403
start := time.Now()
415-
404+
if len(batchState.blockState.transactionsForInclusion) == 0 {
405+
log.Trace(fmt.Sprintf("[%s] Sleep on SequencerTimeoutOnEmptyTxPool", logPrefix), "time in ms", batchContext.cfg.zk.SequencerTimeoutOnEmptyTxPool.Milliseconds())
406+
time.Sleep(batchContext.cfg.zk.SequencerTimeoutOnEmptyTxPool)
407+
} else {
408+
log.Trace(fmt.Sprintf("[%s] Yielded transactions from the pool", logPrefix), "txCount", len(batchState.blockState.transactionsForInclusion))
409+
}
416410
badTxHashes := make([]common.Hash, 0)
417411
minedTxHashes := make([]common.Hash, 0)
418412

@@ -432,6 +426,22 @@ func sequencingBatchStep(
432426
}
433427

434428
txHash := transaction.Hash()
429+
430+
if _, ok := transaction.GetSender(); !ok {
431+
signer := types.MakeSigner(cfg.chainConfig, executionAt, 0)
432+
sender, err := signer.Sender(transaction)
433+
if err != nil {
434+
log.Warn("[extractTransaction] Failed to recover sender from transaction, skipping and removing from pool",
435+
"error", err,
436+
"hash", transaction.Hash())
437+
badTxHashes = append(badTxHashes, txHash)
438+
batchState.blockState.transactionsToDiscard = append(batchState.blockState.transactionsToDiscard, batchState.blockState.transactionHashesToSlots[txHash])
439+
continue
440+
}
441+
442+
transaction.SetSender(sender)
443+
}
444+
435445
effectiveGas := batchState.blockState.getL1EffectiveGases(cfg, i)
436446

437447
// The copying of this structure is intentional

zk/stages/stage_sequence_execute_transactions.go

+1-23
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
"github.com/ledgerwatch/erigon/core/vm/evmtypes"
1818
"github.com/ledgerwatch/erigon/zk/utils"
1919
"github.com/ledgerwatch/log/v3"
20-
"github.com/ledgerwatch/secp256k1"
2120
)
2221

2322
func getNextPoolTransactions(ctx context.Context, cfg SequenceBlockCfg, executionAt, forkId uint64, alreadyYielded mapset.Set[[32]byte]) ([]types.Transaction, []common.Hash, bool, error) {
@@ -90,8 +89,6 @@ func extractTransactionsFromSlot(slot *types2.TxsRlp, currentHeight uint64, cfg
9089
transactions := make([]types.Transaction, 0, len(slot.Txs))
9190
toRemove := make([]common.Hash, 0)
9291

93-
signer := types.MakeSigner(cfg.chainConfig, currentHeight, 0)
94-
9592
type result struct {
9693
index int
9794
transaction types.Transaction
@@ -104,8 +101,6 @@ func extractTransactionsFromSlot(slot *types2.TxsRlp, currentHeight uint64, cfg
104101

105102
// we do this in sequnce to avoid concurrent map writes
106103
for idx, txBytes := range slot.Txs {
107-
cryptoContext := secp256k1.ContextForThread(1)
108-
109104
res := &result{index: idx}
110105

111106
var err error = nil
@@ -130,24 +125,7 @@ func extractTransactionsFromSlot(slot *types2.TxsRlp, currentHeight uint64, cfg
130125
continue
131126
}
132127

133-
err = nil
134-
var sender common.Address
135-
senderPtr, found := cfg.senderCache[slot.TxIds[idx]]
136-
if !found {
137-
sender, err = signer.SenderWithContext(cryptoContext, transaction)
138-
if err != nil {
139-
res.toRemove = true
140-
res.id = slot.TxIds[idx]
141-
res.err = err
142-
results[idx] = res
143-
continue
144-
}
145-
cfg.senderCache[slot.TxIds[idx]] = &sender
146-
} else {
147-
sender = *senderPtr
148-
}
149-
150-
transaction.SetSender(sender)
128+
// Recover sender later only for those transactions that are included in the block
151129
res.transaction = transaction
152130
res.id = slot.TxIds[idx]
153131
results[idx] = res

zk/stages/stage_sequence_execute_utils.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ type SequenceBlockCfg struct {
8686

8787
infoTreeUpdater *l1infotree.Updater
8888

89-
txCache map[common.Hash]*types.Transaction
90-
senderCache map[common.Hash]*common.Address
89+
txCache map[common.Hash]*types.Transaction
9190
}
9291

9392
func StageSequenceBlocksCfg(
@@ -145,7 +144,6 @@ func StageSequenceBlocksCfg(
145144
yieldSize: yieldSize,
146145
infoTreeUpdater: infoTreeUpdater,
147146
txCache: make(map[common.Hash]*types.Transaction),
148-
senderCache: make(map[common.Hash]*common.Address),
149147
}
150148
}
151149

0 commit comments

Comments
 (0)