Skip to content

Commit

Permalink
fix UI
Browse files Browse the repository at this point in the history
  • Loading branch information
LexLuthr committed Oct 14, 2024
1 parent a876912 commit b9419b0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
13 changes: 8 additions & 5 deletions deps/apiinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"sync"
"time"

logging "github.com/ipfs/go-log/v2"
"github.com/urfave/cli/v2"
"golang.org/x/xerrors"

Expand All @@ -22,6 +23,8 @@ import (
cliutil "github.com/filecoin-project/lotus/cli/util"
)

var clog = logging.Logger("curio/chain")

func GetFullNodeAPIV1Curio(ctx *cli.Context, ainfoCfg []string) (api.Chain, jsonrpc.ClientCloser, error) {
if tn, ok := ctx.App.Metadata["testnode-full"]; ok {
return tn.(api.Chain), func() {}, nil
Expand Down Expand Up @@ -52,7 +55,7 @@ func GetFullNodeAPIV1Curio(ctx *cli.Context, ainfoCfg []string) (api.Chain, json
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())
clog.Warnf("Not able to establish connection to node with addr: %s, Reason: %s", head.addr, err.Error())
continue
}
fullNodes = append(fullNodes, v1api)
Expand Down Expand Up @@ -156,7 +159,7 @@ func FullNodeProxy[T api.Chain](ins []T, outstr *api.ChainStruct) {
unhealthyProviders[i] = true
healthyLk.Unlock()

log.Errorw("rpc check chain head call failed", "fail_type", "rpc_error", "provider", i, "error", err)
clog.Debugw("rpc check chain head call failed", "fail_type", "rpc_error", "provider", i, "error", err)
return
}

Expand All @@ -170,7 +173,7 @@ func FullNodeProxy[T api.Chain](ins []T, outstr *api.ChainStruct) {
// if we're behind the best tipset, mark as unhealthy
unhealthyProviders[i] = ch.Height() < bestKnownTipset.Height()-maxBehindBestHealthy
if unhealthyProviders[i] {
log.Errorw("rpc check chain head call failed", "fail_type", "behind_best", "provider", i, "height", ch.Height(), "best_height", bestKnownTipset.Height())
clog.Debugw("rpc check chain head call failed", "fail_type", "behind_best", "provider", i, "height", ch.Height(), "best_height", bestKnownTipset.Height())
}
}
healthyLk.Unlock()
Expand Down Expand Up @@ -259,7 +262,7 @@ func FullNodeProxy[T api.Chain](ins []T, outstr *api.ChainStruct) {
func Retry[T any](ctx context.Context, attempts int, initialBackoff time.Duration, errorTypes []error, f func(isRetry bool) (T, error)) (result T, err error) {
for i := 0; i < attempts; i++ {
if i > 0 {
log.Info("Retrying after error:", err)
clog.Debugw("Retrying after error:", err)
time.Sleep(initialBackoff)
initialBackoff *= 2
}
Expand All @@ -271,7 +274,7 @@ func Retry[T any](ctx context.Context, attempts int, initialBackoff time.Duratio
return result, ctx.Err()
}
}
log.Errorf("Failed after %d attempts, last error: %s", attempts, err)
clog.Errorf("Failed after %d attempts, last error: %s", attempts, err)
return result, err
}

Expand Down
19 changes: 10 additions & 9 deletions web/api/webrpc/sync_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,18 @@ func (a *WebRPC) SyncerState(ctx context.Context) ([]RpcInfo, error) {
}
}

rpcInfos := map[string]minimalApiInfo{} // config name -> api info
confNameToAddr := map[string]string{} // config name -> api address
rpcInfos := make(map[string]string) // config name -> api info
confNameToAddr := make(map[string][]string) // config name -> api addresses

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 {
rpcInfos[name] = addr
ai := cliutil.ParseApiInfo(addr)
confNameToAddr[name] = ai.Addr
confNameToAddr[name] = append(confNameToAddr[name], ai.Addr)
}

return nil
Expand All @@ -101,7 +100,7 @@ func (a *WebRPC) SyncerState(ctx context.Context) ([]RpcInfo, error) {

var wg sync.WaitGroup
for _, info := range rpcInfos {
ai := cliutil.ParseApiInfo(info.Apis.ChainApiInfo[0])
ai := cliutil.ParseApiInfo(info)
if dedup[ai.Addr] {
continue
}
Expand All @@ -110,9 +109,11 @@ func (a *WebRPC) SyncerState(ctx context.Context) ([]RpcInfo, error) {
go func() {
defer wg.Done()
var clayers []string
for layer, a := range confNameToAddr {
if a == ai.Addr {
clayers = append(clayers, layer)
for layer, adrs := range confNameToAddr {
for _, adr := range adrs {
if adr == ai.Addr {
clayers = append(clayers, layer)
}
}
}

Expand Down

0 comments on commit b9419b0

Please sign in to comment.