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

feat(taiko_api): reduce the frequency of zlib compression when fetching txpool content #323

Merged
merged 3 commits into from
Sep 30, 2024
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
26 changes: 18 additions & 8 deletions miner/taiko_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,19 +294,29 @@ loop:
env.tcount++
txs.Shift()

// Encode and compress the txList, if the byte length is > maxBytesPerTxList, remove the latest tx and break.
b, err := encodeAndCompressTxList(env.txs)
data, err := rlp.EncodeToBytes(env.txs)
if err != nil {
log.Trace("Failed to rlp encode and compress the pending transaction %s: %w", tx.Hash(), err)
log.Trace("Failed to rlp encode the pending transaction %s: %w", tx.Hash(), err)
txs.Pop()
continue
}
if len(b) > int(maxBytesPerTxList) {
env.txs = env.txs[0 : env.tcount-1]
env.state.RevertToSnapshot(snap)
env.gasPool.SetGas(gasPool)
break loop

if len(data) >= int(maxBytesPerTxList) {
// Encode and compress the txList, if the byte length is > maxBytesPerTxList, remove the latest tx and break.
b, err := compress(data)
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]
env.state.RevertToSnapshot(snap)
env.gasPool.SetGas(gasPool)
break loop
}
}

default:
// Transaction is regarded as invalid, drop all consecutive transactions from
// the same sender because of `nonce-too-high` clause.
Expand Down
50 changes: 50 additions & 0 deletions miner/taiko_worker_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package miner

import (
"testing"

"github.com/ethereum/go-ethereum/consensus/clique"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/params"
"github.com/stretchr/testify/assert"
)

func testGenerateWorker(t *testing.T, txCount int) *worker {
t.Parallel()
var (
db = rawdb.NewMemoryDatabase()
config = *params.AllCliqueProtocolChanges
)
config.Taiko = true
config.Clique = &params.CliqueConfig{Period: 1, Epoch: 30000}
engine := clique.New(config.Clique, db)

w, b := newTestWorker(t, &config, engine, db, 0)
//defer w.close()

for i := 0; i < txCount; i++ {
b.txPool.Add([]*types.Transaction{b.newRandomTx(true)}, true, false)
b.txPool.Add([]*types.Transaction{b.newRandomTx(false)}, true, false)
}

return w
}

func TestBuildTransactionsLists(t *testing.T) {
w := testGenerateWorker(t, 1000)
defer w.close()

maxBytesPerTxList := (params.BlobTxBytesPerFieldElement - 1) * params.BlobTxFieldElementsPerBlob
txLst, err := w.BuildTransactionsLists(
testBankAddress,
nil,
240_000_000,
uint64(maxBytesPerTxList),
nil,
1,
0)
assert.NoError(t, err)
assert.LessOrEqual(t, 1, len(txLst))
assert.LessOrEqual(t, txLst[0].BytesLength, uint64(maxBytesPerTxList))
}
Loading