Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v2] Disperser server GetBlobCommitment endpoint #899

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion disperser/apiserver/server_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import (
"time"

"github.com/Layr-Labs/eigenda/api"
pbcommon "github.com/Layr-Labs/eigenda/api/grpc/common"
pb "github.com/Layr-Labs/eigenda/api/grpc/disperser/v2"
"github.com/Layr-Labs/eigenda/common"
healthcheck "github.com/Layr-Labs/eigenda/common/healthcheck"
"github.com/Layr-Labs/eigenda/core"
corev2 "github.com/Layr-Labs/eigenda/core/v2"
"github.com/Layr-Labs/eigenda/disperser"
"github.com/Layr-Labs/eigenda/disperser/common/v2/blobstore"
"github.com/Layr-Labs/eigenda/encoding"
"github.com/Layr-Labs/eigensdk-go/logging"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
Expand All @@ -38,6 +40,7 @@ type DispersalServerV2 struct {
chainReader core.Reader
ratelimiter common.RateLimiter
authenticator corev2.BlobRequestAuthenticator
prover encoding.Prover
logger logging.Logger

// state
Expand All @@ -55,6 +58,7 @@ func NewDispersalServerV2(
chainReader core.Reader,
ratelimiter common.RateLimiter,
authenticator corev2.BlobRequestAuthenticator,
prover encoding.Prover,
maxNumSymbolsPerBlob uint64,
onchainStateRefreshInterval time.Duration,
_logger logging.Logger,
Expand All @@ -70,6 +74,7 @@ func NewDispersalServerV2(
chainReader: chainReader,
ratelimiter: ratelimiter,
authenticator: authenticator,
prover: prover,
logger: logger,

onchainState: OnchainState{},
Expand Down Expand Up @@ -149,7 +154,40 @@ func (s *DispersalServerV2) GetBlobStatus(ctx context.Context, req *pb.BlobStatu
}

func (s *DispersalServerV2) GetBlobCommitment(ctx context.Context, req *pb.BlobCommitmentRequest) (*pb.BlobCommitmentReply, error) {
return &pb.BlobCommitmentReply{}, api.NewErrorUnimplemented()
if s.prover == nil {
return nil, api.NewErrorUnimplemented()
}
blobSize := len(req.GetData())
if blobSize == 0 {
return nil, api.NewErrorInvalidArg("data is empty")
}
if uint64(blobSize) > s.maxNumSymbolsPerBlob*encoding.BYTES_PER_SYMBOL {
return nil, api.NewErrorInvalidArg(fmt.Sprintf("blob size cannot exceed %v bytes", s.maxNumSymbolsPerBlob*encoding.BYTES_PER_SYMBOL))
}
c, err := s.prover.GetCommitments(req.GetData())
if err != nil {
return nil, api.NewErrorInternal("failed to get commitments")
}
commitment, err := c.Commitment.Serialize()
if err != nil {
return nil, api.NewErrorInternal("failed to serialize commitment")
}
lengthCommitment, err := c.LengthCommitment.Serialize()
if err != nil {
return nil, api.NewErrorInternal("failed to serialize length commitment")
}
lengthProof, err := c.LengthProof.Serialize()
if err != nil {
return nil, api.NewErrorInternal("failed to serialize length proof")
}

return &pb.BlobCommitmentReply{
BlobCommitment: &pbcommon.BlobCommitment{
Commitment: commitment,
LengthCommitment: lengthCommitment,
LengthProof: lengthProof,
Length: uint32(c.Length),
}}, nil
}

func (s *DispersalServerV2) RefreshAllowlist() error {
Expand Down
27 changes: 23 additions & 4 deletions disperser/apiserver/server_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/Layr-Labs/eigenda/disperser/apiserver"
dispv2 "github.com/Layr-Labs/eigenda/disperser/common/v2"
"github.com/Layr-Labs/eigenda/disperser/common/v2/blobstore"
"github.com/Layr-Labs/eigenda/encoding"
"github.com/Layr-Labs/eigenda/encoding/utils/codec"
"github.com/Layr-Labs/eigensdk-go/logging"
"google.golang.org/grpc/peer"
Expand All @@ -28,6 +29,7 @@ import (
"github.com/Layr-Labs/eigenda/disperser"
"github.com/stretchr/testify/assert"
tmock "github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
)

type testComponents struct {
Expand Down Expand Up @@ -209,10 +211,27 @@ func TestV2GetBlobStatus(t *testing.T) {

func TestV2GetBlobCommitment(t *testing.T) {
c := newTestServerV2(t)
_, err := c.DispersalServerV2.GetBlobCommitment(context.Background(), &pbv2.BlobCommitmentRequest{
Data: []byte{1},
data := make([]byte, 50)
_, err := rand.Read(data)
assert.NoError(t, err)

data = codec.ConvertByPaddingEmptyByte(data)
commit, err := prover.GetCommitments(data)
require.NoError(t, err)
reply, err := c.DispersalServerV2.GetBlobCommitment(context.Background(), &pbv2.BlobCommitmentRequest{
Data: data,
})
assert.ErrorContains(t, err, "not implemented")
require.NoError(t, err)
commitment, err := new(encoding.G1Commitment).Deserialize(reply.BlobCommitment.Commitment)
require.NoError(t, err)
assert.Equal(t, commit.Commitment, commitment)
lengthCommitment, err := new(encoding.G2Commitment).Deserialize(reply.BlobCommitment.LengthCommitment)
require.NoError(t, err)
assert.Equal(t, commit.LengthCommitment, lengthCommitment)
lengthProof, err := new(encoding.G2Commitment).Deserialize(reply.BlobCommitment.LengthProof)
require.NoError(t, err)
assert.Equal(t, commit.LengthProof, lengthProof)
assert.Equal(t, uint32(commit.Length), reply.BlobCommitment.Length)
}

func newTestServerV2(t *testing.T) *testComponents {
Expand Down Expand Up @@ -246,7 +265,7 @@ func newTestServerV2(t *testing.T) *testComponents {
s := apiserver.NewDispersalServerV2(disperser.ServerConfig{
GrpcPort: "51002",
GrpcTimeout: 1 * time.Second,
}, rateConfig, blobStore, blobMetadataStore, chainReader, nil, auth.NewAuthenticator(), 100, time.Hour, logger)
}, rateConfig, blobStore, blobMetadataStore, chainReader, nil, auth.NewAuthenticator(), prover, 100, time.Hour, logger)

err = s.RefreshOnchainState(context.Background())
assert.NoError(t, err)
Expand Down
3 changes: 3 additions & 0 deletions disperser/cmd/apiserver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/Layr-Labs/eigenda/disperser/apiserver"
"github.com/Layr-Labs/eigenda/disperser/cmd/apiserver/flags"
"github.com/Layr-Labs/eigenda/disperser/common/blobstore"
"github.com/Layr-Labs/eigenda/encoding/kzg"
"github.com/urfave/cli"
)

Expand All @@ -31,6 +32,7 @@ type Config struct {
MetricsConfig disperser.MetricsConfig
RatelimiterConfig ratelimit.Config
RateConfig apiserver.RateConfig
EncodingConfig kzg.KzgConfig
EnableRatelimiter bool
EnablePaymentMeterer bool
UpdateInterval int
Expand Down Expand Up @@ -88,6 +90,7 @@ func NewConfig(ctx *cli.Context) (Config, error) {
},
RatelimiterConfig: ratelimiterConfig,
RateConfig: rateConfig,
EncodingConfig: kzg.ReadCLIConfig(ctx),
EnableRatelimiter: ctx.GlobalBool(flags.EnableRatelimiter.Name),
EnablePaymentMeterer: ctx.GlobalBool(flags.EnablePaymentMeterer.Name),
ReservationsTableName: ctx.GlobalString(flags.ReservationsTableName.Name),
Expand Down
70 changes: 70 additions & 0 deletions disperser/cmd/apiserver/flags/flags.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package flags

import (
"runtime"
"time"

"github.com/Layr-Labs/eigenda/common"
"github.com/Layr-Labs/eigenda/common/aws"
"github.com/Layr-Labs/eigenda/common/geth"
"github.com/Layr-Labs/eigenda/common/ratelimit"
"github.com/Layr-Labs/eigenda/disperser/apiserver"
"github.com/Layr-Labs/eigenda/encoding/kzg"
"github.com/urfave/cli"
)

Expand Down Expand Up @@ -154,6 +156,73 @@ var (
}
)

var kzgFlags = []cli.Flag{
// KZG flags for encoding
// These are copied from encoding/kzg/cli.go as optional flags for compatibility between v1 and v2 dispersers
// These flags are only used in v2 disperser
cli.StringFlag{
Name: kzg.G1PathFlagName,
Usage: "Path to G1 SRS",
Required: false,
EnvVar: common.PrefixEnvVar(envVarPrefix, "G1_PATH"),
},
cli.StringFlag{
Name: kzg.G2PathFlagName,
Usage: "Path to G2 SRS. Either this flag or G2_POWER_OF_2_PATH needs to be specified. For operator node, if both are specified, the node uses G2_POWER_OF_2_PATH first, if failed then tries to G2_PATH",
Required: false,
EnvVar: common.PrefixEnvVar(envVarPrefix, "G2_PATH"),
},
cli.StringFlag{
Name: kzg.CachePathFlagName,
Usage: "Path to SRS Table directory",
Required: false,
EnvVar: common.PrefixEnvVar(envVarPrefix, "CACHE_PATH"),
},
cli.Uint64Flag{
Name: kzg.SRSOrderFlagName,
Usage: "Order of the SRS",
Required: false,
EnvVar: common.PrefixEnvVar(envVarPrefix, "SRS_ORDER"),
},
cli.Uint64Flag{
Name: kzg.SRSLoadingNumberFlagName,
Usage: "Number of SRS points to load into memory",
Required: false,
EnvVar: common.PrefixEnvVar(envVarPrefix, "SRS_LOAD"),
},
cli.Uint64Flag{
Name: kzg.NumWorkerFlagName,
Usage: "Number of workers for multithreading",
Required: false,
EnvVar: common.PrefixEnvVar(envVarPrefix, "NUM_WORKERS"),
Value: uint64(runtime.GOMAXPROCS(0)),
},
cli.BoolFlag{
Name: kzg.VerboseFlagName,
Usage: "Enable to see verbose output for encoding/decoding",
Required: false,
EnvVar: common.PrefixEnvVar(envVarPrefix, "VERBOSE"),
},
cli.BoolFlag{
Name: kzg.CacheEncodedBlobsFlagName,
Usage: "Enable to cache encoded results",
Required: false,
EnvVar: common.PrefixEnvVar(envVarPrefix, "CACHE_ENCODED_BLOBS"),
},
cli.BoolFlag{
Name: kzg.PreloadEncoderFlagName,
Usage: "Set to enable Encoder PreLoading",
Required: false,
EnvVar: common.PrefixEnvVar(envVarPrefix, "PRELOAD_ENCODER"),
},
cli.StringFlag{
Name: kzg.G2PowerOf2PathFlagName,
Usage: "Path to G2 SRS points that are on power of 2. Either this flag or G2_PATH needs to be specified. For operator node, if both are specified, the node uses G2_POWER_OF_2_PATH first, if failed then tries to G2_PATH",
Required: false,
EnvVar: common.PrefixEnvVar(envVarPrefix, "G2_POWER_OF_2_PATH"),
},
}

var requiredFlags = []cli.Flag{
S3BucketNameFlag,
DynamoDBTableNameFlag,
Expand Down Expand Up @@ -189,4 +258,5 @@ func init() {
Flags = append(Flags, ratelimit.RatelimiterCLIFlags(envVarPrefix, FlagPrefix)...)
Flags = append(Flags, aws.ClientFlags(envVarPrefix, FlagPrefix)...)
Flags = append(Flags, apiserver.CLIFlags(envVarPrefix)...)
Flags = append(Flags, kzgFlags...)
}
6 changes: 6 additions & 0 deletions disperser/cmd/apiserver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/Layr-Labs/eigenda/disperser/common/blobstore"
blobstorev2 "github.com/Layr-Labs/eigenda/disperser/common/v2/blobstore"
"github.com/Layr-Labs/eigenda/encoding/fft"
"github.com/Layr-Labs/eigenda/encoding/kzg/prover"
"github.com/prometheus/client_golang/prometheus"

"github.com/Layr-Labs/eigenda/common/aws/dynamodb"
Expand Down Expand Up @@ -161,6 +162,10 @@ func RunDisperserServer(ctx *cli.Context) error {
bucketName := config.BlobstoreConfig.BucketName
logger.Info("Blob store", "bucket", bucketName)
if config.DisperserVersion == V2 {
prover, err := prover.NewProver(&config.EncodingConfig, true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The prover setup takes around ~20 seconds with 16 cpus since we need to load the G2 points. Also is the disperser still a singleton in V2?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it has to be a singleton anymore now that payments aren't handled locally. @mooselumph is that correct?

if err != nil {
return fmt.Errorf("failed to create encoder: %w", err)
}
blobMetadataStore := blobstorev2.NewBlobMetadataStore(dynamoClient, logger, config.BlobstoreConfig.TableName)
blobStore := blobstorev2.NewBlobStore(bucketName, s3Client, logger)

Expand All @@ -172,6 +177,7 @@ func RunDisperserServer(ctx *cli.Context) error {
transactor,
ratelimiter,
authv2.NewAuthenticator(),
prover,
uint64(config.MaxNumSymbolsPerBlob),
config.OnchainStateRefreshInterval,
logger,
Expand Down
Loading