Skip to content

Commit

Permalink
chore(deps): bump curio to v1.24.4
Browse files Browse the repository at this point in the history
  • Loading branch information
strahe committed Feb 18, 2025
1 parent d509adf commit dc7ca9b
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 24 deletions.
19 changes: 15 additions & 4 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import (
"net/http"
"os"
"os/signal"
"strings"
"time"

"github.com/prometheus/client_golang/api"

"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"
Expand Down Expand Up @@ -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()

Expand Down
95 changes: 93 additions & 2 deletions cmd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"context"
"fmt"
"net/http"
"net/url"
"os"
"strings"
Expand All @@ -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) {
Expand Down Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
27 changes: 13 additions & 14 deletions graph/curiorpc/proxy_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion graph/curiorpc/webrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit dc7ca9b

Please sign in to comment.