unexport repo types; use a global var for every repo type

This commit is contained in:
Anton Evangelatov 2022-02-16 12:26:41 +01:00
parent e3edab66e3
commit f1f878a000
47 changed files with 107 additions and 99 deletions

View File

@ -121,7 +121,7 @@ func NewGeneratorWithSectorsAndUpgradeSchedule(numSectors int, us stmgr.UpgradeS
policy.SetSupportedProofTypes(abi.RegisteredSealProof_StackedDrg2KiBV1) policy.SetSupportedProofTypes(abi.RegisteredSealProof_StackedDrg2KiBV1)
mr := repo.NewMemory(nil) mr := repo.NewMemory(nil)
lr, err := mr.Lock(repo.StorageMinerRepoType{}) lr, err := mr.Lock(repo.StorageMiner)
if err != nil { if err != nil {
return nil, xerrors.Errorf("taking mem-repo lock failed: %w", err) return nil, xerrors.Errorf("taking mem-repo lock failed: %w", err)
} }

View File

@ -48,7 +48,7 @@ func BenchmarkGetRandomness(b *testing.B) {
b.Fatal(err) b.Fatal(err)
} }
lr, err := r.Lock(repo.FullNodeRepoType{}) lr, err := r.Lock(repo.FullNode)
if err != nil { if err != nil {
b.Fatal(err) b.Fatal(err)
} }

View File

@ -114,7 +114,7 @@ var AuthApiInfoToken = &cli.Command{
ti, ok := cctx.App.Metadata["repoType"] ti, ok := cctx.App.Metadata["repoType"]
if !ok { if !ok {
log.Errorf("unknown repo type, are you sure you want to use GetCommonAPI?") log.Errorf("unknown repo type, are you sure you want to use GetCommonAPI?")
ti = repo.FullNodeRepoType{} ti = repo.FullNode
} }
t, ok := ti.(repo.RepoType) t, ok := ti.(repo.RepoType)
if !ok { if !ok {

View File

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

View File

@ -26,7 +26,7 @@ var PprofGoroutines = &cli.Command{
ti, ok := cctx.App.Metadata["repoType"] ti, ok := cctx.App.Metadata["repoType"]
if !ok { if !ok {
log.Errorf("unknown repo type, are you sure you want to use GetAPI?") log.Errorf("unknown repo type, are you sure you want to use GetAPI?")
ti = repo.FullNodeRepoType{} ti = repo.FullNode
} }
t, ok := ti.(repo.RepoType) t, ok := ti.(repo.RepoType)
if !ok { if !ok {

View File

@ -200,7 +200,7 @@ func GetCommonAPI(ctx *cli.Context) (api.CommonNet, jsonrpc.ClientCloser, error)
ti, ok := ctx.App.Metadata["repoType"] ti, ok := ctx.App.Metadata["repoType"]
if !ok { if !ok {
log.Errorf("unknown repo type, are you sure you want to use GetCommonAPI?") log.Errorf("unknown repo type, are you sure you want to use GetCommonAPI?")
ti = repo.FullNodeRepoType{} ti = repo.FullNode
} }
t, ok := ti.(repo.RepoType) t, ok := ti.(repo.RepoType)
if !ok { if !ok {
@ -232,7 +232,7 @@ func GetFullNodeAPI(ctx *cli.Context) (v0api.FullNode, jsonrpc.ClientCloser, err
return &v0api.WrapperV1Full{FullNode: tn.(v1api.FullNode)}, func() {}, nil return &v0api.WrapperV1Full{FullNode: tn.(v1api.FullNode)}, func() {}, nil
} }
addr, headers, err := GetRawAPI(ctx, repo.FullNodeRepoType{}, "v0") addr, headers, err := GetRawAPI(ctx, repo.FullNode, "v0")
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -249,7 +249,7 @@ func GetFullNodeAPIV1(ctx *cli.Context) (v1api.FullNode, jsonrpc.ClientCloser, e
return tn.(v1api.FullNode), func() {}, nil return tn.(v1api.FullNode), func() {}, nil
} }
addr, headers, err := GetRawAPI(ctx, repo.FullNodeRepoType{}, "v1") addr, headers, err := GetRawAPI(ctx, repo.FullNode, "v1")
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -293,7 +293,7 @@ func GetStorageMinerAPI(ctx *cli.Context, opts ...GetStorageMinerOption) (api.St
return tn.(api.StorageMiner), func() {}, nil return tn.(api.StorageMiner), func() {}, nil
} }
addr, headers, err := GetRawAPI(ctx, repo.StorageMinerRepoType{}, "v0") addr, headers, err := GetRawAPI(ctx, repo.StorageMiner, "v0")
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -322,7 +322,7 @@ func GetStorageMinerAPI(ctx *cli.Context, opts ...GetStorageMinerOption) (api.St
} }
func GetWorkerAPI(ctx *cli.Context) (api.Worker, jsonrpc.ClientCloser, error) { func GetWorkerAPI(ctx *cli.Context) (api.Worker, jsonrpc.ClientCloser, error) {
addr, headers, err := GetRawAPI(ctx, repo.WorkerRepoType{}, "v0") addr, headers, err := GetRawAPI(ctx, repo.Worker, "v0")
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -340,7 +340,7 @@ func GetMarketsAPI(ctx *cli.Context) (api.StorageMiner, jsonrpc.ClientCloser, er
return tn.(api.StorageMiner), func() {}, nil return tn.(api.StorageMiner), func() {}, nil
} }
addr, headers, err := GetRawAPI(ctx, repo.MarketsRepoType{}, "v0") addr, headers, err := GetRawAPI(ctx, repo.Markets, "v0")
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -356,7 +356,7 @@ func GetMarketsAPI(ctx *cli.Context) (api.StorageMiner, jsonrpc.ClientCloser, er
} }
func GetGatewayAPI(ctx *cli.Context) (api.Gateway, jsonrpc.ClientCloser, error) { func GetGatewayAPI(ctx *cli.Context) (api.Gateway, jsonrpc.ClientCloser, error) {
addr, headers, err := GetRawAPI(ctx, repo.FullNodeRepoType{}, "v1") addr, headers, err := GetRawAPI(ctx, repo.FullNode, "v1")
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -369,7 +369,7 @@ func GetGatewayAPI(ctx *cli.Context) (api.Gateway, jsonrpc.ClientCloser, error)
} }
func GetGatewayAPIV0(ctx *cli.Context) (v0api.Gateway, jsonrpc.ClientCloser, error) { func GetGatewayAPIV0(ctx *cli.Context) (v0api.Gateway, jsonrpc.ClientCloser, error) {
addr, headers, err := GetRawAPI(ctx, repo.FullNodeRepoType{}, "v0") addr, headers, err := GetRawAPI(ctx, repo.FullNode, "v0")
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }

View File

@ -40,7 +40,7 @@ func TestWorkerKeyChange(t *testing.T) {
run := func(cmd *cli.Command, args ...string) error { run := func(cmd *cli.Command, args ...string) error {
app := cli.NewApp() app := cli.NewApp()
app.Metadata = map[string]interface{}{ app.Metadata = map[string]interface{}{
"repoType": repo.StorageMinerRepoType{}, "repoType": repo.StorageMiner,
"testnode-full": client1, "testnode-full": client1,
"testnode-storage": miner, "testnode-storage": miner,
} }

View File

@ -36,7 +36,7 @@ func TestMinerAllInfo(t *testing.T) {
run := func(t *testing.T) { run := func(t *testing.T) {
app := cli.NewApp() app := cli.NewApp()
app.Metadata = map[string]interface{}{ app.Metadata = map[string]interface{}{
"repoType": repo.StorageMinerRepoType{}, "repoType": repo.StorageMiner,
"testnode-full": client, "testnode-full": client,
"testnode-storage": miner, "testnode-storage": miner,
} }

View File

@ -9,6 +9,6 @@ import (
"github.com/filecoin-project/lotus/node/repo" "github.com/filecoin-project/lotus/node/repo"
) )
var backupCmd = lcli.BackupCmd(FlagMinerRepo, repo.StorageMinerRepoType{}, func(cctx *cli.Context) (lcli.BackupAPI, jsonrpc.ClientCloser, error) { var backupCmd = lcli.BackupCmd(FlagMinerRepo, repo.StorageMiner, func(cctx *cli.Context) (lcli.BackupAPI, jsonrpc.ClientCloser, error) {
return lcli.GetStorageMinerAPI(cctx) return lcli.GetStorageMinerAPI(cctx)
}) })

View File

@ -66,7 +66,7 @@ var configUpdateCmd = &cli.Command{
return xerrors.Errorf("repo not initialized") return xerrors.Errorf("repo not initialized")
} }
lr, err := r.LockRO(repo.StorageMinerRepoType{}) lr, err := r.LockRO(repo.StorageMiner)
if err != nil { if err != nil {
return xerrors.Errorf("locking repo: %w", err) return xerrors.Errorf("locking repo: %w", err)
} }

View File

@ -203,12 +203,12 @@ var initCmd = &cli.Command{
log.Info("Initializing repo") log.Info("Initializing repo")
if err := r.Init(repo.StorageMinerRepoType{}); err != nil { if err := r.Init(repo.StorageMiner); err != nil {
return err return err
} }
{ {
lr, err := r.Lock(repo.StorageMinerRepoType{}) lr, err := r.Lock(repo.StorageMiner)
if err != nil { if err != nil {
return err return err
} }
@ -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 { 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.StorageMinerRepoType{}) lr, err := r.Lock(repo.StorageMiner)
if err != nil { if err != nil {
return err return err
} }

View File

@ -159,11 +159,11 @@ func restore(ctx context.Context, cctx *cli.Context, targetPath string, strConfi
log.Info("Initializing repo") log.Info("Initializing repo")
if err := r.Init(repo.StorageMinerRepoType{}); err != nil { if err := r.Init(repo.StorageMiner); err != nil {
return err return err
} }
lr, err := r.Lock(repo.StorageMinerRepoType{}) lr, err := r.Lock(repo.StorageMiner)
if err != nil { if err != nil {
return err return err
} }

View File

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

View File

@ -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) return xerrors.Errorf("repo at '%s' is not initialized, run 'lotus-miner init' to set it up", minerRepoPath)
} }
lr, err := r.Lock(repo.StorageMinerRepoType{}) lr, err := r.Lock(repo.StorageMiner)
if err != nil { if err != nil {
return err return err
} }

View File

@ -108,7 +108,7 @@ func main() {
Commands: local, Commands: local,
} }
app.Setup() app.Setup()
app.Metadata["repoType"] = repo.WorkerRepoType{} app.Metadata["repoType"] = repo.Worker
if err := app.Run(os.Args); err != nil { if err := app.Run(os.Args); err != nil {
log.Warnf("%+v", err) log.Warnf("%+v", err)
@ -310,11 +310,11 @@ var runCmd = &cli.Command{
return err return err
} }
if !ok { if !ok {
if err := r.Init(repo.WorkerRepoType{}); err != nil { if err := r.Init(repo.Worker); err != nil {
return err return err
} }
lr, err := r.Lock(repo.WorkerRepoType{}) lr, err := r.Lock(repo.Worker)
if err != nil { if err != nil {
return err return err
} }
@ -359,7 +359,7 @@ var runCmd = &cli.Command{
} }
} }
lr, err := r.Lock(repo.WorkerRepoType{}) lr, err := r.Lock(repo.Worker)
if err != nil { if err != nil {
return err return err
} }
@ -397,7 +397,7 @@ var runCmd = &cli.Command{
} }
// Setup remote sector store // Setup remote sector store
sminfo, err := lcli.GetAPIInfo(cctx, repo.StorageMinerRepoType{}) sminfo, err := lcli.GetAPIInfo(cctx, repo.StorageMiner)
if err != nil { if err != nil {
return xerrors.Errorf("could not get api info: %w", err) return xerrors.Errorf("could not get api info: %w", err)
} }
@ -484,7 +484,7 @@ var runCmd = &cli.Command{
return xerrors.Errorf("setting api endpoint: %w", err) return xerrors.Errorf("setting api endpoint: %w", err)
} }
ainfo, err := lcli.GetAPIInfo(cctx, repo.StorageMinerRepoType{}) ainfo, err := lcli.GetAPIInfo(cctx, repo.StorageMiner)
if err != nil { if err != nil {
return xerrors.Errorf("could not get miner API info: %w", err) return xerrors.Errorf("could not get miner API info: %w", err)
} }

View File

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

View File

@ -67,7 +67,7 @@ var exportCarCmd = &cli.Command{
return xerrors.Errorf("lotus repo doesn't exist") return xerrors.Errorf("lotus repo doesn't exist")
} }
lr, err := r.Lock(repo.FullNodeRepoType{}) lr, err := r.Lock(repo.FullNode)
if err != nil { if err != nil {
return err return err
} }

View File

@ -59,7 +59,7 @@ var exportChainCmd = &cli.Command{
return xerrors.Errorf("lotus repo doesn't exist") return xerrors.Errorf("lotus repo doesn't exist")
} }
lr, err := r.Lock(repo.FullNodeRepoType{}) lr, err := r.Lock(repo.FullNode)
if err != nil { if err != nil {
return err return err
} }

View File

@ -35,7 +35,7 @@ var importCarCmd = &cli.Command{
return xerrors.Errorf("lotus repo doesn't exist") return xerrors.Errorf("lotus repo doesn't exist")
} }
lr, err := r.Lock(repo.FullNodeRepoType{}) lr, err := r.Lock(repo.FullNode)
if err != nil { if err != nil {
return err return err
} }
@ -112,7 +112,7 @@ var importObjectCmd = &cli.Command{
return xerrors.Errorf("lotus repo doesn't exist") return xerrors.Errorf("lotus repo doesn't exist")
} }
lr, err := r.Lock(repo.FullNodeRepoType{}) lr, err := r.Lock(repo.FullNode)
if err != nil { if err != nil {
return err return err
} }

View File

@ -183,7 +183,7 @@ var keyinfoImportCmd = &cli.Command{
return err return err
} }
lkrepo, err := fsrepo.Lock(repo.FullNodeRepoType{}) lkrepo, err := fsrepo.Lock(repo.FullNode)
if err != nil { if err != nil {
return err return err
} }

View File

@ -301,7 +301,7 @@ func openLockedRepo(path string) (repo.LockedRepo, error) {
} }
// Lock the repo // Lock the repo
lr, err := rpo.Lock(repo.StorageMinerRepoType{}) lr, err := rpo.Lock(repo.StorageMiner)
if err != nil { if err != nil {
return nil, xerrors.Errorf("locking repo %s: %w", path, err) return nil, xerrors.Errorf("locking repo %s: %w", path, err)
} }

View File

@ -47,7 +47,7 @@ var migrationsCmd = &cli.Command{
return err return err
} }
lkrepo, err := fsrepo.Lock(repo.FullNodeRepoType{}) lkrepo, err := fsrepo.Lock(repo.FullNode)
if err != nil { if err != nil {
return err return err
} }

View File

@ -54,7 +54,7 @@ var minerPeeridCmd = &cli.Command{
return err return err
} }
lkrepo, err := fsrepo.Lock(repo.FullNodeRepoType{}) lkrepo, err := fsrepo.Lock(repo.FullNode)
if err != nil { if err != nil {
return err return err
} }

View File

@ -50,7 +50,7 @@ var minerTypesCmd = &cli.Command{
return err return err
} }
lkrepo, err := fsrepo.Lock(repo.FullNodeRepoType{}) lkrepo, err := fsrepo.Lock(repo.FullNode)
if err != nil { if err != nil {
return err return err
} }

View File

@ -123,7 +123,7 @@ var stateTreePruneCmd = &cli.Command{
return err return err
} }
lkrepo, err := fsrepo.Lock(repo.FullNodeRepoType{}) lkrepo, err := fsrepo.Lock(repo.FullNode)
if err != nil { if err != nil {
return err return err
} }

View File

@ -36,9 +36,9 @@ var rpcCmd = &cli.Command{
Action: func(cctx *cli.Context) error { Action: func(cctx *cli.Context) error {
var rt repo.RepoType var rt repo.RepoType
if cctx.Bool("miner") { if cctx.Bool("miner") {
rt = repo.StorageMinerRepoType{} rt = repo.StorageMiner
} else { } else {
rt = repo.FullNodeRepoType{} rt = repo.FullNode
} }
addr, headers, err := lcli.GetRawAPI(cctx, rt, cctx.String("version")) addr, headers, err := lcli.GetRawAPI(cctx, rt, cctx.String("version"))
@ -125,7 +125,7 @@ var rpcCmd = &cli.Command{
return send(cctx.Args().Get(0), params) return send(cctx.Args().Get(0), params)
} }
cctx.App.Metadata["repoType"] = repo.FullNodeRepoType{} cctx.App.Metadata["repoType"] = repo.FullNode
if err := lcli.VersionCmd.Action(cctx); err != nil { if err := lcli.VersionCmd.Action(cctx); err != nil {
return err return err
} }

View File

@ -67,7 +67,7 @@ var splitstoreRollbackCmd = &cli.Command{
return xerrors.Errorf("lotus repo doesn't exist") return xerrors.Errorf("lotus repo doesn't exist")
} }
lr, err := r.Lock(repo.FullNodeRepoType{}) lr, err := r.Lock(repo.FullNode)
if err != nil { if err != nil {
return xerrors.Errorf("error locking repo: %w", err) return xerrors.Errorf("error locking repo: %w", err)
} }
@ -153,7 +153,7 @@ var splitstoreClearCmd = &cli.Command{
return xerrors.Errorf("lotus repo doesn't exist") return xerrors.Errorf("lotus repo doesn't exist")
} }
lr, err := r.Lock(repo.FullNodeRepoType{}) lr, err := r.Lock(repo.FullNode)
if err != nil { if err != nil {
return xerrors.Errorf("error locking repo: %w", err) return xerrors.Errorf("error locking repo: %w", err)
} }

View File

@ -53,7 +53,7 @@ var terminationsCmd = &cli.Command{
return err return err
} }
lkrepo, err := fsrepo.Lock(repo.FullNodeRepoType{}) lkrepo, err := fsrepo.Lock(repo.FullNode)
if err != nil { if err != nil {
return err return err
} }

View File

@ -41,7 +41,7 @@ func OpenNode(ctx context.Context, path string) (*Node, error) {
// NewNode constructs a new node from the given repo. // NewNode constructs a new node from the given repo.
func NewNode(ctx context.Context, r repo.Repo) (nd *Node, _err error) { func NewNode(ctx context.Context, r repo.Repo) (nd *Node, _err error) {
lr, err := r.Lock(repo.FullNodeRepoType{}) lr, err := r.Lock(repo.FullNode)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -278,7 +278,7 @@ func openRepo(cctx *cli.Context) (repo.LockedRepo, types.KeyStore, error) {
return nil, nil, err return nil, nil, err
} }
if !ok { if !ok {
if err := r.Init(repo.WorkerRepoType{}); err != nil { if err := r.Init(repo.Worker); err != nil {
return nil, nil, err return nil, nil, err
} }
} }

View File

@ -18,7 +18,7 @@ import (
"github.com/filecoin-project/lotus/node/repo" "github.com/filecoin-project/lotus/node/repo"
) )
var backupCmd = lcli.BackupCmd("repo", repo.FullNodeRepoType{}, func(cctx *cli.Context) (lcli.BackupAPI, jsonrpc.ClientCloser, error) { var backupCmd = lcli.BackupCmd("repo", repo.FullNode, func(cctx *cli.Context) (lcli.BackupAPI, jsonrpc.ClientCloser, error) {
return lcli.GetFullNodeAPI(cctx) return lcli.GetFullNodeAPI(cctx)
}) })
@ -39,7 +39,7 @@ func restore(cctx *cli.Context, r repo.Repo) error {
} }
defer f.Close() // nolint:errcheck defer f.Close() // nolint:errcheck
lr, err := r.Lock(repo.FullNodeRepoType{}) lr, err := r.Lock(repo.FullNode)
if err != nil { if err != nil {
return err return err
} }

View File

@ -66,7 +66,7 @@ var configUpdateCmd = &cli.Command{
return xerrors.Errorf("repo not initialized") return xerrors.Errorf("repo not initialized")
} }
lr, err := r.LockRO(repo.FullNodeRepoType{}) lr, err := r.LockRO(repo.FullNode)
if err != nil { if err != nil {
return xerrors.Errorf("locking repo: %w", err) return xerrors.Errorf("locking repo: %w", err)
} }

View File

@ -227,7 +227,7 @@ var DaemonCmd = &cli.Command{
r.SetConfigPath(cctx.String("config")) r.SetConfigPath(cctx.String("config"))
} }
err = r.Init(repo.FullNodeRepoType{}) err = r.Init(repo.FullNode)
if err != nil && err != repo.ErrRepoExists { if err != nil && err != repo.ErrRepoExists {
return xerrors.Errorf("repo init error: %w", err) return xerrors.Errorf("repo init error: %w", err)
} }
@ -462,7 +462,7 @@ func ImportChain(ctx context.Context, r repo.Repo, fname string, snapshot bool)
l = st.Size() l = st.Size()
} }
lr, err := r.Lock(repo.FullNodeRepoType{}) lr, err := r.Lock(repo.FullNode)
if err != nil { if err != nil {
return err return err
} }

View File

@ -106,7 +106,7 @@ func main() {
app.Setup() app.Setup()
app.Metadata["traceContext"] = ctx app.Metadata["traceContext"] = ctx
app.Metadata["repoType"] = repo.FullNodeRepoType{} app.Metadata["repoType"] = repo.FullNode
lcli.RunApp(app) lcli.RunApp(app)
} }

View File

@ -341,8 +341,8 @@ FIXME: This section needs to be clarified / corrected...I don't fully understand
At the end of the `Repo()` function we see two mutually exclusive configuration calls based on the `RepoType` (`node/repo/fsrepo.go`). At the end of the `Repo()` function we see two mutually exclusive configuration calls based on the `RepoType` (`node/repo/fsrepo.go`).
```Go ```Go
ApplyIf(isType(repo.FullNodeRepoType{}), ConfigFullNode(c)), ApplyIf(isType(repo.FullNode), ConfigFullNode(c)),
ApplyIf(isType(repo.StorageMinerRepoType{}), ConfigStorageMiner(c)), ApplyIf(isType(repo.StorageMiner), ConfigStorageMiner(c)),
``` ```
As we said, the repo fully identifies the node so a repo type is also a *node* type, in this case a full node or a miner. (FIXME: What is the difference between the two, does *full* imply miner?) In this case the `daemon` command will create a `FullNode`, this is specified in the command logic itself in `main.DaemonCmd()`, the `FsRepo` created (and passed to `node.Repo()`) will be initiated with that type (see `(*FsRepo).Init(t RepoType)`). As we said, the repo fully identifies the node so a repo type is also a *node* type, in this case a full node or a miner. (FIXME: What is the difference between the two, does *full* imply miner?) In this case the `daemon` command will create a `FullNode`, this is specified in the command logic itself in `main.DaemonCmd()`, the `FsRepo` created (and passed to `node.Repo()`) will be initiated with that type (see `(*FsRepo).Init(t RepoType)`).
@ -352,7 +352,7 @@ FIXME: Much of this might need to be subsumed into the p2p section
The `node.Online()` configuration function (`node/builder.go`) initializes components that involve connecting to, The `node.Online()` configuration function (`node/builder.go`) initializes components that involve connecting to,
or interacting with, the Filecoin network. These connections are managed through the libp2p stack (FIXME link to this section when it exists). or interacting with, the Filecoin network. These connections are managed through the libp2p stack (FIXME link to this section when it exists).
We discuss some of the components found in the full node type (that is, included in the `ApplyIf(isType(repo.FullNodeRepoType{}),` call). We discuss some of the components found in the full node type (that is, included in the `ApplyIf(isType(repo.FullNode),` call).
#### Chainstore #### Chainstore

View File

@ -73,8 +73,8 @@ func TestMoveShared(t *testing.T) {
openRepo := func(dir string) repo.LockedRepo { openRepo := func(dir string) repo.LockedRepo {
r, err := repo.NewFS(dir) r, err := repo.NewFS(dir)
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, r.Init(repo.WorkerRepoType{})) require.NoError(t, r.Init(repo.Worker))
lr, err := r.Lock(repo.WorkerRepoType{}) lr, err := r.Lock(repo.Worker)
require.NoError(t, err) require.NoError(t, err)
t.Cleanup(func() { t.Cleanup(func() {

View File

@ -146,7 +146,7 @@ func TestSimultanenousTransferLimit(t *testing.T) {
) )
runTest := func(t *testing.T) { runTest := func(t *testing.T) {
client, miner, ens := kit.EnsembleMinimal(t, kit.MockProofs(), kit.ConstructorOpts( client, miner, ens := kit.EnsembleMinimal(t, kit.MockProofs(), kit.ConstructorOpts(
node.ApplyIf(node.IsType(repo.StorageMinerRepoType{}), node.Override(new(dtypes.StagingGraphsync), modules.StagingGraphsync(graphsyncThrottle, 0, graphsyncThrottle))), node.ApplyIf(node.IsType(repo.StorageMiner), node.Override(new(dtypes.StagingGraphsync), modules.StagingGraphsync(graphsyncThrottle, 0, graphsyncThrottle))),
node.Override(new(dtypes.Graphsync), modules.Graphsync(graphsyncThrottle, graphsyncThrottle)), node.Override(new(dtypes.Graphsync), modules.Graphsync(graphsyncThrottle, graphsyncThrottle)),
)) ))
ens.InterconnectAll().BeginMining(250 * time.Millisecond) ens.InterconnectAll().BeginMining(250 * time.Millisecond)

View File

@ -443,7 +443,7 @@ func (n *Ensemble) Start() *Ensemble {
r := repo.NewMemory(nil) r := repo.NewMemory(nil)
lr, err := r.Lock(repo.StorageMinerRepoType{}) lr, err := r.Lock(repo.StorageMiner)
require.NoError(n.t, err) require.NoError(n.t, err)
c, err := lr.Config() c, err := lr.Config()

View File

@ -35,7 +35,7 @@ func TestDealsWithFinalizeEarly(t *testing.T) {
var blockTime = 50 * time.Millisecond var blockTime = 50 * time.Millisecond
client, miner, ens := kit.EnsembleMinimal(t, kit.ThroughRPC(), kit.ConstructorOpts( client, miner, ens := kit.EnsembleMinimal(t, kit.ThroughRPC(), kit.ConstructorOpts(
node.ApplyIf(node.IsType(repo.StorageMinerRepoType{}), node.Override(new(dtypes.GetSealingConfigFunc), func() (dtypes.GetSealingConfigFunc, error) { node.ApplyIf(node.IsType(repo.StorageMiner), node.Override(new(dtypes.GetSealingConfigFunc), func() (dtypes.GetSealingConfigFunc, error) {
return func() (sealiface.Config, error) { return func() (sealiface.Config, error) {
cf := config.DefaultStorageMiner() cf := config.DefaultStorageMiner()
cf.Sealing.FinalizeEarly = true cf.Sealing.FinalizeEarly = true

View File

@ -38,7 +38,7 @@ func TestMinerBalanceCollateral(t *testing.T) {
defer cancel() defer cancel()
opts := kit.ConstructorOpts( opts := kit.ConstructorOpts(
node.ApplyIf(node.IsType(repo.StorageMinerRepoType{}), node.Override(new(dtypes.GetSealingConfigFunc), func() (dtypes.GetSealingConfigFunc, error) { node.ApplyIf(node.IsType(repo.StorageMiner), node.Override(new(dtypes.GetSealingConfigFunc), func() (dtypes.GetSealingConfigFunc, error) {
return func() (sealiface.Config, error) { return func() (sealiface.Config, error) {
return sealiface.Config{ return sealiface.Config{
MaxWaitDealsSectors: 4, MaxWaitDealsSectors: 4,

View File

@ -227,12 +227,12 @@ func IsType(t repo.RepoType) func(s *Settings) bool {
return func(s *Settings) bool { return s.nodeType.Type() == t.Type() } return func(s *Settings) bool { return s.nodeType.Type() == t.Type() }
} }
func isFullOrLiteNode(s *Settings) bool { return s.nodeType.Type() == repo.FullNodeRepoType{}.Type() } func isFullOrLiteNode(s *Settings) bool { return s.nodeType.Type() == repo.FullNode.Type() }
func isFullNode(s *Settings) bool { func isFullNode(s *Settings) bool {
return s.nodeType.Type() == repo.FullNodeRepoType{}.Type() && !s.Lite return s.nodeType.Type() == repo.FullNode.Type() && !s.Lite
} }
func isLiteNode(s *Settings) bool { func isLiteNode(s *Settings) bool {
return s.nodeType.Type() == repo.FullNodeRepoType{}.Type() && s.Lite return s.nodeType.Type() == repo.FullNode.Type() && s.Lite
} }
func Base() Option { func Base() Option {
@ -245,7 +245,7 @@ func Base() Option {
LibP2P, LibP2P,
), ),
ApplyIf(isFullOrLiteNode, ChainNode), ApplyIf(isFullOrLiteNode, ChainNode),
ApplyIf(IsType(repo.StorageMinerRepoType{}), MinerNode), ApplyIf(IsType(repo.StorageMiner), MinerNode),
) )
} }
@ -318,8 +318,8 @@ func Repo(r repo.Repo) Option {
Override(new(*dtypes.APIAlg), modules.APISecret), Override(new(*dtypes.APIAlg), modules.APISecret),
ApplyIf(IsType(repo.FullNodeRepoType{}), ConfigFullNode(c)), ApplyIf(IsType(repo.FullNode), ConfigFullNode(c)),
ApplyIf(IsType(repo.StorageMinerRepoType{}), ConfigStorageMiner(c)), ApplyIf(IsType(repo.StorageMiner), ConfigStorageMiner(c)),
)(settings) )(settings)
} }
} }

View File

@ -248,7 +248,7 @@ func Lite(enable bool) FullOption {
func FullAPI(out *api.FullNode, fopts ...FullOption) Option { func FullAPI(out *api.FullNode, fopts ...FullOption) Option {
return Options( return Options(
func(s *Settings) error { func(s *Settings) error {
s.nodeType = repo.FullNodeRepoType{} s.nodeType = repo.FullNode
s.enableLibp2pNode = true s.enableLibp2pNode = true
return nil return nil
}, },

View File

@ -221,7 +221,7 @@ func StorageMiner(out *api.StorageMiner, subsystemsCfg config.MinerSubsystemConf
), ),
func(s *Settings) error { func(s *Settings) error {
s.nodeType = repo.StorageMinerRepoType{} s.nodeType = repo.StorageMiner
s.enableLibp2pNode = subsystemsCfg.EnableMarkets s.enableLibp2pNode = subsystemsCfg.EnableMarkets
return nil return nil
}, },

View File

@ -44,11 +44,11 @@ const (
func NewRepoTypeFromString(t string) RepoType { func NewRepoTypeFromString(t string) RepoType {
switch t { switch t {
case "FullNode": case "FullNode":
return FullNodeRepoType{} return FullNode
case "StorageMiner": case "StorageMiner":
return StorageMinerRepoType{} return StorageMiner
case "Worker": case "Worker":
return WorkerRepoType{} return Worker
case "Wallet": case "Wallet":
return WalletRepoType{} return WalletRepoType{}
default: default:
@ -61,47 +61,55 @@ type RepoType interface {
Config() interface{} Config() interface{}
} }
type FullNodeRepoType struct { var FullNode fullNode
type fullNode struct {
} }
func (f FullNodeRepoType) Type() string { func (f fullNode) Type() string {
return "FullNode" return "FullNode"
} }
func (f FullNodeRepoType) Config() interface{} { func (f fullNode) Config() interface{} {
return config.DefaultFullNode() return config.DefaultFullNode()
} }
type StorageMinerRepoType struct { var StorageMiner storageMiner
type storageMiner struct {
} }
func (f StorageMinerRepoType) Type() string { func (f storageMiner) Type() string {
return "StorageMiner" return "StorageMiner"
} }
func (f StorageMinerRepoType) Config() interface{} { func (f storageMiner) Config() interface{} {
return config.DefaultStorageMiner() return config.DefaultStorageMiner()
} }
type MarketsRepoType struct { var Markets markets
type markets struct {
} }
func (f MarketsRepoType) Type() string { func (f markets) Type() string {
return "Markets" return "Markets"
} }
func (f MarketsRepoType) Config() interface{} { func (f markets) Config() interface{} {
return config.DefaultStorageMiner() return config.DefaultStorageMiner()
} }
type WorkerRepoType struct { type worker struct {
} }
func (f WorkerRepoType) Type() string { var Worker worker
func (f worker) Type() string {
return "Worker" return "Worker"
} }
func (f WorkerRepoType) Config() interface{} { func (f worker) Config() interface{} {
return &struct{}{} return &struct{}{}
} }

View File

@ -18,7 +18,7 @@ func genFsRepo(t *testing.T) (*FsRepo, func()) {
t.Fatal(err) t.Fatal(err)
} }
err = repo.Init(FullNodeRepoType{}) err = repo.Init(FullNode)
if err != ErrRepoExists && err != nil { if err != ErrRepoExists && err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -21,12 +21,12 @@ func basicTest(t *testing.T, repo Repo) {
} }
assert.Nil(t, apima, "with no api endpoint, return should be nil") assert.Nil(t, apima, "with no api endpoint, return should be nil")
lrepo, err := repo.Lock(FullNodeRepoType{}) lrepo, err := repo.Lock(FullNode)
assert.NoError(t, err, "should be able to lock once") assert.NoError(t, err, "should be able to lock once")
assert.NotNil(t, lrepo, "locked repo shouldn't be nil") assert.NotNil(t, lrepo, "locked repo shouldn't be nil")
{ {
lrepo2, err := repo.Lock(FullNodeRepoType{}) lrepo2, err := repo.Lock(FullNode)
if assert.Error(t, err) { if assert.Error(t, err) {
assert.Equal(t, ErrRepoAlreadyLocked, err) assert.Equal(t, ErrRepoAlreadyLocked, err)
} }
@ -36,7 +36,7 @@ func basicTest(t *testing.T, repo Repo) {
err = lrepo.Close() err = lrepo.Close()
assert.NoError(t, err, "should be able to unlock") assert.NoError(t, err, "should be able to unlock")
lrepo, err = repo.Lock(FullNodeRepoType{}) lrepo, err = repo.Lock(FullNode)
assert.NoError(t, err, "should be able to relock") assert.NoError(t, err, "should be able to relock")
assert.NotNil(t, lrepo, "locked repo shouldn't be nil") assert.NotNil(t, lrepo, "locked repo shouldn't be nil")
@ -80,7 +80,7 @@ func basicTest(t *testing.T, repo Repo) {
k1 := types.KeyInfo{Type: "foo"} k1 := types.KeyInfo{Type: "foo"}
k2 := types.KeyInfo{Type: "bar"} k2 := types.KeyInfo{Type: "bar"}
lrepo, err = repo.Lock(FullNodeRepoType{}) lrepo, err = repo.Lock(FullNode)
assert.NoError(t, err, "should be able to relock") assert.NoError(t, err, "should be able to relock")
assert.NotNil(t, lrepo, "locked repo shouldn't be nil") assert.NotNil(t, lrepo, "locked repo shouldn't be nil")

View File

@ -138,7 +138,7 @@ func PrepareMiner(t *TestEnvironment) (*LotusMiner, error) {
return nil, err return nil, err
} }
err = minerRepo.Init(repo.StorageMinerRepoType{}) err = minerRepo.Init(repo.StorageMiner)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -146,7 +146,7 @@ func PrepareMiner(t *TestEnvironment) (*LotusMiner, error) {
var subsystems config.MinerSubsystemConfig var subsystems config.MinerSubsystemConfig
{ {
lr, err := minerRepo.Lock(repo.StorageMinerRepoType{}) lr, err := minerRepo.Lock(repo.StorageMiner)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -244,7 +244,7 @@ func PrepareMiner(t *TestEnvironment) (*LotusMiner, error) {
return nil, err return nil, err
} }
err = nodeRepo.Init(repo.FullNodeRepoType{}) err = nodeRepo.Init(repo.FullNode)
if err != nil { if err != nil {
return nil, err return nil, err
} }