diff --git a/encoding/bitmap.go b/encoding/bitmap.go index 87fc31c..7ada6d6 100644 --- a/encoding/bitmap.go +++ b/encoding/bitmap.go @@ -24,6 +24,7 @@ func ConstructSkippedBitmap(batchIndex uint64, chunks []*Chunk, totalL1MessagePo if tx.Type != types.L1MessageTxType { continue } + currentIndex := tx.Nonce if currentIndex < nextIndex { diff --git a/encoding/codecv0/codecv0.go b/encoding/codecv0/codecv0.go index ad76891..3f1e718 100644 --- a/encoding/codecv0/codecv0.go +++ b/encoding/codecv0/codecv0.go @@ -160,6 +160,7 @@ func (c *DAChunk) Encode() ([]byte, error) { if txData.Type == types.L1MessageTxType { continue } + var txLen [4]byte rlpTxData, err := encoding.ConvertTxDataToRLPEncoding(txData) if err != nil { @@ -320,6 +321,7 @@ func EstimateBlockL1CommitCalldataSize(b *encoding.Block) (uint64, error) { if txData.Type == types.L1MessageTxType { continue } + size += 4 // 4 bytes payload length txPayloadLength, err := getTxPayloadLength(txData) if err != nil { diff --git a/encoding/codecv1/codecv1.go b/encoding/codecv1/codecv1.go index db54069..77573da 100644 --- a/encoding/codecv1/codecv1.go +++ b/encoding/codecv1/codecv1.go @@ -203,17 +203,19 @@ func (c *DAChunk) Hash() (common.Hash, error) { // concatenate l1 tx hashes for _, blockTxs := range c.Transactions { for _, txData := range blockTxs { - if txData.Type == types.L1MessageTxType { - txHash := strings.TrimPrefix(txData.TxHash, "0x") - hashBytes, err := hex.DecodeString(txHash) - if err != nil { - return common.Hash{}, err - } - if len(hashBytes) != 32 { - return common.Hash{}, fmt.Errorf("unexpected hash: %s", txData.TxHash) - } - dataBytes = append(dataBytes, hashBytes...) + if txData.Type != types.L1MessageTxType { + continue + } + + txHash := strings.TrimPrefix(txData.TxHash, "0x") + hashBytes, err := hex.DecodeString(txHash) + if err != nil { + return common.Hash{}, err + } + if len(hashBytes) != 32 { + return common.Hash{}, fmt.Errorf("unexpected hash: %s", txData.TxHash) } + dataBytes = append(dataBytes, hashBytes...) } } @@ -316,14 +318,16 @@ func constructBlobPayload(chunks []*encoding.Chunk) (*kzg4844.Blob, common.Hash, for _, block := range chunk.Blocks { for _, tx := range block.Transactions { - if tx.Type != types.L1MessageTxType { - // encode L2 txs into blob payload - rlpTxData, err := encoding.ConvertTxDataToRLPEncoding(tx) - if err != nil { - return nil, common.Hash{}, nil, err - } - blobBytes = append(blobBytes, rlpTxData...) + if tx.Type == types.L1MessageTxType { + continue } + + // encode L2 txs into blob payload + rlpTxData, err := encoding.ConvertTxDataToRLPEncoding(tx) + if err != nil { + return nil, common.Hash{}, nil, err + } + blobBytes = append(blobBytes, rlpTxData...) } } @@ -505,13 +509,15 @@ func chunkL1CommitBlobDataSize(c *encoding.Chunk) (uint64, error) { var dataSize uint64 for _, block := range c.Blocks { for _, tx := range block.Transactions { - if tx.Type != types.L1MessageTxType { - rlpTxData, err := encoding.ConvertTxDataToRLPEncoding(tx) - if err != nil { - return 0, err - } - dataSize += uint64(len(rlpTxData)) + if tx.Type == types.L1MessageTxType { + continue + } + + rlpTxData, err := encoding.ConvertTxDataToRLPEncoding(tx) + if err != nil { + return 0, err } + dataSize += uint64(len(rlpTxData)) } } return dataSize, nil diff --git a/encoding/codecv2/codecv2.go b/encoding/codecv2/codecv2.go index 2e563b3..bc2d517 100644 --- a/encoding/codecv2/codecv2.go +++ b/encoding/codecv2/codecv2.go @@ -180,17 +180,19 @@ func (c *DAChunk) Hash() (common.Hash, error) { // concatenate l1 tx hashes for _, blockTxs := range c.Transactions { for _, txData := range blockTxs { - if txData.Type == types.L1MessageTxType { - txHash := strings.TrimPrefix(txData.TxHash, "0x") - hashBytes, err := hex.DecodeString(txHash) - if err != nil { - return common.Hash{}, err - } - if len(hashBytes) != 32 { - return common.Hash{}, fmt.Errorf("unexpected hash: %s", txData.TxHash) - } - dataBytes = append(dataBytes, hashBytes...) + if txData.Type != types.L1MessageTxType { + continue + } + + txHash := strings.TrimPrefix(txData.TxHash, "0x") + hashBytes, err := hex.DecodeString(txHash) + if err != nil { + return common.Hash{}, err + } + if len(hashBytes) != 32 { + return common.Hash{}, fmt.Errorf("unexpected hash: %s", txData.TxHash) } + dataBytes = append(dataBytes, hashBytes...) } } @@ -276,14 +278,16 @@ func constructBlobPayload(chunks []*encoding.Chunk) (*kzg4844.Blob, common.Hash, for _, block := range chunk.Blocks { for _, tx := range block.Transactions { - if tx.Type != types.L1MessageTxType { - // encode L2 txs into blob payload - rlpTxData, err := encoding.ConvertTxDataToRLPEncoding(tx) - if err != nil { - return nil, common.Hash{}, nil, err - } - blobBytes = append(blobBytes, rlpTxData...) + if tx.Type == types.L1MessageTxType { + continue } + + // encode L2 txs into blob payload + rlpTxData, err := encoding.ConvertTxDataToRLPEncoding(tx) + if err != nil { + return nil, common.Hash{}, nil, err + } + blobBytes = append(blobBytes, rlpTxData...) } } @@ -472,14 +476,16 @@ func constructBatchPayload(chunks []*encoding.Chunk) ([]byte, error) { for _, block := range chunk.Blocks { for _, tx := range block.Transactions { - if tx.Type != types.L1MessageTxType { - // encode L2 txs into batch payload - rlpTxData, err := encoding.ConvertTxDataToRLPEncoding(tx) - if err != nil { - return nil, err - } - batchBytes = append(batchBytes, rlpTxData...) + if tx.Type == types.L1MessageTxType { + continue + } + + // encode L2 txs into batch payload + rlpTxData, err := encoding.ConvertTxDataToRLPEncoding(tx) + if err != nil { + return nil, err } + batchBytes = append(batchBytes, rlpTxData...) } }