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-02-27 00:42:39 +00:00
|
|
|
|
2020-04-06 18:07:26 +00:00
|
|
|
"golang.org/x/xerrors"
|
2020-01-15 20:49:11 +00:00
|
|
|
|
2020-04-06 20:23:37 +00:00
|
|
|
"github.com/filecoin-project/go-statemachine"
|
2020-02-08 02:18:32 +00:00
|
|
|
"github.com/filecoin-project/specs-actors/actors/abi"
|
2020-04-06 18:07:26 +00:00
|
|
|
"github.com/filecoin-project/specs-actors/actors/abi/big"
|
2020-02-12 07:44:20 +00:00
|
|
|
"github.com/filecoin-project/specs-actors/actors/builtin"
|
2020-02-11 03:31:28 +00:00
|
|
|
"github.com/filecoin-project/specs-actors/actors/builtin/miner"
|
2020-04-06 18:07:26 +00:00
|
|
|
"github.com/filecoin-project/specs-actors/actors/crypto"
|
|
|
|
"github.com/filecoin-project/specs-storage/storage"
|
2020-01-15 20:49:11 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (m *Sealing) handlePacking(ctx statemachine.Context, sector SectorInfo) error {
|
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-03-03 22:19:22 +00:00
|
|
|
ubytes := abi.PaddedPieceSize(m.sealer.SectorSize()).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
|
|
|
}
|
|
|
|
|
2020-04-07 21:44:33 +00:00
|
|
|
fillerPieces, err := m.pledgeSector(ctx.Context(), m.minerSector(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
|
|
|
}
|
|
|
|
|
2020-06-02 21:45:28 +00:00
|
|
|
func (m *Sealing) getTicket(ctx statemachine.Context, sector SectorInfo) (abi.SealRandomness, abi.ChainEpoch, 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 {
|
|
|
|
log.Errorf("handlePreCommit1: api error, not proceeding: %+v", err)
|
2020-06-02 21:45:28 +00:00
|
|
|
return nil, 0, nil
|
|
|
|
}
|
|
|
|
|
2020-06-03 12:14:06 +00:00
|
|
|
ticketEpoch := epoch - SealRandomnessLookback
|
2020-06-02 21:45:28 +00:00
|
|
|
buf := new(bytes.Buffer)
|
|
|
|
if err := m.maddr.MarshalCBOR(buf); err != nil {
|
|
|
|
return nil, 0, err
|
|
|
|
}
|
|
|
|
|
|
|
|
pci, err := m.api.StateSectorPreCommitInfo(ctx.Context(), m.maddr, sector.SectorNumber, tok)
|
|
|
|
if err != nil {
|
|
|
|
return nil, 0, xerrors.Errorf("getting precommit info: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if pci != nil {
|
|
|
|
ticketEpoch = pci.Info.SealRandEpoch
|
|
|
|
}
|
|
|
|
|
|
|
|
rand, err := m.api.ChainGetRandomness(ctx.Context(), tok, crypto.DomainSeparationTag_SealRandomness, ticketEpoch, buf.Bytes())
|
|
|
|
if err != nil {
|
|
|
|
return nil, 0, err
|
2020-04-07 20:26:43 +00:00
|
|
|
}
|
|
|
|
|
2020-06-02 21:45:28 +00:00
|
|
|
return abi.SealRandomness(rand), ticketEpoch, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Sealing) handlePreCommit1(ctx statemachine.Context, sector SectorInfo) error {
|
2020-01-22 19:47:29 +00:00
|
|
|
if err := checkPieces(ctx.Context(), 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-04-07 21:44:33 +00:00
|
|
|
return ctx.Send(SectorPackingFailed{xerrors.Errorf("invalid dealIDs in sector: %w", err)})
|
2020-01-23 16:02:55 +00:00
|
|
|
case *ErrExpiredDeals: // Probably not much we can do here, maybe re-pack the sector?
|
2020-04-07 21:44:33 +00:00
|
|
|
return ctx.Send(SectorPackingFailed{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
|
|
|
}
|
|
|
|
|
2020-04-06 22:31:33 +00:00
|
|
|
log.Infow("performing sector replication...", "sector", sector.SectorNumber)
|
2020-06-02 21:45:28 +00:00
|
|
|
ticketValue, ticketEpoch, err := m.getTicket(ctx, sector)
|
2020-01-15 20:49:11 +00:00
|
|
|
if err != nil {
|
2020-04-03 16:54:01 +00:00
|
|
|
return ctx.Send(SectorSealPreCommitFailed{xerrors.Errorf("getting ticket failed: %w", err)})
|
2020-01-15 20:49:11 +00:00
|
|
|
}
|
|
|
|
|
2020-04-06 22:31:33 +00:00
|
|
|
pc1o, err := m.sealer.SealPreCommit1(ctx.Context(), m.minerSector(sector.SectorNumber), ticketValue, sector.pieceInfos())
|
2020-03-03 22:19:22 +00:00
|
|
|
if err != nil {
|
2020-04-03 16:54:01 +00:00
|
|
|
return ctx.Send(SectorSealPreCommitFailed{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,
|
2020-04-06 18:07:26 +00:00
|
|
|
TicketValue: ticketValue,
|
|
|
|
TicketEpoch: ticketEpoch,
|
2020-04-03 16:54:01 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Sealing) handlePreCommit2(ctx statemachine.Context, sector SectorInfo) error {
|
2020-04-06 22:31:33 +00:00
|
|
|
cids, err := m.sealer.SealPreCommit2(ctx.Context(), m.minerSector(sector.SectorNumber), sector.PreCommit1Out)
|
2020-01-15 20:49:11 +00:00
|
|
|
if err != nil {
|
2020-04-03 16:54:01 +00:00
|
|
|
return ctx.Send(SectorSealPreCommitFailed{xerrors.Errorf("seal pre commit(2) failed: %w", err)})
|
2020-01-15 20:49:11 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Sealing) handlePreCommitting(ctx statemachine.Context, sector SectorInfo) 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)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
waddr, err := m.api.StateMinerWorkerAddress(ctx.Context(), m.maddr, tok)
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("handlePreCommitting: api error, not proceeding: %+v", err)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
return 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)
|
|
|
|
return ctx.Send(SectorSealPreCommitFailed{xerrors.Errorf("bad CommD error: %w", err)})
|
2020-01-23 16:02:55 +00:00
|
|
|
case *ErrExpiredTicket:
|
2020-04-03 16:54:01 +00:00
|
|
|
return ctx.Send(SectorSealPreCommitFailed{xerrors.Errorf("ticket expired: %w", err)})
|
2020-06-02 21:45:28 +00:00
|
|
|
case *ErrBadTicket:
|
|
|
|
return ctx.Send(SectorSealPreCommitFailed{xerrors.Errorf("bad expired: %w", err)})
|
|
|
|
case *ErrPrecommitOnChain:
|
|
|
|
return ctx.Send(SectorPreCommitLanded{TipSet: tok}) // we re-did precommit
|
2020-01-23 15:38:01 +00:00
|
|
|
default:
|
2020-04-03 17:45:48 +00:00
|
|
|
return 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 {
|
|
|
|
return ctx.Send(SectorSealPreCommitFailed{xerrors.Errorf("handlePreCommitting: failed to compute pre-commit expiry: %w", err)})
|
|
|
|
}
|
|
|
|
|
2020-02-14 00:24:24 +00:00
|
|
|
params := &miner.SectorPreCommitInfo{
|
2020-04-07 22:26:07 +00:00
|
|
|
Expiration: expiration,
|
2020-04-06 22:31:33 +00:00
|
|
|
SectorNumber: sector.SectorNumber,
|
2020-02-28 20:52:14 +00:00
|
|
|
RegisteredProof: 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-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
|
|
|
}
|
|
|
|
|
2020-04-06 22:31:33 +00:00
|
|
|
log.Info("submitting precommit for sector: ", sector.SectorNumber)
|
2020-04-09 17:34:07 +00:00
|
|
|
mcid, err := m.api.SendMsg(ctx.Context(), waddr, m.maddr, builtin.MethodsMiner.PreCommitSector, big.NewInt(0), big.NewInt(1), 1000000, enc.Bytes())
|
2020-01-15 20:49:11 +00:00
|
|
|
if err != nil {
|
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
|
|
|
}
|
|
|
|
|
2020-04-06 18:07:26 +00:00
|
|
|
return ctx.Send(SectorPreCommitted{Message: mcid})
|
2020-01-15 20:49:11 +00:00
|
|
|
}
|
|
|
|
|
2020-05-18 22:49:21 +00:00
|
|
|
func (m *Sealing) handlePreCommitWait(ctx statemachine.Context, sector SectorInfo) error {
|
2020-01-15 20:49:11 +00:00
|
|
|
// would be ideal to just use the events.Called handler, but it wouldnt 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
|
|
|
}
|
|
|
|
|
|
|
|
if mw.Receipt.ExitCode != 0 {
|
|
|
|
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-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 {
|
|
|
|
pci, err := m.api.StateSectorPreCommitInfo(ctx.Context(), m.maddr, sector.SectorNumber, sector.PreCommitTipSet)
|
2020-04-04 02:55:19 +00:00
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("getting precommit info: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
randHeight := pci.PreCommitEpoch + miner.PreCommitChallengeDelay
|
2020-01-15 20:49:11 +00:00
|
|
|
|
2020-04-06 18:07:26 +00:00
|
|
|
err = m.events.ChainAt(func(ectx context.Context, tok TipSetToken, curH abi.ChainEpoch) error {
|
2020-04-20 18:21:11 +00:00
|
|
|
buf := new(bytes.Buffer)
|
|
|
|
if err := m.maddr.MarshalCBOR(buf); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
rand, err := m.api.ChainGetRandomness(ectx, tok, crypto.DomainSeparationTag_InteractiveSealChallengeSeed, randHeight, buf.Bytes())
|
2020-01-15 20:49:11 +00:00
|
|
|
if err != nil {
|
|
|
|
err = xerrors.Errorf("failed to get randomness for computing seal proof: %w", err)
|
|
|
|
|
2020-04-06 20:23:37 +00:00
|
|
|
_ = ctx.Send(SectorFatalError{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 {
|
|
|
|
log.Info("scheduling seal proof computation...")
|
|
|
|
|
2020-04-06 22:31:33 +00:00
|
|
|
log.Infof("KOMIT %d %x(%d); %x(%d); %v; r:%x; d:%x", 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-03-17 20:19:52 +00:00
|
|
|
cids := storage.SectorCids{
|
|
|
|
Unsealed: *sector.CommD,
|
|
|
|
Sealed: *sector.CommR,
|
|
|
|
}
|
2020-04-06 22:31:33 +00:00
|
|
|
c2in, err := m.sealer.SealCommit1(ctx.Context(), m.minerSector(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-04-06 22:31:33 +00:00
|
|
|
proof, err := m.sealer.SealCommit2(ctx.Context(), m.minerSector(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
|
|
|
}
|
|
|
|
|
2020-04-09 17:34:07 +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 {
|
2020-04-04 01:50:05 +00:00
|
|
|
return ctx.Send(SectorCommitFailed{xerrors.Errorf("commit check error: %w", err)})
|
|
|
|
}
|
|
|
|
|
2020-01-15 20:49:11 +00:00
|
|
|
// TODO: Consider splitting states and persist proof for faster recovery
|
|
|
|
|
2020-02-12 07:44:20 +00:00
|
|
|
params := &miner.ProveCommitSectorParams{
|
2020-04-06 22:31:33 +00:00
|
|
|
SectorNumber: sector.SectorNumber,
|
2020-02-18 07:15:30 +00:00
|
|
|
Proof: proof,
|
2020-02-12 07:44:20 +00:00
|
|
|
}
|
2020-01-15 20:49:11 +00:00
|
|
|
|
2020-04-06 18:07:26 +00:00
|
|
|
enc := new(bytes.Buffer)
|
|
|
|
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-04-09 17:34:07 +00:00
|
|
|
waddr, err := m.api.StateMinerWorkerAddress(ctx.Context(), m.maddr, tok)
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("handleCommitting: api error, not proceeding: %+v", err)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-04-23 11:42:51 +00:00
|
|
|
collateral, err := m.api.StateMinerInitialPledgeCollateral(ctx.Context(), m.maddr, sector.SectorNumber, tok)
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("getting initial pledge collateral: %w", err)
|
|
|
|
}
|
|
|
|
|
2020-01-16 02:53:59 +00:00
|
|
|
// TODO: check seed / ticket are up to date
|
2020-04-23 11:42:51 +00:00
|
|
|
mcid, err := m.api.SendMsg(ctx.Context(), waddr, m.maddr, builtin.MethodsMiner.ProveCommitSector, collateral, big.NewInt(1), 1000000, 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)})
|
|
|
|
}
|
|
|
|
|
|
|
|
return ctx.Send(SectorCommitted{
|
2020-03-22 20:44:27 +00:00
|
|
|
Proof: proof,
|
2020-04-06 18:07:26 +00:00
|
|
|
Message: mcid,
|
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)})
|
|
|
|
}
|
|
|
|
|
|
|
|
if mw.Receipt.ExitCode != 0 {
|
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-05-28 00:10:50 +00:00
|
|
|
_, err = m.api.StateSectorGetInfo(ctx.Context(), m.maddr, sector.SectorNumber, mw.TipSetTok)
|
|
|
|
if err != nil {
|
|
|
|
return ctx.Send(SectorCommitFailed{xerrors.Errorf("proof validation failed, sector not found in sector set after cron: %w", err)})
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
2020-04-06 22:31:33 +00:00
|
|
|
if err := m.sealer.FinalizeSector(ctx.Context(), m.minerSector(sector.SectorNumber)); 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{})
|
|
|
|
}
|
|
|
|
|
2020-01-15 20:49:11 +00:00
|
|
|
func (m *Sealing) handleFaulty(ctx statemachine.Context, sector SectorInfo) error {
|
|
|
|
// TODO: check if the fault has already been reported, and that this sector is even valid
|
|
|
|
|
|
|
|
// TODO: coalesce faulty sector reporting
|
2020-04-15 18:00:29 +00:00
|
|
|
|
|
|
|
// TODO: ReportFaultFailed
|
2020-02-14 00:24:24 +00:00
|
|
|
bf := abi.NewBitField()
|
2020-04-06 22:31:33 +00:00
|
|
|
bf.Set(uint64(sector.SectorNumber))
|
2020-01-15 20:49:11 +00:00
|
|
|
|
2020-04-15 18:00:29 +00:00
|
|
|
deadlines, err := m.api.StateMinerDeadlines(ctx.Context(), m.maddr, nil)
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("handleFaulty: api error, not proceeding: %+v", err)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
deadline := -1
|
|
|
|
for d, field := range deadlines.Due {
|
|
|
|
set, err := field.IsSet(uint64(sector.SectorNumber))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if set {
|
|
|
|
deadline = d
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if deadline == -1 {
|
|
|
|
log.Errorf("handleFaulty: deadline not found")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
params := &miner.DeclareFaultsParams{
|
|
|
|
Faults: []miner.FaultDeclaration{
|
|
|
|
{
|
|
|
|
Deadline: uint64(deadline),
|
|
|
|
Sectors: bf,
|
|
|
|
},
|
|
|
|
},
|
2020-01-15 20:49:11 +00:00
|
|
|
}
|
|
|
|
|
2020-04-06 18:07:26 +00:00
|
|
|
enc := new(bytes.Buffer)
|
|
|
|
if err := params.MarshalCBOR(enc); err != nil {
|
|
|
|
return ctx.Send(SectorCommitFailed{xerrors.Errorf("failed to serialize declare fault params: %w", err)})
|
2020-01-15 20:49:11 +00:00
|
|
|
}
|
|
|
|
|
2020-04-09 17:34:07 +00:00
|
|
|
tok, _, err := m.api.ChainHead(ctx.Context())
|
|
|
|
if err != nil {
|
2020-04-09 17:46:44 +00:00
|
|
|
log.Errorf("handleFaulty: api error, not proceeding: %+v", err)
|
2020-04-09 17:34:07 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
waddr, err := m.api.StateMinerWorkerAddress(ctx.Context(), m.maddr, tok)
|
|
|
|
if err != nil {
|
2020-04-09 17:46:44 +00:00
|
|
|
log.Errorf("handleFaulty: api error, not proceeding: %+v", err)
|
2020-04-09 17:34:07 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-04-15 18:00:29 +00:00
|
|
|
mcid, err := m.api.SendMsg(ctx.Context(), waddr, m.maddr, builtin.MethodsMiner.DeclareFaults, big.NewInt(0), big.NewInt(1), 1000000, enc.Bytes())
|
2020-01-15 20:49:11 +00:00
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("failed to push declare faults message to network: %w", err)
|
|
|
|
}
|
|
|
|
|
2020-04-06 18:07:26 +00:00
|
|
|
return ctx.Send(SectorFaultReported{reportMsg: mcid})
|
2020-01-15 20:49:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Sealing) handleFaultReported(ctx statemachine.Context, sector SectorInfo) error {
|
|
|
|
if sector.FaultReportMsg == nil {
|
|
|
|
return xerrors.Errorf("entered fault reported state without a FaultReportMsg cid")
|
|
|
|
}
|
|
|
|
|
|
|
|
mw, err := m.api.StateWaitMsg(ctx.Context(), *sector.FaultReportMsg)
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("failed to wait for fault declaration: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if mw.Receipt.ExitCode != 0 {
|
2020-04-06 22:31:33 +00:00
|
|
|
log.Errorf("UNHANDLED: declaring sector fault failed (exit=%d, msg=%s) (id: %d)", mw.Receipt.ExitCode, *sector.FaultReportMsg, sector.SectorNumber)
|
2020-01-15 20:49:11 +00:00
|
|
|
return xerrors.Errorf("UNHANDLED: submitting fault declaration failed (exit %d)", mw.Receipt.ExitCode)
|
|
|
|
}
|
|
|
|
|
|
|
|
return ctx.Send(SectorFaultedFinal{})
|
|
|
|
}
|