From 4b576cde50b3f768be1735ea1673358c8e95dccb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Mon, 9 Mar 2020 06:56:32 +0100 Subject: [PATCH 1/5] storagemgr: Actually set updated config in AddLocalStorage --- storage/sealmgr/advmgr/manager.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/storage/sealmgr/advmgr/manager.go b/storage/sealmgr/advmgr/manager.go index 675a6ffe1..9a7bb63c1 100644 --- a/storage/sealmgr/advmgr/manager.go +++ b/storage/sealmgr/advmgr/manager.go @@ -96,12 +96,18 @@ func (m *Manager) AddLocalStorage(path string) error { return xerrors.Errorf("opening local path: %w", err) } + // TODO: Locks! + sc, err := m.storage.localStorage.GetStorage() if err != nil { return xerrors.Errorf("get storage config: %w", err) } sc.StoragePaths = append(sc.StoragePaths, config.LocalPath{Path: path}) + + if err := m.storage.localStorage.SetStorage(sc); err != nil { + return xerrors.Errorf("get storage config: %w", err) + } return nil } From c87ebe85905e91acfc0e21544efd6fc5fab4af20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Mon, 9 Mar 2020 07:13:22 +0100 Subject: [PATCH 2/5] storageminer: storage attach cmd --- cmd/lotus-storage-miner/init.go | 2 +- cmd/lotus-storage-miner/main.go | 1 + cmd/lotus-storage-miner/storage.go | 99 ++++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 cmd/lotus-storage-miner/storage.go diff --git a/cmd/lotus-storage-miner/init.go b/cmd/lotus-storage-miner/init.go index 03537d820..280123707 100644 --- a/cmd/lotus-storage-miner/init.go +++ b/cmd/lotus-storage-miner/init.go @@ -198,7 +198,7 @@ var initCmd = &cli.Command{ } if err := ioutil.WriteFile(filepath.Join(lr.Path(), "sectorstore.json"), b, 0644); err != nil { - return xerrors.Errorf("persisting storage metadata (%s): %w", filepath.Join(lr.Path(), "storage.json"), err) + return xerrors.Errorf("persisting storage metadata (%s): %w", filepath.Join(lr.Path(), "sectorstore.json"), err) } } diff --git a/cmd/lotus-storage-miner/main.go b/cmd/lotus-storage-miner/main.go index 8399268ea..4549332e0 100644 --- a/cmd/lotus-storage-miner/main.go +++ b/cmd/lotus-storage-miner/main.go @@ -29,6 +29,7 @@ func main() { rewardsCmd, runCmd, sectorsCmd, + storageCmd, setPriceCmd, } jaeger := tracing.SetupJaegerTracing("lotus") diff --git a/cmd/lotus-storage-miner/storage.go b/cmd/lotus-storage-miner/storage.go new file mode 100644 index 000000000..22ea2c214 --- /dev/null +++ b/cmd/lotus-storage-miner/storage.go @@ -0,0 +1,99 @@ +package main + +import ( + "encoding/json" + "io/ioutil" + "os" + "path/filepath" + + "github.com/google/uuid" + "github.com/mitchellh/go-homedir" + "golang.org/x/xerrors" + "gopkg.in/urfave/cli.v2" + + lcli "github.com/filecoin-project/lotus/cli" + "github.com/filecoin-project/lotus/node/config" +) + +const metaFile = "sectorstore.json" + +var storageCmd = &cli.Command{ + Name: "storage", + Usage: "manage sector storage", + Subcommands: []*cli.Command{ + storageAttachCmd, + }, +} + +var storageAttachCmd = &cli.Command{ + Name: "attach", + Usage: "attach local storage path", + Flags: []cli.Flag{ + &cli.BoolFlag{ + Name: "init", + Usage: "initialize the path first", + }, + &cli.Uint64Flag{ + Name: "weight", + Usage: "(for init) path weight", + Value: 10, + }, + &cli.BoolFlag{ + Name: "seal", + Usage: "(for init) use path for sealing", + }, + &cli.BoolFlag{ + Name: "store", + Usage: "(for init) use path for long-term storage", + }, + }, + Action: func(cctx *cli.Context) error { + nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + if err != nil { + return err + } + defer closer() + ctx := lcli.ReqContext(cctx) + + if !cctx.Args().Present() { + return xerrors.Errorf("must specify storage path to attach") + } + + p, err := homedir.Expand(cctx.Args().First()) + if err != nil { + return xerrors.Errorf("expanding path: %w", err) + } + + if cctx.Bool("init") { + _, err := os.Stat(filepath.Join(p, metaFile)) + if !os.IsNotExist(err) { + if err == nil { + return xerrors.Errorf("path is already initialized") + } + return err + } + + cfg := &config.StorageMeta{ + ID: uuid.New().String(), + Weight: cctx.Uint64("weight"), + CanSeal: cctx.Bool("seal"), + CanStore: cctx.Bool("store"), + } + + if !(cfg.CanStore || cfg.CanSeal) { + return xerrors.Errorf("must specify at least one of --store of --seal") + } + + b, err := json.MarshalIndent(cfg, "", " ") + if err != nil { + return xerrors.Errorf("marshaling storage config: %w", err) + } + + if err := ioutil.WriteFile(filepath.Join(p, metaFile), b, 0644); err != nil { + return xerrors.Errorf("persisting storage metadata (%s): %w", filepath.Join(p, metaFile), err) + } + } + + return nodeApi.StorageAddLocal(ctx, p) + }, +} From 33fcf8eb4419b12fe433b77300fba4b6e29e67cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Mon, 9 Mar 2020 07:13:45 +0100 Subject: [PATCH 3/5] gofmt, mod tidy --- api/apistruct/struct.go | 4 ++-- cmd/lotus-storage-miner/storage.go | 8 ++++---- go.sum | 2 -- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/api/apistruct/struct.go b/api/apistruct/struct.go index 430f131e4..5e260473c 100644 --- a/api/apistruct/struct.go +++ b/api/apistruct/struct.go @@ -93,14 +93,14 @@ type FullNodeStruct struct { WalletExport func(context.Context, address.Address) (*types.KeyInfo, error) `perm:"admin"` WalletImport func(context.Context, *types.KeyInfo) (address.Address, error) `perm:"admin"` - ClientImport func(ctx context.Context, ref api.FileRef) (cid.Cid, error) `perm:"admin"` + ClientImport func(ctx context.Context, ref api.FileRef) (cid.Cid, error) `perm:"admin"` ClientListImports func(ctx context.Context) ([]api.Import, error) `perm:"write"` ClientHasLocal func(ctx context.Context, root cid.Cid) (bool, error) `perm:"write"` ClientFindData func(ctx context.Context, root cid.Cid) ([]api.QueryOffer, error) `perm:"read"` ClientStartDeal func(ctx context.Context, params *api.StartDealParams) (*cid.Cid, error) `perm:"admin"` ClientGetDealInfo func(context.Context, cid.Cid) (*api.DealInfo, error) `perm:"read"` ClientListDeals func(ctx context.Context) ([]api.DealInfo, error) `perm:"write"` - ClientRetrieve func(ctx context.Context, order api.RetrievalOrder, ref api.FileRef) error `perm:"admin"` + ClientRetrieve func(ctx context.Context, order api.RetrievalOrder, ref api.FileRef) error `perm:"admin"` ClientQueryAsk func(ctx context.Context, p peer.ID, miner address.Address) (*storagemarket.SignedStorageAsk, error) `perm:"read"` StateMinerSectors func(context.Context, address.Address, types.TipSetKey) ([]*api.ChainSectorInfo, error) `perm:"read"` diff --git a/cmd/lotus-storage-miner/storage.go b/cmd/lotus-storage-miner/storage.go index 22ea2c214..59d0a169f 100644 --- a/cmd/lotus-storage-miner/storage.go +++ b/cmd/lotus-storage-miner/storage.go @@ -30,20 +30,20 @@ var storageAttachCmd = &cli.Command{ Usage: "attach local storage path", Flags: []cli.Flag{ &cli.BoolFlag{ - Name: "init", + Name: "init", Usage: "initialize the path first", }, &cli.Uint64Flag{ - Name: "weight", + Name: "weight", Usage: "(for init) path weight", Value: 10, }, &cli.BoolFlag{ - Name: "seal", + Name: "seal", Usage: "(for init) use path for sealing", }, &cli.BoolFlag{ - Name: "store", + Name: "store", Usage: "(for init) use path for long-term storage", }, }, diff --git a/go.sum b/go.sum index 4cb5a6d96..abdafc182 100644 --- a/go.sum +++ b/go.sum @@ -120,8 +120,6 @@ github.com/filecoin-project/go-padreader v0.0.0-20200210211231-548257017ca6/go.m github.com/filecoin-project/go-paramfetch v0.0.2-0.20200218225740-47c639bab663 h1:eYxi6vI5CyeXD15X1bB3bledDXbqKxqf0wQzTLgwYwA= github.com/filecoin-project/go-paramfetch v0.0.2-0.20200218225740-47c639bab663/go.mod h1:fZzmf4tftbwf9S37XRifoJlz7nCjRdIrMGLR07dKLCc= github.com/filecoin-project/go-sectorbuilder v0.0.2-0.20200226210935-4739f8749f56/go.mod h1:tzTc9BxxSbjlIzhFwm5h9oBkXKkRuLxeiWspntwnKyw= -github.com/filecoin-project/go-sectorbuilder v0.0.2-0.20200306043753-5cdbe369b47d h1:tRS0QB50rhUaetohnt3GwKNGk28WOhkdniHvP461HXc= -github.com/filecoin-project/go-sectorbuilder v0.0.2-0.20200306043753-5cdbe369b47d/go.mod h1:NcE+iL0bbYnamGmYQgCPVGbSaf8VF2/CLra/61B3I3I= github.com/filecoin-project/go-sectorbuilder v0.0.2-0.20200306215829-15085af52c2b h1:/08Z7ZXHt1qRGz1Ipd0suMgJOmuind8MDwG9va+OPz0= github.com/filecoin-project/go-sectorbuilder v0.0.2-0.20200306215829-15085af52c2b/go.mod h1:NcE+iL0bbYnamGmYQgCPVGbSaf8VF2/CLra/61B3I3I= github.com/filecoin-project/go-statemachine v0.0.0-20200226041606-2074af6d51d9 h1:k9qVR9ItcziSB2rxtlkN/MDWNlbsI6yzec+zjUatLW0= From 1cf26fc652c096077f39e76ef519170319dd8e9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Mon, 9 Mar 2020 07:21:42 +0100 Subject: [PATCH 4/5] repo: Implement memrepo.SetStorage --- node/repo/memrepo.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/node/repo/memrepo.go b/node/repo/memrepo.go index 919c09376..ae5d3be65 100644 --- a/node/repo/memrepo.go +++ b/node/repo/memrepo.go @@ -40,16 +40,22 @@ type lockedMemRepo struct { tempDir string token *byte + sc *config.StorageConfig } func (lmem *lockedMemRepo) GetStorage() (config.StorageConfig, error) { - return config.StorageConfig{StoragePaths: []config.LocalPath{ - {Path: lmem.Path()}, - }}, nil + if lmem.sc == nil { + lmem.sc = &config.StorageConfig{StoragePaths: []config.LocalPath{ + {Path: lmem.Path()}, + }} + } + + return *lmem.sc, nil } -func (lmem *lockedMemRepo) SetStorage(config.StorageConfig) error { - panic("implement me") +func (lmem *lockedMemRepo) SetStorage(sc config.StorageConfig) error { + lmem.sc = &sc + return nil } func (lmem *lockedMemRepo) Path() string { From 0b14ab80003acb6e75b19f0823c12d7310b464d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Mon, 9 Mar 2020 07:27:07 +0100 Subject: [PATCH 5/5] fountain: Fix miner wait page title --- cmd/lotus-fountain/site/wait.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/lotus-fountain/site/wait.html b/cmd/lotus-fountain/site/wait.html index 97ac4795d..ea2d64236 100644 --- a/cmd/lotus-fountain/site/wait.html +++ b/cmd/lotus-fountain/site/wait.html @@ -1,7 +1,7 @@ - Sending Funds - Lotus Fountain + Creating Storage Miner (wait) - Lotus Fountain