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

Simplify startup commands #66

Merged
merged 1 commit into from
Dec 13, 2021
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
19 changes: 13 additions & 6 deletions api/clients/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,30 +57,37 @@ func NewIMarketEvent(stream *marketevent.MarketEventStream) (MarketRequestEvent,
return stream, nil
}

var ClientsOpts = func(server bool, mCfg *config.Messager, signerCfg *config.Signer) builder.Option {
var ClientsOpts = func(server bool, mode string, mCfg *config.Messager, signerCfg *config.Signer) builder.Option {
opts := builder.Options(
builder.Override(new(IMixMessage), NewMixMsgClient),
builder.ApplyIfElse(
func(s *builder.Settings) bool {
return len(mCfg.Url) > 0
},
builder.Override(new(IVenusMessager), MessagerClient),
builder.Override(new(IVenusMessager), func() IVenusMessager { return IVenusMessager(nil) })),
builder.Override(new(IVenusMessager), func() IVenusMessager { return IVenusMessager(nil) }),
),
builder.ApplyIf(
func(s *builder.Settings) bool {
return len(signerCfg.SignerType) > 0 && len(signerCfg.Url) > 0
},
builder.Override(new(ISinger), NewISignerClient),
builder.Override(ReplaceWalletMethod, ConvertWalletToISinge)),
builder.Override(ReplaceWalletMethod, ConvertWalletToISinge),
),
)

if server {
return builder.Options(opts,
builder.Override(new(apiface.FullNode), NodeClient),

builder.Override(new(*marketevent.MarketEventStream), NewMarketEvent),
builder.Override(new(marketevent.IMarketEventAPI), NewMarketEventAPI),
builder.Override(new(MarketRequestEvent), builder.From(new(*marketevent.MarketEventStream))),
builder.ApplyIf(
func(s *builder.Settings) bool {
return mode == "solo"
},
builder.Override(new(*marketevent.MarketEventStream), NewMarketEvent),
builder.Override(new(marketevent.IMarketEventAPI), NewMarketEventAPI),
builder.Override(new(MarketRequestEvent), NewIMarketEvent),
),
)
} else {
return builder.Options(opts,
Expand Down
43 changes: 30 additions & 13 deletions cmd/market-client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,22 @@ var (

NodeUrlFlag = &cli.StringFlag{
Name: "node-url",
Usage: "url to connect to daemon service",
Usage: "url to connect to full node",
Required: true,
}
AuthTokenFlag = &cli.StringFlag{
Name: "auth-token",
Usage: "token for connect venus componets, this flag can set token for messager and node",
NodeTokenFlag = &cli.StringFlag{
Name: "node-token",
Usage: "token for connect full node",
}

MessagerUrlFlag = &cli.StringFlag{
Name: "messager-url",
Usage: "url to connect messager service",
Usage: "url to connect the venus-messager service of the chain service layer",
}

AuthTokenFlag = &cli.StringFlag{
Name: "auth-token",
Usage: "token used to connect venus chain service components, eg. venus-meassger, venus",
}

SignerUrlFlag = &cli.StringFlag{
Expand Down Expand Up @@ -87,7 +93,7 @@ func main() {

app := &cli.App{
Name: "market-client",
Usage: "venus-market client",
Usage: "venus stores or retrieves the market client",
Version: constants.UserVersion(),
EnableBashCompletion: true,
Flags: []cli.Flag{
Expand All @@ -97,9 +103,11 @@ func main() {
localCommand,
&cli.Command{
Name: "run",
Usage: "run market client daemon",
Usage: "run market client daemon,(1) connect full node service: ./market-client run --node-url=<...> --node-token=<...> --addr=<WALLET_ADDR>;" +
"(2) connect venus shared service: ./market-client run --node-url=<...> --messager-url=<...> --auth-token=<...> --signer-url=<...> --signer-token=<...> --addr=<WALLET_ADDR>.",
Flags: []cli.Flag{
NodeUrlFlag,
NodeTokenFlag,
MessagerUrlFlag,
AuthTokenFlag,
SignerUrlFlag,
Expand All @@ -125,19 +133,28 @@ func flagData(cctx *cli.Context, cfg *config.MarketClientConfig) error {
cfg.Node.Url = cctx.String("node-url")
}

if cctx.IsSet("messager-url") {
cfg.Messager.Url = cctx.String("messager-url")
if cctx.IsSet("node-token") {
cfg.Node.Token = cctx.String("node-token")
}

if cctx.IsSet("auth-token") {
if cctx.IsSet("messager-url") {
if !cctx.IsSet("auth-token") {
return xerrors.Errorf("the auth-token must be set when connecting to the venus chain service")
}

cfg.Node.Token = cctx.String("auth-token")

cfg.Messager.Url = cctx.String("messager-url")
cfg.Messager.Token = cctx.String("auth-token")
}

if cctx.IsSet("signer-url") {
if !cctx.IsSet("signer-token") {
return xerrors.Errorf("signer-url is set, but signer-token is not set")
}

cfg.Signer.SignerType = "wallet"
cfg.Signer.Url = cctx.String("signer-url")
}
if cctx.IsSet("signer-token") {
cfg.Signer.Token = cctx.String("signer-token")
}

Expand Down Expand Up @@ -212,7 +229,7 @@ func marketClient(cctx *cli.Context) error {

config.ConfigClientOpts(cfg),

clients2.ClientsOpts(false, &cfg.Messager, &cfg.Signer),
clients2.ClientsOpts(false, "", &cfg.Messager, &cfg.Signer),
models.DBOptions(false, nil),
network.NetworkOpts(false, cfg.SimultaneousTransfers),
paychmgr.PaychOpts,
Expand Down
112 changes: 8 additions & 104 deletions cmd/venus-market/main.go
Original file line number Diff line number Diff line change
@@ -1,51 +1,29 @@
package main

import (
"context"
mux2 "github.com/gorilla/mux"
"log"
"os"
"strings"

"github.com/urfave/cli/v2"
"go.uber.org/fx"
"golang.org/x/xerrors"

"github.com/filecoin-project/go-address"

metrics2 "github.com/ipfs/go-metrics-interface"

"github.com/ipfs-force-community/venus-common-utils/builder"
"github.com/ipfs-force-community/venus-common-utils/journal"
"github.com/ipfs-force-community/venus-common-utils/metrics"

"github.com/filecoin-project/venus-market/api"
"github.com/filecoin-project/venus-market/api/clients"
"github.com/filecoin-project/venus-market/api/impl"
cli2 "github.com/filecoin-project/venus-market/cli"
"github.com/filecoin-project/venus-market/config"
"github.com/filecoin-project/venus-market/dagstore"
"github.com/filecoin-project/venus-market/fundmgr"
minermgr2 "github.com/filecoin-project/venus-market/minermgr"
"github.com/filecoin-project/venus-market/models"
"github.com/filecoin-project/venus-market/network"
"github.com/filecoin-project/venus-market/paychmgr"
"github.com/filecoin-project/venus-market/piecestorage"
"github.com/filecoin-project/venus-market/retrievalprovider"
"github.com/filecoin-project/venus-market/rpc"
"github.com/filecoin-project/venus-market/storageprovider"
"github.com/filecoin-project/venus-market/types"
"github.com/filecoin-project/venus-market/utils"

_ "github.com/filecoin-project/venus-market/network"
"github.com/filecoin-project/venus-market/piecestorage"

"github.com/filecoin-project/venus/pkg/constants"
_ "github.com/filecoin-project/venus/pkg/crypto/bls"
_ "github.com/filecoin-project/venus/pkg/crypto/secp"
)

// Invokes are called in the order they are defined.
//nolint:golint
// nolint:golint
var (
InitJournalKey = builder.NextInvoke() //nolint
ExtractApiKey = builder.NextInvoke()
Expand Down Expand Up @@ -109,9 +87,10 @@ var (
Name: "mysql-dsn",
Usage: "mysql connection string",
}

MinerListFlag = &cli.StringSliceFlag{
Name: "miner",
Usage: "support miner( f01000:jimmy)",
Usage: "support miner(f01000:jimmy)",
}
)

Expand All @@ -125,25 +104,8 @@ func main() {
RepoFlag,
},
Commands: []*cli.Command{
{
Name: "run",
Usage: "run market daemon",
Flags: []cli.Flag{
NodeUrlFlag,
NodeTokenFlag,
AuthUrlFlag,
AuthTokeFlag,
MessagerUrlFlag,
MessagerTokenFlag,
SignerTypeFlag,
SignerUrlFlag,
SignerTokenFlag,
PieceStorageFlag,
MysqlDsnFlag,
MinerListFlag,
},
Action: daemon,
},
soloRunCmd,
poolRunCmd,
cli2.PiecesCmd,
cli2.RetrievalDealsCmd,
cli2.StorageDealsCmd,
Expand All @@ -162,7 +124,6 @@ func main() {

func prepare(cctx *cli.Context) (*config.MarketConfig, error) {
cfg := config.DefaultMarketConfig
cfg.HomeDir = cctx.String("repo")
cfgPath, err := cfg.ConfigPath()
if err != nil {
return nil, err
Expand All @@ -184,6 +145,7 @@ func prepare(cctx *cli.Context) (*config.MarketConfig, error) {
if err != nil {
return nil, err
}

err = flagData(cctx, cfg)
if err != nil {
return nil, xerrors.Errorf("parser data from flag %w", err)
Expand All @@ -194,63 +156,6 @@ func prepare(cctx *cli.Context) (*config.MarketConfig, error) {
return cfg, nil
}

func daemon(cctx *cli.Context) error {
utils.SetupLogLevels()
ctx := cctx.Context
cfg, err := prepare(cctx)
if err != nil {
return err
}

resAPI := &impl.MarketNodeImpl{}
shutdownChan := make(chan struct{})
_, err = builder.New(ctx,
//defaults
builder.Override(new(journal.DisabledEvents), journal.EnvDisabledEvents),
builder.Override(new(journal.Journal), func(lc fx.Lifecycle, home config.IHome, disabled journal.DisabledEvents) (journal.Journal, error) {
return journal.OpenFilesystemJournal(lc, home.MustHomePath(), "venus-market", disabled)
}),

builder.Override(new(metrics.MetricsCtx), func() context.Context {
return metrics2.CtxScope(context.Background(), "venus-market")
}),
builder.Override(new(types.ShutdownChan), shutdownChan),
//config
config.ConfigServerOpts(cfg),

// miner manager
minermgr2.MinerMgrOpts(cfg),

//clients
clients.ClientsOpts(true, &cfg.Messager, &cfg.Signer),
models.DBOptions(true, &cfg.Mysql),
network.NetworkOpts(true, cfg.SimultaneousTransfers),
piecestorage.PieceStorageOpts(cfg),
fundmgr.FundMgrOpts,
dagstore.DagstoreOpts,
paychmgr.PaychOpts,
// Markets
storageprovider.StorageProviderOpts(cfg),
retrievalprovider.RetrievalProviderOpts(cfg),

func(s *builder.Settings) error {
s.Invokes[ExtractApiKey] = builder.InvokeOption{
Priority: 10,
Option: fx.Populate(resAPI),
}
return nil
},
)
if err != nil {
return xerrors.Errorf("initializing node: %w", err)
}
finishCh := utils.MonitorShutdown(shutdownChan)

mux := mux2.NewRouter()
mux.Handle("resource", rpc.NewPieceStorageServer(resAPI.PieceStorage))
return rpc.ServeRPC(ctx, cfg, &cfg.API, mux, 1000, cli2.API_NAMESPACE_VENUS_MARKET, "", api.MarketFullNode(resAPI), finishCh)
}

func flagData(cctx *cli.Context, cfg *config.MarketConfig) error {
if cctx.IsSet("repo") {
cfg.HomeDir = cctx.String("repo")
Expand Down Expand Up @@ -278,6 +183,7 @@ func flagData(cctx *cli.Context, cfg *config.MarketConfig) error {

if cctx.IsSet("auth-token") {
cfg.Node.Token = cctx.String("auth-token")

if len(cfg.AuthNode.Url) > 0 {
cfg.AuthNode.Token = cctx.String("auth-token")
}
Expand All @@ -294,11 +200,9 @@ func flagData(cctx *cli.Context, cfg *config.MarketConfig) error {
if cctx.IsSet("node-token") {
cfg.Node.Token = cctx.String("node-token")
}

if cctx.IsSet("messager-token") {
cfg.Messager.Token = cctx.String("messager-token")
}

if cctx.IsSet("signer-token") {
cfg.Signer.Token = cctx.String("signer-token")
}
Expand Down
Loading