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-client): add chain ID to TryDecompress() #18444

Merged
merged 2 commits into from
Nov 5, 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
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
Loading