bc5e298e2b
Add a timer to auto-start sector sealing
195 lines
4.0 KiB
Go
195 lines
4.0 KiB
Go
package sealing
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/ipfs/go-cid"
|
|
|
|
sectorstorage "github.com/filecoin-project/sector-storage"
|
|
"github.com/filecoin-project/specs-actors/actors/abi"
|
|
"github.com/filecoin-project/specs-actors/actors/abi/big"
|
|
"github.com/filecoin-project/specs-actors/actors/builtin/miner"
|
|
"github.com/filecoin-project/specs-actors/actors/runtime/exitcode"
|
|
"github.com/filecoin-project/specs-storage/storage"
|
|
)
|
|
|
|
// Piece is a tuple of piece and deal info
|
|
type PieceWithDealInfo struct {
|
|
Piece abi.PieceInfo
|
|
DealInfo DealInfo
|
|
}
|
|
|
|
// Piece is a tuple of piece info and optional deal
|
|
type Piece struct {
|
|
Piece abi.PieceInfo
|
|
DealInfo *DealInfo // nil for pieces which do not appear in deals (e.g. filler pieces)
|
|
}
|
|
|
|
// DealInfo is a tuple of deal identity and its schedule
|
|
type DealInfo struct {
|
|
DealID abi.DealID
|
|
DealSchedule DealSchedule
|
|
KeepUnsealed bool
|
|
}
|
|
|
|
// 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
|
|
}
|
|
|
|
type Log struct {
|
|
Timestamp uint64
|
|
Trace string // for errors
|
|
|
|
Message string
|
|
|
|
// additional data (Event info)
|
|
Kind string
|
|
}
|
|
|
|
type SectorInfo struct {
|
|
State SectorState
|
|
SectorNumber abi.SectorNumber
|
|
|
|
SectorType abi.RegisteredSealProof
|
|
|
|
// Packing
|
|
Pieces []Piece
|
|
|
|
// PreCommit1
|
|
TicketValue abi.SealRandomness
|
|
TicketEpoch abi.ChainEpoch
|
|
PreCommit1Out storage.PreCommit1Out
|
|
|
|
// PreCommit2
|
|
CommD *cid.Cid
|
|
CommR *cid.Cid
|
|
Proof []byte
|
|
|
|
PreCommitInfo *miner.SectorPreCommitInfo
|
|
PreCommitDeposit big.Int
|
|
PreCommitMessage *cid.Cid
|
|
PreCommitTipSet TipSetToken
|
|
|
|
PreCommit2Fails uint64
|
|
|
|
// WaitSeed
|
|
SeedValue abi.InteractiveSealRandomness
|
|
SeedEpoch abi.ChainEpoch
|
|
|
|
// Committing
|
|
CommitMessage *cid.Cid
|
|
InvalidProofs uint64 // failed proof computations (doesn't validate with proof inputs; can't compute)
|
|
|
|
// Faults
|
|
FaultReportMsg *cid.Cid
|
|
|
|
// Debug
|
|
LastErr string
|
|
|
|
Log []Log
|
|
}
|
|
|
|
func (t *SectorInfo) pieceInfos() []abi.PieceInfo {
|
|
out := make([]abi.PieceInfo, len(t.Pieces))
|
|
for i, p := range t.Pieces {
|
|
out[i] = p.Piece
|
|
}
|
|
return out
|
|
}
|
|
|
|
func (t *SectorInfo) dealIDs() []abi.DealID {
|
|
out := make([]abi.DealID, 0, len(t.Pieces))
|
|
for _, p := range t.Pieces {
|
|
if p.DealInfo == nil {
|
|
continue
|
|
}
|
|
out = append(out, p.DealInfo.DealID)
|
|
}
|
|
return out
|
|
}
|
|
|
|
func (t *SectorInfo) existingPieceSizes() []abi.UnpaddedPieceSize {
|
|
out := make([]abi.UnpaddedPieceSize, len(t.Pieces))
|
|
for i, p := range t.Pieces {
|
|
out[i] = p.Piece.Size.Unpadded()
|
|
}
|
|
return out
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
// Returns list of offset/length tuples of sector data ranges which clients
|
|
// requested to keep unsealed
|
|
func (t *SectorInfo) keepUnsealedRanges(invert bool) []storage.Range {
|
|
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
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
type GetSealingDelayFunc func() (time.Duration, error)
|
|
|
|
func (mr *MessageReceipt) Equals(o *MessageReceipt) bool {
|
|
return mr.ExitCode == o.ExitCode && bytes.Equal(mr.Return, o.Return) && mr.GasUsed == o.GasUsed
|
|
}
|