Skip to content

Commit

Permalink
Merge branch 'Layr-Labs:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
bxue-l2 authored Sep 1, 2024
2 parents c45e59b + 081d690 commit f154031
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 43 deletions.
131 changes: 101 additions & 30 deletions disperser/api/grpc/encoder/encoder.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion disperser/api/proto/encoder/encoder.proto
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,17 @@ message EncodeBlobRequest {
EncodingParams encoding_params = 2;
}

// EncodeBlobReply returns all encoded chunks along with BlobCommitment for the same,
enum ChunkEncodingFormat {
UNKNOWN = 0;
GNARK = 1;
GOB = 2;
}

// EncodeBlobReply returns all encoded chunks along with BlobCommitment for the same,
// where Chunk is the smallest unit that is distributed to DA nodes
message EncodeBlobReply {
BlobCommitment commitment = 1;
repeated bytes chunks = 2;
// How the above chunks are encoded.
ChunkEncodingFormat chunk_encoding_format = 3;
}
7 changes: 4 additions & 3 deletions disperser/cmd/encoder/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ func NewConfig(ctx *cli.Context) (Config, error) {
EncoderConfig: kzg.ReadCLIConfig(ctx),
LoggerConfig: *loggerConfig,
ServerConfig: &encoder.ServerConfig{
GrpcPort: ctx.GlobalString(flags.GrpcPortFlag.Name),
MaxConcurrentRequests: ctx.GlobalInt(flags.MaxConcurrentRequestsFlag.Name),
RequestPoolSize: ctx.GlobalInt(flags.RequestPoolSizeFlag.Name),
GrpcPort: ctx.GlobalString(flags.GrpcPortFlag.Name),
MaxConcurrentRequests: ctx.GlobalInt(flags.MaxConcurrentRequestsFlag.Name),
RequestPoolSize: ctx.GlobalInt(flags.RequestPoolSizeFlag.Name),
EnableGnarkChunkEncoding: ctx.Bool(flags.EnableGnarkChunkEncodingFlag.Name),
},
MetricsConfig: encoder.MetrisConfig{
HTTPPort: ctx.GlobalString(flags.MetricsHTTPPort.Name),
Expand Down
7 changes: 7 additions & 0 deletions disperser/cmd/encoder/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ var (
Value: 32,
EnvVar: common.PrefixEnvVar(envVarPrefix, "REQUEST_POOL_SIZE"),
}
EnableGnarkChunkEncodingFlag = cli.BoolFlag{
Name: common.PrefixFlag(FlagPrefix, "enable-gnark-chunk-encoding"),
Usage: "if true, will produce chunks in Gnark, instead of Gob",
Required: false,
EnvVar: common.PrefixEnvVar(envVarPrefix, "ENABLE_GNARK_CHUNK_ENCODING"),
}
)

var requiredFlags = []cli.Flag{
Expand All @@ -58,6 +64,7 @@ var optionalFlags = []cli.Flag{
EnableMetrics,
MaxConcurrentRequestsFlag,
RequestPoolSizeFlag,
EnableGnarkChunkEncodingFlag,
}

// Flags contains the list of configuration options available to the binary.
Expand Down
15 changes: 11 additions & 4 deletions disperser/encoder/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,18 @@ func (c client) EncodeBlob(ctx context.Context, data []byte, encodingParams enco
if err != nil {
return nil, nil, err
}
var format core.ChunkEncodingFormat
switch reply.GetChunkEncodingFormat() {
case pb.ChunkEncodingFormat_GNARK:
format = core.GnarkChunkEncodingFormat
case pb.ChunkEncodingFormat_GOB:
format = core.GobChunkEncodingFormat
case pb.ChunkEncodingFormat_UNKNOWN:
format = core.GobChunkEncodingFormat
}
chunksData := &core.ChunksData{
Chunks: reply.GetChunks(),
// TODO(jianoaix): plumb the encoding format for the encoder server. For now it's fine
// as it's hard coded using Gob at Encoder server.
Format: core.GobChunkEncodingFormat,
Chunks: reply.GetChunks(),
Format: format,
ChunkLen: int(encodingParams.ChunkLength),
}
return &encoding.BlobCommitments{
Expand Down
7 changes: 4 additions & 3 deletions disperser/encoder/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ const (
)

type ServerConfig struct {
GrpcPort string
MaxConcurrentRequests int
RequestPoolSize int
GrpcPort string
MaxConcurrentRequests int
RequestPoolSize int
EnableGnarkChunkEncoding bool
}
17 changes: 15 additions & 2 deletions disperser/encoder/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,20 @@ func (s *Server) handleEncoding(ctx context.Context, req *pb.EncodeBlobRequest)

var chunksData [][]byte

var format pb.ChunkEncodingFormat
if s.config.EnableGnarkChunkEncoding {
format = pb.ChunkEncodingFormat_GNARK
} else {
format = pb.ChunkEncodingFormat_GOB
}

for _, chunk := range chunks {
chunkSerialized, err := chunk.Serialize()
var chunkSerialized []byte
if s.config.EnableGnarkChunkEncoding {
chunkSerialized, err = chunk.SerializeGnark()
} else {
chunkSerialized, err = chunk.Serialize()
}
if err != nil {
return nil, err
}
Expand All @@ -135,7 +147,8 @@ func (s *Server) handleEncoding(ctx context.Context, req *pb.EncodeBlobRequest)
LengthProof: lengthProofData,
Length: uint32(commits.Length),
},
Chunks: chunksData,
Chunks: chunksData,
ChunkEncodingFormat: format,
}, nil
}

Expand Down

0 comments on commit f154031

Please sign in to comment.