start integrating sector builder
This commit is contained in:
parent
f80050307c
commit
f1432826d5
1
go.mod
1
go.mod
@ -7,6 +7,7 @@ require (
|
||||
github.com/BurntSushi/toml v0.3.1
|
||||
github.com/filecoin-project/go-bls-sigs v0.0.0-20190718224239-4bc4b8a7bbf8
|
||||
github.com/filecoin-project/go-leb128 v0.0.0-20190212224330-8d79a5489543
|
||||
github.com/filecoin-project/go-sectorbuilder v0.0.0-00010101000000-000000000000
|
||||
github.com/gbrlsnchs/jwt/v3 v3.0.0-beta.1
|
||||
github.com/gorilla/websocket v1.4.0
|
||||
github.com/ipfs/go-bitswap v0.1.5
|
||||
|
73
lib/sectorbuilder/sectorbuilder.go
Normal file
73
lib/sectorbuilder/sectorbuilder.go
Normal file
@ -0,0 +1,73 @@
|
||||
package sectorbuilder
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/filecoin-project/go-lotus/chain/address"
|
||||
sectorbuilder "github.com/filecoin-project/go-sectorbuilder"
|
||||
)
|
||||
|
||||
const CommLen = sectorbuilder.CommitmentBytesLen
|
||||
|
||||
type SectorBuilder struct {
|
||||
handle unsafe.Pointer
|
||||
}
|
||||
|
||||
type SectorBuilderConfig struct {
|
||||
SectorSize uint64
|
||||
Miner address.Address
|
||||
SealedDir string
|
||||
StagedDir string
|
||||
MetadataDir string
|
||||
}
|
||||
|
||||
func New(cfg *SectorBuilderConfig) (*SectorBuilder, error) {
|
||||
var proverId [31]byte
|
||||
copy(proverId[:], cfg.Miner.Payload())
|
||||
|
||||
sbp, err := sectorbuilder.InitSectorBuilder(cfg.SectorSize, 2, 2, 1, cfg.MetadataDir, [31]byte{}, cfg.SealedDir, cfg.StagedDir, 16)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &SectorBuilder{
|
||||
handle: sbp,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (sb *SectorBuilder) Destroy() {
|
||||
sectorbuilder.DestroySectorBuilder(sb.handle)
|
||||
}
|
||||
|
||||
func (sb *SectorBuilder) AddPiece(pieceKey string, pieceSize uint64, piecePath string) (uint64, error) {
|
||||
return sectorbuilder.AddPiece(sb.handle, pieceKey, pieceSize, piecePath)
|
||||
}
|
||||
|
||||
// TODO: should *really really* return an io.ReadCloser
|
||||
func (sb *SectorBuilder) ReadPieceFromSealedSector(pieceKey string) ([]byte, error) {
|
||||
return sectorbuilder.ReadPieceFromSealedSector(sb.handle, pieceKey)
|
||||
}
|
||||
|
||||
func (sb *SectorBuilder) SealAllStagedSectors() error {
|
||||
return sectorbuilder.SealAllStagedSectors(sb.handle)
|
||||
}
|
||||
|
||||
func (sb *SectorBuilder) SealStatus(sector uint64) (sectorbuilder.SectorSealingStatus, error) {
|
||||
return sectorbuilder.GetSectorSealingStatusByID(sb.handle, sector)
|
||||
}
|
||||
|
||||
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?
|
||||
// does it checkpoint itself?
|
||||
return sectorbuilder.GeneratePoSt(sb.handle, sortedCommRs, challengeSeed)
|
||||
}
|
||||
|
||||
func VerifySeal(sectorSize uint64, commR, commD, commRStar [CommLen]byte, proverID address.Address, sectorID uint64, proof []byte) (bool, error) {
|
||||
panic("TODO")
|
||||
// return sectorbuilder.VerifySeal(sectorSize, commR, commD, commRStar, providerID, sectorID, proof)
|
||||
}
|
||||
|
||||
func VerifyPost(sectorSize uint64, sortedCommRs [][CommLen]byte, challengeSeed [CommLen]byte, proofs [][]byte, faults []uint64) (bool, error) {
|
||||
// sectorbuilder.VerifyPost()
|
||||
panic("no")
|
||||
}
|
@ -28,6 +28,7 @@ import (
|
||||
"github.com/filecoin-project/go-lotus/chain/store"
|
||||
"github.com/filecoin-project/go-lotus/chain/types"
|
||||
"github.com/filecoin-project/go-lotus/chain/wallet"
|
||||
"github.com/filecoin-project/go-lotus/lib/sectorbuilder"
|
||||
"github.com/filecoin-project/go-lotus/node/config"
|
||||
"github.com/filecoin-project/go-lotus/node/hello"
|
||||
"github.com/filecoin-project/go-lotus/node/impl"
|
||||
@ -246,6 +247,11 @@ func Config(cfg *config.Root) Option {
|
||||
ApplyIf(func(s *Settings) bool { return s.Online },
|
||||
Override(StartListeningKey, lp2p.StartListening(cfg.Libp2p.ListenAddresses)),
|
||||
),
|
||||
|
||||
ApplyIf(func(s *Settings) bool { return s.nodeType == nodeStorageMiner },
|
||||
Override(new(*sectorbuilder.SectorBuilderConfig), modules.SectorBuilderConfig),
|
||||
Override(new(*sectorbuilder.SectorBuilder), sectorbuilder.New),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -2,10 +2,13 @@ package impl
|
||||
|
||||
import (
|
||||
"github.com/filecoin-project/go-lotus/api"
|
||||
"github.com/filecoin-project/go-lotus/lib/sectorbuilder"
|
||||
)
|
||||
|
||||
type StorageMinerAPI struct {
|
||||
CommonAPI
|
||||
|
||||
SectorBuilder *sectorbuilder.SectorBuilder
|
||||
}
|
||||
|
||||
var _ api.StorageMiner = &StorageMinerAPI{}
|
||||
|
@ -30,8 +30,10 @@ import (
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/filecoin-project/go-lotus/api"
|
||||
"github.com/filecoin-project/go-lotus/chain/address"
|
||||
"github.com/filecoin-project/go-lotus/chain/store"
|
||||
"github.com/filecoin-project/go-lotus/chain/types"
|
||||
"github.com/filecoin-project/go-lotus/lib/sectorbuilder"
|
||||
"github.com/filecoin-project/go-lotus/node/modules/helpers"
|
||||
"github.com/filecoin-project/go-lotus/node/repo"
|
||||
)
|
||||
@ -216,3 +218,23 @@ 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")
|
||||
|
||||
// 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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user