From 98c60357f437400c224067fbc9409981d91ede26 Mon Sep 17 00:00:00 2001 From: David Date: Thu, 6 Jun 2024 01:41:21 +0800 Subject: [PATCH 1/4] feat(miner): introduce `bytesLimitCheckStep` --- miner/taiko_worker.go | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/miner/taiko_worker.go b/miner/taiko_worker.go index 3ffbe95ba37d..7bda44cd05b0 100644 --- a/miner/taiko_worker.go +++ b/miner/taiko_worker.go @@ -20,6 +20,10 @@ import ( "github.com/holiman/uint256" ) +const ( + bytesLimitCheckStep = 10 +) + // BuildTransactionsLists builds multiple transactions lists which satisfy all the given conditions // 1. All transactions should all be able to pay the given base fee. // 2. The total gas used should not exceed the given blockMaxGasLimit @@ -265,14 +269,19 @@ 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 + if env.tcount%bytesLimitCheckStep == 0 { + 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) { + if env.tcount > bytesLimitCheckStep { + env.txs = env.txs[0 : env.tcount-bytesLimitCheckStep] + } + break + } } // Check whether the tx is replay protected. If we're not in the EIP155 hf @@ -286,7 +295,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 From 5fb33fd42ff63619e037f305296bd24198711ec9 Mon Sep 17 00:00:00 2001 From: David Date: Thu, 6 Jun 2024 02:44:23 +0800 Subject: [PATCH 2/4] feat: compress --- miner/taiko_worker.go | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/miner/taiko_worker.go b/miner/taiko_worker.go index 7bda44cd05b0..58439c00e626 100644 --- a/miner/taiko_worker.go +++ b/miner/taiko_worker.go @@ -20,10 +20,6 @@ import ( "github.com/holiman/uint256" ) -const ( - bytesLimitCheckStep = 10 -) - // BuildTransactionsLists builds multiple transactions lists which satisfy all the given conditions // 1. All transactions should all be able to pay the given base fee. // 2. The total gas used should not exceed the given blockMaxGasLimit @@ -269,21 +265,6 @@ func (w *worker) commitL2Transactions( // during transaction acceptance is the transaction pool. from, _ := types.Sender(env.signer, tx) - if env.tcount%bytesLimitCheckStep == 0 { - 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) { - if env.tcount > bytesLimitCheckStep { - env.txs = env.txs[0 : env.tcount-bytesLimitCheckStep] - } - 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) { @@ -313,6 +294,17 @@ func (w *worker) commitL2Transactions( log.Trace("Transaction failed, account skipped", "hash", ltx.Hash, "err", err) txs.Pop() } + + 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 + } } } From dfc27860848931a55d718bcdf14b651e3076b793 Mon Sep 17 00:00:00 2001 From: David Date: Thu, 6 Jun 2024 10:35:29 +0800 Subject: [PATCH 3/4] Update miner/taiko_worker.go Co-authored-by: Roger <50648015+RogerLamTd@users.noreply.github.com> --- miner/taiko_worker.go | 1 + 1 file changed, 1 insertion(+) diff --git a/miner/taiko_worker.go b/miner/taiko_worker.go index 58439c00e626..5417518905b4 100644 --- a/miner/taiko_worker.go +++ b/miner/taiko_worker.go @@ -295,6 +295,7 @@ func (w *worker) commitL2Transactions( 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) From 93750417a308cd243548a145c7214f6cbbd6b912 Mon Sep 17 00:00:00 2001 From: David Date: Thu, 6 Jun 2024 10:39:34 +0800 Subject: [PATCH 4/4] feat: update comment --- miner/taiko_worker.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/miner/taiko_worker.go b/miner/taiko_worker.go index 5417518905b4..d71219623bd6 100644 --- a/miner/taiko_worker.go +++ b/miner/taiko_worker.go @@ -295,7 +295,7 @@ func (w *worker) commitL2Transactions( txs.Pop() } - // Encode and compress the txList, if the byte length is > maxBytesPerTxList, remove the latest tx and break + // 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)