feat(miner): compress the txlist bytes after checking the transaction is executable (#269)

* feat(miner): introduce `bytesLimitCheckStep`

* feat: compress

* Update miner/taiko_worker.go

Co-authored-by: Roger <50648015+RogerLamTd@users.noreply.github.com>

---------

Co-authored-by: Roger <50648015+RogerLamTd@users.noreply.github.com>
This commit is contained in:
David 2024-06-06 09:54:06 +07:00 committed by GitHub
parent 8bd80e422f
commit aa70708a69
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -265,16 +265,6 @@ func (w *worker) commitL2Transactions(
// during transaction acceptance is the transaction pool.
from, _ := types.Sender(env.signer, tx)
b, err := encodeAndComporeessTxList(append(env.txs, tx))
if err != nil {
log.Trace("Failed to rlp encode and compress the pending transaction %s: %w", tx.Hash(), err)
txs.Pop()
continue
}
if len(b) > int(maxBytesPerTxList) {
break
}
// Check whether the tx is replay protected. If we're not in the EIP155 hf
// phase, start ignoring the sender until we do.
if tx.Protected() && !w.chainConfig.IsEIP155(env.header.Number) {
@ -286,7 +276,7 @@ func (w *worker) commitL2Transactions(
// Start executing the transaction
env.state.SetTxContext(tx.Hash(), env.tcount)
_, err = w.commitTransaction(env, tx)
_, err := w.commitTransaction(env, tx)
switch {
case errors.Is(err, core.ErrNonceTooLow):
// New head notification data race between the transaction pool and miner, shift
@ -304,6 +294,18 @@ func (w *worker) commitL2Transactions(
log.Trace("Transaction failed, account skipped", "hash", ltx.Hash, "err", err)
txs.Pop()
}
// Encode and compress the txList, if the byte length is > maxBytesPerTxList, remove the latest tx and break.
b, err := encodeAndComporeessTxList(append(env.txs, tx))
if err != nil {
log.Trace("Failed to rlp encode and compress the pending transaction %s: %w", tx.Hash(), err)
txs.Pop()
continue
}
if len(b) > int(maxBytesPerTxList) {
env.txs = env.txs[0 : env.tcount-1]
break
}
}
}