can we store it? YES WE CAN
This commit is contained in:
parent
f1432826d5
commit
4fb4835b35
@ -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)
|
||||
}
|
||||
|
@ -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{}
|
||||
|
@ -21,6 +21,7 @@ func main() {
|
||||
local := []*cli.Command{
|
||||
runCmd,
|
||||
initCmd,
|
||||
storeGarbageCmd,
|
||||
}
|
||||
jaeger := tracing.SetupJaegerTracing("lotus")
|
||||
defer func() {
|
||||
|
@ -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
|
||||
},
|
||||
}
|
||||
|
@ -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),
|
||||
),
|
||||
)
|
||||
|
@ -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{}
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user