Skip to content

Commit ef5f1a6

Browse files
author
colinlyguo
committed
address comments
1 parent 4f78d1a commit ef5f1a6

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

encoding/codecv0.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,6 @@ func (d *DACodecV0) NewDABlock(block *Block, totalL1MessagePoppedBefore uint64)
6060

6161
// NewDAChunk creates a new DAChunk from the given Chunk and the total number of L1 messages popped before.
6262
func (d *DACodecV0) NewDAChunk(chunk *Chunk, totalL1MessagePoppedBefore uint64) (DAChunk, error) {
63-
var blocks []DABlock
64-
var txs [][]*types.TransactionData
65-
6663
if chunk == nil {
6764
return nil, errors.New("chunk is nil")
6865
}
@@ -75,6 +72,9 @@ func (d *DACodecV0) NewDAChunk(chunk *Chunk, totalL1MessagePoppedBefore uint64)
7572
return nil, fmt.Errorf("number of blocks (%d) exceeds maximum allowed (%d)", len(chunk.Blocks), math.MaxUint8)
7673
}
7774

75+
blocks := make([]DABlock, 0, len(chunk.Blocks))
76+
txs := make([][]*types.TransactionData, 0, len(chunk.Blocks))
77+
7878
for _, block := range chunk.Blocks {
7979
b, err := d.NewDABlock(block, totalL1MessagePoppedBefore)
8080
if err != nil {
@@ -97,7 +97,7 @@ func (d *DACodecV0) NewDAChunk(chunk *Chunk, totalL1MessagePoppedBefore uint64)
9797

9898
// DecodeDAChunksRawTx takes a byte slice and decodes it into a []*DAChunkRawTx.
9999
func (d *DACodecV0) DecodeDAChunksRawTx(chunkBytes [][]byte) ([]*DAChunkRawTx, error) {
100-
var chunks []*DAChunkRawTx
100+
chunks := make([]*DAChunkRawTx, 0, len(chunkBytes))
101101
for _, chunk := range chunkBytes {
102102
if len(chunk) < 1 {
103103
return nil, fmt.Errorf("invalid chunk, length is less than 1")

encoding/codecv0_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ func newDABatchV0(version uint8, batchIndex, l1MessagePopped, totalL1MessagePopp
237237

238238
// Encode serializes the DABatchV0 into bytes.
239239
func (b *daBatchV0) Encode() []byte {
240-
batchBytes := make([]byte, daBatchV0OffsetSkippedL1MessageBitmap+len(b.skippedL1MessageBitmap))
240+
batchBytes := make([]byte, daBatchV0EncodedMinLength+len(b.skippedL1MessageBitmap))
241241
batchBytes[daBatchOffsetVersion] = b.version
242242
binary.BigEndian.PutUint64(batchBytes[daBatchOffsetBatchIndex:daBatchV0OffsetL1MessagePopped], b.batchIndex)
243243
binary.BigEndian.PutUint64(batchBytes[daBatchV0OffsetL1MessagePopped:daBatchV0OffsetTotalL1MessagePopped], b.l1MessagePopped)

encoding/codecv1.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ func (d *DACodecV1) Version() CodecVersion {
2525

2626
// NewDAChunk creates a new DAChunk from the given Chunk and the total number of L1 messages popped before.
2727
func (d *DACodecV1) NewDAChunk(chunk *Chunk, totalL1MessagePoppedBefore uint64) (DAChunk, error) {
28-
var blocks []DABlock
29-
var txs [][]*types.TransactionData
30-
3128
if chunk == nil {
3229
return nil, errors.New("chunk is nil")
3330
}
@@ -40,6 +37,9 @@ func (d *DACodecV1) NewDAChunk(chunk *Chunk, totalL1MessagePoppedBefore uint64)
4037
return nil, fmt.Errorf("number of blocks (%d) exceeds maximum allowed (%d)", len(chunk.Blocks), math.MaxUint8)
4138
}
4239

40+
blocks := make([]DABlock, 0, len(chunk.Blocks))
41+
txs := make([][]*types.TransactionData, 0, len(chunk.Blocks))
42+
4343
for _, block := range chunk.Blocks {
4444
b, err := d.NewDABlock(block, totalL1MessagePoppedBefore)
4545
if err != nil {
@@ -60,9 +60,9 @@ func (d *DACodecV1) NewDAChunk(chunk *Chunk, totalL1MessagePoppedBefore uint64)
6060

6161
// DecodeDAChunksRawTx takes a byte slice and decodes it into a []*DAChunkRawTx.
6262
// Beginning from codecv1 tx data posted to blobs, not to chunk bytes in calldata
63-
func (d *DACodecV1) DecodeDAChunksRawTx(bytes [][]byte) ([]*DAChunkRawTx, error) {
64-
var chunks []*DAChunkRawTx
65-
for _, chunk := range bytes {
63+
func (d *DACodecV1) DecodeDAChunksRawTx(chunkBytes [][]byte) ([]*DAChunkRawTx, error) {
64+
chunks := make([]*DAChunkRawTx, 0, len(chunkBytes))
65+
for _, chunk := range chunkBytes {
6666
if len(chunk) < 1 {
6767
return nil, fmt.Errorf("invalid chunk, length is less than 1")
6868
}

encoding/codecv1_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func newDABatchV1(version uint8, batchIndex, l1MessagePopped, totalL1MessagePopp
103103

104104
// Encode serializes the DABatchV1 into bytes.
105105
func (b *daBatchV1) Encode() []byte {
106-
batchBytes := make([]byte, daBatchV1OffsetSkippedL1MessageBitmap+len(b.skippedL1MessageBitmap))
106+
batchBytes := make([]byte, daBatchV1EncodedMinLength+len(b.skippedL1MessageBitmap))
107107
batchBytes[daBatchOffsetVersion] = b.version
108108
binary.BigEndian.PutUint64(batchBytes[daBatchOffsetBatchIndex:daBatchV1OffsetL1MessagePopped], b.batchIndex)
109109
binary.BigEndian.PutUint64(batchBytes[daBatchV1OffsetL1MessagePopped:daBatchV1OffsetTotalL1MessagePopped], b.l1MessagePopped)

0 commit comments

Comments
 (0)