Skip to content
This repository has been archived by the owner on Dec 19, 2022. It is now read-only.

Commit

Permalink
opt config that use venus-market (#151)
Browse files Browse the repository at this point in the history
Co-authored-by: 一页素书 <2931107265@qq.com>
  • Loading branch information
diwufeiwen and ta0li committed Jan 17, 2022
1 parent 761e5cd commit f66c5d8
Show file tree
Hide file tree
Showing 10 changed files with 146 additions and 96 deletions.
10 changes: 5 additions & 5 deletions api/market-client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import (
"go.uber.org/fx"
)

func NewMarketRPC(lc fx.Lifecycle, marketCfg *config.MarketConfig) (api.MarketFullNode, error) {
if marketCfg.Url == "" {
log.Warnf("market config is empty ...")
func NewMarketNodeRPCAPIV0(lc fx.Lifecycle, mCfg *config.MarketNodeConfig) (api.MarketFullNode, error) {
if mCfg.Url == "" {
log.Warnf("market node config is empty ...")
return &api.MarketFullNodeStruct{}, nil
}

apiInfo := apiinfo.APIInfo{
Addr: marketCfg.Url,
Token: []byte(marketCfg.Token),
Addr: mCfg.Url,
Token: []byte(mCfg.Token),
}

addr, err := apiInfo.DialArgs("v0")
Expand Down
127 changes: 74 additions & 53 deletions app/venus-sealer/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,14 @@ var initCmd = &cli.Command{
},

&cli.StringFlag{
Name: "market-url",
Usage: "market url",
Name: "market-node",
Value: "solo",
Usage: "indicate the deployment method of the venus-market, one of `solo`, `pool`, Default: `solo`",
},
&cli.StringFlag{
Name: "market-url",
Usage: "market url",
Required: true,
},
&cli.StringFlag{
Name: "market-token",
Expand All @@ -152,11 +158,8 @@ var initCmd = &cli.Command{
},
Action: func(cctx *cli.Context) error {
ctx := api.ReqContext(cctx)

log.Info("Initializing venus sealer")
gasPrice, err := types.BigFromString(cctx.String("gas-premium"))
if err != nil {
return xerrors.Errorf("failed to parse gas-price flag: %s", err)
}

symlink := cctx.Bool("symlink-imported-sectors")
if symlink {
Expand All @@ -169,16 +172,28 @@ var initCmd = &cli.Command{
return err
}

setAuthToken(defaultCfg, cctx)
err = parseFlag(defaultCfg, cctx)
err = parseServiceFlag(defaultCfg, cctx)
if err != nil {
return err
}
if err := checkURL(defaultCfg); err != nil {

if err := checkServiceConfig(defaultCfg); err != nil {
return err
}

log.Info("Checking if repo exists")

defaultCfg.ConfigPath = config.FsConfig(defaultCfg.DataDir)
exit, err := config.ConfigExist(defaultCfg.DataDir)
if err != nil {
return err
}
if exit {
return xerrors.Errorf("repo is already initialized at %s", defaultCfg.DataDir)
}

log.Info("Checking proof parameters")

ps, err := asset.Asset("fixtures/_assets/proof-params/parameters.json")
if err != nil {
return err
Expand All @@ -204,17 +219,6 @@ var initCmd = &cli.Command{
}
}

log.Info("Checking if repo exists")

defaultCfg.ConfigPath = config.FsConfig(defaultCfg.DataDir)
exit, err := config.ConfigExist(defaultCfg.DataDir)
if err != nil {
return err
}
if exit {
return xerrors.Errorf("repo is already initialized at %s", defaultCfg.DataDir)
}

log.Info("Checking full node version")

v, err := fullNode.Version(ctx)
Expand All @@ -227,16 +231,8 @@ var initCmd = &cli.Command{
}

log.Info("Initializing repo")
messagerClient, closer, err := api.NewMessageRPC(&defaultCfg.Messager)
if err != nil {
return err
}
defer closer()

log.Info("Initializing repo")

{
//write config
// write config
err = config.SaveConfig(defaultCfg.ConfigPath, defaultCfg)
if err != nil {
return err
Expand Down Expand Up @@ -289,10 +285,22 @@ var initCmd = &cli.Command{
}
}

messagerClient, closer, err := api.NewMessageRPC(&defaultCfg.Messager)
if err != nil {
return err
}
defer closer()

ssize, err := units.RAMInBytes(cctx.String("sector-size"))
if err != nil {
return fmt.Errorf("failed to parse sector size: %w", err)
}

gasPrice, err := types.BigFromString(cctx.String("gas-premium"))
if err != nil {
return xerrors.Errorf("failed to parse gas-price flag: %s", err)
}

minerAddr, err := storageMinerInit(ctx, cctx, fullNode, messagerClient, defaultCfg, abi.SectorSize(ssize), gasPrice)
if err != nil {
log.Errorf("Failed to initialize venus-miner: %+v", err)
Expand Down Expand Up @@ -320,52 +328,55 @@ var initCmd = &cli.Command{
},
}

func setAuthToken(cfg *config.StorageMiner, cctx *cli.Context) {
func parseServiceFlag(cfg *config.StorageMiner, cctx *cli.Context) error {
cfg.DataDir = cctx.String("repo")

if cctx.IsSet("auth-token") {
authToken := cctx.String("auth-token")

cfg.Node.Token = authToken

cfg.Messager.Token = authToken

cfg.RegisterProof.Token = authToken
cfg.RegisterMarket.Token = authToken
cfg.RegisterMarket.Token = authToken
}
}

func parseFlag(cfg *config.StorageMiner, cctx *cli.Context) error {
cfg.DataDir = cctx.String("repo")
cfg.MarketNode.Token = authToken

if cctx.IsSet("messager-url") {
cfg.Messager.Url = cctx.String("messager-url")
cfg.RegisterMarket.Token = authToken
}

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

if cctx.IsSet("gateway-url") {
cfg.RegisterProof.Urls = cctx.StringSlice("gateway-url")
}

if cctx.IsSet("market-url") {
cfg.RegisterMarket.Urls = []string{cctx.String("market-url")}
cfg.Market.Url = cctx.String("market-url")
}

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

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

if cctx.IsSet("gateway-url") {
cfg.RegisterProof.Urls = cctx.StringSlice("gateway-url")
}
if cctx.IsSet("gateway-token") {
cfg.RegisterProof.Token = cctx.String("gateway-token")
}

cfg.MarketNode.Mode = cctx.String("market-node")
cfg.MarketNode.Url = cctx.String("market-url")
if cctx.IsSet("market-token") {
cfg.Market.Token = cctx.String("market-token")
cfg.RegisterMarket.Token = cctx.String("market-token")
cfg.MarketNode.Token = cctx.String("market-token")
}
if cfg.MarketNode.Mode == "solo" { // when venus-market is deployed independently, it not only provides services but also handles events
cfg.RegisterMarket.Urls = []string{cfg.MarketNode.Url}
cfg.RegisterMarket.Token = cfg.MarketNode.Token
} else {
cfg.RegisterMarket.Urls = cfg.RegisterProof.Urls
cfg.RegisterMarket.Token = cfg.RegisterProof.Token
}

if cctx.IsSet("piecestorage") {
Expand All @@ -389,9 +400,9 @@ func parseMultiAddr(url string) error {
return err
}

func checkURL(cfg *config.StorageMiner) error {
func checkServiceConfig(cfg *config.StorageMiner) error {
if err := parseMultiAddr(cfg.Messager.Url); err != nil {
return xerrors.Errorf("message url: %w", err)
return xerrors.Errorf("messager node url: %w", err)
}

if err := parseMultiAddr(cfg.Node.Url); err != nil {
Expand All @@ -400,7 +411,17 @@ func checkURL(cfg *config.StorageMiner) error {

for _, url := range cfg.RegisterProof.Urls {
if err := parseMultiAddr(url); err != nil {
return xerrors.Errorf("gateway url:[%s]: %w", url, err)
return xerrors.Errorf("gateway node url:[%s]: %w", url, err)
}
}

if err := parseMultiAddr(cfg.MarketNode.Url); err != nil {
return xerrors.Errorf("market node url: %w", err)
}

for _, url := range cfg.RegisterMarket.Urls {
if err := parseMultiAddr(url); err != nil {
return xerrors.Errorf("register market node url:[%s]: %w", url, err)
}
}

Expand Down
33 changes: 18 additions & 15 deletions builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@ package venus_sealer

import (
"context"

logging "github.com/ipfs/go-log/v2"
metricsi "github.com/ipfs/go-metrics-interface"
"github.com/multiformats/go-multiaddr"
"go.uber.org/fx"
"golang.org/x/xerrors"

"github.com/filecoin-project/go-state-types/abi"
storage2 "github.com/filecoin-project/specs-storage/storage"
api2 "github.com/filecoin-project/venus-market/api"
config2 "github.com/filecoin-project/venus-market/config"

api3 "github.com/filecoin-project/venus-market/api"
config3 "github.com/filecoin-project/venus-market/config"
"github.com/filecoin-project/venus-market/piecestorage"

"github.com/filecoin-project/venus-sealer/api"
"github.com/filecoin-project/venus-sealer/api/impl"
"github.com/filecoin-project/venus-sealer/config"
Expand All @@ -15,19 +24,14 @@ import (
"github.com/filecoin-project/venus-sealer/models"
"github.com/filecoin-project/venus-sealer/models/repo"
"github.com/filecoin-project/venus-sealer/proof_client"
sectorstorage "github.com/filecoin-project/venus-sealer/sector-storage"
"github.com/filecoin-project/venus-sealer/sector-storage"
"github.com/filecoin-project/venus-sealer/sector-storage/ffiwrapper"
"github.com/filecoin-project/venus-sealer/sector-storage/stores"
"github.com/filecoin-project/venus-sealer/sector-storage/storiface"
"github.com/filecoin-project/venus-sealer/service"
"github.com/filecoin-project/venus-sealer/storage"
"github.com/filecoin-project/venus-sealer/storage/sectorblocks"
"github.com/filecoin-project/venus-sealer/types"
logging "github.com/ipfs/go-log/v2"
metricsi "github.com/ipfs/go-metrics-interface"
"github.com/multiformats/go-multiaddr"
"go.uber.org/fx"
"golang.org/x/xerrors"
)

var log = logging.Logger("modules")
Expand All @@ -51,7 +55,7 @@ const (

//proof
StartProofEventKey
StartWalletEventKey
StartMarketEventKey
WarmupKey
_nInvokes // keep this last
)
Expand Down Expand Up @@ -145,6 +149,7 @@ func Online(cfg *config.StorageMiner) Option {
Override(new(storage2.Prover), From(new(sectorstorage.SectorManager))),
Override(new(storiface.WorkerReturn), From(new(sectorstorage.SectorManager))),

Override(new(types.MarketMode), types.MarketMode(cfg.MarketNode.Mode)),
Override(new(types.GetSealingConfigFunc), NewGetSealConfigFunc),
Override(new(*sectorblocks.SectorBlocks), sectorblocks.NewSectorBlocks),
Override(new(*storage.Miner), StorageMiner(config.DefaultMainnetStorageMiner().Fees)),
Expand All @@ -154,7 +159,7 @@ func Online(cfg *config.StorageMiner) Option {
Override(AutoMigrateKey, models.AutoMigrate),
Override(SetNetParamsKey, SetupNetParams),
Override(StartProofEventKey, proof_client.StartProofEvent),
Override(StartWalletEventKey, market_client.StartMarketEvent),
Override(StartMarketEventKey, market_client.StartMarketEvent),
Override(WarmupKey, DoPoStWarmup),
)
}
Expand All @@ -169,19 +174,17 @@ func Repo(cfg *config.StorageMiner) Option {
Override(new(sectorstorage.SealerConfig), cfg.Storage),
Override(new(*storage.AddressSelector), AddressSelector(&cfg.Addresses)),
Override(new(*config.DbConfig), &cfg.DB),
Override(new(*config2.PieceStorage), &cfg.PieceStorage),
Override(new(*config3.PieceStorage), &cfg.PieceStorage),
Override(new(*config.StorageMiner), cfg),
Override(new(*config.MessagerConfig), &cfg.Messager),
Override(new(*config.MarketConfig), &cfg.Market),
Override(new(*config.MarketNodeConfig), &cfg.MarketNode),
Override(new(*config.RegisterMarketConfig), &cfg.RegisterMarket),
Override(new(*config.RegisterProofConfig), &cfg.RegisterProof),
ConfigAPI(cfg),

Override(new(api.IMessager), api.NewMessageRPC),
Override(new(api2.MarketFullNode), api.NewMarketRPC),
Override(new(api3.MarketFullNode), api.NewMarketNodeRPCAPIV0),
Override(new(piecestorage.IPieceStorage), NewPieceStorage),
Override(new(*market_client.MarketEventClient), market_client.NewMarketEventClient),
Override(new(*proof_client.ProofEventClient), proof_client.NewProofEventClient),
Override(new(repo.Repo), models.SetDataBase),
Providers(
service.NewDealRefServiceService,
Expand Down
5 changes: 3 additions & 2 deletions config/def.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type StorageMiner struct {
JWT JWTConfig
Messager MessagerConfig

Market MarketConfig
MarketNode MarketNodeConfig
PieceStorage config.PieceStorage
RegisterProof RegisterProofConfig
RegisterMarket RegisterMarketConfig
Expand All @@ -80,7 +80,8 @@ type MessagerConfig struct {
Token string
}

type MarketConfig struct {
type MarketNodeConfig struct {
Mode string
Url string
Token string
}
Expand Down
Loading

0 comments on commit f66c5d8

Please sign in to comment.