Browse Source

proto: add strict linting and fix up existing protos

Passing the strict lint checks requires a number of backwards-
incompatible changes:

- Rename the NodePrivileged service to NodePrivilegedService.
  This is only used in CLI tooling, which are upgraded at the same
  time as the server binary.

- The Publicrpc service was renamed to PublicRPCService.

- The EmitterChain type is renamed to ChainID.

- The default value for the ChainID type is renamed to
  CHAIN_ID_UNSPECIFIED. This value wasn't referenced anywhere.

- The response and request types for GetLastHeartbeats were updated
  to match the rpc method name.

Change-Id: I3954130d3b25ab1f859390407bba3d3c02ffe03c
Leo 4 năm trước cách đây
mục cha
commit
63b77714ec

+ 4 - 4
bridge/cmd/guardiand/adminclient.go

@@ -50,25 +50,25 @@ var AdminClientInjectGuardianSetUpdateCmd = &cobra.Command{
 	Args:  cobra.ExactArgs(1),
 }
 
-func getAdminClient(ctx context.Context, addr string) (*grpc.ClientConn, error, nodev1.NodePrivilegedClient) {
+func getAdminClient(ctx context.Context, addr string) (*grpc.ClientConn, error, nodev1.NodePrivilegedServiceClient) {
 	conn, err := grpc.DialContext(ctx, fmt.Sprintf("unix:///%s", addr), grpc.WithInsecure())
 
 	if err != nil {
 		log.Fatalf("failed to connect to %s: %v", addr, err)
 	}
 
-	c := nodev1.NewNodePrivilegedClient(conn)
+	c := nodev1.NewNodePrivilegedServiceClient(conn)
 	return conn, err, c
 }
 
-func getPublicrpcClient(ctx context.Context, addr string) (*grpc.ClientConn, error, publicrpcv1.PublicrpcClient) {
+func getPublicRPCServiceClient(ctx context.Context, addr string) (*grpc.ClientConn, error, publicrpcv1.PublicRPCServiceClient) {
 	conn, err := grpc.DialContext(ctx, fmt.Sprintf("unix:///%s", addr), grpc.WithInsecure())
 
 	if err != nil {
 		log.Fatalf("failed to connect to %s: %v", addr, err)
 	}
 
-	c := publicrpcv1.NewPublicrpcClient(conn)
+	c := publicrpcv1.NewPublicRPCServiceClient(conn)
 	return conn, err, c
 }
 

+ 2 - 2
bridge/cmd/guardiand/adminnodes.go

@@ -32,13 +32,13 @@ var AdminClientListNodes = &cobra.Command{
 
 func runListNodes(cmd *cobra.Command, args []string) {
 	ctx := context.Background()
-	conn, err, c := getPublicrpcClient(ctx, *clientSocketPath)
+	conn, err, c := getPublicRPCServiceClient(ctx, *clientSocketPath)
 	defer conn.Close()
 	if err != nil {
 		log.Fatalf("failed to get publicrpc client: %v", err)
 	}
 
-	lastHeartbeats, err := c.GetLastHeartbeats(ctx, &publicrpcv1.GetLastHeartbeatRequest{})
+	lastHeartbeats, err := c.GetLastHeartbeats(ctx, &publicrpcv1.GetLastHeartbeatsRequest{})
 	if err != nil {
 		log.Fatalf("failed to list nodes: %v", err)
 	}

+ 3 - 3
bridge/cmd/guardiand/adminserver.go

@@ -29,7 +29,7 @@ import (
 )
 
 type nodePrivilegedService struct {
-	nodev1.UnimplementedNodePrivilegedServer
+	nodev1.UnimplementedNodePrivilegedServiceServer
 	injectC chan<- *vaa.VAA
 	logger  *zap.Logger
 }
@@ -173,8 +173,8 @@ func adminServiceRunnable(logger *zap.Logger, socketPath string, injectC chan<-
 	publicrpcService := publicrpc.NewPublicrpcServer(logger, db, gst)
 
 	grpcServer := newGRPCServer(logger)
-	nodev1.RegisterNodePrivilegedServer(grpcServer, nodeService)
-	publicrpcv1.RegisterPublicrpcServer(grpcServer, publicrpcService)
+	nodev1.RegisterNodePrivilegedServiceServer(grpcServer, nodeService)
+	publicrpcv1.RegisterPublicRPCServiceServer(grpcServer, publicrpcService)
 	return supervisor.GRPCServer(grpcServer, l, false), nil
 }
 

+ 1 - 1
bridge/cmd/guardiand/publicrpc.go

@@ -22,7 +22,7 @@ func publicrpcServiceRunnable(logger *zap.Logger, listenAddr string, db *db.Data
 
 	rpcServer := publicrpc.NewPublicrpcServer(logger, db, gst)
 	grpcServer := newGRPCServer(logger)
-	publicrpcv1.RegisterPublicrpcServer(grpcServer, rpcServer)
+	publicrpcv1.RegisterPublicRPCServiceServer(grpcServer, rpcServer)
 
 	return supervisor.GRPCServer(grpcServer, l, false), grpcServer, nil
 }

+ 1 - 1
bridge/cmd/guardiand/publicweb.go

@@ -64,7 +64,7 @@ func publicwebServiceRunnable(
 		}
 
 		gwmux := runtime.NewServeMux()
-		err = publicrpcv1.RegisterPublicrpcHandler(ctx, gwmux, conn)
+		err = publicrpcv1.RegisterPublicRPCServiceHandler(ctx, gwmux, conn)
 		if err != nil {
 			panic(err)
 		}

+ 5 - 5
bridge/pkg/publicrpc/publicrpcserver.go

@@ -15,7 +15,7 @@ import (
 
 // PublicrpcServer implements the publicrpc gRPC service.
 type PublicrpcServer struct {
-	publicrpcv1.UnimplementedPublicrpcServer
+	publicrpcv1.UnsafePublicRPCServiceServer
 	logger *zap.Logger
 	db     *db.Database
 	gst    *common.GuardianSetState
@@ -33,21 +33,21 @@ func NewPublicrpcServer(
 	}
 }
 
-func (s *PublicrpcServer) GetLastHeartbeats(ctx context.Context, req *publicrpcv1.GetLastHeartbeatRequest) (*publicrpcv1.GetLastHeartbeatResponse, error) {
+func (s *PublicrpcServer) GetLastHeartbeats(ctx context.Context, req *publicrpcv1.GetLastHeartbeatsRequest) (*publicrpcv1.GetLastHeartbeatsResponse, error) {
 	gs := s.gst.Get()
 	if gs == nil {
 		return nil, status.Error(codes.Unavailable, "guardian set not fetched from chain yet")
 	}
 
-	resp := &publicrpcv1.GetLastHeartbeatResponse{
-		Entries: make([]*publicrpcv1.GetLastHeartbeatResponse_Entry, 0),
+	resp := &publicrpcv1.GetLastHeartbeatsResponse{
+		Entries: make([]*publicrpcv1.GetLastHeartbeatsResponse_Entry, 0),
 	}
 
 	// Fetch all heartbeats (including from nodes not in the guardian set - which
 	// can happen either with --disableHeartbeatVerify or when the guardian set changes)
 	for addr, v := range s.gst.GetAll() {
 		for peerId, hb := range v {
-			resp.Entries = append(resp.Entries, &publicrpcv1.GetLastHeartbeatResponse_Entry{
+			resp.Entries = append(resp.Entries, &publicrpcv1.GetLastHeartbeatsResponse_Entry{
 				VerifiedGuardianAddr: addr.Hex(),
 				P2PNodeAddr:          peerId.Pretty(),
 				RawHeartbeat:         hb,

+ 3 - 2
buf.yaml

@@ -9,8 +9,9 @@ build:
     - proto
 lint:
   use:
-    - BASIC
-    - FILE_LOWER_SNAKE_CASE
+    - DEFAULT
+    # https://github.com/twitchtv/twirp/issues/70#issuecomment-470367807
+    - UNARY_RPC
 breaking:
   use:
     - WIRE_JSON

+ 2 - 2
proto/node/v1/node.proto

@@ -4,9 +4,9 @@ package node.v1;
 
 option go_package = "github.com/certusone/wormhole/bridge/pkg/proto/node/v1;nodev1";
 
-// NodePrivileged exposes an administrative API. It runs on a UNIX socket and is authenticated
+// NodePrivilegedService exposes an administrative API. It runs on a UNIX socket and is authenticated
 // using Linux filesystem permissions.
-service NodePrivileged {
+service NodePrivilegedService {
   // InjectGovernanceVAA injects a governance VAA into the guardian node.
   // The node will inject the VAA into the aggregator and sign/broadcast the VAA signature.
   //

+ 8 - 8
proto/publicrpc/v1/publicrpc.proto

@@ -7,8 +7,8 @@ option go_package = "github.com/certusone/wormhole/bridge/pkg/proto/publicrpc/v1
 import "gossip/v1/gossip.proto";
 import "google/api/annotations.proto";
 
-enum EmitterChain {
-  CHAIN_ID_UNKNOWN = 0;
+enum ChainID {
+  CHAIN_ID_UNSPECIFIED = 0;
   CHAIN_ID_SOLANA = 1;
   CHAIN_ID_ETHEREUM = 2;
   CHAIN_ID_TERRA = 3;
@@ -18,19 +18,19 @@ enum EmitterChain {
 // MessageID is a VAA's globally unique identifier (see data availability design document).
 message MessageID {
   // Emitter chain ID.
-  EmitterChain emitter_chain = 1;
+  ChainID emitter_chain = 1;
   // Hex-encoded (without leading 0x) emitter address.
   string emitter_address = 2;
   // Sequence number for (emitter_chain, emitter_address).
   int64 sequence = 3;
 }
 
-// Publicrpc service exposes endpoints to be consumed externally; GUIs, historical record keeping, etc.
-service Publicrpc {
+// PublicRPCService service exposes endpoints to be consumed externally; GUIs, historical record keeping, etc.
+service PublicRPCService {
   // GetLastHeartbeats returns the last heartbeat received for each guardian node in the
   // node's active guardian set. Heartbeats received by nodes not in the guardian set are ignored.
   // The heartbeat value is null if no heartbeat has yet been received.
-  rpc GetLastHeartbeats (GetLastHeartbeatRequest) returns (GetLastHeartbeatResponse) {
+  rpc GetLastHeartbeats (GetLastHeartbeatsRequest) returns (GetLastHeartbeatsResponse) {
     option (google.api.http) = {
       get: "/v1/heartbeats"
     };
@@ -58,10 +58,10 @@ message GetSignedVAAResponse {
   bytes vaa_bytes = 1;
 }
 
-message GetLastHeartbeatRequest {
+message GetLastHeartbeatsRequest {
 }
 
-message GetLastHeartbeatResponse {
+message GetLastHeartbeatsResponse {
   message Entry {
     // Verified, hex-encoded (with leading 0x) guardian address. This is the guardian address
     // which signed this heartbeat. The GuardianAddr field inside the heartbeat

+ 2 - 2
sdk/js/src/rpc/getSignedVAA.ts

@@ -1,7 +1,7 @@
 import { ChainId } from "../utils/consts";
 import {
   GrpcWebImpl,
-  PublicrpcClientImpl,
+  PublicRPCServiceClientImpl,
 } from "../proto/publicrpc/v1/publicrpc";
 
 export async function getSignedVAA(
@@ -11,7 +11,7 @@ export async function getSignedVAA(
   sequence: string
 ) {
   const rpc = new GrpcWebImpl(host, {});
-  const api = new PublicrpcClientImpl(rpc);
+  const api = new PublicRPCServiceClientImpl(rpc);
   return await api.GetSignedVAA({
     messageId: {
       emitterChain,