From dc7ca9b9fb514ee87c67e534c3090afcf942960c Mon Sep 17 00:00:00 2001 From: Lee Date: Tue, 18 Feb 2025 21:25:00 +0800 Subject: [PATCH] chore(deps): bump curio to v1.24.4 --- cmd/run.go | 19 ++++++-- cmd/utils.go | 95 ++++++++++++++++++++++++++++++++++++- go.mod | 2 +- go.sum | 4 +- graph/curiorpc/proxy_gen.go | 27 +++++------ graph/curiorpc/webrpc.go | 3 +- 6 files changed, 126 insertions(+), 24 deletions(-) diff --git a/cmd/run.go b/cmd/run.go index 59101a5..f17450c 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -7,6 +7,7 @@ import ( "net/http" "os" "os/signal" + "strings" "time" "github.com/prometheus/client_golang/api" @@ -14,6 +15,7 @@ import ( "github.com/strahe/curio-dashboard/graph/resolvers" "github.com/99designs/gqlgen/graphql/playground" + "github.com/filecoin-project/curio/build" cliutil "github.com/filecoin-project/lotus/cli/util" "github.com/labstack/echo/v4" "github.com/labstack/echo/v4/middleware" @@ -42,15 +44,24 @@ var runCmd = &cli.Command{ } defer harmonyDB.Close() - chainAPI, closer, err := getChainAPI(cctx, cfg.Chain) + curioAPI, closer, err := getCurioWebRPCV0(cctx, cfg) if err != nil { - return fmt.Errorf("failed to get chain API: %w", err) + return fmt.Errorf("failed to get curio web rpc: %w", err) } defer closer() - curioAPI, closer, err := getCurioWebRPCV0(cctx, cfg) + curioVersion, err := curioAPI.Version(cctx.Context) if err != nil { - return fmt.Errorf("failed to get curio web rpc: %w", err) + return fmt.Errorf("failed to get curio version: %w", err) + } + + if strings.Split(curioVersion, "+")[0] != build.BuildVersion { + return fmt.Errorf("curio version mismatch: %s != %s", strings.Split(curioVersion, "+")[0], build.BuildVersion) + } + + chainAPI, closer, err := getChainAPI(cctx, cfg.Chain, curioVersion) + if err != nil { + return fmt.Errorf("failed to get chain API: %w", err) } defer closer() diff --git a/cmd/utils.go b/cmd/utils.go index 56925e3..f156866 100644 --- a/cmd/utils.go +++ b/cmd/utils.go @@ -3,6 +3,7 @@ package main import ( "context" "fmt" + "net/http" "net/url" "os" "strings" @@ -11,20 +12,23 @@ import ( "github.com/filecoin-project/curio/deps" "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-jsonrpc" + lapi "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" + cliutil "github.com/filecoin-project/lotus/cli/util" "github.com/strahe/curio-dashboard/config" "github.com/strahe/curio-dashboard/graph/curiorpc" "github.com/urfave/cli/v2" + "golang.org/x/xerrors" ) -func getChainAPI(cctx *cli.Context, cfg config.ChainConfig) (api.Chain, jsonrpc.ClientCloser, error) { +func getChainAPI(cctx *cli.Context, cfg config.ChainConfig, curioVersion string) (api.Chain, jsonrpc.ClientCloser, error) { apiInfo := cfg.APIs if os.Getenv("FULLNODE_API_INFO") != "" { apiInfo = strings.Split(os.Getenv("FULLNODE_API_INFO"), ",") } - return deps.GetFullNodeAPIV1Curio(cctx, apiInfo) + return GetFullNodeAPIV1Curio(cctx, apiInfo, curioVersion) } func getCurioWebRPCV0(ctx *cli.Context, cfg *config.Config) (curiorpc.WebRPC, jsonrpc.ClientCloser, error) { @@ -96,3 +100,90 @@ func setupNetwork(ctx context.Context, node api.Chain) error { } return nil } + +type httpHead struct { + addr string + header http.Header +} + +func GetFullNodeAPIV1Curio(ctx *cli.Context, ainfoCfg []string, curioVersion string) (api.Chain, jsonrpc.ClientCloser, error) { + if len(ainfoCfg) == 0 { + return nil, nil, xerrors.Errorf("no full node API endpoints provided") + } + + var httpHeads []httpHead + version := "v1" + for _, i := range ainfoCfg { + ainfo := cliutil.ParseApiInfo(i) + addr, err := ainfo.DialArgs(version) + if err != nil { + return nil, nil, xerrors.Errorf("could not get DialArgs: %w", err) + } + httpHeads = append(httpHeads, httpHead{addr: addr, header: ainfo.AuthHeader()}) + } + + if cliutil.IsVeryVerbose { + _, _ = fmt.Fprintln(ctx.App.Writer, "using full node API v1 endpoint:", httpHeads[0].addr) + } + + var fullNodes []api.Chain + var closers []jsonrpc.ClientCloser + + // Check network compatibility for each node + for _, head := range httpHeads { + v1api, closer, err := newChainNodeRPCV1(ctx.Context, head.addr, head.header) + if err != nil { + log.Warnf("Not able to establish connection to node with addr: %s, Reason: %s", head.addr, err.Error()) + continue + } + + // Validate network match + networkName, err := v1api.StateNetworkName(ctx.Context) + if err != nil { + log.Warnf("Failed to get network name from node %s: %s", head.addr, err.Error()) + closer() + continue + } + + if networkName == "calibrationnet" { + networkName = "calibnet" + } + + sp := strings.SplitN(curioVersion, "+", 3) + if len(sp) == 3 { + // version + build + commit + if sp[1] != string(networkName) { + log.Warnf("Network mismatch for node %s: curio built for %s but node is on %s", + head.addr, curioVersion, networkName) + closer() + continue + } + } + + fullNodes = append(fullNodes, v1api) + closers = append(closers, closer) + } + + if len(fullNodes) == 0 { + return nil, nil, xerrors.Errorf("failed to establish connection with all nodes") + } + + finalCloser := func() { + for _, c := range closers { + c() + } + } + + var v1API api.ChainStruct + deps.FullNodeProxy(fullNodes, &v1API) + + return &v1API, finalCloser, nil +} + +func newChainNodeRPCV1(ctx context.Context, addr string, requestHeader http.Header, opts ...jsonrpc.Option) (api.Chain, jsonrpc.ClientCloser, error) { + var res api.ChainStruct + closer, err := jsonrpc.NewMergeClient(ctx, addr, "Filecoin", + api.GetInternalStructs(&res), requestHeader, append([]jsonrpc.Option{jsonrpc.WithErrors(lapi.RPCErrors)}, opts...)...) + + return &res, closer, err +} diff --git a/go.mod b/go.mod index c8f69ee..669519b 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.23.4 require ( github.com/99designs/gqlgen v0.17.55 github.com/BurntSushi/toml v1.4.0 - github.com/filecoin-project/curio v1.24.3 + github.com/filecoin-project/curio v1.24.4 github.com/filecoin-project/go-address v1.2.0 github.com/filecoin-project/go-jsonrpc v0.7.0 github.com/filecoin-project/go-state-types v0.16.0-rc1 diff --git a/go.sum b/go.sum index 6098ef5..c95bf47 100644 --- a/go.sum +++ b/go.sum @@ -190,8 +190,8 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7 github.com/fatih/color v1.8.0/go.mod h1:3l45GVGkyrnYNl9HoIjnp2NnNWvh6hLAqD8yTfGjnw8= github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM= github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE= -github.com/filecoin-project/curio v1.24.3 h1:sHPBH97S2DjIGiwbfRbGCLdeCyno3XFnr2+1dlsp7X4= -github.com/filecoin-project/curio v1.24.3/go.mod h1:k5whzLGVx087O0G0jEZtYgoVGH51QmxWEq5WuF8BNMw= +github.com/filecoin-project/curio v1.24.4 h1:WK36FroTo5397fKQZIIy12V6bq69O0zjGsb+FtmWWoQ= +github.com/filecoin-project/curio v1.24.4/go.mod h1:k5whzLGVx087O0G0jEZtYgoVGH51QmxWEq5WuF8BNMw= github.com/filecoin-project/go-address v0.0.3/go.mod h1:jr8JxKsYx+lQlQZmF5i2U0Z+cGQ59wMIps/8YW/lDj8= github.com/filecoin-project/go-address v0.0.5/go.mod h1:jr8JxKsYx+lQlQZmF5i2U0Z+cGQ59wMIps/8YW/lDj8= github.com/filecoin-project/go-address v1.2.0 h1:NHmWUE/J7Pi2JZX3gZt32XuY69o9StVZeJxdBodIwOE= diff --git a/graph/curiorpc/proxy_gen.go b/graph/curiorpc/proxy_gen.go index 8d713ec..bde06e8 100644 --- a/graph/curiorpc/proxy_gen.go +++ b/graph/curiorpc/proxy_gen.go @@ -6,7 +6,6 @@ import ( "context" "github.com/filecoin-project/curio/web/api/webrpc" - "github.com/filecoin-project/go-address" "golang.org/x/xerrors" ) @@ -19,8 +18,6 @@ type WebRPCStruct struct { type WebRPCMethods struct { ActorList func(p0 context.Context) ([]string, error) `` - ActorSectorExpirations func(p0 context.Context, p1 address.Address) (*webrpc.SectorExpirations, error) `` - ActorSummary func(p0 context.Context) ([]webrpc.ActorSummary, error) `` AddAllowDenyList func(p0 context.Context, p1 string, p2 bool) error `` @@ -103,6 +100,8 @@ type WebRPCMethods struct { UpgradeSectors func(p0 context.Context) ([]webrpc.UpgradeSector, error) `` + Version func(p0 context.Context) (string, error) `` + WinStats func(p0 context.Context) ([]webrpc.WinStats, error) `` } @@ -120,17 +119,6 @@ func (s *WebRPCStub) ActorList(p0 context.Context) ([]string, error) { return *new([]string), ErrNotSupported } -func (s *WebRPCStruct) ActorSectorExpirations(p0 context.Context, p1 address.Address) (*webrpc.SectorExpirations, error) { - if s.Internal.ActorSectorExpirations == nil { - return nil, ErrNotSupported - } - return s.Internal.ActorSectorExpirations(p0, p1) -} - -func (s *WebRPCStub) ActorSectorExpirations(p0 context.Context, p1 address.Address) (*webrpc.SectorExpirations, error) { - return nil, ErrNotSupported -} - func (s *WebRPCStruct) ActorSummary(p0 context.Context) ([]webrpc.ActorSummary, error) { if s.Internal.ActorSummary == nil { return *new([]webrpc.ActorSummary), ErrNotSupported @@ -582,6 +570,17 @@ func (s *WebRPCStub) UpgradeSectors(p0 context.Context) ([]webrpc.UpgradeSector, return *new([]webrpc.UpgradeSector), ErrNotSupported } +func (s *WebRPCStruct) Version(p0 context.Context) (string, error) { + if s.Internal.Version == nil { + return "", ErrNotSupported + } + return s.Internal.Version(p0) +} + +func (s *WebRPCStub) Version(p0 context.Context) (string, error) { + return "", ErrNotSupported +} + func (s *WebRPCStruct) WinStats(p0 context.Context) ([]webrpc.WinStats, error) { if s.Internal.WinStats == nil { return *new([]webrpc.WinStats), ErrNotSupported diff --git a/graph/curiorpc/webrpc.go b/graph/curiorpc/webrpc.go index 5926c5f..ad8ae86 100644 --- a/graph/curiorpc/webrpc.go +++ b/graph/curiorpc/webrpc.go @@ -8,7 +8,8 @@ import ( ) type WebRPC interface { - ActorSectorExpirations(ctx context.Context, maddr address.Address) (*webrpc.SectorExpirations, error) + Version(context.Context) (string, error) + ActorSummary(ctx context.Context) ([]webrpc.ActorSummary, error) ActorList(ctx context.Context) ([]string, error) ClusterMachines(ctx context.Context) ([]webrpc.MachineSummary, error)