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

Add GRPC API for querying the list of members for a given round #236

Closed
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
275 changes: 200 additions & 75 deletions release/proto/go/rpc/api/v1/api.pb.go

Large diffs are not rendered by default.

103 changes: 103 additions & 0 deletions release/proto/go/rpc/api/v1/api.pb.gw.go

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

38 changes: 38 additions & 0 deletions release/proto/go/rpc/api/v1/api_grpc.pb.go

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

50 changes: 43 additions & 7 deletions release/proto/openapiv2/rpc/api/v1/api.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,37 @@
]
}
},
"/v1/rounds/{roundId}": {
"get": {
"summary": "GetRound returns details about the given round",
"operationId": "PoetService_GetRound",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/v1GetRoundResponse"
}
},
"default": {
"description": "An unexpected error response.",
"schema": {
"$ref": "#/definitions/rpcStatus"
}
}
},
"parameters": [
{
"name": "roundId",
"in": "path",
"required": true,
"type": "string"
}
],
"tags": [
"PoetService"
]
}
},
"/v1/start": {
"post": {
"summary": "Start is used to start the service.",
Expand Down Expand Up @@ -228,6 +259,18 @@
}
}
},
"v1GetRoundResponse": {
"type": "object",
"properties": {
"members": {
"type": "array",
"items": {
"type": "string",
"format": "byte"
}
}
}
},
"v1MerkleProof": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -257,13 +300,6 @@
"proof": {
"$ref": "#/definitions/v1MerkleProof"
},
"members": {
"type": "array",
"items": {
"type": "string",
"format": "byte"
}
},
"leaves": {
"type": "string",
"format": "uint64"
Expand Down
20 changes: 18 additions & 2 deletions rpc/api/v1/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ service PoetService {
get: "/v1/proofs/{round_id}"
};
}

/**
GetRound returns details about the given round
*/
rpc GetRound(GetRoundRequest) returns (GetRoundResponse) {
option (google.api.http) = {
get: "/v1/rounds/{round_id}"
};
}
}

message StartRequest {
Expand Down Expand Up @@ -108,8 +117,7 @@ message MerkleProof {

message PoetProof {
MerkleProof proof = 1;
repeated bytes members = 2;
uint64 leaves = 3;
uint64 leaves = 2;
}

message GetProofRequest {
Expand All @@ -120,3 +128,11 @@ message GetProofResponse {
PoetProof proof = 1;
bytes pubkey = 2;
}

message GetRoundRequest {
string round_id = 1;
}

message GetRoundResponse {
repeated bytes members = 1;
}
26 changes: 20 additions & 6 deletions rpc/rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

// rpcServer is a gRPC, RPC front end to poet.
type rpcServer struct {
proofsDb *service.ProofsDatabase
serviceDB *service.ServiceDatabase
s *service.Service
gtwManager *gateway.Manager
cfg config.Config
Expand All @@ -36,12 +36,12 @@ var _ api.PoetServiceServer = (*rpcServer)(nil)
// NewServer creates and returns a new instance of the rpcServer.
func NewServer(
svc *service.Service,
proofsDb *service.ProofsDatabase,
proofsDb *service.ServiceDatabase,
gtwManager *gateway.Manager,
cfg config.Config,
) *rpcServer {
return &rpcServer{
proofsDb: proofsDb,
serviceDB: proofsDb,
s: svc,
cfg: cfg,
gtwManager: gtwManager,
Expand Down Expand Up @@ -180,7 +180,7 @@ func (r *rpcServer) GetProof(ctx context.Context, in *api.GetProofRequest) (*api
}
}

proof, err := r.proofsDb.Get(ctx, in.RoundId)
proof, err := r.serviceDB.GetProof(ctx, in.RoundId)
switch {
case errors.Is(err, service.ErrNotFound):
return nil, status.Error(codes.NotFound, "proof not found")
Expand All @@ -192,8 +192,7 @@ func (r *rpcServer) GetProof(ctx context.Context, in *api.GetProofRequest) (*api
ProvenLeaves: proof.ProvenLeaves,
ProofNodes: proof.ProofNodes,
},
Members: proof.Members,
Leaves: proof.NumLeaves,
Leaves: proof.NumLeaves,
},
Pubkey: proof.ServicePubKey,
}
Expand All @@ -203,3 +202,18 @@ func (r *rpcServer) GetProof(ctx context.Context, in *api.GetProofRequest) (*api
return nil, status.Error(codes.Internal, err.Error())
}
}

// GetRound implements apiv1.PoetServiceServer.
func (r *rpcServer) GetRound(ctx context.Context, in *api.GetRoundRequest) (*api.GetRoundResponse, error) {
members, err := r.serviceDB.GetRoundMembers(ctx, in.RoundId)
switch {
case errors.Is(err, service.ErrNotFound):
return nil, status.Error(codes.NotFound, "round not found")
case err == nil:
out := api.GetRoundResponse{Members: members}

return &out, nil
default:
return nil, status.Error(codes.Internal, err.Error())
}
}
2 changes: 1 addition & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (s *Server) Start(ctx context.Context) error {
}

proofsDbPath := filepath.Join(s.cfg.DataDir, "proofs")
proofsDb, err := service.NewProofsDatabase(proofsDbPath, s.svc.ProofsChan())
proofsDb, err := service.NewServiceDatabase(proofsDbPath, s.svc.ProofsChan(), s.svc.RoundsDataChan())
if err != nil {
return fmt.Errorf("failed to create proofs DB: %w", err)
}
Expand Down
Loading