81ba6ab6f0
* feat: lp mig - first few steps * lp mig: default tasks * code comments * docs * lp-mig-progress * shared * comments and todos * fix: curio: rename lotus-provider to curio (#11645) * rename provider to curio * install gotext * fix lint errors, mod tidy * fix typo * fix API_INFO and add gotext to circleCI * add back gotext * add gotext after remerge * lp: channels doc * finish easy-migration TODOs * out generate * merging and more renames * avoid make-all * minor doc stuff * cu: make gen * make gen fix * make gen * tryfix * go mod tidy * minor ez migration fixes * ez setup - ui cleanups * better error message * guided setup colors * better path to saveconfigtolayer * loadconfigwithupgrades fix * readMiner oops * guided - homedir * err if miner is running * prompt error should exit * process already running, miner_id sectors in migration * dont prompt for language a second time * check miner stopped * unlock repo * render and sql oops * curio easyMig - some fixes * easyMigration runs successfully * lint * review fixes * fix backup path * fixes1 * fixes2 * fixes 3 --------- Co-authored-by: LexLuthr <88259624+LexLuthr@users.noreply.github.com> Co-authored-by: LexLuthr <lexluthr@protocol.ai>
95 lines
2.9 KiB
Go
95 lines
2.9 KiB
Go
package deps
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/urfave/cli/v2"
|
|
"golang.org/x/xerrors"
|
|
|
|
"github.com/filecoin-project/go-jsonrpc"
|
|
|
|
"github.com/filecoin-project/lotus/api"
|
|
"github.com/filecoin-project/lotus/api/client"
|
|
"github.com/filecoin-project/lotus/api/v1api"
|
|
cliutil "github.com/filecoin-project/lotus/cli/util"
|
|
)
|
|
|
|
func getFullNodeAPIV1Curio(ctx *cli.Context, ainfoCfg []string, opts ...cliutil.GetFullNodeOption) (v1api.FullNode, jsonrpc.ClientCloser, error) {
|
|
if tn, ok := ctx.App.Metadata["testnode-full"]; ok {
|
|
return tn.(v1api.FullNode), func() {}, nil
|
|
}
|
|
|
|
var options cliutil.GetFullNodeOptions
|
|
for _, opt := range opts {
|
|
opt(&options)
|
|
}
|
|
|
|
var rpcOpts []jsonrpc.Option
|
|
if options.EthSubHandler != nil {
|
|
rpcOpts = append(rpcOpts, jsonrpc.WithClientHandler("Filecoin", options.EthSubHandler), jsonrpc.WithClientHandlerAlias("eth_subscription", "Filecoin.EthSubscription"))
|
|
}
|
|
|
|
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()})
|
|
}
|
|
}
|
|
|
|
if cliutil.IsVeryVerbose {
|
|
_, _ = fmt.Fprintln(ctx.App.Writer, "using full node API v1 endpoint:", httpHeads[0].addr)
|
|
}
|
|
|
|
var fullNodes []api.FullNode
|
|
var closers []jsonrpc.ClientCloser
|
|
|
|
for _, head := range httpHeads {
|
|
v1api, closer, err := client.NewFullNodeRPCV1(ctx.Context, head.addr, head.header, rpcOpts...)
|
|
if err != nil {
|
|
log.Warnf("Not able to establish connection to node with addr: %s, Reason: %s", head.addr, err.Error())
|
|
continue
|
|
}
|
|
fullNodes = append(fullNodes, v1api)
|
|
closers = append(closers, closer)
|
|
}
|
|
|
|
// When running in cluster mode and trying to establish connections to multiple nodes, fail
|
|
// if less than 2 lotus nodes are actually running
|
|
if len(httpHeads) > 1 && len(fullNodes) < 2 {
|
|
return nil, nil, xerrors.Errorf("Not able to establish connection to more than a single node")
|
|
}
|
|
|
|
finalCloser := func() {
|
|
for _, c := range closers {
|
|
c()
|
|
}
|
|
}
|
|
|
|
var v1API api.FullNodeStruct
|
|
cliutil.FullNodeProxy(fullNodes, &v1API)
|
|
|
|
v, err := v1API.Version(ctx.Context)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
if !v.APIVersion.EqMajorMinor(api.FullAPIVersion1) {
|
|
return nil, nil, xerrors.Errorf("Remote API version didn't match (expected %s, remote %s)", api.FullAPIVersion1, v.APIVersion)
|
|
}
|
|
return &v1API, finalCloser, nil
|
|
}
|
|
|
|
type httpHead struct {
|
|
addr string
|
|
header http.Header
|
|
}
|