diff --git a/api/api.go b/api/api.go index 5d46ef5fa..598777695 100644 --- a/api/api.go +++ b/api/api.go @@ -115,4 +115,7 @@ type FullNode interface { // Full API is a low-level interface to the Filecoin network storage miner node type StorageMiner interface { Common + + // Temp api for testing + StoreGarbageData(context.Context) (uint64, error) } diff --git a/api/struct.go b/api/struct.go index 430619d44..8f24bc272 100644 --- a/api/struct.go +++ b/api/struct.go @@ -68,6 +68,7 @@ type StorageMinerStruct struct { CommonStruct Internal struct { + StoreGarbageData func(context.Context) (uint64, error) } } @@ -185,6 +186,10 @@ func (c *FullNodeStruct) ChainNotify(ctx context.Context) (<-chan *store.HeadCha return c.Internal.ChainNotify(ctx) } +func (c *StorageMinerStruct) StoreGarbageData(ctx context.Context) (uint64, error) { + return c.Internal.StoreGarbageData(ctx) +} + var _ Common = &CommonStruct{} var _ FullNode = &FullNodeStruct{} var _ StorageMiner = &StorageMinerStruct{} diff --git a/cmd/lotus-storage-miner/main.go b/cmd/lotus-storage-miner/main.go index 390b50a37..10142d3f8 100644 --- a/cmd/lotus-storage-miner/main.go +++ b/cmd/lotus-storage-miner/main.go @@ -21,6 +21,7 @@ func main() { local := []*cli.Command{ runCmd, initCmd, + storeGarbageCmd, } jaeger := tracing.SetupJaegerTracing("lotus") defer func() { diff --git a/cmd/lotus-storage-miner/run.go b/cmd/lotus-storage-miner/run.go index 42a26eb23..6919d44b2 100644 --- a/cmd/lotus-storage-miner/run.go +++ b/cmd/lotus-storage-miner/run.go @@ -11,7 +11,9 @@ import ( lcli "github.com/filecoin-project/go-lotus/cli" "github.com/filecoin-project/go-lotus/lib/auth" "github.com/filecoin-project/go-lotus/lib/jsonrpc" + "github.com/filecoin-project/go-lotus/lib/sectorbuilder" "github.com/filecoin-project/go-lotus/node" + "github.com/filecoin-project/go-lotus/node/modules" "github.com/filecoin-project/go-lotus/node/repo" ) @@ -36,7 +38,8 @@ var runCmd = &cli.Command{ return err } - r, err := repo.NewFS(cctx.String(FlagStorageRepo)) + storageRepoPath := cctx.String(FlagStorageRepo) + r, err := repo.NewFS(storageRepoPath) if err != nil { return err } @@ -46,7 +49,7 @@ var runCmd = &cli.Command{ return err } if !ok { - return xerrors.Errorf("repo at '%s' is not initialized, run 'lotus-storage-miner init' to set it up", cctx.String(FlagStorageRepo)) + return xerrors.Errorf("repo at '%s' is not initialized, run 'lotus-storage-miner init' to set it up", storageRepoPath) } var minerapi api.StorageMiner @@ -62,6 +65,7 @@ var runCmd = &cli.Command{ } return lr.SetAPIEndpoint(apima) }), + node.Override(new(*sectorbuilder.SectorBuilderConfig), modules.SectorBuilderConfig(storageRepoPath)), ) if err != nil { return err @@ -83,3 +87,21 @@ var runCmd = &cli.Command{ return http.ListenAndServe("127.0.0.1:"+cctx.String("api"), http.DefaultServeMux) }, } + +var storeGarbageCmd = &cli.Command{ + Name: "store-garbage", + Usage: "store random data in a sector", + Action: func(cctx *cli.Context) error { + nodeApi, err := lcli.GetAPI(cctx) + if err != nil { + return err + } + ctx := lcli.ReqContext(cctx) + + _ = ctx + _ = nodeApi + // ??? + // wait a second, i need the api handler for the storage miner... + return nil + }, +} diff --git a/node/builder.go b/node/builder.go index c8c61dc3b..191a340c6 100644 --- a/node/builder.go +++ b/node/builder.go @@ -249,7 +249,6 @@ func Config(cfg *config.Root) Option { ), ApplyIf(func(s *Settings) bool { return s.nodeType == nodeStorageMiner }, - Override(new(*sectorbuilder.SectorBuilderConfig), modules.SectorBuilderConfig), Override(new(*sectorbuilder.SectorBuilder), sectorbuilder.New), ), ) diff --git a/node/impl/storminer.go b/node/impl/storminer.go index dfaad454c..cd41b2531 100644 --- a/node/impl/storminer.go +++ b/node/impl/storminer.go @@ -1,6 +1,9 @@ package impl import ( + "context" + "io/ioutil" + "github.com/filecoin-project/go-lotus/api" "github.com/filecoin-project/go-lotus/lib/sectorbuilder" ) @@ -11,4 +14,24 @@ type StorageMinerAPI struct { SectorBuilder *sectorbuilder.SectorBuilder } +func (sm *StorageMinerAPI) StoreGarbageData(ctx context.Context) (uint64, error) { + data := make([]byte, 1024) + fi, err := ioutil.TempFile("", "lotus-garbage") + if err != nil { + return 0, err + } + + if _, err := fi.Write(data); err != nil { + return 0, err + } + fi.Close() + + sectorId, err := sm.SectorBuilder.AddPiece("foo", 1024, fi.Name()) + if err != nil { + return 0, err + } + + return sectorId, err +} + var _ api.StorageMiner = &StorageMinerAPI{} diff --git a/node/modules/core.go b/node/modules/core.go index 8892e9b7d..b6678d46a 100644 --- a/node/modules/core.go +++ b/node/modules/core.go @@ -219,22 +219,24 @@ func LoadGenesis(genBytes []byte) func(blockstore.Blockstore) Genesis { } } -func SectorBuilderConfig(storagePath string) (*sectorbuilder.SectorBuilderConfig, error) { - metadata := filepath.Join(storagePath, "meta") - sealed := filepath.Join(storagePath, "sealed") - staging := filepath.Join(storagePath, "staging") +func SectorBuilderConfig(storagePath string) func() (*sectorbuilder.SectorBuilderConfig, error) { + return func() (*sectorbuilder.SectorBuilderConfig, error) { + metadata := filepath.Join(storagePath, "meta") + sealed := filepath.Join(storagePath, "sealed") + staging := filepath.Join(storagePath, "staging") - // TODO: get the address of the miner actor - minerAddr, err := address.NewIDAddress(42) - if err != nil { - return nil, err + // TODO: get the address of the miner actor + minerAddr, err := address.NewIDAddress(42) + if err != nil { + return nil, err + } + + return §orbuilder.SectorBuilderConfig{ + Miner: minerAddr, + SectorSize: 1024, + MetadataDir: metadata, + SealedDir: sealed, + StagedDir: staging, + }, nil } - - return §orbuilder.SectorBuilderConfig{ - Miner: minerAddr, - SectorSize: 1024, - MetadataDir: metadata, - SealedDir: sealed, - StagedDir: staging, - }, nil }