Skip to content

Commit

Permalink
[v2] Encoder server with EncodeBlob method (#866)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmanc authored Nov 8, 2024
1 parent 6e14746 commit 8f6b812
Show file tree
Hide file tree
Showing 42 changed files with 1,576 additions and 208 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ COPY api /app/api
COPY contracts /app/contracts
COPY indexer /app/indexer
COPY encoding /app/encoding
COPY relay /app/relay

# Churner build stage
FROM common-builder AS churner-builder
Expand Down
3 changes: 2 additions & 1 deletion common/aws/cli.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package aws

import (
"time"

"github.com/Layr-Labs/eigenda/common"
"github.com/urfave/cli"
"time"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion common/aws/s3/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"context"
"errors"
"golang.org/x/sync/errgroup"
"runtime"
"sync"

Expand All @@ -15,6 +14,7 @@ import (
"github.com/aws/aws-sdk-go-v2/credentials"
"github.com/aws/aws-sdk-go-v2/feature/s3/manager"
"github.com/aws/aws-sdk-go-v2/service/s3"
"golang.org/x/sync/errgroup"
)

var (
Expand Down
9 changes: 5 additions & 4 deletions common/aws/s3/scoped_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package s3

import (
"fmt"
v2 "github.com/Layr-Labs/eigenda/core/v2"

corev2 "github.com/Layr-Labs/eigenda/core/v2"
)

const (
Expand Down Expand Up @@ -38,18 +39,18 @@ func ScopedKey(namespace string, baseKey string, prefixLength int) string {

// ScopedBlobKey returns a key scoped to the blob namespace. Used to name files containing blobs in S3.
// A key scoped for blobs will never collide with a key scoped for chunks or proofs.
func ScopedBlobKey(blobKey v2.BlobKey) string {
func ScopedBlobKey(blobKey corev2.BlobKey) string {
return ScopedKey(blobNamespace, blobKey.Hex(), prefixLength)
}

// ScopedChunkKey returns a key scoped to the chunk namespace. Used to name files containing chunks in S3.
// A key scoped for chunks will never collide with a key scoped for blobs or proofs.
func ScopedChunkKey(blobKey v2.BlobKey) string {
func ScopedChunkKey(blobKey corev2.BlobKey) string {
return ScopedKey(chunkNamespace, blobKey.Hex(), prefixLength)
}

// ScopedProofKey returns a key scoped to the proof namespace. Used to name files containing proofs in S3.
// A key scoped for proofs will never collide with a key scoped for blobs or chunks.
func ScopedProofKey(blobKey v2.BlobKey) string {
func ScopedProofKey(blobKey corev2.BlobKey) string {
return ScopedKey(proofNamespace, blobKey.Hex(), prefixLength)
}
22 changes: 22 additions & 0 deletions core/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,25 @@ func NextPowerOf2[T constraints.Integer](d T) T {
nextPower := math.Ceil(math.Log2(float64(d)))
return T(math.Pow(2.0, nextPower))
}

// PadToPowerOf2 pads a byte slice to the nearest power of 2 length by appending zeros
func PadToPowerOf2(data []byte) []byte {
length := len(data)
if length == 0 {
return []byte{0}
}

// If length is already a power of 2, return original
if length&(length-1) == 0 {
return data
}

// Create a new slice with the power-of-2 length
paddedData := make([]byte, NextPowerOf2(uint64(len(data))))

// Copy original data
copy(paddedData, data)

// The remaining bytes will be zero by default
return paddedData
}
11 changes: 11 additions & 0 deletions core/v2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ func HexToBlobKey(h string) (BlobKey, error) {
return BlobKey(b), nil
}

func BytesToBlobKey(bytes []byte) (BlobKey, error) {
// Validate length
if len(bytes) != 32 {
return BlobKey{}, fmt.Errorf("invalid blob key length: expected 32 bytes, got %d", len(bytes))
}

var blobKey BlobKey
copy(blobKey[:], bytes)
return blobKey, nil
}

// BlobHeader contains all metadata related to a blob including commitments and parameters for encoding
type BlobHeader struct {
BlobVersion BlobVersion
Expand Down
Loading

0 comments on commit 8f6b812

Please sign in to comment.