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): introduce TryDecompressHekla() #17735

Merged
merged 1 commit into from
Jul 4, 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
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
}
Loading