forked from Layr-Labs/eigenda
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[v2] Node v2 gRPC Entrypoint (Layr-Labs#797)
- Loading branch information
Showing
6 changed files
with
289 additions
and
96 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,81 @@ | ||
package grpc | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"net" | ||
|
||
pb "github.com/Layr-Labs/eigenda/api/grpc/node" | ||
pbv2 "github.com/Layr-Labs/eigenda/api/grpc/node/v2" | ||
"github.com/Layr-Labs/eigenda/common/healthcheck" | ||
"github.com/Layr-Labs/eigenda/node" | ||
"github.com/Layr-Labs/eigensdk-go/logging" | ||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/reflection" | ||
) | ||
|
||
const localhost = "0.0.0.0" | ||
|
||
func RunServers(serverV1 *Server, serverV2 *ServerV2, config *node.Config, logger logging.Logger) error { | ||
if serverV1 == nil { | ||
return errors.New("node V1 server is not configured") | ||
} | ||
if serverV2 == nil { | ||
return errors.New("node V2 server is not configured") | ||
} | ||
|
||
go func() { | ||
for { | ||
addr := fmt.Sprintf("%s:%s", localhost, config.InternalDispersalPort) | ||
listener, err := net.Listen("tcp", addr) | ||
if err != nil { | ||
logger.Fatalf("Could not start tcp listener: %v", err) | ||
} | ||
|
||
opt := grpc.MaxRecvMsgSize(60 * 1024 * 1024 * 1024) // 60 GiB | ||
gs := grpc.NewServer(opt) | ||
|
||
// Register reflection service on gRPC server | ||
// This makes "grpcurl -plaintext localhost:9000 list" command work | ||
reflection.Register(gs) | ||
|
||
pb.RegisterDispersalServer(gs, serverV1) | ||
pbv2.RegisterDispersalServer(gs, serverV2) | ||
|
||
healthcheck.RegisterHealthServer("node.Dispersal", gs) | ||
|
||
logger.Info("port", config.InternalDispersalPort, "address", listener.Addr().String(), "GRPC Listening") | ||
if err := gs.Serve(listener); err != nil { | ||
logger.Error("dispersal server failed; restarting.", "err", err) | ||
} | ||
} | ||
}() | ||
|
||
go func() { | ||
for { | ||
addr := fmt.Sprintf("%s:%s", localhost, config.InternalRetrievalPort) | ||
listener, err := net.Listen("tcp", addr) | ||
if err != nil { | ||
logger.Fatalf("Could not start tcp listener: %v", err) | ||
} | ||
|
||
opt := grpc.MaxRecvMsgSize(1024 * 1024 * 300) // 300 MiB | ||
gs := grpc.NewServer(opt) | ||
|
||
// Register reflection service on gRPC server | ||
// This makes "grpcurl -plaintext localhost:9000 list" command work | ||
reflection.Register(gs) | ||
|
||
pb.RegisterRetrievalServer(gs, serverV1) | ||
pbv2.RegisterRetrievalServer(gs, serverV2) | ||
healthcheck.RegisterHealthServer("node.Retrieval", gs) | ||
|
||
logger.Info("port", config.InternalRetrievalPort, "address", listener.Addr().String(), "GRPC Listening") | ||
if err := gs.Serve(listener); err != nil { | ||
logger.Error("retrieval server failed; restarting.", "err", err) | ||
} | ||
} | ||
}() | ||
|
||
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
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,62 @@ | ||
package grpc | ||
|
||
import ( | ||
"context" | ||
"runtime" | ||
"sync" | ||
|
||
"github.com/Layr-Labs/eigenda/api" | ||
pb "github.com/Layr-Labs/eigenda/api/grpc/node/v2" | ||
"github.com/Layr-Labs/eigenda/common" | ||
"github.com/Layr-Labs/eigenda/node" | ||
"github.com/Layr-Labs/eigensdk-go/logging" | ||
"github.com/shirou/gopsutil/mem" | ||
"google.golang.org/grpc/codes" | ||
) | ||
|
||
// ServerV2 implements the Node v2 proto APIs. | ||
type ServerV2 struct { | ||
pb.UnimplementedDispersalServer | ||
pb.UnimplementedRetrievalServer | ||
|
||
node *node.Node | ||
config *node.Config | ||
logger logging.Logger | ||
|
||
ratelimiter common.RateLimiter | ||
|
||
mu *sync.Mutex | ||
} | ||
|
||
// NewServerV2 creates a new Server instance with the provided parameters. | ||
func NewServerV2(config *node.Config, node *node.Node, logger logging.Logger, ratelimiter common.RateLimiter) *ServerV2 { | ||
return &ServerV2{ | ||
config: config, | ||
logger: logger, | ||
node: node, | ||
ratelimiter: ratelimiter, | ||
mu: &sync.Mutex{}, | ||
} | ||
} | ||
|
||
func (s *ServerV2) NodeInfo(ctx context.Context, in *pb.NodeInfoRequest) (*pb.NodeInfoReply, error) { | ||
if s.config.DisableNodeInfoResources { | ||
return &pb.NodeInfoReply{Semver: node.SemVer}, nil | ||
} | ||
|
||
memBytes := uint64(0) | ||
v, err := mem.VirtualMemory() | ||
if err == nil { | ||
memBytes = v.Total | ||
} | ||
|
||
return &pb.NodeInfoReply{Semver: node.SemVer, Os: runtime.GOOS, Arch: runtime.GOARCH, NumCpu: uint32(runtime.GOMAXPROCS(0)), MemBytes: memBytes}, nil | ||
} | ||
|
||
func (s *ServerV2) StoreChunks(ctx context.Context, in *pb.StoreChunksRequest) (*pb.StoreChunksReply, error) { | ||
return &pb.StoreChunksReply{}, api.NewGRPCError(codes.Unimplemented, "not implemented") | ||
} | ||
|
||
func (s *ServerV2) GetChunks(context.Context, *pb.GetChunksRequest) (*pb.GetChunksReply, error) { | ||
return &pb.GetChunksReply{}, api.NewGRPCError(codes.Unimplemented, "not implemented") | ||
} |
Oops, something went wrong.