-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
160 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package apiserver | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"net" | ||
|
||
"github.com/Layr-Labs/eigenda/api" | ||
pb "github.com/Layr-Labs/eigenda/api/grpc/disperser/v2" | ||
healthcheck "github.com/Layr-Labs/eigenda/common/healthcheck" | ||
"github.com/Layr-Labs/eigenda/disperser" | ||
"github.com/Layr-Labs/eigensdk-go/logging" | ||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/reflection" | ||
) | ||
|
||
type DispersalServerV2 struct { | ||
pb.UnimplementedDisperserServer | ||
|
||
serverConfig disperser.ServerConfig | ||
logger logging.Logger | ||
} | ||
|
||
// NewDispersalServerV2 creates a new Server struct with the provided parameters. | ||
func NewDispersalServerV2( | ||
serverConfig disperser.ServerConfig, | ||
_logger logging.Logger, | ||
) *DispersalServerV2 { | ||
logger := _logger.With("component", "DispersalServerV2") | ||
|
||
return &DispersalServerV2{ | ||
serverConfig: serverConfig, | ||
logger: logger, | ||
} | ||
} | ||
|
||
func (s *DispersalServerV2) DisperseBlob(ctx context.Context, req *pb.DisperseBlobRequest) (*pb.DisperseBlobReply, error) { | ||
return &pb.DisperseBlobReply{}, api.NewGRPCError(codes.Unimplemented, "not implemented") | ||
} | ||
|
||
func (s *DispersalServerV2) GetBlobStatus(ctx context.Context, req *pb.BlobStatusRequest) (*pb.BlobStatusReply, error) { | ||
return &pb.BlobStatusReply{}, api.NewGRPCError(codes.Unimplemented, "not implemented") | ||
} | ||
|
||
func (s *DispersalServerV2) GetBlobCommitment(ctx context.Context, req *pb.BlobCommitmentRequest) (*pb.BlobCommitmentReply, error) { | ||
return &pb.BlobCommitmentReply{}, api.NewGRPCError(codes.Unimplemented, "not implemented") | ||
} | ||
|
||
func (s *DispersalServerV2) Start(ctx context.Context) error { | ||
// Serve grpc requests | ||
addr := fmt.Sprintf("%s:%s", disperser.Localhost, s.serverConfig.GrpcPort) | ||
listener, err := net.Listen("tcp", addr) | ||
if err != nil { | ||
return errors.New("could not start tcp listener") | ||
} | ||
|
||
opt := grpc.MaxRecvMsgSize(1024 * 1024 * 300) // 300 MiB | ||
|
||
gs := grpc.NewServer(opt) | ||
reflection.Register(gs) | ||
pb.RegisterDisperserServer(gs, s) | ||
|
||
// Register Server for Health Checks | ||
name := pb.Disperser_ServiceDesc.ServiceName | ||
healthcheck.RegisterHealthServer(name, gs) | ||
|
||
s.logger.Info("GRPC Listening", "port", s.serverConfig.GrpcPort, "address", listener.Addr().String()) | ||
|
||
if err := gs.Serve(listener); err != nil { | ||
return errors.New("could not start GRPC server") | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package apiserver_test | ||
|
||
import ( | ||
"context" | ||
"crypto/rand" | ||
"testing" | ||
"time" | ||
|
||
"github.com/Layr-Labs/eigenda/disperser/apiserver" | ||
"github.com/Layr-Labs/eigenda/encoding/utils/codec" | ||
"github.com/Layr-Labs/eigensdk-go/logging" | ||
|
||
pbv2 "github.com/Layr-Labs/eigenda/api/grpc/disperser/v2" | ||
"github.com/Layr-Labs/eigenda/disperser" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestV2DisperseBlob(t *testing.T) { | ||
data := make([]byte, 3*1024) | ||
_, err := rand.Read(data) | ||
assert.NoError(t, err) | ||
|
||
data = codec.ConvertByPaddingEmptyByte(data) | ||
_, err = dispersalServerV2.DisperseBlob(context.Background(), &pbv2.DisperseBlobRequest{ | ||
Data: data, | ||
BlobHeader: &pbv2.BlobHeader{}, | ||
}) | ||
assert.ErrorContains(t, err, "not implemented") | ||
} | ||
|
||
func TestV2GetBlobStatus(t *testing.T) { | ||
_, err := dispersalServerV2.GetBlobStatus(context.Background(), &pbv2.BlobStatusRequest{ | ||
BlobKey: []byte{1}, | ||
}) | ||
assert.ErrorContains(t, err, "not implemented") | ||
} | ||
|
||
func TestV2GetBlobCommitment(t *testing.T) { | ||
_, err := dispersalServerV2.GetBlobCommitment(context.Background(), &pbv2.BlobCommitmentRequest{ | ||
Data: []byte{1}, | ||
}) | ||
assert.ErrorContains(t, err, "not implemented") | ||
} | ||
|
||
func newTestServerV2() *apiserver.DispersalServerV2 { | ||
logger := logging.NewNoopLogger() | ||
return apiserver.NewDispersalServerV2(disperser.ServerConfig{ | ||
GrpcPort: "51002", | ||
GrpcTimeout: 1 * time.Second, | ||
}, logger) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters