Skip to content

Commit

Permalink
feat(taiko-client): introduce TryDecompressHekla() (#17735)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha committed Jul 4, 2024
1 parent 9d18504 commit 67a7a37
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/taiko-client/driver/chain_syncer/blob/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ 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"
Expand Down Expand Up @@ -260,13 +261,20 @@ 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(event.BlockId, txListBytes, event.Meta.BlobUsed)
} else {
decompressedTxListBytes = s.txListDecompressor.TryDecompress(event.BlockId, txListBytes, event.Meta.BlobUsed)
}

// Decompress the transactions list and try to insert a new head block to L2 EE.
payloadData, err := s.insertNewHead(
ctx,
event,
parent,
s.state.GetHeadBlockID(),
s.txListDecompressor.TryDecompress(event.BlockId, txListBytes, event.Meta.BlobUsed),
decompressedTxListBytes,
&rawdb.L1Origin{
BlockID: event.BlockId,
L2BlockHash: common.Hash{}, // Will be set by taiko-geth.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,44 @@ func (v *TxListDecompressor) TryDecompress(
log.Info("Transaction list is valid", "blockID", blockID)
return txListBytes
}

// 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(
blockID *big.Int,
txListBytes []byte,
blobUsed bool,
) []byte {
// If the transaction list is empty, it's valid.
if len(txListBytes) == 0 {
return []byte{}
}

var (
txs types.Transactions
err error
)

// Decompress the transaction list bytes.
if txListBytes, err = utils.Decompress(txListBytes); err != nil {
log.Info("Failed to decompress tx list bytes", "blockID", blockID, "error", err)
return []byte{}
}

// If calldata is used, the compressed bytes of the transaction list must be
// less than or equal to maxBytesPerTxList.
if !blobUsed && (len(txListBytes) > int(v.maxBytesPerTxList)) {
log.Info("Compressed transactions list binary too large", "length", len(txListBytes), "blockID", blockID)
return []byte{}
}

// Try to RLP decode the transaction list bytes.
if err = rlp.DecodeBytes(txListBytes, &txs); err != nil {
log.Info("Failed to decode transactions list bytes", "blockID", blockID, "error", err)
return []byte{}
}

log.Info("Transaction list is valid", "blockID", blockID)
return txListBytes
}

0 comments on commit 67a7a37

Please sign in to comment.