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>
94 lines
1.7 KiB
Go
94 lines
1.7 KiB
Go
package hapi
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/filecoin-project/lotus/api/client"
|
|
cliutil "github.com/filecoin-project/lotus/cli/util"
|
|
)
|
|
|
|
func (a *app) watchRpc() {
|
|
ticker := time.NewTicker(watchInterval)
|
|
for {
|
|
err := a.updateRpc(context.TODO())
|
|
if err != nil {
|
|
log.Errorw("updating rpc info", "error", err)
|
|
}
|
|
select {
|
|
case <-ticker.C:
|
|
}
|
|
}
|
|
}
|
|
|
|
type minimalApiInfo struct {
|
|
Apis struct {
|
|
ChainApiInfo []string
|
|
}
|
|
}
|
|
|
|
func (a *app) updateRpc(ctx context.Context) error {
|
|
rpcInfos := map[string]minimalApiInfo{} // config name -> api info
|
|
confNameToAddr := map[string]string{} // config name -> api address
|
|
|
|
err := forEachConfig[minimalApiInfo](a, func(name string, info minimalApiInfo) error {
|
|
if len(info.Apis.ChainApiInfo) == 0 {
|
|
return nil
|
|
}
|
|
|
|
rpcInfos[name] = info
|
|
|
|
for _, addr := range info.Apis.ChainApiInfo {
|
|
ai := cliutil.ParseApiInfo(addr)
|
|
confNameToAddr[name] = ai.Addr
|
|
}
|
|
|
|
return nil
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
apiInfos := map[string][]byte{} // api address -> token
|
|
|
|
// for dedup by address
|
|
for _, info := range rpcInfos {
|
|
ai := cliutil.ParseApiInfo(info.Apis.ChainApiInfo[0])
|
|
apiInfos[ai.Addr] = ai.Token
|
|
}
|
|
|
|
a.rpcInfoLk.Lock()
|
|
|
|
// todo improve this shared rpc logic
|
|
if a.workingApi == nil {
|
|
for addr, token := range apiInfos {
|
|
ai := cliutil.APIInfo{
|
|
Addr: addr,
|
|
Token: token,
|
|
}
|
|
|
|
da, err := ai.DialArgs("v1")
|
|
if err != nil {
|
|
continue
|
|
}
|
|
|
|
ah := ai.AuthHeader()
|
|
|
|
v1api, closer, err := client.NewFullNodeRPCV1(ctx, da, ah)
|
|
if err != nil {
|
|
continue
|
|
}
|
|
go func() {
|
|
<-ctx.Done()
|
|
closer()
|
|
}()
|
|
|
|
a.workingApi = v1api
|
|
}
|
|
}
|
|
|
|
a.rpcInfoLk.Unlock()
|
|
|
|
return nil
|
|
}
|