Skip to content

Commit

Permalink
add NewDABatchFromParams
Browse files Browse the repository at this point in the history
  • Loading branch information
jonastheis committed Jan 22, 2025
1 parent 8c2a5cc commit 9117170
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
4 changes: 4 additions & 0 deletions encoding/codecv0.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ func (d *DACodecV0) NewDABatchFromBytes(data []byte) (DABatch, error) {
), nil
}

func (d *DACodecV0) NewDABatchFromParams(_ uint64, _, _ common.Hash) (DABatch, error) {
return nil, nil
}

// EstimateBlockL1CommitCalldataSize calculates the calldata size in l1 commit for this block approximately.
func (d *DACodecV0) EstimateBlockL1CommitCalldataSize(b *Block) (uint64, error) {
var size uint64
Expand Down
6 changes: 5 additions & 1 deletion encoding/codecv7.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (d *DACodecV7) NewDABatch(batch *Batch) (DABatch, error) {
return nil, fmt.Errorf("failed to construct blob: %w", err)
}

daBatch, err := newDABatchV7(CodecV7, batch.Index, batch.ParentBatchHash, blobVersionedHash, blob, blobBytes)
daBatch, err := newDABatchV7(CodecV7, batch.Index, blobVersionedHash, batch.ParentBatchHash, blob, blobBytes)
if err != nil {
return nil, fmt.Errorf("failed to construct DABatch: %w", err)
}
Expand Down Expand Up @@ -170,6 +170,10 @@ func (d *DACodecV7) NewDABatchFromBytes(data []byte) (DABatch, error) {
return daBatch, nil
}

func (d *DACodecV7) NewDABatchFromParams(batchIndex uint64, blobVersionedHash, parentBatchHash common.Hash) (DABatch, error) {
return newDABatchV7(CodecV7, batchIndex, blobVersionedHash, parentBatchHash, nil, nil)
}

func (d *DACodecV7) DecodeDAChunksRawTx(_ [][]byte) ([]*DAChunkRawTx, error) {
return nil, nil
}
Expand Down
8 changes: 4 additions & 4 deletions encoding/codecv7_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,20 @@ const (
type daBatchV7 struct {
version CodecVersion
batchIndex uint64
parentBatchHash common.Hash
blobVersionedHash common.Hash
parentBatchHash common.Hash

blob *kzg4844.Blob
blobBytes []byte
}

// newDABatchV7 is a constructor for daBatchV7 that calls blobDataProofForPICircuit internally.
func newDABatchV7(version CodecVersion, batchIndex uint64, parentBatchHash, blobVersionedHash common.Hash, blob *kzg4844.Blob, blobBytes []byte) (*daBatchV7, error) {
func newDABatchV7(version CodecVersion, batchIndex uint64, blobVersionedHash, parentBatchHash common.Hash, blob *kzg4844.Blob, blobBytes []byte) (*daBatchV7, error) {
daBatch := &daBatchV7{
version: version,
batchIndex: batchIndex,
parentBatchHash: parentBatchHash,
blobVersionedHash: blobVersionedHash,
parentBatchHash: parentBatchHash,
blob: blob,
blobBytes: blobBytes,
}
Expand All @@ -81,7 +81,7 @@ func decodeDABatchV7(data []byte) (*daBatchV7, error) {
blobVersionedHash := common.BytesToHash(data[daBatchV7OffsetBlobVersionedHash:daBatchV7OffsetParentBatchHash])
parentBatchHash := common.BytesToHash(data[daBatchV7OffsetParentBatchHash:daBatchV7EncodedLength])

return newDABatchV7(version, batchIndex, parentBatchHash, blobVersionedHash, nil, nil)
return newDABatchV7(version, batchIndex, blobVersionedHash, parentBatchHash, nil, nil)
}

// Encode serializes the DABatchV3 into bytes.
Expand Down
1 change: 1 addition & 0 deletions encoding/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type Codec interface {
NewDAChunk(*Chunk, uint64) (DAChunk, error)
NewDABatch(*Batch) (DABatch, error)
NewDABatchFromBytes([]byte) (DABatch, error)
NewDABatchFromParams(batchIndex uint64, blobVersionedHash, parentBatchHash common.Hash) (DABatch, error)

DecodeDAChunksRawTx(chunkBytes [][]byte) ([]*DAChunkRawTx, error)
DecodeTxsFromBlob(blob *kzg4844.Blob, chunks []*DAChunkRawTx) error
Expand Down

0 comments on commit 9117170

Please sign in to comment.