Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: move network validation to GetFullNodeAPIV1Curio #345

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ func SetAddressNetwork(n address.Network) {
address.CurrentNetwork = n
}

const TicketRandomnessLookback = abi.ChainEpoch(1)
const TicketRandomnessLookback = abi.ChainEpoch(1)
7 changes: 6 additions & 1 deletion cmd/curio/run.go
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert this file to its original form. There is still unused code there.

Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,12 @@ var runCmd = &cli.Command{
return xerrors.Errorf("starting market RPCs: %w", err)
}

err = rpc.ListenAndServe(ctx, dependencies, shutdownChan) // Monitor for shutdown.
if err != nil {
return err
}
defer closer()

err = rpc.ListenAndServe(ctx, dependencies, shutdownChan)
if err != nil {
return err
}
Expand Down
41 changes: 30 additions & 11 deletions deps/apiinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
lapi "github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/chain/types"
cliutil "github.com/filecoin-project/lotus/cli/util"
"github.com/filecoin-project/lotus/build"
)

var clog = logging.Logger("curio/chain")
Expand All @@ -30,20 +31,20 @@ func GetFullNodeAPIV1Curio(ctx *cli.Context, ainfoCfg []string) (api.Chain, json
if tn, ok := ctx.App.Metadata["testnode-full"]; ok {
return tn.(api.Chain), func() {}, nil
}

if len(ainfoCfg) == 0 {
LexLuthr marked this conversation as resolved.
Show resolved Hide resolved
return nil, nil, xerrors.Errorf("could not get API info: none configured. \nConsider getting base.toml with './curio config get base >/tmp/base.toml' \nthen adding \n[APIs] \n ChainApiInfo = [\" result_from lotus auth api-info --perm=admin \"]\n and updating it with './curio config set /tmp/base.toml'")
}

var httpHeads []httpHead
version := "v1"
{
if len(ainfoCfg) == 0 {
return nil, nil, xerrors.Errorf("could not get API info: none configured. \nConsider getting base.toml with './curio config get base >/tmp/base.toml' \nthen adding \n[APIs] \n ChainApiInfo = [\" result_from lotus auth api-info --perm=admin \"]\n and updating it with './curio config set /tmp/base.toml'")
}
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()})
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 {
Expand All @@ -53,12 +54,30 @@ func GetFullNodeAPIV1Curio(ctx *cli.Context, ainfoCfg []string) (api.Chain, json
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 {
clog.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 {
clog.Warnf("Failed to get network name from node %s: %s", head.addr, err.Error())
closer()
continue
}

// Compare with binary's network using BuildTypeString()
if string(networkName) != build.BuildTypeString() {
clog.Warnf("Network mismatch for node %s: binary built for %s but node is on %s",
head.addr, build.BuildTypeString(), networkName)
closer()
continue
}

fullNodes = append(fullNodes, v1api)
closers = append(closers, closer)
}
Expand Down