From 63b77714ecb563ad74d42fdf17fce29c1b1300bd Mon Sep 17 00:00:00 2001 From: Leo Date: Sun, 22 Aug 2021 00:34:58 +0200 Subject: [PATCH] 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 --- bridge/cmd/guardiand/adminclient.go | 8 ++++---- bridge/cmd/guardiand/adminnodes.go | 4 ++-- bridge/cmd/guardiand/adminserver.go | 6 +++--- bridge/cmd/guardiand/publicrpc.go | 2 +- bridge/cmd/guardiand/publicweb.go | 2 +- bridge/pkg/publicrpc/publicrpcserver.go | 10 +++++----- buf.yaml | 5 +++-- proto/node/v1/node.proto | 4 ++-- proto/publicrpc/v1/publicrpc.proto | 16 ++++++++-------- sdk/js/src/rpc/getSignedVAA.ts | 4 ++-- 10 files changed, 31 insertions(+), 30 deletions(-) diff --git a/bridge/cmd/guardiand/adminclient.go b/bridge/cmd/guardiand/adminclient.go index 663a673be..7dc69f968 100644 --- a/bridge/cmd/guardiand/adminclient.go +++ b/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 } diff --git a/bridge/cmd/guardiand/adminnodes.go b/bridge/cmd/guardiand/adminnodes.go index 61c9752e9..c63c140c7 100644 --- a/bridge/cmd/guardiand/adminnodes.go +++ b/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) } diff --git a/bridge/cmd/guardiand/adminserver.go b/bridge/cmd/guardiand/adminserver.go index a150dca65..56fb1dd69 100644 --- a/bridge/cmd/guardiand/adminserver.go +++ b/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 } diff --git a/bridge/cmd/guardiand/publicrpc.go b/bridge/cmd/guardiand/publicrpc.go index 93300489f..5e12a87e1 100644 --- a/bridge/cmd/guardiand/publicrpc.go +++ b/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 } diff --git a/bridge/cmd/guardiand/publicweb.go b/bridge/cmd/guardiand/publicweb.go index 2a3802388..2c24a2726 100644 --- a/bridge/cmd/guardiand/publicweb.go +++ b/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) } diff --git a/bridge/pkg/publicrpc/publicrpcserver.go b/bridge/pkg/publicrpc/publicrpcserver.go index 07bf2d9f3..6308134e3 100644 --- a/bridge/pkg/publicrpc/publicrpcserver.go +++ b/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, diff --git a/buf.yaml b/buf.yaml index f35986871..6f035b7e2 100644 --- a/buf.yaml +++ b/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 diff --git a/proto/node/v1/node.proto b/proto/node/v1/node.proto index ed1c0a0cd..cbad77299 100644 --- a/proto/node/v1/node.proto +++ b/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. // diff --git a/proto/publicrpc/v1/publicrpc.proto b/proto/publicrpc/v1/publicrpc.proto index 947baf40a..98435e036 100644 --- a/proto/publicrpc/v1/publicrpc.proto +++ b/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 diff --git a/sdk/js/src/rpc/getSignedVAA.ts b/sdk/js/src/rpc/getSignedVAA.ts index c3c1bde20..c0c88e835 100644 --- a/sdk/js/src/rpc/getSignedVAA.ts +++ b/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,