2020-01-15 20:49:11 +00:00
|
|
|
package sealing
|
|
|
|
|
|
|
|
import (
|
2020-04-06 20:23:37 +00:00
|
|
|
"bytes"
|
2020-06-24 21:55:41 +00:00
|
|
|
"context"
|
2020-07-06 17:04:11 +00:00
|
|
|
"time"
|
2020-04-06 20:23:37 +00:00
|
|
|
|
2020-04-06 20:27:14 +00:00
|
|
|
"github.com/ipfs/go-cid"
|
|
|
|
|
2020-06-24 21:55:41 +00:00
|
|
|
sectorstorage "github.com/filecoin-project/sector-storage"
|
2020-02-08 02:18:32 +00:00
|
|
|
"github.com/filecoin-project/specs-actors/actors/abi"
|
2020-07-01 14:33:59 +00:00
|
|
|
"github.com/filecoin-project/specs-actors/actors/abi/big"
|
2020-06-26 15:58:29 +00:00
|
|
|
"github.com/filecoin-project/specs-actors/actors/builtin/miner"
|
2020-04-06 20:23:37 +00:00
|
|
|
"github.com/filecoin-project/specs-actors/actors/runtime/exitcode"
|
2020-04-03 16:54:01 +00:00
|
|
|
"github.com/filecoin-project/specs-storage/storage"
|
2020-01-15 20:49:11 +00:00
|
|
|
)
|
|
|
|
|
2020-04-08 14:52:20 +00:00
|
|
|
// Piece is a tuple of piece and deal info
|
2020-04-07 21:44:33 +00:00
|
|
|
type PieceWithDealInfo struct {
|
|
|
|
Piece abi.PieceInfo
|
|
|
|
DealInfo DealInfo
|
|
|
|
}
|
|
|
|
|
2020-04-08 14:52:20 +00:00
|
|
|
// Piece is a tuple of piece info and optional deal
|
|
|
|
type Piece struct {
|
2020-04-07 21:44:33 +00:00
|
|
|
Piece abi.PieceInfo
|
2020-04-08 14:52:20 +00:00
|
|
|
DealInfo *DealInfo // nil for pieces which do not appear in deals (e.g. filler pieces)
|
2020-04-07 21:44:33 +00:00
|
|
|
}
|
2020-01-15 20:49:11 +00:00
|
|
|
|
2020-04-07 21:44:33 +00:00
|
|
|
// DealInfo is a tuple of deal identity and its schedule
|
|
|
|
type DealInfo struct {
|
|
|
|
DealID abi.DealID
|
|
|
|
DealSchedule DealSchedule
|
2020-07-02 20:09:59 +00:00
|
|
|
KeepUnsealed bool
|
2020-04-07 21:44:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// DealSchedule communicates the time interval of a storage deal. The deal must
|
|
|
|
// appear in a sealed (proven) sector no later than StartEpoch, otherwise it
|
|
|
|
// is invalid.
|
|
|
|
type DealSchedule struct {
|
|
|
|
StartEpoch abi.ChainEpoch
|
|
|
|
EndEpoch abi.ChainEpoch
|
2020-01-15 20:49:11 +00:00
|
|
|
}
|
|
|
|
|
2020-01-22 02:41:39 +00:00
|
|
|
type Log struct {
|
|
|
|
Timestamp uint64
|
|
|
|
Trace string // for errors
|
|
|
|
|
|
|
|
Message string
|
|
|
|
|
|
|
|
// additional data (Event info)
|
2020-01-23 14:18:05 +00:00
|
|
|
Kind string
|
2020-01-22 02:41:39 +00:00
|
|
|
}
|
|
|
|
|
2020-01-15 20:49:11 +00:00
|
|
|
type SectorInfo struct {
|
2020-04-06 22:31:33 +00:00
|
|
|
State SectorState
|
2020-06-02 20:30:40 +00:00
|
|
|
SectorNumber abi.SectorNumber
|
2020-01-15 20:49:11 +00:00
|
|
|
|
2020-06-15 13:13:35 +00:00
|
|
|
SectorType abi.RegisteredSealProof
|
2020-02-27 00:42:39 +00:00
|
|
|
|
2020-01-15 20:49:11 +00:00
|
|
|
// Packing
|
2020-04-08 14:52:20 +00:00
|
|
|
Pieces []Piece
|
2020-01-15 20:49:11 +00:00
|
|
|
|
2020-04-03 16:54:01 +00:00
|
|
|
// PreCommit1
|
2020-04-06 18:07:26 +00:00
|
|
|
TicketValue abi.SealRandomness
|
|
|
|
TicketEpoch abi.ChainEpoch
|
2020-04-03 16:54:01 +00:00
|
|
|
PreCommit1Out storage.PreCommit1Out
|
|
|
|
|
|
|
|
// PreCommit2
|
|
|
|
CommD *cid.Cid
|
|
|
|
CommR *cid.Cid
|
|
|
|
Proof []byte
|
2020-01-15 20:49:11 +00:00
|
|
|
|
2020-06-26 16:01:50 +00:00
|
|
|
PreCommitInfo *miner.SectorPreCommitInfo
|
2020-07-01 14:33:59 +00:00
|
|
|
PreCommitDeposit big.Int
|
2020-01-15 20:49:11 +00:00
|
|
|
PreCommitMessage *cid.Cid
|
2020-05-18 22:49:21 +00:00
|
|
|
PreCommitTipSet TipSetToken
|
2020-01-15 20:49:11 +00:00
|
|
|
|
2020-06-04 15:29:31 +00:00
|
|
|
PreCommit2Fails uint64
|
|
|
|
|
2020-01-20 22:04:46 +00:00
|
|
|
// WaitSeed
|
2020-04-06 18:07:26 +00:00
|
|
|
SeedValue abi.InteractiveSealRandomness
|
|
|
|
SeedEpoch abi.ChainEpoch
|
2020-01-15 20:49:11 +00:00
|
|
|
|
|
|
|
// Committing
|
|
|
|
CommitMessage *cid.Cid
|
2020-06-02 20:30:40 +00:00
|
|
|
InvalidProofs uint64 // failed proof computations (doesn't validate with proof inputs; can't compute)
|
2020-01-15 20:49:11 +00:00
|
|
|
|
|
|
|
// Faults
|
|
|
|
FaultReportMsg *cid.Cid
|
|
|
|
|
|
|
|
// Debug
|
|
|
|
LastErr string
|
2020-01-16 01:25:49 +00:00
|
|
|
|
2020-01-22 02:41:39 +00:00
|
|
|
Log []Log
|
2020-01-15 20:49:11 +00:00
|
|
|
}
|
|
|
|
|
2020-02-27 00:42:39 +00:00
|
|
|
func (t *SectorInfo) pieceInfos() []abi.PieceInfo {
|
2020-04-08 14:52:20 +00:00
|
|
|
out := make([]abi.PieceInfo, len(t.Pieces))
|
2020-04-08 14:56:35 +00:00
|
|
|
for i, p := range t.Pieces {
|
|
|
|
out[i] = p.Piece
|
2020-01-15 20:49:11 +00:00
|
|
|
}
|
|
|
|
return out
|
|
|
|
}
|
|
|
|
|
2020-04-07 21:44:33 +00:00
|
|
|
func (t *SectorInfo) dealIDs() []abi.DealID {
|
2020-04-08 14:52:20 +00:00
|
|
|
out := make([]abi.DealID, 0, len(t.Pieces))
|
2020-04-08 14:56:35 +00:00
|
|
|
for _, p := range t.Pieces {
|
|
|
|
if p.DealInfo == nil {
|
2020-02-23 00:47:47 +00:00
|
|
|
continue
|
|
|
|
}
|
2020-04-08 14:56:35 +00:00
|
|
|
out = append(out, p.DealInfo.DealID)
|
2020-01-15 20:49:11 +00:00
|
|
|
}
|
|
|
|
return out
|
|
|
|
}
|
|
|
|
|
2020-04-07 21:44:33 +00:00
|
|
|
func (t *SectorInfo) existingPieceSizes() []abi.UnpaddedPieceSize {
|
2020-04-08 14:52:20 +00:00
|
|
|
out := make([]abi.UnpaddedPieceSize, len(t.Pieces))
|
2020-04-08 14:56:35 +00:00
|
|
|
for i, p := range t.Pieces {
|
|
|
|
out[i] = p.Piece.Size.Unpadded()
|
2020-01-15 20:49:11 +00:00
|
|
|
}
|
|
|
|
return out
|
|
|
|
}
|
2020-04-06 20:23:37 +00:00
|
|
|
|
2020-06-24 21:55:41 +00:00
|
|
|
func (t *SectorInfo) hasDeals() bool {
|
|
|
|
for _, piece := range t.Pieces {
|
|
|
|
if piece.DealInfo != nil {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *SectorInfo) sealingCtx(ctx context.Context) context.Context {
|
|
|
|
// TODO: can also take start epoch into account to give priority to sectors
|
|
|
|
// we need sealed sooner
|
|
|
|
|
|
|
|
if t.hasDeals() {
|
|
|
|
return sectorstorage.WithPriority(ctx, DealSectorPriority)
|
|
|
|
}
|
|
|
|
|
|
|
|
return ctx
|
|
|
|
}
|
|
|
|
|
2020-07-07 00:14:25 +00:00
|
|
|
// Returns list of offset/length tuples of sector data ranges which clients
|
|
|
|
// requested to keep unsealed
|
|
|
|
func (t *SectorInfo) keepUnsealedRanges(invert bool) []storage.Range {
|
2020-07-02 20:09:59 +00:00
|
|
|
var out []storage.Range
|
|
|
|
|
|
|
|
var at abi.UnpaddedPieceSize
|
|
|
|
for _, piece := range t.Pieces {
|
|
|
|
psize := piece.Piece.Size.Unpadded()
|
|
|
|
at += psize
|
|
|
|
|
|
|
|
if piece.DealInfo == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if piece.DealInfo.KeepUnsealed == invert {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
out = append(out, storage.Range{
|
|
|
|
Offset: at - psize,
|
|
|
|
Size: psize,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return out
|
|
|
|
}
|
|
|
|
|
2020-04-06 20:23:37 +00:00
|
|
|
type SectorIDCounter interface {
|
|
|
|
Next() (abi.SectorNumber, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
type TipSetToken []byte
|
|
|
|
|
|
|
|
type MsgLookup struct {
|
|
|
|
Receipt MessageReceipt
|
|
|
|
TipSetTok TipSetToken
|
|
|
|
Height abi.ChainEpoch
|
|
|
|
}
|
|
|
|
|
|
|
|
type MessageReceipt struct {
|
|
|
|
ExitCode exitcode.ExitCode
|
|
|
|
Return []byte
|
|
|
|
GasUsed int64
|
|
|
|
}
|
|
|
|
|
2020-07-06 17:04:11 +00:00
|
|
|
type GetSealingDelayFunc func() (time.Duration, error)
|
|
|
|
|
2020-04-06 20:23:37 +00:00
|
|
|
func (mr *MessageReceipt) Equals(o *MessageReceipt) bool {
|
|
|
|
return mr.ExitCode == o.ExitCode && bytes.Equal(mr.Return, o.Return) && mr.GasUsed == o.GasUsed
|
|
|
|
}
|