Wire up sector builder commands through the api

This commit is contained in:
whyrusleeping
2019-07-29 12:08:47 -07:00
parent 26232f0b9a
commit b83ff6b9dc
8 changed files with 183 additions and 27 deletions
+20 -2
View File
@@ -2,7 +2,9 @@ package impl
import (
"context"
"fmt"
"io/ioutil"
"math/rand"
"github.com/filecoin-project/go-lotus/api"
"github.com/filecoin-project/go-lotus/lib/sectorbuilder"
@@ -15,7 +17,8 @@ type StorageMinerAPI struct {
}
func (sm *StorageMinerAPI) StoreGarbageData(ctx context.Context) (uint64, error) {
data := make([]byte, 1024)
maxSize := uint64(1016) // this is the most data we can fit in a 1024 byte sector
data := make([]byte, maxSize)
fi, err := ioutil.TempFile("", "lotus-garbage")
if err != nil {
return 0, err
@@ -26,7 +29,8 @@ func (sm *StorageMinerAPI) StoreGarbageData(ctx context.Context) (uint64, error)
}
fi.Close()
sectorId, err := sm.SectorBuilder.AddPiece("foo", 1024, fi.Name())
name := fmt.Sprintf("fake-file-%d", rand.Intn(100000000))
sectorId, err := sm.SectorBuilder.AddPiece(name, maxSize, fi.Name())
if err != nil {
return 0, err
}
@@ -34,4 +38,18 @@ func (sm *StorageMinerAPI) StoreGarbageData(ctx context.Context) (uint64, error)
return sectorId, err
}
func (sm *StorageMinerAPI) SectorsStatus(ctx context.Context, sid uint64) (sectorbuilder.SectorSealingStatus, error) {
return sm.SectorBuilder.SealStatus(sid)
}
// List all staged sectors
func (sm *StorageMinerAPI) SectorsStagedList(context.Context) ([]sectorbuilder.StagedSectorMetadata, error) {
return sm.SectorBuilder.GetAllStagedSectors()
}
// Seal all staged sectors
func (sm *StorageMinerAPI) SectorsStagedSeal(context.Context) error {
return sm.SectorBuilder.SealAllStagedSectors()
}
var _ api.StorageMiner = &StorageMinerAPI{}
+9 -3
View File
@@ -26,6 +26,7 @@ import (
"github.com/libp2p/go-libp2p-core/peerstore"
"github.com/libp2p/go-libp2p-core/routing"
record "github.com/libp2p/go-libp2p-record"
"github.com/mitchellh/go-homedir"
"go.uber.org/fx"
"golang.org/x/xerrors"
@@ -221,9 +222,14 @@ func LoadGenesis(genBytes []byte) func(blockstore.Blockstore) Genesis {
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")
sp, err := homedir.Expand(storagePath)
if err != nil {
return nil, err
}
metadata := filepath.Join(sp, "meta")
sealed := filepath.Join(sp, "sealed")
staging := filepath.Join(sp, "staging")
// TODO: get the address of the miner actor
minerAddr, err := address.NewIDAddress(42)