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

fix:check gateway fail #177

Merged
merged 1 commit into from
Mar 9, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 4 additions & 1 deletion node/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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),
)

Expand Down
18 changes: 7 additions & 11 deletions node/config/def.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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" {
Expand Down
25 changes: 12 additions & 13 deletions node/modules/miner-manager/auth_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down