-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add grpc aggregator support (#90)
* delete useless codes * add proto * fix lint and bugs * add ignore * impl the rpc by grpc * add operator grpc client impl
- Loading branch information
Showing
22 changed files
with
1,595 additions
and
138 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,4 +25,5 @@ coverage.html | |
logs.txt | ||
|
||
bin | ||
contracts/broadcast | ||
contracts/broadcast | ||
.vscode |
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 |
---|---|---|
|
@@ -13,6 +13,9 @@ CHAINID=31337 | |
STRATEGY_ADDRESS=0x7a2088a1bFc9d81c55368AE168C2C02570cB814F | ||
DEPLOYMENT_FILES_DIR=contracts/script/output/${CHAINID} | ||
|
||
PROTOS := ./api/proto | ||
PROTO_GEN := ./api/grpc | ||
|
||
-----------------------------: ## | ||
|
||
___CONTRACTS___: ## | ||
|
@@ -25,6 +28,22 @@ bindings: ## generates contract bindings | |
|
||
__CLI__: ## | ||
|
||
clean: | ||
find $(PROTO_GEN) -name "*.pb.go" -type f | xargs rm -rf | ||
mkdir -p $(PROTO_GEN) | ||
|
||
protoc: clean | ||
protoc -I $(PROTOS) \ | ||
--go_out=$(PROTO_GEN) \ | ||
--go_opt=paths=source_relative \ | ||
--go-grpc_out=$(PROTO_GEN) \ | ||
--go-grpc_opt=paths=source_relative \ | ||
$(PROTOS)/**/*.proto | ||
|
||
lint: | ||
staticcheck ./... | ||
golangci-lint run | ||
|
||
build: build-operator build-aggregator build-cli | ||
|
||
build-operator: | ||
|
@@ -40,3 +59,4 @@ _____HELPER_____: ## | |
mocks: ## generates mocks for tests | ||
go install go.uber.org/mock/[email protected] | ||
go generate ./... | ||
|
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,110 @@ | ||
package rpc | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net" | ||
"sync" | ||
|
||
"github.com/Layr-Labs/eigensdk-go/logging" | ||
"github.com/alt-research/avs/api/grpc/aggregator" | ||
"github.com/alt-research/avs/core/message" | ||
"google.golang.org/grpc" | ||
) | ||
|
||
type GRpcHandler struct { | ||
aggregator.UnimplementedAggregatorServer | ||
logger logging.Logger | ||
aggreagtor AggregatorRpcHandler | ||
wg *sync.WaitGroup | ||
} | ||
|
||
func NewGRpcHandler(logger logging.Logger, aggreagtor AggregatorRpcHandler) *GRpcHandler { | ||
return &GRpcHandler{ | ||
logger: logger, | ||
aggreagtor: aggreagtor, | ||
wg: &sync.WaitGroup{}, | ||
} | ||
} | ||
|
||
func (s *GRpcHandler) StartServer(ctx context.Context, serverIpPortAddr string) { | ||
s.logger.Info("Start GRpcServer", "addr", serverIpPortAddr) | ||
|
||
lis, err := net.Listen("tcp", serverIpPortAddr) | ||
if err != nil { | ||
s.logger.Fatalf("GRpcServer failed to listen: %v", err) | ||
} | ||
|
||
server := grpc.NewServer() | ||
aggregator.RegisterAggregatorServer(server, s) | ||
|
||
serverErr := make(chan error, 1) | ||
|
||
s.wg.Add(1) | ||
go func() { | ||
defer s.wg.Done() | ||
serverErr <- server.Serve(lis) | ||
}() | ||
|
||
select { | ||
case <-ctx.Done(): | ||
s.logger.Info("Stop GRpcServer by Done") | ||
server.Stop() | ||
case err = <-serverErr: | ||
} | ||
|
||
if err != nil { | ||
s.logger.Error("GRpcServer serve stopped by error", "err", err) | ||
} else { | ||
s.logger.Info("GRpcServer serve stopped") | ||
} | ||
} | ||
|
||
func (s *GRpcHandler) Wait() { | ||
s.wg.Wait() | ||
} | ||
|
||
// Send Init operator to aggregator from operator, will check if the config is matching | ||
func (s *GRpcHandler) InitOperator(ctx context.Context, req *aggregator.InitOperatorRequest) (*aggregator.InitOperatorResponse, error) { | ||
msg, err := message.NewInitOperatorRequest(req) | ||
if err != nil { | ||
return nil, fmt.Errorf("initOperator message convert error: %v", err.Error()) | ||
} | ||
|
||
resp, err := s.aggreagtor.InitOperator(msg) | ||
if err != nil { | ||
return nil, fmt.Errorf("initOperator handler error: %v", err.Error()) | ||
} | ||
|
||
return resp.ToPbType(), nil | ||
} | ||
|
||
// Create a alert task | ||
func (s *GRpcHandler) CreateTask(ctx context.Context, req *aggregator.CreateTaskRequest) (*aggregator.CreateTaskResponse, error) { | ||
msg, err := message.NewCreateTaskRequest(req) | ||
if err != nil { | ||
return nil, fmt.Errorf("createTask message convert error: %v", err.Error()) | ||
} | ||
|
||
resp, err := s.aggreagtor.CreateTask(msg) | ||
if err != nil { | ||
return nil, fmt.Errorf("createTask handler error: %v", err.Error()) | ||
} | ||
|
||
return resp.ToPbType(), nil | ||
} | ||
|
||
// Send signed task for alert | ||
func (s *GRpcHandler) ProcessSignedTaskResponse(ctx context.Context, req *aggregator.SignedTaskRespRequest) (*aggregator.SignedTaskRespResponse, error) { | ||
msg, err := message.NewSignedTaskRespRequest(req) | ||
if err != nil { | ||
return nil, fmt.Errorf("processSignedTaskResponse message convert error: %v", err.Error()) | ||
} | ||
|
||
resp, err := s.aggreagtor.ProcessSignedTaskResponse(msg) | ||
if err != nil { | ||
return nil, fmt.Errorf("processSignedTaskResponse handler error: %v", err.Error()) | ||
} | ||
|
||
return resp.ToPbType(), 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
Oops, something went wrong.