storageminer: Init with default local storage

This commit is contained in:
Łukasz Magiera
2020-03-05 02:12:52 +01:00
parent 7db1dd52bd
commit c91d970c41
4 changed files with 51 additions and 13 deletions
+1 -1
View File
@@ -145,7 +145,7 @@ func PreSeal(maddr address.Address, pt abi.RegisteredProof, offset abi.SectorNum
return nil, nil, xerrors.Errorf("marshaling storage config: %w", err)
}
if err := ioutil.WriteFile(filepath.Join(sbroot, "storage.json"), b, 0644); err != nil {
if err := ioutil.WriteFile(filepath.Join(sbroot, "sectorstore.json"), b, 0644); err != nil {
return nil, nil, xerrors.Errorf("persisting storage metadata (%s): %w", filepath.Join(sbroot, "storage.json"), err)
}
}
+40 -10
View File
@@ -8,6 +8,7 @@ import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strconv"
"github.com/filecoin-project/go-sectorbuilder"
@@ -16,6 +17,7 @@ import (
miner2 "github.com/filecoin-project/specs-actors/actors/builtin/miner"
"github.com/filecoin-project/specs-actors/actors/builtin/power"
crypto2 "github.com/filecoin-project/specs-actors/actors/crypto"
"github.com/google/uuid"
"github.com/filecoin-project/go-address"
cborutil "github.com/filecoin-project/go-cbor-util"
@@ -91,6 +93,10 @@ var initCmd = &cli.Command{
Name: "symlink-imported-sectors",
Usage: "attempt to symlink to presealed sectors instead of copying them into place",
},
&cli.BoolFlag{
Name: "no-local-storage",
Usage: "don't use storageminer repo for sector storage",
},
},
Action: func(cctx *cli.Context) error {
log.Info("Initializing lotus storage miner")
@@ -157,25 +163,48 @@ var initCmd = &cli.Command{
return err
}
if pssb := cctx.StringSlice("pre-sealed-sectors"); len(pssb) != 0 {
log.Infof("Setting up storage config with presealed sector", pssb)
{
lr, err := r.Lock(repo.StorageMiner)
if err != nil {
return err
}
var sc config.StorageConfig
for _, psp := range pssb {
psp, err := homedir.Expand(psp)
if err != nil {
return err
if pssb := cctx.StringSlice("pre-sealed-sectors"); len(pssb) != 0 {
log.Infof("Setting up storage config with presealed sector", pssb)
for _, psp := range pssb {
psp, err := homedir.Expand(psp)
if err != nil {
return err
}
sc.StoragePaths = append(sc.StoragePaths, config.LocalPath{
Path: psp,
})
}
sc.StoragePaths = append(sc.StoragePaths, config.LocalPath{
Path: psp,
})
}
if !cctx.Bool("no-local-storage") {
b, err := json.MarshalIndent(&config.StorageMeta{
ID: uuid.New().String(),
Weight: 10,
CanSeal: true,
CanStore: true,
}, "", " ")
if err != nil {
return xerrors.Errorf("marshaling storage config: %w", err)
}
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)
}
}
sc.StoragePaths = append(sc.StoragePaths, config.LocalPath{
Path: lr.Path(),
})
if err := lr.SetStorage(sc); err != nil {
return xerrors.Errorf("set storage config: %w", err)
}
@@ -185,6 +214,7 @@ var initCmd = &cli.Command{
}
}
if err := storageMinerInit(ctx, cctx, api, r, ssize); err != nil {
log.Errorf("Failed to initialize lotus-storage-miner: %+v", err)
path, err := homedir.Expand(repoPath)