2020-09-06 16:47:16 +00:00
|
|
|
package storiface
|
2020-09-06 16:54:00 +00:00
|
|
|
|
2022-06-17 11:31:05 +00:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"io"
|
2022-08-31 11:56:25 +00:00
|
|
|
"net/http"
|
2021-12-03 11:33:23 +00:00
|
|
|
|
2022-06-17 11:31:05 +00:00
|
|
|
"github.com/ipfs/go-cid"
|
2020-09-06 16:54:00 +00:00
|
|
|
|
2022-06-17 11:31:05 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
|
|
|
"github.com/filecoin-project/go-state-types/proof"
|
2020-09-06 16:54:00 +00:00
|
|
|
)
|
|
|
|
|
2022-06-17 11:31:05 +00:00
|
|
|
type Data = io.Reader
|
2020-09-06 16:54:00 +00:00
|
|
|
|
2022-06-17 11:31:05 +00:00
|
|
|
type SectorRef struct {
|
|
|
|
ID abi.SectorID
|
|
|
|
ProofType abi.RegisteredSealProof
|
|
|
|
}
|
|
|
|
|
|
|
|
var NoSectorRef = SectorRef{}
|
|
|
|
|
2022-06-17 11:52:19 +00:00
|
|
|
type ProverPoSt interface {
|
2022-06-17 11:31:05 +00:00
|
|
|
GenerateWinningPoSt(ctx context.Context, minerID abi.ActorID, sectorInfo []proof.ExtendedSectorInfo, randomness abi.PoStRandomness) ([]proof.PoStProof, error)
|
2023-04-05 19:25:16 +00:00
|
|
|
GenerateWindowPoSt(ctx context.Context, minerID abi.ActorID, ppt abi.RegisteredPoStProof, sectorInfo []proof.ExtendedSectorInfo, randomness abi.PoStRandomness) (proof []proof.PoStProof, skipped []abi.SectorID, err error)
|
2022-06-17 11:31:05 +00:00
|
|
|
|
|
|
|
GenerateWinningPoStWithVanilla(ctx context.Context, proofType abi.RegisteredPoStProof, minerID abi.ActorID, randomness abi.PoStRandomness, proofs [][]byte) ([]proof.PoStProof, error)
|
|
|
|
GenerateWindowPoStWithVanilla(ctx context.Context, proofType abi.RegisteredPoStProof, minerID abi.ActorID, randomness abi.PoStRandomness, proofs [][]byte, partitionIdx int) (proof.PoStProof, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
type PreCommit1Out []byte
|
|
|
|
|
|
|
|
type Commit1Out []byte
|
|
|
|
|
|
|
|
type Proof []byte
|
2021-12-03 11:33:23 +00:00
|
|
|
|
2022-06-17 11:31:05 +00:00
|
|
|
type SectorCids struct {
|
|
|
|
Unsealed cid.Cid
|
|
|
|
Sealed cid.Cid
|
2021-12-03 11:33:23 +00:00
|
|
|
}
|
|
|
|
|
2022-06-17 11:31:05 +00:00
|
|
|
type Range struct {
|
|
|
|
Offset abi.UnpaddedPieceSize
|
|
|
|
Size abi.UnpaddedPieceSize
|
2021-12-03 11:33:23 +00:00
|
|
|
}
|
|
|
|
|
2022-06-17 11:31:05 +00:00
|
|
|
type ReplicaUpdateProof []byte
|
|
|
|
type ReplicaVanillaProofs [][]byte
|
|
|
|
|
|
|
|
type ReplicaUpdateOut struct {
|
|
|
|
NewSealed cid.Cid
|
|
|
|
NewUnsealed cid.Cid
|
|
|
|
}
|
|
|
|
|
|
|
|
type Sealer interface {
|
2022-06-17 11:52:19 +00:00
|
|
|
NewSector(ctx context.Context, sector SectorRef) error
|
|
|
|
DataCid(ctx context.Context, pieceSize abi.UnpaddedPieceSize, pieceData Data) (abi.PieceInfo, error)
|
|
|
|
AddPiece(ctx context.Context, sector SectorRef, pieceSizes []abi.UnpaddedPieceSize, newPieceSize abi.UnpaddedPieceSize, pieceData Data) (abi.PieceInfo, error)
|
|
|
|
|
2022-06-17 11:31:05 +00:00
|
|
|
SealPreCommit1(ctx context.Context, sector SectorRef, ticket abi.SealRandomness, pieces []abi.PieceInfo) (PreCommit1Out, error)
|
|
|
|
SealPreCommit2(ctx context.Context, sector SectorRef, pc1o PreCommit1Out) (SectorCids, error)
|
|
|
|
|
|
|
|
SealCommit1(ctx context.Context, sector SectorRef, ticket abi.SealRandomness, seed abi.InteractiveSealRandomness, pieces []abi.PieceInfo, cids SectorCids) (Commit1Out, error)
|
|
|
|
SealCommit2(ctx context.Context, sector SectorRef, c1o Commit1Out) (Proof, error)
|
|
|
|
|
2022-11-16 16:07:42 +00:00
|
|
|
FinalizeSector(ctx context.Context, sector SectorRef) error
|
2022-06-17 11:31:05 +00:00
|
|
|
|
|
|
|
// ReleaseUnsealed marks parts of the unsealed sector file as safe to drop
|
|
|
|
// (called by the fsm on restart, allows storage to keep no persistent
|
|
|
|
// state about unsealed fast-retrieval copies)
|
2022-11-16 16:07:42 +00:00
|
|
|
ReleaseUnsealed(ctx context.Context, sector SectorRef, keepUnsealed []Range) error
|
2022-11-15 15:16:03 +00:00
|
|
|
// ReleaseSectorKey removes `sealed` from all storage
|
|
|
|
// called after successful sector upgrade
|
2022-06-17 11:31:05 +00:00
|
|
|
ReleaseSectorKey(ctx context.Context, sector SectorRef) error
|
2022-11-15 15:16:03 +00:00
|
|
|
// ReleaseReplicaUpgrade removes `update` / `update-cache` from all storage
|
|
|
|
// called when aborting sector upgrade
|
2022-06-17 11:31:05 +00:00
|
|
|
ReleaseReplicaUpgrade(ctx context.Context, sector SectorRef) error
|
|
|
|
|
|
|
|
// Removes all data associated with the specified sector
|
|
|
|
Remove(ctx context.Context, sector SectorRef) error
|
|
|
|
|
|
|
|
// Generate snap deals replica update
|
|
|
|
ReplicaUpdate(ctx context.Context, sector SectorRef, pieces []abi.PieceInfo) (ReplicaUpdateOut, error)
|
|
|
|
|
|
|
|
// Prove that snap deals replica was done correctly
|
|
|
|
ProveReplicaUpdate1(ctx context.Context, sector SectorRef, sectorKey, newSealed, newUnsealed cid.Cid) (ReplicaVanillaProofs, error)
|
|
|
|
ProveReplicaUpdate2(ctx context.Context, sector SectorRef, sectorKey, newSealed, newUnsealed cid.Cid, vanillaProofs ReplicaVanillaProofs) (ReplicaUpdateProof, error)
|
|
|
|
|
|
|
|
// GenerateSectorKeyFromData computes sector key given unsealed data and updated replica
|
|
|
|
GenerateSectorKeyFromData(ctx context.Context, sector SectorRef, unsealed cid.Cid) error
|
|
|
|
|
2022-11-16 16:07:42 +00:00
|
|
|
FinalizeReplicaUpdate(ctx context.Context, sector SectorRef) error
|
2022-08-31 11:56:25 +00:00
|
|
|
|
2022-09-16 21:45:23 +00:00
|
|
|
DownloadSectorData(ctx context.Context, sector SectorRef, finalized bool, src map[SectorFileType]SectorLocation) error
|
2021-12-03 11:33:23 +00:00
|
|
|
}
|
2022-06-17 11:52:19 +00:00
|
|
|
|
|
|
|
type Unsealer interface {
|
|
|
|
UnsealPiece(ctx context.Context, sector SectorRef, offset UnpaddedByteIndex, size abi.UnpaddedPieceSize, randomness abi.SealRandomness, commd cid.Cid) error
|
|
|
|
ReadPiece(ctx context.Context, writer io.Writer, sector SectorRef, offset UnpaddedByteIndex, size abi.UnpaddedPieceSize) (bool, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
type Storage interface {
|
|
|
|
ProverPoSt
|
|
|
|
Sealer
|
|
|
|
Unsealer
|
|
|
|
}
|
|
|
|
|
|
|
|
type Validator interface {
|
|
|
|
CanCommit(sector SectorPaths) (bool, error)
|
|
|
|
CanProve(sector SectorPaths) (bool, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
type Verifier interface {
|
|
|
|
VerifySeal(proof.SealVerifyInfo) (bool, error)
|
|
|
|
VerifyAggregateSeals(aggregate proof.AggregateSealVerifyProofAndInfos) (bool, error)
|
|
|
|
VerifyReplicaUpdate(update proof.ReplicaUpdateInfo) (bool, error)
|
|
|
|
VerifyWinningPoSt(ctx context.Context, info proof.WinningPoStVerifyInfo) (bool, error)
|
|
|
|
VerifyWindowPoSt(ctx context.Context, info proof.WindowPoStVerifyInfo) (bool, error)
|
|
|
|
|
|
|
|
GenerateWinningPoStSectorChallenge(context.Context, abi.RegisteredPoStProof, abi.ActorID, abi.PoStRandomness, uint64) ([]uint64, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prover contains cheap proving-related methods
|
|
|
|
type Prover interface {
|
|
|
|
// TODO: move GenerateWinningPoStSectorChallenge from the Verifier interface to here
|
|
|
|
|
|
|
|
AggregateSealProofs(aggregateInfo proof.AggregateSealVerifyProofAndInfos, proofs [][]byte) ([]byte, error)
|
|
|
|
}
|
2022-08-31 11:56:25 +00:00
|
|
|
|
2022-09-16 21:45:23 +00:00
|
|
|
type SectorLocation struct {
|
2022-08-31 11:56:25 +00:00
|
|
|
// Local when set to true indicates to lotus that sector data is already
|
|
|
|
// available locally; When set lotus will skip fetching sector data, and
|
|
|
|
// only check that sector data exists in sector storage
|
|
|
|
Local bool
|
|
|
|
|
|
|
|
// URL to the sector data
|
|
|
|
// For sealed/unsealed sector, lotus expects octet-stream
|
2022-09-09 11:31:03 +00:00
|
|
|
// For cache, lotus expects a tar archive with cache files
|
2022-08-31 11:56:25 +00:00
|
|
|
// Valid schemas:
|
|
|
|
// - http:// / https://
|
|
|
|
URL string
|
|
|
|
|
|
|
|
// optional http headers to use when requesting sector data
|
2022-09-02 15:12:58 +00:00
|
|
|
Headers []SecDataHttpHeader
|
|
|
|
}
|
|
|
|
|
2022-09-16 21:45:23 +00:00
|
|
|
func (sd *SectorLocation) HttpHeaders() http.Header {
|
2022-09-02 15:12:58 +00:00
|
|
|
out := http.Header{}
|
|
|
|
for _, header := range sd.Headers {
|
|
|
|
out[header.Key] = append(out[header.Key], header.Value)
|
|
|
|
}
|
|
|
|
return out
|
|
|
|
}
|
|
|
|
|
|
|
|
// note: we can't use http.Header as that's backed by a go map, which is all kinds of messy
|
|
|
|
type SecDataHttpHeader struct {
|
|
|
|
Key string
|
|
|
|
Value string
|
2022-08-31 11:56:25 +00:00
|
|
|
}
|
2022-11-01 11:01:31 +00:00
|
|
|
|
|
|
|
// StorageConfig .lotusstorage/storage.json
|
|
|
|
type StorageConfig struct {
|
|
|
|
StoragePaths []LocalPath
|
|
|
|
}
|
|
|
|
|
|
|
|
type LocalPath struct {
|
|
|
|
Path string
|
|
|
|
}
|
|
|
|
|
|
|
|
// LocalStorageMeta [path]/sectorstore.json
|
|
|
|
type LocalStorageMeta struct {
|
|
|
|
ID ID
|
|
|
|
|
|
|
|
// A high weight means data is more likely to be stored in this path
|
|
|
|
Weight uint64 // 0 = readonly
|
|
|
|
|
|
|
|
// Intermediate data for the sealing process will be stored here
|
|
|
|
CanSeal bool
|
|
|
|
|
|
|
|
// Finalized sectors that will be proved over time will be stored here
|
|
|
|
CanStore bool
|
|
|
|
|
|
|
|
// MaxStorage specifies the maximum number of bytes to use for sector storage
|
|
|
|
// (0 = unlimited)
|
|
|
|
MaxStorage uint64
|
|
|
|
|
|
|
|
// List of storage groups this path belongs to
|
|
|
|
Groups []string
|
|
|
|
|
|
|
|
// List of storage groups to which data from this path can be moved. If none
|
|
|
|
// are specified, allow to all
|
|
|
|
AllowTo []string
|
|
|
|
|
|
|
|
// AllowTypes lists sector file types which are allowed to be put into this
|
|
|
|
// path. If empty, all file types are allowed.
|
|
|
|
//
|
|
|
|
// Valid values:
|
|
|
|
// - "unsealed"
|
|
|
|
// - "sealed"
|
|
|
|
// - "cache"
|
|
|
|
// - "update"
|
|
|
|
// - "update-cache"
|
|
|
|
// Any other value will generate a warning and be ignored.
|
|
|
|
AllowTypes []string
|
|
|
|
|
|
|
|
// DenyTypes lists sector file types which aren't allowed to be put into this
|
|
|
|
// path.
|
|
|
|
//
|
|
|
|
// Valid values:
|
|
|
|
// - "unsealed"
|
|
|
|
// - "sealed"
|
|
|
|
// - "cache"
|
|
|
|
// - "update"
|
|
|
|
// - "update-cache"
|
|
|
|
// Any other value will generate a warning and be ignored.
|
|
|
|
DenyTypes []string
|
|
|
|
}
|