@@ -17,22 +17,32 @@ import (
1717 ctypes "github.com/akash-network/akash-api/go/node/cert/v1beta3"
1818 leasev1 "github.com/akash-network/akash-api/go/provider/lease/v1"
1919 providerv1 "github.com/akash-network/akash-api/go/provider/v1"
20+ cmblog "github.com/tendermint/tendermint/libs/log"
2021
2122 "github.com/akash-network/provider"
2223 "github.com/akash-network/provider/gateway/utils"
2324 "github.com/akash-network/provider/tools/fromctx"
2425)
2526
27+ var (
28+ _ providerv1.ProviderRPCServer = (* server )(nil )
29+ _ leasev1.LeaseRPCServer = (* server )(nil )
30+ )
31+
32+ type server struct {
33+ * providerV1
34+ * leaseV1
35+ }
36+
2637func Serve (ctx context.Context , endpoint string , certs []tls.Certificate , c provider.Client ) error {
2738 group , err := fromctx .ErrGroupFromCtx (ctx )
2839 if err != nil {
2940 return err
3041 }
3142
32- var (
33- grpcSrv = newServer (ctx , certs , c )
34- log = fromctx .LogcFromCtx (ctx )
35- )
43+ grpcSrv := newServer (ctx , certs , c )
44+
45+ log := fromctx .LogcFromCtx (ctx )
3646
3747 group .Go (func () error {
3848 grpcLis , err := net .Listen ("tcp" , endpoint )
@@ -56,16 +66,6 @@ func Serve(ctx context.Context, endpoint string, certs []tls.Certificate, c prov
5666 return nil
5767}
5868
59- var (
60- _ providerv1.ProviderRPCServer = (* server )(nil )
61- _ leasev1.LeaseRPCServer = (* server )(nil )
62- )
63-
64- type server struct {
65- * providerV1
66- * leaseV1
67- }
68-
6969func newServer (ctx context.Context , certs []tls.Certificate , c provider.Client ) * grpc.Server {
7070 // InsecureSkipVerify is set to true due to inability to use normal TLS verification
7171 // certificate validation and authentication performed later in mtlsHandler
@@ -88,7 +88,7 @@ func newServer(ctx context.Context, certs []tls.Certificate, c provider.Client)
8888 }),
8989 grpc .ChainUnaryInterceptor (
9090 mtlsInterceptor (cquery ),
91- errorLogInterceptor (),
91+ errorLogInterceptor (fromctx . LogcFromCtx ( ctx ) ),
9292 ),
9393 )
9494
@@ -111,10 +111,10 @@ func newServer(ctx context.Context, certs []tls.Certificate, c provider.Client)
111111}
112112
113113func mtlsInterceptor (cquery ctypes.QueryClient ) grpc.UnaryServerInterceptor {
114- return func (ctx context.Context , req any , _ * grpc.UnaryServerInfo , h grpc.UnaryHandler ) (any , error ) {
114+ return func (ctx context.Context , req any , _ * grpc.UnaryServerInfo , next grpc.UnaryHandler ) (any , error ) {
115115 if p , ok := peer .FromContext (ctx ); ok {
116116 if mtls , ok := p .AuthInfo .(credentials.TLSInfo ); ok {
117- owner , err := utils .VerifyCertChain (ctx , mtls .State .PeerCertificates , "" , x509 .ExtKeyUsageServerAuth , cquery )
117+ owner , err := utils .VerifyOwnerCert (ctx , mtls .State .PeerCertificates , "" , x509 .ExtKeyUsageServerAuth , cquery )
118118 if err != nil {
119119 return nil , fmt .Errorf ("verify cert chain: %w" , err )
120120 }
@@ -125,18 +125,18 @@ func mtlsInterceptor(cquery ctypes.QueryClient) grpc.UnaryServerInterceptor {
125125 }
126126 }
127127
128- return h (ctx , req )
128+ return next (ctx , req )
129129 }
130130}
131131
132132// TODO(andrewhare): Possibly replace this with
133133// https://github.com/grpc-ecosystem/go-grpc-middleware/tree/main/interceptors/logging
134134// to get full request/response logging?
135- func errorLogInterceptor () grpc.UnaryServerInterceptor {
136- return func (ctx context.Context , req any , i * grpc.UnaryServerInfo , h grpc.UnaryHandler ) (any , error ) {
137- resp , err := h (ctx , req )
135+ func errorLogInterceptor (l cmblog. Logger ) grpc.UnaryServerInterceptor {
136+ return func (ctx context.Context , req any , i * grpc.UnaryServerInfo , next grpc.UnaryHandler ) (any , error ) {
137+ resp , err := next (ctx , req )
138138 if err != nil {
139- fromctx . LogcFromCtx ( ctx ) .Error (i .FullMethod , "err" , err )
139+ l .Error (i .FullMethod , "err" , err )
140140 }
141141
142142 return resp , err
0 commit comments