From fd26f79ea8a62ae528a05b7666c5da1aad01da26 Mon Sep 17 00:00:00 2001 From: hunjixin <1084400399@qq.com> Date: Mon, 6 Mar 2023 14:33:22 +0800 Subject: [PATCH] fix:check gateway fail& jwt auth stop running --- node/builder.go | 5 ++++- node/config/def.go | 18 ++++++---------- node/modules/miner-manager/auth_manager.go | 25 +++++++++++----------- 3 files changed, 23 insertions(+), 25 deletions(-) diff --git a/node/builder.go b/node/builder.go index 44d376c..ec83fb9 100644 --- a/node/builder.go +++ b/node/builder.go @@ -5,6 +5,8 @@ import ( "encoding/json" "fmt" + "github.com/filecoin-project/venus-auth/jwtclient" + "github.com/multiformats/go-multiaddr" logging "github.com/ipfs/go-log/v2" @@ -119,7 +121,8 @@ func ConfigMinerOptions(c interface{}) Option { If(cfg.SlashFilter.Type == string(slashfilter.Local), Override(new(slashfilter.SlashFilterAPI), slashfilter.NewLocal)), If(cfg.SlashFilter.Type == string(slashfilter.MySQL), Override(new(slashfilter.SlashFilterAPI), slashfilter.NewMysql)), - Override(new(minermanager.MinerManageAPI), minermanager.NewMinerManager(cfg.Auth.Addr, cfg.Auth.Token)), + Override(new(jwtclient.IAuthClient), minermanager.NewVenusAuth(cfg.Auth.Addr, cfg.Auth.Token)), + Override(new(minermanager.MinerManageAPI), minermanager.NewMinerManager), Override(new(miner.MiningAPI), modules.NewMinerProcessor), ) diff --git a/node/config/def.go b/node/config/def.go index bf5603e..655d6a1 100644 --- a/node/config/def.go +++ b/node/config/def.go @@ -5,8 +5,6 @@ import ( "net/url" "time" - "github.com/multiformats/go-multiaddr" - logging "github.com/ipfs/go-log/v2" "github.com/ipfs-force-community/metrics" @@ -101,23 +99,21 @@ func DefaultMinerConfig() *MinerConfig { } func Check(cfg *MinerConfig) error { - _, err := multiaddr.NewMultiaddr(cfg.API.ListenAddress) - if err != nil { - return fmt.Errorf("config listen address not validat %s, %w", cfg.API.ListenAddress, err) + if len(cfg.API.ListenAddress) > 0 { + return fmt.Errorf("must config listen address") } - _, err = multiaddr.NewMultiaddr(cfg.FullNode.Addr) - if err != nil { - return fmt.Errorf("config full node not validat %v, %w", cfg.FullNode, err) + if len(cfg.FullNode.Addr) > 0 && len(cfg.FullNode.Token) > 0 { + return fmt.Errorf("must config full node url and token") } - _, err = url.Parse(cfg.Auth.Addr) + _, err := url.Parse(cfg.Auth.Addr) if err != nil { return fmt.Errorf("auth url format not correct %s %w", cfg.Auth.Addr, err) } - for _, addr := range cfg.Gateway.ListenAPI { - return fmt.Errorf("gateway multiaddr format not correct %s %w", addr, err) + if len(cfg.Gateway.ListenAPI) == 0 { + return fmt.Errorf("config at lease one gateway url") } if cfg.SlashFilter.Type == "mysql" { diff --git a/node/modules/miner-manager/auth_manager.go b/node/modules/miner-manager/auth_manager.go index 5792083..ac06be1 100644 --- a/node/modules/miner-manager/auth_manager.go +++ b/node/modules/miner-manager/auth_manager.go @@ -28,21 +28,20 @@ type MinerManage struct { lk sync.Mutex } -func NewMinerManager(url, token string) func() (MinerManageAPI, error) { - return func() (MinerManageAPI, error) { - authClient, err := jwtclient.NewAuthClient(url, token) - if err != nil { - return nil, err - } - m := &MinerManage{authClient: authClient} - - _, err = m.Update(context.TODO(), 0, 0) - if err != nil { - return nil, err - } +func NewVenusAuth(url, token string) func() (jwtclient.IAuthClient, error) { + return func() (jwtclient.IAuthClient, error) { + return jwtclient.NewAuthClient(url, token) + } +} - return m, nil +func NewMinerManager(authClient jwtclient.IAuthClient) (MinerManageAPI, error) { + m := &MinerManage{authClient: authClient} + _, err := m.Update(context.TODO(), 0, 0) + if err != nil { + return nil, err } + + return m, nil } func (m *MinerManage) Has(ctx context.Context, mAddr address.Address) bool {