Skip to content

Commit

Permalink
refactor RepoType
Browse files Browse the repository at this point in the history
  • Loading branch information
nonsense committed Feb 14, 2022
1 parent bac708f commit 4df3c89
Show file tree
Hide file tree
Showing 50 changed files with 242 additions and 218 deletions.
2 changes: 1 addition & 1 deletion chain/gen/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func NewGeneratorWithSectorsAndUpgradeSchedule(numSectors int, us stmgr.UpgradeS
policy.SetSupportedProofTypes(abi.RegisteredSealProof_StackedDrg2KiBV1)

mr := repo.NewMemory(nil)
lr, err := mr.Lock(repo.StorageMiner)
lr, err := mr.Lock(repo.StorageMinerRepoType{})
if err != nil {
return nil, xerrors.Errorf("taking mem-repo lock failed: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion chain/store/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func BenchmarkGetRandomness(b *testing.B) {
b.Fatal(err)
}

lr, err := r.Lock(repo.FullNode)
lr, err := r.Lock(repo.FullNodeRepoType{})
if err != nil {
b.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion cli/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ var AuthApiInfoToken = &cli.Command{
ti, ok := cctx.App.Metadata["repoType"]
if !ok {
log.Errorf("unknown repo type, are you sure you want to use GetCommonAPI?")
ti = repo.FullNode
ti = repo.FullNodeRepoType{}
}
t, ok := ti.(repo.RepoType)
if !ok {
Expand Down
4 changes: 2 additions & 2 deletions cli/client_retr.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ var clientRetrieveCatCmd = &cli.Command{
return ShowHelp(cctx, fmt.Errorf("incorrect number of arguments"))
}

ainfo, err := GetAPIInfo(cctx, repo.FullNode)
ainfo, err := GetAPIInfo(cctx, repo.FullNodeRepoType{})
if err != nil {
return xerrors.Errorf("could not get API info: %w", err)
}
Expand Down Expand Up @@ -482,7 +482,7 @@ var clientRetrieveLsCmd = &cli.Command{
return ShowHelp(cctx, fmt.Errorf("incorrect number of arguments"))
}

ainfo, err := GetAPIInfo(cctx, repo.FullNode)
ainfo, err := GetAPIInfo(cctx, repo.FullNodeRepoType{})
if err != nil {
return xerrors.Errorf("could not get API info: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion cli/pprof.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var PprofGoroutines = &cli.Command{
ti, ok := cctx.App.Metadata["repoType"]
if !ok {
log.Errorf("unknown repo type, are you sure you want to use GetAPI?")
ti = repo.FullNode
ti = repo.FullNodeRepoType{}
}
t, ok := ti.(repo.RepoType)
if !ok {
Expand Down
46 changes: 23 additions & 23 deletions cli/util/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ const (
// of the API server (only used by the tests), in the order of precedence they
// should be applied for the requested kind of node.
func flagsForAPI(t repo.RepoType) []string {
switch t {
case repo.FullNode:
switch t.Type() {
case "FullNode":
return []string{"api-url"}
case repo.StorageMiner:
case "StorageMiner":
return []string{"miner-api-url"}
case repo.Worker:
case "Worker":
return []string{"worker-api-url"}
case repo.Markets:
case "Markets":
// support split markets-miner and monolith deployments.
return []string{"markets-api-url", "miner-api-url"}
default:
Expand All @@ -48,14 +48,14 @@ func flagsForAPI(t repo.RepoType) []string {
}

func flagsForRepo(t repo.RepoType) []string {
switch t {
case repo.FullNode:
switch t.Type() {
case "FullNode":
return []string{"repo"}
case repo.StorageMiner:
case "StorageMiner":
return []string{"miner-repo"}
case repo.Worker:
case "Worker":
return []string{"worker-repo"}
case repo.Markets:
case "Markets":
// support split markets-miner and monolith deployments.
return []string{"markets-repo", "miner-repo"}
default:
Expand All @@ -69,15 +69,15 @@ func flagsForRepo(t repo.RepoType) []string {
// It returns the current variables and deprecated ones separately, so that
// the user can log a warning when deprecated ones are found to be in use.
func EnvsForAPIInfos(t repo.RepoType) (primary string, fallbacks []string, deprecated []string) {
switch t {
case repo.FullNode:
switch t.Type() {
case "FullNode":
return "FULLNODE_API_INFO", nil, nil
case repo.StorageMiner:
case "StorageMiner":
// TODO remove deprecated deprecation period
return "MINER_API_INFO", nil, []string{"STORAGE_API_INFO"}
case repo.Worker:
case "Worker":
return "WORKER_API_INFO", nil, nil
case repo.Markets:
case "Markets":
// support split markets-miner and monolith deployments.
return "MARKETS_API_INFO", []string{"MINER_API_INFO"}, nil
default:
Expand Down Expand Up @@ -200,7 +200,7 @@ func GetCommonAPI(ctx *cli.Context) (api.CommonNet, jsonrpc.ClientCloser, error)
ti, ok := ctx.App.Metadata["repoType"]
if !ok {
log.Errorf("unknown repo type, are you sure you want to use GetCommonAPI?")
ti = repo.FullNode
ti = repo.FullNodeRepoType{}
}
t, ok := ti.(repo.RepoType)
if !ok {
Expand All @@ -227,7 +227,7 @@ func GetFullNodeAPI(ctx *cli.Context) (v0api.FullNode, jsonrpc.ClientCloser, err
return &v0api.WrapperV1Full{FullNode: tn.(v1api.FullNode)}, func() {}, nil
}

addr, headers, err := GetRawAPI(ctx, repo.FullNode, "v0")
addr, headers, err := GetRawAPI(ctx, repo.FullNodeRepoType{}, "v0")
if err != nil {
return nil, nil, err
}
Expand All @@ -244,7 +244,7 @@ func GetFullNodeAPIV1(ctx *cli.Context) (v1api.FullNode, jsonrpc.ClientCloser, e
return tn.(v1api.FullNode), func() {}, nil
}

addr, headers, err := GetRawAPI(ctx, repo.FullNode, "v1")
addr, headers, err := GetRawAPI(ctx, repo.FullNodeRepoType{}, "v1")
if err != nil {
return nil, nil, err
}
Expand Down Expand Up @@ -288,7 +288,7 @@ func GetStorageMinerAPI(ctx *cli.Context, opts ...GetStorageMinerOption) (api.St
return tn.(api.StorageMiner), func() {}, nil
}

addr, headers, err := GetRawAPI(ctx, repo.StorageMiner, "v0")
addr, headers, err := GetRawAPI(ctx, repo.StorageMinerRepoType{}, "v0")
if err != nil {
return nil, nil, err
}
Expand Down Expand Up @@ -317,7 +317,7 @@ func GetStorageMinerAPI(ctx *cli.Context, opts ...GetStorageMinerOption) (api.St
}

func GetWorkerAPI(ctx *cli.Context) (api.Worker, jsonrpc.ClientCloser, error) {
addr, headers, err := GetRawAPI(ctx, repo.Worker, "v0")
addr, headers, err := GetRawAPI(ctx, repo.WorkerRepoType{}, "v0")
if err != nil {
return nil, nil, err
}
Expand All @@ -335,7 +335,7 @@ func GetMarketsAPI(ctx *cli.Context) (api.StorageMiner, jsonrpc.ClientCloser, er
return tn.(api.StorageMiner), func() {}, nil
}

addr, headers, err := GetRawAPI(ctx, repo.Markets, "v0")
addr, headers, err := GetRawAPI(ctx, repo.MarketsRepoType{}, "v0")
if err != nil {
return nil, nil, err
}
Expand All @@ -351,7 +351,7 @@ func GetMarketsAPI(ctx *cli.Context) (api.StorageMiner, jsonrpc.ClientCloser, er
}

func GetGatewayAPI(ctx *cli.Context) (api.Gateway, jsonrpc.ClientCloser, error) {
addr, headers, err := GetRawAPI(ctx, repo.FullNode, "v1")
addr, headers, err := GetRawAPI(ctx, repo.FullNodeRepoType{}, "v1")
if err != nil {
return nil, nil, err
}
Expand All @@ -364,7 +364,7 @@ func GetGatewayAPI(ctx *cli.Context) (api.Gateway, jsonrpc.ClientCloser, error)
}

func GetGatewayAPIV0(ctx *cli.Context) (v0api.Gateway, jsonrpc.ClientCloser, error) {
addr, headers, err := GetRawAPI(ctx, repo.FullNode, "v0")
addr, headers, err := GetRawAPI(ctx, repo.FullNodeRepoType{}, "v0")
if err != nil {
return nil, nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/lotus-miner/actor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestWorkerKeyChange(t *testing.T) {
run := func(cmd *cli.Command, args ...string) error {
app := cli.NewApp()
app.Metadata = map[string]interface{}{
"repoType": repo.StorageMiner,
"repoType": repo.StorageMinerRepoType{},
"testnode-full": client1,
"testnode-storage": miner,
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/lotus-miner/allinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestMinerAllInfo(t *testing.T) {
run := func(t *testing.T) {
app := cli.NewApp()
app.Metadata = map[string]interface{}{
"repoType": repo.StorageMiner,
"repoType": repo.StorageMinerRepoType{},
"testnode-full": client,
"testnode-storage": miner,
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/lotus-miner/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ import (
"github.com/filecoin-project/lotus/node/repo"
)

var backupCmd = lcli.BackupCmd(FlagMinerRepo, repo.StorageMiner, func(cctx *cli.Context) (lcli.BackupAPI, jsonrpc.ClientCloser, error) {
var backupCmd = lcli.BackupCmd(FlagMinerRepo, repo.StorageMinerRepoType{}, func(cctx *cli.Context) (lcli.BackupAPI, jsonrpc.ClientCloser, error) {
return lcli.GetStorageMinerAPI(cctx)
})
2 changes: 1 addition & 1 deletion cmd/lotus-miner/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ var configUpdateCmd = &cli.Command{
return xerrors.Errorf("repo not initialized")
}

lr, err := r.LockRO(repo.StorageMiner)
lr, err := r.LockRO(repo.StorageMinerRepoType{})
if err != nil {
return xerrors.Errorf("locking repo: %w", err)
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/lotus-miner/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,12 @@ var initCmd = &cli.Command{

log.Info("Initializing repo")

if err := r.Init(repo.StorageMiner); err != nil {
if err := r.Init(repo.StorageMinerRepoType{}); err != nil {
return err
}

{
lr, err := r.Lock(repo.StorageMiner)
lr, err := r.Lock(repo.StorageMinerRepoType{})
if err != nil {
return err
}
Expand Down Expand Up @@ -410,7 +410,7 @@ func findMarketDealID(ctx context.Context, api v1api.FullNode, deal market2.Deal
}

func storageMinerInit(ctx context.Context, cctx *cli.Context, api v1api.FullNode, r repo.Repo, ssize abi.SectorSize, gasPrice types.BigInt) error {
lr, err := r.Lock(repo.StorageMiner)
lr, err := r.Lock(repo.StorageMinerRepoType{})
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/lotus-miner/init_restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,11 @@ func restore(ctx context.Context, cctx *cli.Context, targetPath string, strConfi

log.Info("Initializing repo")

if err := r.Init(repo.StorageMiner); err != nil {
if err := r.Init(repo.StorageMinerRepoType{}); err != nil {
return err
}

lr, err := r.Lock(repo.StorageMiner)
lr, err := r.Lock(repo.StorageMinerRepoType{})
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/lotus-miner/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func main() {
return err
}
}
c.App.Metadata["repoType"] = repo.Markets
c.App.Metadata["repoType"] = repo.MarketsRepoType{}
return nil
}

Expand Down Expand Up @@ -150,7 +150,7 @@ func main() {
// this command is explicitly called on markets, inform
// common commands by overriding the repoType.
if c.Bool("call-on-markets") {
c.App.Metadata["repoType"] = repo.Markets
c.App.Metadata["repoType"] = repo.MarketsRepoType{}
}
return nil
},
Expand All @@ -164,7 +164,7 @@ func main() {
},
}
app.Setup()
app.Metadata["repoType"] = repo.StorageMiner
app.Metadata["repoType"] = repo.StorageMinerRepoType{}
lcli.RunApp(app)
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/lotus-miner/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ var runCmd = &cli.Command{
return xerrors.Errorf("repo at '%s' is not initialized, run 'lotus-miner init' to set it up", minerRepoPath)
}

lr, err := r.Lock(repo.StorageMiner)
lr, err := r.Lock(repo.StorageMinerRepoType{})
if err != nil {
return err
}
Expand Down
12 changes: 6 additions & 6 deletions cmd/lotus-seal-worker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func main() {
Commands: local,
}
app.Setup()
app.Metadata["repoType"] = repo.Worker
app.Metadata["repoType"] = repo.WorkerRepoType{}

if err := app.Run(os.Args); err != nil {
log.Warnf("%+v", err)
Expand Down Expand Up @@ -302,11 +302,11 @@ var runCmd = &cli.Command{
return err
}
if !ok {
if err := r.Init(repo.Worker); err != nil {
if err := r.Init(repo.WorkerRepoType{}); err != nil {
return err
}

lr, err := r.Lock(repo.Worker)
lr, err := r.Lock(repo.WorkerRepoType{})
if err != nil {
return err
}
Expand Down Expand Up @@ -351,7 +351,7 @@ var runCmd = &cli.Command{
}
}

lr, err := r.Lock(repo.Worker)
lr, err := r.Lock(repo.WorkerRepoType{})
if err != nil {
return err
}
Expand Down Expand Up @@ -389,7 +389,7 @@ var runCmd = &cli.Command{
}

// Setup remote sector store
sminfo, err := lcli.GetAPIInfo(cctx, repo.StorageMiner)
sminfo, err := lcli.GetAPIInfo(cctx, repo.StorageMinerRepoType{})
if err != nil {
return xerrors.Errorf("could not get api info: %w", err)
}
Expand Down Expand Up @@ -476,7 +476,7 @@ var runCmd = &cli.Command{
return xerrors.Errorf("setting api endpoint: %w", err)
}

ainfo, err := lcli.GetAPIInfo(cctx, repo.StorageMiner)
ainfo, err := lcli.GetAPIInfo(cctx, repo.StorageMinerRepoType{})
if err != nil {
return xerrors.Errorf("could not get miner API info: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/lotus-shed/balances.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ var chainBalanceStateCmd = &cli.Command{
return err
}

lkrepo, err := fsrepo.Lock(repo.FullNode)
lkrepo, err := fsrepo.Lock(repo.FullNodeRepoType{})
if err != nil {
return err
}
Expand Down Expand Up @@ -710,7 +710,7 @@ var chainPledgeCmd = &cli.Command{
return err
}

lkrepo, err := fsrepo.Lock(repo.FullNode)
lkrepo, err := fsrepo.Lock(repo.FullNodeRepoType{})
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit 4df3c89

Please sign in to comment.