Skip to content

Commit

Permalink
feat(taiko-client): add chain ID to TryDecompress() (#18444)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha authored Nov 5, 2024
1 parent 75ff1f8 commit 10d99d5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 24 deletions.
19 changes: 6 additions & 13 deletions packages/taiko-client/driver/chain_syncer/blob/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/ethereum/go-ethereum/core/rawdb"
"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/taikoxyz/taiko-mono/packages/taiko-client/bindings/metadata"
Expand Down Expand Up @@ -261,23 +260,17 @@ func (s *Syncer) onBlockProposed(
return fmt.Errorf("failed to fetch tx list: %w", err)
}

var decompressedTxListBytes []byte
if s.rpc.L2.ChainID.Cmp(params.HeklaNetworkID) == 0 {
decompressedTxListBytes = s.txListDecompressor.TryDecompressHekla(
meta.GetBlockID(),
txListBytes,
meta.GetBlobUsed(),
)
} else {
decompressedTxListBytes = s.txListDecompressor.TryDecompress(meta.GetBlockID(), txListBytes, meta.GetBlobUsed())
}

// Decompress the transactions list and try to insert a new head block to L2 EE.
payloadData, err := s.insertNewHead(
ctx,
meta,
parent,
decompressedTxListBytes,
s.txListDecompressor.TryDecompress(
s.rpc.L2.ChainID,
meta.GetBlockID(),
txListBytes,
meta.GetBlobUsed(),
),
&rawdb.L1Origin{
BlockID: meta.GetBlockID(),
L2BlockHash: common.Hash{}, // Will be set by taiko-geth.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"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/taikoxyz/taiko-mono/packages/taiko-client/internal/utils"
Expand Down Expand Up @@ -39,6 +40,20 @@ func NewTxListDecompressor(
// less than or equal to maxBytesPerTxList.
// 2. The transaction list bytes must be able to be RLP decoded into a list of transactions.
func (v *TxListDecompressor) TryDecompress(
chainID *big.Int,
blockID *big.Int,
txListBytes []byte,
blobUsed bool,
) []byte {
if chainID.Cmp(params.HeklaNetworkID) == 0 {
return v.tryDecompressHekla(blockID, txListBytes, blobUsed)
}

return v.tryDecompress(blockID, txListBytes, blobUsed)
}

// tryDecompress is the inner implementation of TryDecompress.
func (v *TxListDecompressor) tryDecompress(
blockID *big.Int,
txListBytes []byte,
blobUsed bool,
Expand Down Expand Up @@ -76,10 +91,10 @@ func (v *TxListDecompressor) TryDecompress(
return txListBytes
}

// TryDecompressHekla is the same as TryDecompress, but it's used for Hekla network with
// TryDecompressHekla is the same as tryDecompress, but it's used for Hekla network with
// an incorrect legacy bytes size check.
// ref: https://github.com/taikoxyz/taiko-client/pull/783
func (v *TxListDecompressor) TryDecompressHekla(
func (v *TxListDecompressor) tryDecompressHekla(
blockID *big.Int,
txListBytes []byte,
blobUsed bool,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ func (s *TxListDecompressorTestSuite) SetupTest() {
}

func (s *TxListDecompressorTestSuite) TestZeroBytes() {
s.Empty(s.d.TryDecompress(chainID, []byte{}, false))
s.Empty(s.d.TryDecompress(chainID, common.Big1, []byte{}, false))
}

func (s *TxListDecompressorTestSuite) TestCalldataSize() {
s.Empty(s.d.TryDecompress(chainID, randBytes(rpc.BlockMaxTxListBytes+1), false))
s.Empty(s.d.TryDecompress(chainID, randBytes(rpc.BlockMaxTxListBytes-1), false))
s.Empty(s.d.TryDecompress(chainID, common.Big1, randBytes(rpc.BlockMaxTxListBytes+1), false))
s.Empty(s.d.TryDecompress(chainID, common.Big1, randBytes(rpc.BlockMaxTxListBytes-1), false))
}

func (s *TxListDecompressorTestSuite) TestValidTxList() {
Expand All @@ -53,21 +53,21 @@ func (s *TxListDecompressorTestSuite) TestValidTxList() {
decompressed, err := utils.Decompress(compressed)
s.Nil(err)

s.Equal(s.d.TryDecompress(chainID, compressed, true), decompressed)
s.Equal(s.d.TryDecompress(chainID, compressed, false), decompressed)
s.Equal(s.d.TryDecompress(chainID, common.Big1, compressed, true), decompressed)
s.Equal(s.d.TryDecompress(chainID, common.Big1, compressed, false), decompressed)
}

func (s *TxListDecompressorTestSuite) TestInvalidTxList() {
compressed, err := utils.Compress(randBytes(1024))
s.Nil(err)

s.Zero(len(s.d.TryDecompress(chainID, compressed, true)))
s.Zero(len(s.d.TryDecompress(chainID, compressed, false)))
s.Zero(len(s.d.TryDecompress(chainID, common.Big1, compressed, true)))
s.Zero(len(s.d.TryDecompress(chainID, common.Big1, compressed, false)))
}

func (s *TxListDecompressorTestSuite) TestInvalidZlibBytes() {
s.Zero(len(s.d.TryDecompress(chainID, randBytes(1024), true)))
s.Zero(len(s.d.TryDecompress(chainID, randBytes(1024), false)))
s.Zero(len(s.d.TryDecompress(chainID, common.Big1, randBytes(1024), true)))
s.Zero(len(s.d.TryDecompress(chainID, common.Big1, randBytes(1024), false)))
}

func TestDriverTestSuite(t *testing.T) {
Expand Down

0 comments on commit 10d99d5

Please sign in to comment.