From 81545082bae28bdeb5c3568ff79799b70701698a Mon Sep 17 00:00:00 2001 From: Andrew Hare Date: Sat, 30 Mar 2024 02:15:19 -0600 Subject: [PATCH] fix: REST fallback --- cmd/provider-services/cmd/grpc.go | 15 ++++++++++ cmd/provider-services/cmd/manifest.go | 42 ++++++++++++++++++++------- cmd/provider-services/cmd/run.go | 5 ++-- go.mod | 3 +- go.sum | 6 ++-- 5 files changed, 52 insertions(+), 19 deletions(-) create mode 100644 cmd/provider-services/cmd/grpc.go diff --git a/cmd/provider-services/cmd/grpc.go b/cmd/provider-services/cmd/grpc.go new file mode 100644 index 00000000..c3a62e8c --- /dev/null +++ b/cmd/provider-services/cmd/grpc.go @@ -0,0 +1,15 @@ +package cmd + +import ( + "fmt" + "net" +) + +func grpcURI(hostURI string) (string, error) { + host, _, err := net.SplitHostPort(hostURI) + if err != nil { + return "", fmt.Errorf("split host port: %w", err) + } + + return net.JoinHostPort(host, "8442"), nil +} diff --git a/cmd/provider-services/cmd/manifest.go b/cmd/provider-services/cmd/manifest.go index 45378d68..495a4575 100644 --- a/cmd/provider-services/cmd/manifest.go +++ b/cmd/provider-services/cmd/manifest.go @@ -3,6 +3,7 @@ package cmd import ( "bytes" "context" + "crypto/tls" "encoding/json" "fmt" "time" @@ -22,6 +23,7 @@ import ( aclient "github.com/akash-network/provider/client" gwgrpc "github.com/akash-network/provider/gateway/grpc" + gwrest "github.com/akash-network/provider/gateway/rest" ) var errSubmitManifestFailed = errors.New("submit manifest to some providers has been failed") @@ -111,25 +113,43 @@ func doSendManifest(cmd *cobra.Command, sdlpath string) error { return fmt.Errorf("query client provider: %w", err) } - c, err := gwgrpc.NewClient(ctx, prov.GetProvider().HostURI, cert, cl) + hostURIgRPC, err := grpcURI(prov.GetProvider().HostURI) if err != nil { - return fmt.Errorf("new grpc conn: %w", err) + return fmt.Errorf("grpc uri: %w", err) } - defer c.Close() - res := result{ Provider: provAddr, Status: "PASS", } - if _, err = c.SendManifest(ctx, &leasev1.SendManifestRequest{ - LeaseId: lid, - Manifest: mani, - }); err != nil { - res.Error = err.Error() - res.Status = "FAIL" - submitFailed = true + c, err := gwgrpc.NewClient(ctx, hostURIgRPC, cert, cl) + if err == nil { + defer c.Close() + + if _, err = c.SendManifest(ctx, &leasev1.SendManifestRequest{ + LeaseId: lid, + Manifest: mani, + }); err != nil { + res.Error = err.Error() + res.Status = "FAIL" + submitFailed = true + } + } else { + gclient, err := gwrest.NewClient(cl, provAddr, []tls.Certificate{cert}) + if err != nil { + return fmt.Errorf("gwrest new client: %w", err) + } + + err = gclient.SubmitManifest(cmd.Context(), dseq, mani) + if err != nil { + res.Error = err.Error() + if e, valid := err.(gwrest.ClientResponseError); valid { + res.ErrorMessage = e.Message + } + res.Status = "FAIL" + submitFailed = true + } } results[i] = res diff --git a/cmd/provider-services/cmd/run.go b/cmd/provider-services/cmd/run.go index 19394bbd..bec77b05 100644 --- a/cmd/provider-services/cmd/run.go +++ b/cmd/provider-services/cmd/run.go @@ -11,7 +11,6 @@ import ( "strings" "time" - cltypes "github.com/akash-network/akash-api/go/node/client/types" sdkclient "github.com/cosmos/cosmos-sdk/client" "github.com/pkg/errors" "github.com/shopspring/decimal" @@ -21,6 +20,8 @@ import ( "golang.org/x/sync/errgroup" "k8s.io/client-go/kubernetes" + cltypes "github.com/akash-network/akash-api/go/node/client/types" + "github.com/tendermint/tendermint/libs/log" "github.com/cosmos/cosmos-sdk/client/flags" @@ -204,7 +205,7 @@ func RunCmd() *cobra.Command { panic(err) } - cmd.Flags().String(FlagGatewayGRPCListenAddress, "0.0.0.0:8442", "Gateway gRPC listen address") + cmd.Flags().String(FlagGatewayGRPCListenAddress, "0.0.0.0:8444", "Gateway gRPC listen address") if err := viper.BindPFlag(FlagGatewayGRPCListenAddress, cmd.Flags().Lookup(FlagGatewayGRPCListenAddress)); err != nil { panic(err) } diff --git a/go.mod b/go.mod index 23d8b36e..ded3a1dc 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,6 @@ require ( github.com/cosmos/cosmos-sdk v0.45.16 github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f github.com/fsnotify/fsnotify v1.7.0 - github.com/go-andiamo/splitter v1.2.5 github.com/go-kit/kit v0.12.0 github.com/go-logr/logr v1.2.4 github.com/go-logr/zapr v1.2.4 @@ -262,7 +261,7 @@ require ( google.golang.org/appengine v1.6.8 // indirect google.golang.org/genproto v0.0.0-20240318140521-94a12d6c2237 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20240318140521-94a12d6c2237 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240325203815-454cdb8f5daa // indirect gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/square/go-jose.v2 v2.6.0 // indirect diff --git a/go.sum b/go.sum index b2952cdd..34a99512 100644 --- a/go.sum +++ b/go.sum @@ -629,8 +629,6 @@ github.com/globalsign/mgo v0.0.0-20180905125535-1ca0a4f7cbcb/go.mod h1:xkRDCp4j0 github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q= github.com/glycerine/go-unsnap-stream v0.0.0-20180323001048-9f0cb55181dd/go.mod h1:/20jfyN9Y5QPEAprSgKAUr+glWDY39ZiUEAYOEv5dsE= github.com/glycerine/goconvey v0.0.0-20190410193231-58a59202ab31/go.mod h1:Ogl1Tioa0aV7gstGFO7KhffUsb9M4ydbEbbxpcEDc24= -github.com/go-andiamo/splitter v1.2.5 h1:P3NovWMY2V14TJJSolXBvlOmGSZo3Uz+LtTl2bsV/eY= -github.com/go-andiamo/splitter v1.2.5/go.mod h1:8WHU24t9hcMKU5FXDQb1hysSEC/GPuivIp0uKY1J8gw= github.com/go-asn1-ber/asn1-ber v1.3.1/go.mod h1:hEBeB/ic+5LoWskz+yKT7vGhhPYkProFKoKdwZRWMe0= github.com/go-check/check v0.0.0-20180628173108-788fd7840127/go.mod h1:9ES+weclKsC9YodN5RgxqK/VD9HM9JsCSh7rNhMZE98= github.com/go-chi/chi/v5 v5.0.0/go.mod h1:BBug9lr0cqtdAhsu6R4AAdvufI0/XBzAQSsUqJpoZOs= @@ -2544,8 +2542,8 @@ google.golang.org/genproto v0.0.0-20240318140521-94a12d6c2237 h1:PgNlNSx2Nq2/j4j google.golang.org/genproto v0.0.0-20240318140521-94a12d6c2237/go.mod h1:9sVD8c25Af3p0rGs7S7LLsxWKFiJt/65LdSyqXBkX/Y= google.golang.org/genproto/googleapis/api v0.0.0-20240318140521-94a12d6c2237 h1:RFiFrvy37/mpSpdySBDrUdipW/dHwsRwh3J3+A9VgT4= google.golang.org/genproto/googleapis/api v0.0.0-20240318140521-94a12d6c2237/go.mod h1:Z5Iiy3jtmioajWHDGFk7CeugTyHtPvMHA4UTmUkyalE= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 h1:NnYq6UN9ReLM9/Y01KWNOWyI5xQ9kbIms5GGJVwS/Yc= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240325203815-454cdb8f5daa h1:RBgMaUMP+6soRkik4VoN8ojR2nex2TqZwjSSogic+eo= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240325203815-454cdb8f5daa/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY= google.golang.org/grpc v1.8.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw= google.golang.org/grpc v1.12.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw= google.golang.org/grpc v1.14.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw=