Skip to content

Commit

Permalink
chore(taiko-client): deduplicate compress() function (#18958)
Browse files Browse the repository at this point in the history
  • Loading branch information
estensen authored Feb 19, 2025
1 parent d43bb13 commit ddfa310
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 30 deletions.
31 changes: 1 addition & 30 deletions packages/taiko-client/driver/driver_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package driver

import (
"bytes"
"compress/zlib"
"context"
"fmt"
"math/big"
Expand Down Expand Up @@ -437,7 +435,7 @@ func (s *DriverTestSuite) insertPreconfBlock(
parent, err := s.d.rpc.L2.HeaderByNumber(context.Background(), new(big.Int).SetUint64(l2BlockID-1))
s.Nil(err)

b, err := encodeAndCompressTxList([]*types.Transaction{signedTx})
b, err := utils.EncodeAndCompressTxList([]*types.Transaction{signedTx})
s.Nil(err)

reqBody := &preconfblocks.BuildPreconfBlockRequestBody{
Expand Down Expand Up @@ -652,30 +650,3 @@ func (s *DriverTestSuite) InitProposer() {
func TestDriverTestSuite(t *testing.T) {
suite.Run(t, new(DriverTestSuite))
}

// compress compresses the given txList bytes using zlib.
func compress(txListBytes []byte) ([]byte, error) {
var b bytes.Buffer
w := zlib.NewWriter(&b)
defer w.Close()

if _, err := w.Write(txListBytes); err != nil {
return nil, err
}

if err := w.Flush(); err != nil {
return nil, err
}

return b.Bytes(), nil
}

// encodeAndCompressTxList encodes and compresses the given transactions list.
func encodeAndCompressTxList(txs types.Transactions) ([]byte, error) {
b, err := rlp.EncodeToBytes(txs)
if err != nil {
return nil, err
}

return compress(b)
}
13 changes: 13 additions & 0 deletions packages/taiko-client/pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ import (
"strings"

"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp"
"github.com/joho/godotenv"
"github.com/modern-go/reflect2"
"golang.org/x/exp/constraints"
Expand Down Expand Up @@ -69,6 +71,17 @@ func Min[T constraints.Integer](a, b T) T {
return b
}

// EncodeAndCompressTxList encodes and compresses the given transactions list using RLP encoding
// followed by zlib compression.
func EncodeAndCompressTxList(txs types.Transactions) ([]byte, error) {
b, err := rlp.EncodeToBytes(txs)
if err != nil {
return nil, err
}

return Compress(b)
}

// Compress compresses the given txList bytes using zlib.
func Compress(txList []byte) ([]byte, error) {
var b bytes.Buffer
Expand Down

0 comments on commit ddfa310

Please sign in to comment.