2020-01-15 20:49:11 +00:00
|
|
|
package sealing
|
|
|
|
|
|
|
|
import (
|
2020-04-06 18:07:26 +00:00
|
|
|
"bytes"
|
2020-01-15 20:49:11 +00:00
|
|
|
"context"
|
2020-09-17 02:34:13 +00:00
|
|
|
|
2020-09-30 17:32:19 +00:00
|
|
|
"github.com/ipfs/go-cid"
|
2020-04-06 18:07:26 +00:00
|
|
|
"golang.org/x/xerrors"
|
2020-01-15 20:49:11 +00:00
|
|
|
|
2020-09-07 03:49:10 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
|
|
|
"github.com/filecoin-project/go-state-types/big"
|
|
|
|
"github.com/filecoin-project/go-state-types/crypto"
|
|
|
|
"github.com/filecoin-project/go-state-types/exitcode"
|
2021-05-17 20:51:29 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/network"
|
2020-04-06 20:23:37 +00:00
|
|
|
"github.com/filecoin-project/go-statemachine"
|
2021-03-10 15:16:44 +00:00
|
|
|
"github.com/filecoin-project/specs-actors/v5/actors/runtime/proof"
|
2020-04-06 18:07:26 +00:00
|
|
|
"github.com/filecoin-project/specs-storage/storage"
|
2020-09-30 17:32:19 +00:00
|
|
|
|
2020-12-02 20:47:45 +00:00
|
|
|
"github.com/filecoin-project/lotus/api"
|
2020-10-08 11:10:41 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/actors"
|
2020-09-30 17:32:19 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/actors/builtin/miner"
|
|
|
|
"github.com/filecoin-project/lotus/chain/actors/policy"
|
2020-01-15 20:49:11 +00:00
|
|
|
)
|
|
|
|
|
2020-06-25 15:46:06 +00:00
|
|
|
var DealSectorPriority = 1024
|
2021-02-04 08:42:02 +00:00
|
|
|
var MaxTicketAge = policy.MaxPreCommitRandomnessLookback
|
2020-06-24 21:55:41 +00:00
|
|
|
|
2020-01-15 20:49:11 +00:00
|
|
|
func (m *Sealing) handlePacking(ctx statemachine.Context, sector SectorInfo) error {
|
2021-02-09 17:44:41 +00:00
|
|
|
m.inputLk.Lock()
|
|
|
|
// make sure we not accepting deals into this sector
|
|
|
|
for _, c := range m.assignedPieces[m.minerSectorID(sector.SectorNumber)] {
|
|
|
|
pp := m.pendingPieces[c]
|
|
|
|
delete(m.pendingPieces, c)
|
|
|
|
if pp == nil {
|
|
|
|
log.Errorf("nil assigned pending piece %s", c)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// todo: return to the sealing queue (this is extremely unlikely to happen)
|
2021-05-30 13:13:38 +00:00
|
|
|
pp.accepted(sector.SectorNumber, 0, xerrors.Errorf("sector %d entered packing state early", sector.SectorNumber))
|
2021-02-09 17:44:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
delete(m.openSectors, m.minerSectorID(sector.SectorNumber))
|
|
|
|
delete(m.assignedPieces, m.minerSectorID(sector.SectorNumber))
|
|
|
|
m.inputLk.Unlock()
|
|
|
|
|
2020-04-06 22:31:33 +00:00
|
|
|
log.Infow("performing filling up rest of the sector...", "sector", sector.SectorNumber)
|
2020-01-15 20:49:11 +00:00
|
|
|
|
2020-02-08 02:18:32 +00:00
|
|
|
var allocated abi.UnpaddedPieceSize
|
2020-04-08 14:52:20 +00:00
|
|
|
for _, piece := range sector.Pieces {
|
2020-04-07 21:44:33 +00:00
|
|
|
allocated += piece.Piece.Size.Unpadded()
|
2020-01-15 20:49:11 +00:00
|
|
|
}
|
|
|
|
|
2020-11-04 20:29:08 +00:00
|
|
|
ssize, err := sector.SectorType.SectorSize()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
ubytes := abi.PaddedPieceSize(ssize).Unpadded()
|
2020-01-15 20:49:11 +00:00
|
|
|
|
|
|
|
if allocated > ubytes {
|
|
|
|
return xerrors.Errorf("too much data in sector: %d > %d", allocated, ubytes)
|
|
|
|
}
|
|
|
|
|
|
|
|
fillerSizes, err := fillersFromRem(ubytes - allocated)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(fillerSizes) > 0 {
|
2020-04-06 22:31:33 +00:00
|
|
|
log.Warnf("Creating %d filler pieces for sector %d", len(fillerSizes), sector.SectorNumber)
|
2020-01-15 20:49:11 +00:00
|
|
|
}
|
|
|
|
|
2021-02-16 16:14:59 +00:00
|
|
|
fillerPieces, err := m.padSector(sector.sealingCtx(ctx.Context()), m.minerSector(sector.SectorType, sector.SectorNumber), sector.existingPieceSizes(), fillerSizes...)
|
2020-01-15 20:49:11 +00:00
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("filling up the sector (%v): %w", fillerSizes, err)
|
|
|
|
}
|
|
|
|
|
2020-04-07 21:44:33 +00:00
|
|
|
return ctx.Send(SectorPacked{FillerPieces: fillerPieces})
|
2020-01-15 20:49:11 +00:00
|
|
|
}
|
|
|
|
|
2021-02-16 16:14:59 +00:00
|
|
|
func (m *Sealing) padSector(ctx context.Context, sectorID storage.SectorRef, existingPieceSizes []abi.UnpaddedPieceSize, sizes ...abi.UnpaddedPieceSize) ([]abi.PieceInfo, error) {
|
|
|
|
if len(sizes) == 0 {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Infof("Pledge %d, contains %+v", sectorID, existingPieceSizes)
|
|
|
|
|
|
|
|
out := make([]abi.PieceInfo, len(sizes))
|
|
|
|
for i, size := range sizes {
|
|
|
|
ppi, err := m.sealer.AddPiece(ctx, sectorID, existingPieceSizes, size, NewNullReader(size))
|
|
|
|
if err != nil {
|
|
|
|
return nil, xerrors.Errorf("add piece: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
existingPieceSizes = append(existingPieceSizes, size)
|
|
|
|
|
|
|
|
out[i] = ppi
|
|
|
|
}
|
|
|
|
|
|
|
|
return out, nil
|
|
|
|
}
|
|
|
|
|
2021-05-20 10:36:00 +00:00
|
|
|
func checkTicketExpired(ticket, head abi.ChainEpoch) bool {
|
|
|
|
return head-ticket > MaxTicketAge // TODO: allow configuring expected seal durations
|
2020-11-16 20:58:42 +00:00
|
|
|
}
|
|
|
|
|
2021-06-30 08:32:44 +00:00
|
|
|
func checkProveCommitExpired(preCommitEpoch, msd abi.ChainEpoch, currEpoch abi.ChainEpoch) bool {
|
|
|
|
return currEpoch > preCommitEpoch+msd
|
|
|
|
}
|
|
|
|
|
2021-07-01 02:53:42 +00:00
|
|
|
func (m *Sealing) getTicket(ctx statemachine.Context, sector SectorInfo) (abi.SealRandomness, abi.ChainEpoch, bool, error) {
|
2020-04-23 00:09:52 +00:00
|
|
|
tok, epoch, err := m.api.ChainHead(ctx.Context())
|
2020-04-07 20:26:43 +00:00
|
|
|
if err != nil {
|
2021-07-01 02:53:42 +00:00
|
|
|
log.Errorf("getTicket: api error, not proceeding: %+v", err)
|
|
|
|
return nil, 0, false, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// the reason why the StateMinerSectorAllocated function is placed here, if it is outside,
|
|
|
|
// if the MarshalCBOR function and StateSectorPreCommitInfo function return err, it will be executed
|
|
|
|
allocated, aerr := m.api.StateMinerSectorAllocated(ctx.Context(), m.maddr, sector.SectorNumber, nil)
|
|
|
|
if aerr != nil {
|
|
|
|
log.Errorf("getTicket: api error, checking if sector is allocated: %+v", aerr)
|
|
|
|
return nil, 0, false, nil
|
2020-06-02 21:45:28 +00:00
|
|
|
}
|
|
|
|
|
2020-09-29 00:28:16 +00:00
|
|
|
ticketEpoch := epoch - policy.SealRandomnessLookback
|
2020-06-02 21:45:28 +00:00
|
|
|
buf := new(bytes.Buffer)
|
|
|
|
if err := m.maddr.MarshalCBOR(buf); err != nil {
|
2021-07-01 02:53:42 +00:00
|
|
|
return nil, 0, allocated, err
|
2020-06-02 21:45:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pci, err := m.api.StateSectorPreCommitInfo(ctx.Context(), m.maddr, sector.SectorNumber, tok)
|
|
|
|
if err != nil {
|
2021-07-01 02:53:42 +00:00
|
|
|
return nil, 0, allocated, xerrors.Errorf("getting precommit info: %w", err)
|
2020-06-02 21:45:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if pci != nil {
|
|
|
|
ticketEpoch = pci.Info.SealRandEpoch
|
|
|
|
|
2021-06-30 08:32:44 +00:00
|
|
|
nv, err := m.api.StateNetworkVersion(ctx.Context(), tok)
|
|
|
|
if err != nil {
|
2021-07-01 02:53:42 +00:00
|
|
|
return nil, 0, allocated, xerrors.Errorf("getTicket: StateNetworkVersion: api error, not proceeding: %+v", err)
|
2020-11-23 18:12:54 +00:00
|
|
|
}
|
2021-06-30 08:32:44 +00:00
|
|
|
|
2021-08-10 17:07:30 +00:00
|
|
|
av, err := actors.VersionForNetwork(nv)
|
|
|
|
if err != nil {
|
|
|
|
return nil, 0, allocated, xerrors.Errorf("getTicket: actor version for network error, not proceeding: %w", err)
|
|
|
|
}
|
|
|
|
msd, err := policy.GetMaxProveCommitDuration(av, sector.SectorType)
|
|
|
|
if err != nil {
|
|
|
|
return nil, 0, allocated, xerrors.Errorf("getTicket: max prove commit duration policy error, not proceeding: %w", err)
|
|
|
|
}
|
2021-06-30 08:32:44 +00:00
|
|
|
|
|
|
|
if checkProveCommitExpired(pci.PreCommitEpoch, msd, epoch) {
|
2021-07-01 02:53:42 +00:00
|
|
|
return nil, 0, allocated, xerrors.Errorf("ticket expired for precommitted sector")
|
2020-11-23 18:12:54 +00:00
|
|
|
}
|
2020-11-16 20:58:42 +00:00
|
|
|
}
|
|
|
|
|
2021-07-02 03:44:46 +00:00
|
|
|
if pci == nil && allocated { // allocated is true, sector precommitted but expired, will SectorCommitFailed or SectorRemove
|
2021-07-02 03:38:04 +00:00
|
|
|
return nil, 0, allocated, xerrors.Errorf("sector %s precommitted but expired", sector.SectorNumber)
|
2020-11-16 20:58:42 +00:00
|
|
|
}
|
|
|
|
|
2020-08-11 23:58:35 +00:00
|
|
|
rand, err := m.api.ChainGetRandomnessFromTickets(ctx.Context(), tok, crypto.DomainSeparationTag_SealRandomness, ticketEpoch, buf.Bytes())
|
2020-06-02 21:45:28 +00:00
|
|
|
if err != nil {
|
2021-07-01 02:53:42 +00:00
|
|
|
return nil, 0, allocated, err
|
2020-04-07 20:26:43 +00:00
|
|
|
}
|
|
|
|
|
2021-07-01 02:53:42 +00:00
|
|
|
return abi.SealRandomness(rand), ticketEpoch, allocated, nil
|
2020-06-02 21:45:28 +00:00
|
|
|
}
|
|
|
|
|
2020-09-29 07:57:36 +00:00
|
|
|
func (m *Sealing) handleGetTicket(ctx statemachine.Context, sector SectorInfo) error {
|
2021-07-01 02:53:42 +00:00
|
|
|
ticketValue, ticketEpoch, allocated, err := m.getTicket(ctx, sector)
|
2020-09-29 07:57:36 +00:00
|
|
|
if err != nil {
|
2020-10-13 19:35:29 +00:00
|
|
|
if allocated {
|
|
|
|
if sector.CommitMessage != nil {
|
|
|
|
// Some recovery paths with unfortunate timing lead here
|
|
|
|
return ctx.Send(SectorCommitFailed{xerrors.Errorf("sector %s is committed but got into the GetTicket state", sector.SectorNumber)})
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Errorf("Sector %s precommitted but expired", sector.SectorNumber)
|
|
|
|
return ctx.Send(SectorRemove{})
|
|
|
|
}
|
|
|
|
|
2020-09-29 07:57:36 +00:00
|
|
|
return ctx.Send(SectorSealPreCommit1Failed{xerrors.Errorf("getting ticket failed: %w", err)})
|
|
|
|
}
|
|
|
|
|
|
|
|
return ctx.Send(SectorTicket{
|
|
|
|
TicketValue: ticketValue,
|
|
|
|
TicketEpoch: ticketEpoch,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-06-02 21:45:28 +00:00
|
|
|
func (m *Sealing) handlePreCommit1(ctx statemachine.Context, sector SectorInfo) error {
|
2020-08-27 11:51:13 +00:00
|
|
|
if err := checkPieces(ctx.Context(), m.maddr, sector, m.api); err != nil { // Sanity check state
|
2020-01-23 15:38:01 +00:00
|
|
|
switch err.(type) {
|
2020-01-23 16:02:55 +00:00
|
|
|
case *ErrApi:
|
2020-04-03 16:54:01 +00:00
|
|
|
log.Errorf("handlePreCommit1: api error, not proceeding: %+v", err)
|
2020-01-23 15:38:01 +00:00
|
|
|
return nil
|
2020-01-23 16:02:55 +00:00
|
|
|
case *ErrInvalidDeals:
|
2020-08-27 19:04:43 +00:00
|
|
|
log.Warnf("invalid deals in sector %d: %v", sector.SectorNumber, err)
|
2020-08-27 21:14:46 +00:00
|
|
|
return ctx.Send(SectorInvalidDealIDs{Return: RetPreCommit1})
|
2020-01-23 16:02:55 +00:00
|
|
|
case *ErrExpiredDeals: // Probably not much we can do here, maybe re-pack the sector?
|
2020-08-27 20:41:35 +00:00
|
|
|
return ctx.Send(SectorDealsExpired{xerrors.Errorf("expired dealIDs in sector: %w", err)})
|
2020-01-23 15:38:01 +00:00
|
|
|
default:
|
|
|
|
return xerrors.Errorf("checkPieces sanity check error: %w", err)
|
|
|
|
}
|
2020-01-22 19:47:29 +00:00
|
|
|
}
|
|
|
|
|
2021-06-30 08:32:44 +00:00
|
|
|
tok, height, err := m.api.ChainHead(ctx.Context())
|
2020-01-15 20:49:11 +00:00
|
|
|
if err != nil {
|
2020-09-29 07:57:36 +00:00
|
|
|
log.Errorf("handlePreCommit1: api error, not proceeding: %+v", err)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-05-20 10:36:00 +00:00
|
|
|
if checkTicketExpired(sector.TicketEpoch, height) {
|
2021-06-30 08:32:44 +00:00
|
|
|
pci, err := m.api.StateSectorPreCommitInfo(ctx.Context(), m.maddr, sector.SectorNumber, tok)
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("handlePreCommit1: StateSectorPreCommitInfo: api error, not proceeding: %+v", err)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if pci == nil {
|
|
|
|
return ctx.Send(SectorOldTicket{}) // go get new ticket
|
|
|
|
}
|
|
|
|
|
|
|
|
nv, err := m.api.StateNetworkVersion(ctx.Context(), tok)
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("handlePreCommit1: StateNetworkVersion: api error, not proceeding: %+v", err)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-08-10 17:07:30 +00:00
|
|
|
av, err := actors.VersionForNetwork(nv)
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("handlePreCommit1: VersionForNetwork error, not proceeding: %w", err)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
msd, err := policy.GetMaxProveCommitDuration(av, sector.SectorType)
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("handlePreCommit1: GetMaxProveCommitDuration error, not proceeding: %w", err)
|
|
|
|
return nil
|
|
|
|
}
|
2021-06-30 08:32:44 +00:00
|
|
|
|
|
|
|
// if height > PreCommitEpoch + msd, there is no need to recalculate
|
|
|
|
if checkProveCommitExpired(pci.PreCommitEpoch, msd, height) {
|
|
|
|
return ctx.Send(SectorOldTicket{}) // will be removed
|
|
|
|
}
|
2020-01-15 20:49:11 +00:00
|
|
|
}
|
|
|
|
|
2020-11-04 20:29:08 +00:00
|
|
|
pc1o, err := m.sealer.SealPreCommit1(sector.sealingCtx(ctx.Context()), m.minerSector(sector.SectorType, sector.SectorNumber), sector.TicketValue, sector.pieceInfos())
|
2020-03-03 22:19:22 +00:00
|
|
|
if err != nil {
|
2020-06-04 15:29:31 +00:00
|
|
|
return ctx.Send(SectorSealPreCommit1Failed{xerrors.Errorf("seal pre commit(1) failed: %w", err)})
|
2020-03-03 22:19:22 +00:00
|
|
|
}
|
|
|
|
|
2020-04-03 16:54:01 +00:00
|
|
|
return ctx.Send(SectorPreCommit1{
|
|
|
|
PreCommit1Out: pc1o,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Sealing) handlePreCommit2(ctx statemachine.Context, sector SectorInfo) error {
|
2020-11-04 20:29:08 +00:00
|
|
|
cids, err := m.sealer.SealPreCommit2(sector.sealingCtx(ctx.Context()), m.minerSector(sector.SectorType, sector.SectorNumber), sector.PreCommit1Out)
|
2020-01-15 20:49:11 +00:00
|
|
|
if err != nil {
|
2020-06-04 15:29:31 +00:00
|
|
|
return ctx.Send(SectorSealPreCommit2Failed{xerrors.Errorf("seal pre commit(2) failed: %w", err)})
|
2020-01-15 20:49:11 +00:00
|
|
|
}
|
|
|
|
|
2020-09-30 15:53:15 +00:00
|
|
|
if cids.Unsealed == cid.Undef {
|
|
|
|
return ctx.Send(SectorSealPreCommit1Failed{xerrors.Errorf("seal pre commit(2) returned undefined CommD")})
|
|
|
|
}
|
|
|
|
|
2020-04-03 16:54:01 +00:00
|
|
|
return ctx.Send(SectorPreCommit2{
|
2020-03-22 20:44:27 +00:00
|
|
|
Unsealed: cids.Unsealed,
|
|
|
|
Sealed: cids.Sealed,
|
2020-01-15 20:49:11 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-08-18 22:53:56 +00:00
|
|
|
// TODO: We should probably invoke this method in most (if not all) state transition failures after handlePreCommitting
|
|
|
|
func (m *Sealing) remarkForUpgrade(sid abi.SectorNumber) {
|
|
|
|
err := m.MarkForUpgrade(sid)
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("error re-marking sector %d as for upgrade: %+v", sid, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-18 15:21:10 +00:00
|
|
|
func (m *Sealing) preCommitParams(ctx statemachine.Context, sector SectorInfo) (*miner.SectorPreCommitInfo, big.Int, TipSetToken, error) {
|
2020-04-09 17:34:07 +00:00
|
|
|
tok, height, err := m.api.ChainHead(ctx.Context())
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("handlePreCommitting: api error, not proceeding: %+v", err)
|
2021-05-18 15:21:10 +00:00
|
|
|
return nil, big.Zero(), nil, nil
|
2020-04-09 17:34:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := checkPrecommit(ctx.Context(), m.Address(), sector, tok, height, m.api); err != nil {
|
2020-06-02 21:45:28 +00:00
|
|
|
switch err := err.(type) {
|
2020-01-23 16:02:55 +00:00
|
|
|
case *ErrApi:
|
2020-01-23 15:38:01 +00:00
|
|
|
log.Errorf("handlePreCommitting: api error, not proceeding: %+v", err)
|
2021-05-18 15:21:10 +00:00
|
|
|
return nil, big.Zero(), nil, nil
|
2020-04-03 16:54:01 +00:00
|
|
|
case *ErrBadCommD: // TODO: Should this just back to packing? (not really needed since handlePreCommit1 will do that too)
|
2021-05-18 15:21:10 +00:00
|
|
|
return nil, big.Zero(), nil, ctx.Send(SectorSealPreCommit1Failed{xerrors.Errorf("bad CommD error: %w", err)})
|
2020-01-23 16:02:55 +00:00
|
|
|
case *ErrExpiredTicket:
|
2021-05-18 15:21:10 +00:00
|
|
|
return nil, big.Zero(), nil, ctx.Send(SectorSealPreCommit1Failed{xerrors.Errorf("ticket expired: %w", err)})
|
2020-06-02 21:45:28 +00:00
|
|
|
case *ErrBadTicket:
|
2021-05-18 15:21:10 +00:00
|
|
|
return nil, big.Zero(), nil, ctx.Send(SectorSealPreCommit1Failed{xerrors.Errorf("bad ticket: %w", err)})
|
2020-08-27 11:51:13 +00:00
|
|
|
case *ErrInvalidDeals:
|
2020-08-27 19:04:43 +00:00
|
|
|
log.Warnf("invalid deals in sector %d: %v", sector.SectorNumber, err)
|
2021-05-18 15:21:10 +00:00
|
|
|
return nil, big.Zero(), nil, ctx.Send(SectorInvalidDealIDs{Return: RetPreCommitting})
|
2020-08-27 11:51:13 +00:00
|
|
|
case *ErrExpiredDeals:
|
2021-05-18 15:21:10 +00:00
|
|
|
return nil, big.Zero(), nil, ctx.Send(SectorDealsExpired{xerrors.Errorf("sector deals expired: %w", err)})
|
2020-06-02 21:45:28 +00:00
|
|
|
case *ErrPrecommitOnChain:
|
2021-05-18 15:21:10 +00:00
|
|
|
return nil, big.Zero(), nil, ctx.Send(SectorPreCommitLanded{TipSet: tok}) // we re-did precommit
|
2020-08-18 16:02:13 +00:00
|
|
|
case *ErrSectorNumberAllocated:
|
|
|
|
log.Errorf("handlePreCommitFailed: sector number already allocated, not proceeding: %+v", err)
|
|
|
|
// TODO: check if the sector is committed (not sure how we'd end up here)
|
2021-05-18 15:21:10 +00:00
|
|
|
return nil, big.Zero(), nil, nil
|
2020-01-23 15:38:01 +00:00
|
|
|
default:
|
2021-05-18 15:21:10 +00:00
|
|
|
return nil, big.Zero(), nil, xerrors.Errorf("checkPrecommit sanity check error: %w", err)
|
2020-01-23 15:38:01 +00:00
|
|
|
}
|
2020-01-22 19:47:29 +00:00
|
|
|
}
|
|
|
|
|
2020-04-08 14:52:20 +00:00
|
|
|
expiration, err := m.pcp.Expiration(ctx.Context(), sector.Pieces...)
|
2020-04-07 22:26:07 +00:00
|
|
|
if err != nil {
|
2021-05-18 15:21:10 +00:00
|
|
|
return nil, big.Zero(), nil, ctx.Send(SectorSealPreCommit1Failed{xerrors.Errorf("handlePreCommitting: failed to compute pre-commit expiry: %w", err)})
|
2020-04-07 22:26:07 +00:00
|
|
|
}
|
|
|
|
|
2020-09-17 02:34:13 +00:00
|
|
|
nv, err := m.api.StateNetworkVersion(ctx.Context(), tok)
|
|
|
|
if err != nil {
|
2021-05-18 15:21:10 +00:00
|
|
|
return nil, big.Zero(), nil, ctx.Send(SectorSealPreCommit1Failed{xerrors.Errorf("failed to get network version: %w", err)})
|
2020-09-17 02:34:13 +00:00
|
|
|
}
|
|
|
|
|
2021-08-10 17:07:30 +00:00
|
|
|
av, err := actors.VersionForNetwork(nv)
|
|
|
|
if err != nil {
|
|
|
|
return nil, big.Zero(), nil, ctx.Send(SectorSealPreCommit1Failed{xerrors.Errorf("failed to get actors version: %w", err)})
|
|
|
|
}
|
|
|
|
msd, err := policy.GetMaxProveCommitDuration(av, sector.SectorType)
|
|
|
|
if err != nil {
|
|
|
|
return nil, big.Zero(), nil, ctx.Send(SectorSealPreCommit1Failed{xerrors.Errorf("failed to get max prove commit duration: %w", err)})
|
|
|
|
}
|
2020-09-17 02:34:13 +00:00
|
|
|
|
2021-07-29 07:01:52 +00:00
|
|
|
if minExpiration := sector.TicketEpoch + policy.MaxPreCommitRandomnessLookback + msd + miner.MinSectorExpiration; expiration < minExpiration {
|
2021-07-14 03:52:18 +00:00
|
|
|
expiration = minExpiration
|
|
|
|
}
|
2021-04-23 11:06:54 +00:00
|
|
|
|
|
|
|
// Assume: both precommit msg & commit msg land on chain as early as possible
|
|
|
|
maxExpiration := height + policy.GetPreCommitChallengeDelay() + policy.GetMaxSectorExpirationExtension()
|
|
|
|
if expiration > maxExpiration {
|
|
|
|
expiration = maxExpiration
|
2020-08-12 04:14:37 +00:00
|
|
|
}
|
|
|
|
|
2020-02-14 00:24:24 +00:00
|
|
|
params := &miner.SectorPreCommitInfo{
|
2020-06-15 13:13:35 +00:00
|
|
|
Expiration: expiration,
|
|
|
|
SectorNumber: sector.SectorNumber,
|
|
|
|
SealProof: sector.SectorType,
|
2020-02-12 00:58:55 +00:00
|
|
|
|
2020-02-27 00:42:39 +00:00
|
|
|
SealedCID: *sector.CommR,
|
2020-04-06 18:07:26 +00:00
|
|
|
SealRandEpoch: sector.TicketEpoch,
|
2020-04-07 21:44:33 +00:00
|
|
|
DealIDs: sector.dealIDs(),
|
2020-02-14 21:38:30 +00:00
|
|
|
}
|
2020-01-15 20:49:11 +00:00
|
|
|
|
2020-07-15 14:51:02 +00:00
|
|
|
depositMinimum := m.tryUpgradeSector(ctx.Context(), params)
|
2020-07-01 13:30:25 +00:00
|
|
|
|
2021-05-18 15:21:10 +00:00
|
|
|
collateral, err := m.api.StateMinerPreCommitDepositForPower(ctx.Context(), m.maddr, *params, tok)
|
|
|
|
if err != nil {
|
|
|
|
return nil, big.Zero(), nil, xerrors.Errorf("getting initial pledge collateral: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
deposit := big.Max(depositMinimum, collateral)
|
|
|
|
|
|
|
|
return params, deposit, tok, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Sealing) handlePreCommitting(ctx statemachine.Context, sector SectorInfo) error {
|
2021-05-18 15:37:52 +00:00
|
|
|
cfg, err := m.getConfig()
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("getting config: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if cfg.BatchPreCommits {
|
|
|
|
nv, err := m.api.StateNetworkVersion(ctx.Context(), nil)
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("getting network version: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if nv >= network.Version13 {
|
|
|
|
return ctx.Send(SectorPreCommitBatch{})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-29 16:17:08 +00:00
|
|
|
params, pcd, tok, err := m.preCommitParams(ctx, sector)
|
2021-07-15 11:42:07 +00:00
|
|
|
if err != nil {
|
|
|
|
return ctx.Send(SectorChainPreCommitFailed{xerrors.Errorf("preCommitParams: %w", err)})
|
|
|
|
}
|
|
|
|
if params == nil {
|
|
|
|
return nil // event was sent in preCommitParams
|
2021-05-18 15:21:10 +00:00
|
|
|
}
|
|
|
|
|
2021-07-12 16:46:05 +00:00
|
|
|
deposit, err := collateralSendAmount(ctx.Context(), m.api, m.maddr, cfg, pcd)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2021-06-29 16:17:08 +00:00
|
|
|
}
|
|
|
|
|
2020-04-06 18:07:26 +00:00
|
|
|
enc := new(bytes.Buffer)
|
|
|
|
if err := params.MarshalCBOR(enc); err != nil {
|
|
|
|
return ctx.Send(SectorChainPreCommitFailed{xerrors.Errorf("could not serialize pre-commit sector parameters: %w", err)})
|
2020-01-15 20:49:11 +00:00
|
|
|
}
|
|
|
|
|
2021-05-18 15:21:10 +00:00
|
|
|
mi, err := m.api.StateMinerInfo(ctx.Context(), m.maddr, tok)
|
2020-06-26 15:58:29 +00:00
|
|
|
if err != nil {
|
2021-05-18 15:21:10 +00:00
|
|
|
log.Errorf("handlePreCommitting: api error, not proceeding: %+v", err)
|
|
|
|
return nil
|
2020-06-26 15:58:29 +00:00
|
|
|
}
|
|
|
|
|
2021-06-08 13:43:43 +00:00
|
|
|
goodFunds := big.Add(deposit, big.Int(m.feeCfg.MaxPreCommitGasFee))
|
2020-12-02 20:47:45 +00:00
|
|
|
|
|
|
|
from, _, err := m.addrSel(ctx.Context(), mi, api.PreCommitAddr, goodFunds, deposit)
|
|
|
|
if err != nil {
|
2020-12-02 21:01:09 +00:00
|
|
|
return ctx.Send(SectorChainPreCommitFailed{xerrors.Errorf("no good address to send precommit message from: %w", err)})
|
2020-12-02 20:47:45 +00:00
|
|
|
}
|
2020-07-01 14:33:59 +00:00
|
|
|
|
2020-08-05 01:30:58 +00:00
|
|
|
log.Infof("submitting precommit for sector %d (deposit: %s): ", sector.SectorNumber, deposit)
|
2021-06-08 13:43:43 +00:00
|
|
|
mcid, err := m.api.SendMsg(ctx.Context(), from, m.maddr, miner.Methods.PreCommitSector, deposit, big.Int(m.feeCfg.MaxPreCommitGasFee), enc.Bytes())
|
2020-01-15 20:49:11 +00:00
|
|
|
if err != nil {
|
2020-08-18 22:55:18 +00:00
|
|
|
if params.ReplaceCapacity {
|
2020-08-18 22:53:56 +00:00
|
|
|
m.remarkForUpgrade(params.ReplaceSectorNumber)
|
|
|
|
}
|
2020-04-03 16:54:01 +00:00
|
|
|
return ctx.Send(SectorChainPreCommitFailed{xerrors.Errorf("pushing message to mpool: %w", err)})
|
2020-01-15 20:49:11 +00:00
|
|
|
}
|
|
|
|
|
2021-06-29 16:17:08 +00:00
|
|
|
return ctx.Send(SectorPreCommitted{Message: mcid, PreCommitDeposit: pcd, PreCommitInfo: *params})
|
2020-01-15 20:49:11 +00:00
|
|
|
}
|
|
|
|
|
2021-05-18 15:21:10 +00:00
|
|
|
func (m *Sealing) handleSubmitPreCommitBatch(ctx statemachine.Context, sector SectorInfo) error {
|
|
|
|
if sector.CommD == nil || sector.CommR == nil {
|
2021-06-01 12:35:30 +00:00
|
|
|
return ctx.Send(SectorSealPreCommit1Failed{xerrors.Errorf("sector had nil commR or commD")})
|
2021-05-18 15:21:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
params, deposit, _, err := m.preCommitParams(ctx, sector)
|
2021-07-15 11:42:07 +00:00
|
|
|
if err != nil {
|
|
|
|
return ctx.Send(SectorChainPreCommitFailed{xerrors.Errorf("preCommitParams: %w", err)})
|
|
|
|
}
|
|
|
|
if params == nil {
|
|
|
|
return nil // event was sent in preCommitParams
|
2021-05-18 15:21:10 +00:00
|
|
|
}
|
|
|
|
|
2021-06-01 12:35:30 +00:00
|
|
|
res, err := m.precommiter.AddPreCommit(ctx.Context(), sector, deposit, params)
|
2021-05-18 15:21:10 +00:00
|
|
|
if err != nil {
|
2021-06-01 12:35:30 +00:00
|
|
|
return ctx.Send(SectorChainPreCommitFailed{xerrors.Errorf("queuing precommit batch failed: %w", err)})
|
2021-05-18 15:21:10 +00:00
|
|
|
}
|
|
|
|
|
2021-06-01 12:35:30 +00:00
|
|
|
if res.Error != "" {
|
|
|
|
return ctx.Send(SectorChainPreCommitFailed{xerrors.Errorf("precommit batch error: %s", res.Error)})
|
|
|
|
}
|
|
|
|
|
|
|
|
if res.Msg == nil {
|
|
|
|
return ctx.Send(SectorChainPreCommitFailed{xerrors.Errorf("batch message was nil")})
|
2021-05-18 15:21:10 +00:00
|
|
|
}
|
|
|
|
|
2021-06-01 12:35:30 +00:00
|
|
|
return ctx.Send(SectorPreCommitBatchSent{*res.Msg})
|
2021-05-18 15:21:10 +00:00
|
|
|
}
|
|
|
|
|
2020-05-18 22:49:21 +00:00
|
|
|
func (m *Sealing) handlePreCommitWait(ctx statemachine.Context, sector SectorInfo) error {
|
2020-06-17 18:35:47 +00:00
|
|
|
if sector.PreCommitMessage == nil {
|
|
|
|
return ctx.Send(SectorChainPreCommitFailed{xerrors.Errorf("precommit message was nil")})
|
|
|
|
}
|
|
|
|
|
2020-08-18 22:53:56 +00:00
|
|
|
// would be ideal to just use the events.Called handler, but it wouldn't be able to handle individual message timeouts
|
2020-04-06 22:31:33 +00:00
|
|
|
log.Info("Sector precommitted: ", sector.SectorNumber)
|
2020-01-15 20:49:11 +00:00
|
|
|
mw, err := m.api.StateWaitMsg(ctx.Context(), *sector.PreCommitMessage)
|
|
|
|
if err != nil {
|
2020-04-03 16:54:01 +00:00
|
|
|
return ctx.Send(SectorChainPreCommitFailed{err})
|
2020-01-15 20:49:11 +00:00
|
|
|
}
|
|
|
|
|
2020-08-27 12:02:00 +00:00
|
|
|
switch mw.Receipt.ExitCode {
|
|
|
|
case exitcode.Ok:
|
|
|
|
// this is what we expect
|
2020-11-18 00:08:28 +00:00
|
|
|
case exitcode.SysErrInsufficientFunds:
|
|
|
|
fallthrough
|
2020-08-27 12:02:00 +00:00
|
|
|
case exitcode.SysErrOutOfGas:
|
2020-11-18 00:08:28 +00:00
|
|
|
// gas estimator guessed a wrong number / out of funds:
|
2020-08-27 12:02:00 +00:00
|
|
|
return ctx.Send(SectorRetryPreCommit{})
|
|
|
|
default:
|
2020-01-15 20:49:11 +00:00
|
|
|
log.Error("sector precommit failed: ", mw.Receipt.ExitCode)
|
|
|
|
err := xerrors.Errorf("sector precommit failed: %d", mw.Receipt.ExitCode)
|
2020-04-03 16:54:01 +00:00
|
|
|
return ctx.Send(SectorChainPreCommitFailed{err})
|
2020-01-15 20:49:11 +00:00
|
|
|
}
|
2020-08-27 12:02:00 +00:00
|
|
|
|
2020-04-06 22:31:33 +00:00
|
|
|
log.Info("precommit message landed on chain: ", sector.SectorNumber)
|
2020-01-15 20:49:11 +00:00
|
|
|
|
2020-05-18 22:49:21 +00:00
|
|
|
return ctx.Send(SectorPreCommitLanded{TipSet: mw.TipSetTok})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Sealing) handleWaitSeed(ctx statemachine.Context, sector SectorInfo) error {
|
2020-08-05 01:30:58 +00:00
|
|
|
tok, _, err := m.api.ChainHead(ctx.Context())
|
|
|
|
if err != nil {
|
2020-09-17 02:34:13 +00:00
|
|
|
log.Errorf("handleWaitSeed: api error, not proceeding: %+v", err)
|
2020-08-05 01:30:58 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
pci, err := m.api.StateSectorPreCommitInfo(ctx.Context(), m.maddr, sector.SectorNumber, tok)
|
2020-04-04 02:55:19 +00:00
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("getting precommit info: %w", err)
|
|
|
|
}
|
2020-06-22 08:31:28 +00:00
|
|
|
if pci == nil {
|
|
|
|
return ctx.Send(SectorChainPreCommitFailed{error: xerrors.Errorf("precommit info not found on chain")})
|
|
|
|
}
|
2020-04-04 02:55:19 +00:00
|
|
|
|
2020-09-23 19:24:51 +00:00
|
|
|
randHeight := pci.PreCommitEpoch + policy.GetPreCommitChallengeDelay()
|
2020-01-15 20:49:11 +00:00
|
|
|
|
2020-08-05 01:30:58 +00:00
|
|
|
err = m.events.ChainAt(func(ectx context.Context, _ TipSetToken, curH abi.ChainEpoch) error {
|
|
|
|
// in case of null blocks the randomness can land after the tipset we
|
|
|
|
// get from the events API
|
|
|
|
tok, _, err := m.api.ChainHead(ctx.Context())
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("handleCommitting: api error, not proceeding: %+v", err)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-04-20 18:21:11 +00:00
|
|
|
buf := new(bytes.Buffer)
|
|
|
|
if err := m.maddr.MarshalCBOR(buf); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-08-11 23:58:35 +00:00
|
|
|
rand, err := m.api.ChainGetRandomnessFromBeacon(ectx, tok, crypto.DomainSeparationTag_InteractiveSealChallengeSeed, randHeight, buf.Bytes())
|
2020-01-15 20:49:11 +00:00
|
|
|
if err != nil {
|
2020-06-17 15:19:36 +00:00
|
|
|
err = xerrors.Errorf("failed to get randomness for computing seal proof (ch %d; rh %d; tsk %x): %w", curH, randHeight, tok, err)
|
2020-01-15 20:49:11 +00:00
|
|
|
|
2020-06-17 15:19:36 +00:00
|
|
|
_ = ctx.Send(SectorChainPreCommitFailed{error: err})
|
2020-01-15 20:49:11 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-04-06 20:23:37 +00:00
|
|
|
_ = ctx.Send(SectorSeedReady{SeedValue: abi.InteractiveSealRandomness(rand), SeedEpoch: randHeight})
|
2020-01-15 20:49:11 +00:00
|
|
|
|
|
|
|
return nil
|
2020-04-06 18:07:26 +00:00
|
|
|
}, func(ctx context.Context, ts TipSetToken) error {
|
2020-01-15 20:49:11 +00:00
|
|
|
log.Warn("revert in interactive commit sector step")
|
|
|
|
// TODO: need to cancel running process and restart...
|
|
|
|
return nil
|
2020-04-06 20:23:37 +00:00
|
|
|
}, InteractivePoRepConfidence, randHeight)
|
2020-01-15 20:49:11 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Warn("waitForPreCommitMessage ChainAt errored: ", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Sealing) handleCommitting(ctx statemachine.Context, sector SectorInfo) error {
|
2020-08-18 16:02:13 +00:00
|
|
|
if sector.CommitMessage != nil {
|
|
|
|
log.Warnf("sector %d entered committing state with a commit message cid", sector.SectorNumber)
|
|
|
|
|
|
|
|
ml, err := m.api.StateSearchMsg(ctx.Context(), *sector.CommitMessage)
|
|
|
|
if err != nil {
|
|
|
|
log.Warnf("sector %d searching existing commit message %s: %+v", sector.SectorNumber, *sector.CommitMessage, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if ml != nil {
|
|
|
|
// some weird retry paths can lead here
|
|
|
|
return ctx.Send(SectorRetryCommitWait{})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-11 09:41:28 +00:00
|
|
|
cfg, err := m.getConfig()
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("getting config: %w", err)
|
|
|
|
}
|
|
|
|
|
2020-01-15 20:49:11 +00:00
|
|
|
log.Info("scheduling seal proof computation...")
|
|
|
|
|
2021-07-05 10:51:15 +00:00
|
|
|
log.Infof("KOMIT %d %x(%d); %x(%d); %v; r:%s; d:%s", sector.SectorNumber, sector.TicketValue, sector.TicketEpoch, sector.SeedValue, sector.SeedEpoch, sector.pieceInfos(), sector.CommR, sector.CommD)
|
2020-02-23 20:32:14 +00:00
|
|
|
|
2020-08-21 16:31:28 +00:00
|
|
|
if sector.CommD == nil || sector.CommR == nil {
|
|
|
|
return ctx.Send(SectorCommitFailed{xerrors.Errorf("sector had nil commR or commD")})
|
|
|
|
}
|
|
|
|
|
2020-03-17 20:19:52 +00:00
|
|
|
cids := storage.SectorCids{
|
|
|
|
Unsealed: *sector.CommD,
|
|
|
|
Sealed: *sector.CommR,
|
|
|
|
}
|
2020-11-04 20:29:08 +00:00
|
|
|
c2in, err := m.sealer.SealCommit1(sector.sealingCtx(ctx.Context()), m.minerSector(sector.SectorType, sector.SectorNumber), sector.TicketValue, sector.SeedValue, sector.pieceInfos(), cids)
|
2020-03-03 22:19:22 +00:00
|
|
|
if err != nil {
|
2020-06-02 20:30:40 +00:00
|
|
|
return ctx.Send(SectorComputeProofFailed{xerrors.Errorf("computing seal proof failed(1): %w", err)})
|
2020-03-03 22:19:22 +00:00
|
|
|
}
|
|
|
|
|
2020-11-04 20:29:08 +00:00
|
|
|
proof, err := m.sealer.SealCommit2(sector.sealingCtx(ctx.Context()), m.minerSector(sector.SectorType, sector.SectorNumber), c2in)
|
2020-01-15 20:49:11 +00:00
|
|
|
if err != nil {
|
2020-06-02 20:30:40 +00:00
|
|
|
return ctx.Send(SectorComputeProofFailed{xerrors.Errorf("computing seal proof failed(2): %w", err)})
|
2020-01-15 20:49:11 +00:00
|
|
|
}
|
|
|
|
|
2021-06-11 09:41:28 +00:00
|
|
|
{
|
|
|
|
tok, _, err := m.api.ChainHead(ctx.Context())
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("handleCommitting: api error, not proceeding: %+v", err)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := m.checkCommit(ctx.Context(), sector, proof, tok); err != nil {
|
|
|
|
return ctx.Send(SectorComputeProofFailed{xerrors.Errorf("commit check error: %w", err)})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if cfg.FinalizeEarly {
|
|
|
|
return ctx.Send(SectorProofReady{
|
|
|
|
Proof: proof,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-08-27 10:57:08 +00:00
|
|
|
return ctx.Send(SectorCommitted{
|
|
|
|
Proof: proof,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Sealing) handleSubmitCommit(ctx statemachine.Context, sector SectorInfo) error {
|
2021-03-10 15:16:44 +00:00
|
|
|
cfg, err := m.getConfig()
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("getting config: %w", err)
|
|
|
|
}
|
2021-05-17 20:51:29 +00:00
|
|
|
|
2021-03-10 15:16:44 +00:00
|
|
|
if cfg.AggregateCommits {
|
2021-05-17 20:51:29 +00:00
|
|
|
nv, err := m.api.StateNetworkVersion(ctx.Context(), nil)
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("getting network version: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if nv >= network.Version13 {
|
|
|
|
return ctx.Send(SectorSubmitCommitAggregate{})
|
|
|
|
}
|
2021-03-10 15:16:44 +00:00
|
|
|
}
|
|
|
|
|
2020-04-09 17:34:07 +00:00
|
|
|
tok, _, err := m.api.ChainHead(ctx.Context())
|
|
|
|
if err != nil {
|
2021-06-11 09:41:28 +00:00
|
|
|
log.Errorf("handleSubmitCommit: api error, not proceeding: %+v", err)
|
2020-04-09 17:34:07 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-08-27 10:57:08 +00:00
|
|
|
if err := m.checkCommit(ctx.Context(), sector, sector.Proof, tok); err != nil {
|
2020-04-04 01:50:05 +00:00
|
|
|
return ctx.Send(SectorCommitFailed{xerrors.Errorf("commit check error: %w", err)})
|
|
|
|
}
|
|
|
|
|
2020-04-06 18:07:26 +00:00
|
|
|
enc := new(bytes.Buffer)
|
2020-09-22 04:35:15 +00:00
|
|
|
params := &miner.ProveCommitSectorParams{
|
|
|
|
SectorNumber: sector.SectorNumber,
|
|
|
|
Proof: sector.Proof,
|
|
|
|
}
|
2020-09-17 02:34:13 +00:00
|
|
|
|
2020-09-22 04:35:15 +00:00
|
|
|
if err := params.MarshalCBOR(enc); err != nil {
|
|
|
|
return ctx.Send(SectorCommitFailed{xerrors.Errorf("could not serialize commit sector parameters: %w", err)})
|
2020-01-15 20:49:11 +00:00
|
|
|
}
|
|
|
|
|
2020-12-02 20:47:45 +00:00
|
|
|
mi, err := m.api.StateMinerInfo(ctx.Context(), m.maddr, tok)
|
2020-04-09 17:34:07 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Errorf("handleCommitting: api error, not proceeding: %+v", err)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-08-05 01:30:58 +00:00
|
|
|
pci, err := m.api.StateSectorPreCommitInfo(ctx.Context(), m.maddr, sector.SectorNumber, tok)
|
2020-06-26 15:58:29 +00:00
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("getting precommit info: %w", err)
|
|
|
|
}
|
|
|
|
if pci == nil {
|
|
|
|
return ctx.Send(SectorCommitFailed{error: xerrors.Errorf("precommit info not found on chain")})
|
|
|
|
}
|
|
|
|
|
2020-08-17 07:11:47 +00:00
|
|
|
collateral, err := m.api.StateMinerInitialPledgeCollateral(ctx.Context(), m.maddr, pci.Info, tok)
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("getting initial pledge collateral: %w", err)
|
|
|
|
}
|
|
|
|
|
2020-06-26 15:58:29 +00:00
|
|
|
collateral = big.Sub(collateral, pci.PreCommitDeposit)
|
|
|
|
if collateral.LessThan(big.Zero()) {
|
|
|
|
collateral = big.Zero()
|
|
|
|
}
|
|
|
|
|
2021-07-12 16:46:05 +00:00
|
|
|
collateral, err = collateralSendAmount(ctx.Context(), m.api, m.maddr, cfg, collateral)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2021-06-29 16:17:08 +00:00
|
|
|
}
|
|
|
|
|
2021-06-08 13:43:43 +00:00
|
|
|
goodFunds := big.Add(collateral, big.Int(m.feeCfg.MaxCommitGasFee))
|
2020-12-02 20:47:45 +00:00
|
|
|
|
2020-12-03 11:30:41 +00:00
|
|
|
from, _, err := m.addrSel(ctx.Context(), mi, api.CommitAddr, goodFunds, collateral)
|
2020-12-02 20:47:45 +00:00
|
|
|
if err != nil {
|
2020-12-02 21:01:09 +00:00
|
|
|
return ctx.Send(SectorCommitFailed{xerrors.Errorf("no good address to send commit message from: %w", err)})
|
2020-12-02 20:47:45 +00:00
|
|
|
}
|
|
|
|
|
2020-08-27 10:57:08 +00:00
|
|
|
// TODO: check seed / ticket / deals are up to date
|
2021-06-08 13:43:43 +00:00
|
|
|
mcid, err := m.api.SendMsg(ctx.Context(), from, m.maddr, miner.Methods.ProveCommitSector, collateral, big.Int(m.feeCfg.MaxCommitGasFee), enc.Bytes())
|
2020-01-15 20:49:11 +00:00
|
|
|
if err != nil {
|
|
|
|
return ctx.Send(SectorCommitFailed{xerrors.Errorf("pushing message to mpool: %w", err)})
|
|
|
|
}
|
|
|
|
|
2020-08-27 10:57:08 +00:00
|
|
|
return ctx.Send(SectorCommitSubmitted{
|
2020-04-06 18:07:26 +00:00
|
|
|
Message: mcid,
|
2020-01-15 20:49:11 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-03-10 15:16:44 +00:00
|
|
|
func (m *Sealing) handleSubmitCommitAggregate(ctx statemachine.Context, sector SectorInfo) error {
|
|
|
|
if sector.CommD == nil || sector.CommR == nil {
|
|
|
|
return ctx.Send(SectorCommitFailed{xerrors.Errorf("sector had nil commR or commD")})
|
|
|
|
}
|
|
|
|
|
2021-06-01 09:56:19 +00:00
|
|
|
res, err := m.commiter.AddCommit(ctx.Context(), sector, AggregateInput{
|
2021-06-09 15:18:09 +00:00
|
|
|
Info: proof.AggregateSealVerifyInfo{
|
2021-03-10 15:16:44 +00:00
|
|
|
Number: sector.SectorNumber,
|
|
|
|
Randomness: sector.TicketValue,
|
|
|
|
InteractiveRandomness: sector.SeedValue,
|
|
|
|
SealedCID: *sector.CommR,
|
|
|
|
UnsealedCID: *sector.CommD,
|
|
|
|
},
|
2021-06-09 15:18:09 +00:00
|
|
|
Proof: sector.Proof, // todo: this correct??
|
|
|
|
Spt: sector.SectorType,
|
2021-03-10 15:16:44 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
2021-06-25 09:25:17 +00:00
|
|
|
return ctx.Send(SectorRetrySubmitCommit{})
|
2021-03-10 15:16:44 +00:00
|
|
|
}
|
|
|
|
|
2021-06-01 09:56:19 +00:00
|
|
|
if res.Error != "" {
|
2021-06-25 09:25:17 +00:00
|
|
|
tok, _, err := m.api.ChainHead(ctx.Context())
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("handleSubmitCommit: api error, not proceeding: %+v", err)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := m.checkCommit(ctx.Context(), sector, sector.Proof, tok); err != nil {
|
|
|
|
return ctx.Send(SectorCommitFailed{xerrors.Errorf("commit check error: %w", err)})
|
|
|
|
}
|
|
|
|
|
|
|
|
return ctx.Send(SectorRetrySubmitCommit{})
|
2021-06-01 09:56:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if e, found := res.FailedSectors[sector.SectorNumber]; found {
|
|
|
|
return ctx.Send(SectorCommitFailed{xerrors.Errorf("sector failed in aggregate processing: %s", e)})
|
|
|
|
}
|
|
|
|
|
|
|
|
if res.Msg == nil {
|
|
|
|
return ctx.Send(SectorCommitFailed{xerrors.Errorf("aggregate message was nil")})
|
|
|
|
}
|
|
|
|
|
|
|
|
return ctx.Send(SectorCommitAggregateSent{*res.Msg})
|
2021-03-10 15:16:44 +00:00
|
|
|
}
|
|
|
|
|
2020-01-15 20:49:11 +00:00
|
|
|
func (m *Sealing) handleCommitWait(ctx statemachine.Context, sector SectorInfo) error {
|
|
|
|
if sector.CommitMessage == nil {
|
2020-04-06 22:31:33 +00:00
|
|
|
log.Errorf("sector %d entered commit wait state without a message cid", sector.SectorNumber)
|
2020-01-15 20:49:11 +00:00
|
|
|
return ctx.Send(SectorCommitFailed{xerrors.Errorf("entered commit wait with no commit cid")})
|
|
|
|
}
|
|
|
|
|
|
|
|
mw, err := m.api.StateWaitMsg(ctx.Context(), *sector.CommitMessage)
|
|
|
|
if err != nil {
|
|
|
|
return ctx.Send(SectorCommitFailed{xerrors.Errorf("failed to wait for porep inclusion: %w", err)})
|
|
|
|
}
|
|
|
|
|
2020-08-27 12:02:00 +00:00
|
|
|
switch mw.Receipt.ExitCode {
|
|
|
|
case exitcode.Ok:
|
|
|
|
// this is what we expect
|
2020-11-18 00:08:28 +00:00
|
|
|
case exitcode.SysErrInsufficientFunds:
|
|
|
|
fallthrough
|
2020-08-27 12:02:00 +00:00
|
|
|
case exitcode.SysErrOutOfGas:
|
2020-11-18 00:08:28 +00:00
|
|
|
// gas estimator guessed a wrong number / out of funds
|
2020-08-27 12:02:00 +00:00
|
|
|
return ctx.Send(SectorRetrySubmitCommit{})
|
|
|
|
default:
|
2020-04-06 18:07:26 +00:00
|
|
|
return ctx.Send(SectorCommitFailed{xerrors.Errorf("submitting sector proof failed (exit=%d, msg=%s) (t:%x; s:%x(%d); p:%x)", mw.Receipt.ExitCode, sector.CommitMessage, sector.TicketValue, sector.SeedValue, sector.SeedEpoch, sector.Proof)})
|
2020-01-15 20:49:11 +00:00
|
|
|
}
|
|
|
|
|
2020-08-27 11:51:13 +00:00
|
|
|
si, err := m.api.StateSectorGetInfo(ctx.Context(), m.maddr, sector.SectorNumber, mw.TipSetTok)
|
2020-05-28 00:10:50 +00:00
|
|
|
if err != nil {
|
2020-08-27 11:51:13 +00:00
|
|
|
return ctx.Send(SectorCommitFailed{xerrors.Errorf("proof validation failed, calling StateSectorGetInfo: %w", err)})
|
|
|
|
}
|
|
|
|
if si == nil {
|
|
|
|
return ctx.Send(SectorCommitFailed{xerrors.Errorf("proof validation failed, sector not found in sector set after cron")})
|
2020-05-28 00:10:50 +00:00
|
|
|
}
|
|
|
|
|
2020-01-15 20:49:11 +00:00
|
|
|
return ctx.Send(SectorProving{})
|
|
|
|
}
|
|
|
|
|
2020-01-29 21:25:06 +00:00
|
|
|
func (m *Sealing) handleFinalizeSector(ctx statemachine.Context, sector SectorInfo) error {
|
2020-01-29 22:37:31 +00:00
|
|
|
// TODO: Maybe wait for some finality
|
|
|
|
|
2021-01-26 16:50:31 +00:00
|
|
|
cfg, err := m.getConfig()
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("getting sealing config: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := m.sealer.FinalizeSector(sector.sealingCtx(ctx.Context()), m.minerSector(sector.SectorType, sector.SectorNumber), sector.keepUnsealedRanges(false, cfg.AlwaysKeepUnsealedCopy)); err != nil {
|
2020-03-03 22:19:22 +00:00
|
|
|
return ctx.Send(SectorFinalizeFailed{xerrors.Errorf("finalize sector: %w", err)})
|
2020-01-29 21:25:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ctx.Send(SectorFinalized{})
|
|
|
|
}
|