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

chore(taiko-client): deduplicate compress function #18958

Merged
merged 5 commits into from
Feb 19, 2025
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
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