Wire up sector builder commands through the api
This commit is contained in:
parent
26232f0b9a
commit
b83ff6b9dc
10
api/api.go
10
api/api.go
@ -11,6 +11,7 @@ import (
|
|||||||
"github.com/filecoin-project/go-lotus/chain/store"
|
"github.com/filecoin-project/go-lotus/chain/store"
|
||||||
"github.com/filecoin-project/go-lotus/chain/types"
|
"github.com/filecoin-project/go-lotus/chain/types"
|
||||||
|
|
||||||
|
sectorbuilder "github.com/filecoin-project/go-sectorbuilder"
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
"github.com/ipfs/go-filestore"
|
"github.com/ipfs/go-filestore"
|
||||||
)
|
)
|
||||||
@ -118,4 +119,13 @@ type StorageMiner interface {
|
|||||||
|
|
||||||
// Temp api for testing
|
// Temp api for testing
|
||||||
StoreGarbageData(context.Context) (uint64, error)
|
StoreGarbageData(context.Context) (uint64, error)
|
||||||
|
|
||||||
|
// Get the status of a given sector by ID
|
||||||
|
SectorsStatus(context.Context, uint64) (sectorbuilder.SectorSealingStatus, error)
|
||||||
|
|
||||||
|
// List all staged sectors
|
||||||
|
SectorsStagedList(context.Context) ([]sectorbuilder.StagedSectorMetadata, error)
|
||||||
|
|
||||||
|
// Seal all staged sectors
|
||||||
|
SectorsStagedSeal(context.Context) error
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/filecoin-project/go-lotus/chain/address"
|
"github.com/filecoin-project/go-lotus/chain/address"
|
||||||
"github.com/filecoin-project/go-lotus/chain/store"
|
"github.com/filecoin-project/go-lotus/chain/store"
|
||||||
"github.com/filecoin-project/go-lotus/chain/types"
|
"github.com/filecoin-project/go-lotus/chain/types"
|
||||||
|
sectorbuilder "github.com/filecoin-project/go-sectorbuilder"
|
||||||
|
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
"github.com/libp2p/go-libp2p-core/peer"
|
"github.com/libp2p/go-libp2p-core/peer"
|
||||||
@ -69,6 +70,10 @@ type StorageMinerStruct struct {
|
|||||||
|
|
||||||
Internal struct {
|
Internal struct {
|
||||||
StoreGarbageData func(context.Context) (uint64, error) `perm:"write"`
|
StoreGarbageData func(context.Context) (uint64, error) `perm:"write"`
|
||||||
|
|
||||||
|
SectorsStatus func(context.Context, uint64) (sectorbuilder.SectorSealingStatus, error) `perm:"read"`
|
||||||
|
SectorsStagedList func(context.Context) ([]sectorbuilder.StagedSectorMetadata, error) `perm:"read"`
|
||||||
|
SectorsStagedSeal func(context.Context) error `perm:"write"`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,6 +195,21 @@ func (c *StorageMinerStruct) StoreGarbageData(ctx context.Context) (uint64, erro
|
|||||||
return c.Internal.StoreGarbageData(ctx)
|
return c.Internal.StoreGarbageData(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the status of a given sector by ID
|
||||||
|
func (c *StorageMinerStruct) SectorsStatus(ctx context.Context, sid uint64) (sectorbuilder.SectorSealingStatus, error) {
|
||||||
|
return c.Internal.SectorsStatus(ctx, sid)
|
||||||
|
}
|
||||||
|
|
||||||
|
// List all staged sectors
|
||||||
|
func (c *StorageMinerStruct) SectorsStagedList(ctx context.Context) ([]sectorbuilder.StagedSectorMetadata, error) {
|
||||||
|
return c.Internal.SectorsStagedList(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Seal all staged sectors
|
||||||
|
func (c *StorageMinerStruct) SectorsStagedSeal(ctx context.Context) error {
|
||||||
|
return c.Internal.SectorsStagedSeal(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
var _ Common = &CommonStruct{}
|
var _ Common = &CommonStruct{}
|
||||||
var _ FullNode = &FullNodeStruct{}
|
var _ FullNode = &FullNodeStruct{}
|
||||||
var _ StorageMiner = &StorageMinerStruct{}
|
var _ StorageMiner = &StorageMinerStruct{}
|
||||||
|
@ -22,6 +22,7 @@ func main() {
|
|||||||
runCmd,
|
runCmd,
|
||||||
initCmd,
|
initCmd,
|
||||||
storeGarbageCmd,
|
storeGarbageCmd,
|
||||||
|
sectorsCmd,
|
||||||
}
|
}
|
||||||
jaeger := tracing.SetupJaegerTracing("lotus")
|
jaeger := tracing.SetupJaegerTracing("lotus")
|
||||||
defer func() {
|
defer func() {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
@ -96,23 +95,3 @@ var runCmd = &cli.Command{
|
|||||||
return http.ListenAndServe("127.0.0.1:"+cctx.String("api"), http.DefaultServeMux)
|
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.GetStorageMinerAPI(cctx)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
ctx := lcli.ReqContext(cctx)
|
|
||||||
|
|
||||||
sectorId, err := nodeApi.StoreGarbageData(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Println(sectorId)
|
|
||||||
return nil
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
112
cmd/lotus-storage-miner/sectors.go
Normal file
112
cmd/lotus-storage-miner/sectors.go
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"gopkg.in/urfave/cli.v2"
|
||||||
|
|
||||||
|
lcli "github.com/filecoin-project/go-lotus/cli"
|
||||||
|
)
|
||||||
|
|
||||||
|
var storeGarbageCmd = &cli.Command{
|
||||||
|
Name: "store-garbage",
|
||||||
|
Usage: "store random data in a sector",
|
||||||
|
Action: func(cctx *cli.Context) error {
|
||||||
|
nodeApi, err := lcli.GetStorageMinerAPI(cctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
ctx := lcli.ReqContext(cctx)
|
||||||
|
|
||||||
|
sectorId, err := nodeApi.StoreGarbageData(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println(sectorId)
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var sectorsCmd = &cli.Command{
|
||||||
|
Name: "sectors",
|
||||||
|
Usage: "interact with sector store",
|
||||||
|
Subcommands: []*cli.Command{
|
||||||
|
sectorsStatusCmd,
|
||||||
|
sectorsStagedListCmd,
|
||||||
|
sectorsStagedSealCmd,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var sectorsStatusCmd = &cli.Command{
|
||||||
|
Name: "status",
|
||||||
|
Usage: "Get the seal status of a sector by its ID",
|
||||||
|
Action: func(cctx *cli.Context) error {
|
||||||
|
nodeApi, err := lcli.GetStorageMinerAPI(cctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
ctx := lcli.ReqContext(cctx)
|
||||||
|
|
||||||
|
if !cctx.Args().Present() {
|
||||||
|
return fmt.Errorf("must specify sector ID to get status of")
|
||||||
|
}
|
||||||
|
|
||||||
|
id, err := strconv.ParseUint(cctx.Args().First(), 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
status, err := nodeApi.SectorsStatus(ctx, id)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("SectorID:\t%d\n", status.SectorID)
|
||||||
|
fmt.Printf("SealStatusCode:\t%d\n", status.SealStatusCode)
|
||||||
|
fmt.Printf("SealErrorMsg:\t%q\n", status.SealErrorMsg)
|
||||||
|
fmt.Printf("CommD:\t\t%x\n", status.CommD)
|
||||||
|
fmt.Printf("CommR:\t\t%x\n", status.CommR)
|
||||||
|
fmt.Printf("CommR*:\t\t%x\n", status.CommRStar)
|
||||||
|
fmt.Printf("Proof:\t\t%x\n", status.Proof)
|
||||||
|
fmt.Printf("Pieces:\t\t%s\n", status.Pieces)
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var sectorsStagedListCmd = &cli.Command{
|
||||||
|
Name: "list-staged", // TODO: nest this under a 'staged' subcommand? idk
|
||||||
|
Usage: "List staged sectors",
|
||||||
|
Action: func(cctx *cli.Context) error {
|
||||||
|
nodeApi, err := lcli.GetStorageMinerAPI(cctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
ctx := lcli.ReqContext(cctx)
|
||||||
|
|
||||||
|
staged, err := nodeApi.SectorsStagedList(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, s := range staged {
|
||||||
|
fmt.Println(s)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var sectorsStagedSealCmd = &cli.Command{
|
||||||
|
Name: "seal-staged", // TODO: nest this under a 'staged' subcommand? idk
|
||||||
|
Usage: "Seal staged sectors",
|
||||||
|
Action: func(cctx *cli.Context) error {
|
||||||
|
nodeApi, err := lcli.GetStorageMinerAPI(cctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
ctx := lcli.ReqContext(cctx)
|
||||||
|
|
||||||
|
return nodeApi.SectorsStagedSeal(ctx)
|
||||||
|
},
|
||||||
|
}
|
@ -7,6 +7,10 @@ import (
|
|||||||
sectorbuilder "github.com/filecoin-project/go-sectorbuilder"
|
sectorbuilder "github.com/filecoin-project/go-sectorbuilder"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type SectorSealingStatus = sectorbuilder.SectorSealingStatus
|
||||||
|
|
||||||
|
type StagedSectorMetadata = sectorbuilder.StagedSectorMetadata
|
||||||
|
|
||||||
const CommLen = sectorbuilder.CommitmentBytesLen
|
const CommLen = sectorbuilder.CommitmentBytesLen
|
||||||
|
|
||||||
type SectorBuilder struct {
|
type SectorBuilder struct {
|
||||||
@ -52,16 +56,22 @@ func (sb *SectorBuilder) SealAllStagedSectors() error {
|
|||||||
return sectorbuilder.SealAllStagedSectors(sb.handle)
|
return sectorbuilder.SealAllStagedSectors(sb.handle)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sb *SectorBuilder) SealStatus(sector uint64) (sectorbuilder.SectorSealingStatus, error) {
|
func (sb *SectorBuilder) SealStatus(sector uint64) (SectorSealingStatus, error) {
|
||||||
return sectorbuilder.GetSectorSealingStatusByID(sb.handle, sector)
|
return sectorbuilder.GetSectorSealingStatusByID(sb.handle, sector)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (sb *SectorBuilder) GetAllStagedSectors() ([]StagedSectorMetadata, error) {
|
||||||
|
return sectorbuilder.GetAllStagedSectors(sb.handle)
|
||||||
|
}
|
||||||
|
|
||||||
func (sb *SectorBuilder) GeneratePoSt(sortedCommRs [][CommLen]byte, challengeSeed [CommLen]byte) ([][]byte, []uint64, error) {
|
func (sb *SectorBuilder) GeneratePoSt(sortedCommRs [][CommLen]byte, challengeSeed [CommLen]byte) ([][]byte, []uint64, error) {
|
||||||
// Wait, this is a blocking method with no way of interrupting it?
|
// Wait, this is a blocking method with no way of interrupting it?
|
||||||
// does it checkpoint itself?
|
// does it checkpoint itself?
|
||||||
return sectorbuilder.GeneratePoSt(sb.handle, sortedCommRs, challengeSeed)
|
return sectorbuilder.GeneratePoSt(sb.handle, sortedCommRs, challengeSeed)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var UserBytesForSectorSize = sectorbuilder.GetMaxUserBytesPerStagedSector
|
||||||
|
|
||||||
func VerifySeal(sectorSize uint64, commR, commD, commRStar [CommLen]byte, proverID address.Address, sectorID uint64, proof []byte) (bool, error) {
|
func VerifySeal(sectorSize uint64, commR, commD, commRStar [CommLen]byte, proverID address.Address, sectorID uint64, proof []byte) (bool, error) {
|
||||||
panic("TODO")
|
panic("TODO")
|
||||||
// return sectorbuilder.VerifySeal(sectorSize, commR, commD, commRStar, providerID, sectorID, proof)
|
// return sectorbuilder.VerifySeal(sectorSize, commR, commD, commRStar, providerID, sectorID, proof)
|
||||||
|
@ -2,7 +2,9 @@ package impl
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"math/rand"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-lotus/api"
|
"github.com/filecoin-project/go-lotus/api"
|
||||||
"github.com/filecoin-project/go-lotus/lib/sectorbuilder"
|
"github.com/filecoin-project/go-lotus/lib/sectorbuilder"
|
||||||
@ -15,7 +17,8 @@ type StorageMinerAPI struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (sm *StorageMinerAPI) StoreGarbageData(ctx context.Context) (uint64, error) {
|
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")
|
fi, err := ioutil.TempFile("", "lotus-garbage")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
@ -26,7 +29,8 @@ func (sm *StorageMinerAPI) StoreGarbageData(ctx context.Context) (uint64, error)
|
|||||||
}
|
}
|
||||||
fi.Close()
|
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 {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
@ -34,4 +38,18 @@ func (sm *StorageMinerAPI) StoreGarbageData(ctx context.Context) (uint64, error)
|
|||||||
return sectorId, err
|
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{}
|
var _ api.StorageMiner = &StorageMinerAPI{}
|
||||||
|
@ -26,6 +26,7 @@ import (
|
|||||||
"github.com/libp2p/go-libp2p-core/peerstore"
|
"github.com/libp2p/go-libp2p-core/peerstore"
|
||||||
"github.com/libp2p/go-libp2p-core/routing"
|
"github.com/libp2p/go-libp2p-core/routing"
|
||||||
record "github.com/libp2p/go-libp2p-record"
|
record "github.com/libp2p/go-libp2p-record"
|
||||||
|
"github.com/mitchellh/go-homedir"
|
||||||
"go.uber.org/fx"
|
"go.uber.org/fx"
|
||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
@ -221,9 +222,14 @@ func LoadGenesis(genBytes []byte) func(blockstore.Blockstore) Genesis {
|
|||||||
|
|
||||||
func SectorBuilderConfig(storagePath string) func() (*sectorbuilder.SectorBuilderConfig, error) {
|
func SectorBuilderConfig(storagePath string) func() (*sectorbuilder.SectorBuilderConfig, error) {
|
||||||
return func() (*sectorbuilder.SectorBuilderConfig, error) {
|
return func() (*sectorbuilder.SectorBuilderConfig, error) {
|
||||||
metadata := filepath.Join(storagePath, "meta")
|
sp, err := homedir.Expand(storagePath)
|
||||||
sealed := filepath.Join(storagePath, "sealed")
|
if err != nil {
|
||||||
staging := filepath.Join(storagePath, "staging")
|
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
|
// TODO: get the address of the miner actor
|
||||||
minerAddr, err := address.NewIDAddress(42)
|
minerAddr, err := address.NewIDAddress(42)
|
||||||
|
Loading…
Reference in New Issue
Block a user