2019-07-24 01:13:56 +00:00
|
|
|
package impl
|
2019-07-24 00:58:31 +00:00
|
|
|
|
|
|
|
import (
|
2019-07-27 01:54:03 +00:00
|
|
|
"context"
|
2019-07-27 21:08:10 +00:00
|
|
|
"fmt"
|
2019-08-10 01:54:45 +00:00
|
|
|
"github.com/filecoin-project/go-lotus/chain/address"
|
2019-07-27 01:54:03 +00:00
|
|
|
"io/ioutil"
|
2019-07-27 21:08:10 +00:00
|
|
|
"math/rand"
|
2019-07-27 01:54:03 +00:00
|
|
|
|
2019-07-24 00:58:31 +00:00
|
|
|
"github.com/filecoin-project/go-lotus/api"
|
2019-07-27 00:45:27 +00:00
|
|
|
"github.com/filecoin-project/go-lotus/lib/sectorbuilder"
|
2019-07-30 00:46:56 +00:00
|
|
|
"github.com/filecoin-project/go-lotus/storage"
|
2019-07-24 00:58:31 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type StorageMinerAPI struct {
|
|
|
|
CommonAPI
|
2019-07-27 00:45:27 +00:00
|
|
|
|
2019-08-10 01:54:45 +00:00
|
|
|
SectorBuilderConfig *sectorbuilder.SectorBuilderConfig
|
|
|
|
SectorBuilder *sectorbuilder.SectorBuilder
|
2019-07-30 00:46:56 +00:00
|
|
|
|
|
|
|
Miner *storage.Miner
|
2019-07-24 00:58:31 +00:00
|
|
|
}
|
|
|
|
|
2019-08-10 01:54:45 +00:00
|
|
|
func (sm *StorageMinerAPI) ActorAddresses(context.Context) ([]address.Address, error) {
|
|
|
|
return []address.Address{sm.SectorBuilderConfig.Miner}, nil
|
|
|
|
}
|
|
|
|
|
2019-07-27 01:54:03 +00:00
|
|
|
func (sm *StorageMinerAPI) StoreGarbageData(ctx context.Context) (uint64, error) {
|
2019-07-27 21:08:10 +00:00
|
|
|
maxSize := uint64(1016) // this is the most data we can fit in a 1024 byte sector
|
|
|
|
data := make([]byte, maxSize)
|
2019-07-27 01:54:03 +00:00
|
|
|
fi, err := ioutil.TempFile("", "lotus-garbage")
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, err := fi.Write(data); err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
fi.Close()
|
|
|
|
|
2019-07-27 21:08:10 +00:00
|
|
|
name := fmt.Sprintf("fake-file-%d", rand.Intn(100000000))
|
|
|
|
sectorId, err := sm.SectorBuilder.AddPiece(name, maxSize, fi.Name())
|
2019-07-27 01:54:03 +00:00
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return sectorId, err
|
|
|
|
}
|
|
|
|
|
2019-07-27 21:08:10 +00:00
|
|
|
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()
|
|
|
|
}
|
|
|
|
|
2019-07-24 00:58:31 +00:00
|
|
|
var _ api.StorageMiner = &StorageMinerAPI{}
|