Add separate state for waiting for commit message

This commit is contained in:
whyrusleeping 2019-12-05 18:40:57 -08:00
parent 8780faf07a
commit d92ba5fbba
3 changed files with 26 additions and 12 deletions

View File

@ -20,6 +20,7 @@ const (
PreCommitting // on chain pre-commit PreCommitting // on chain pre-commit
PreCommitted // waiting for seed PreCommitted // waiting for seed
Committing Committing
CommitWait // waiting for message to land on chain
Proving Proving
SealFailed SealFailed

View File

@ -131,6 +131,7 @@ func (m *Miner) handlePreCommitted(ctx context.Context, sector SectorInfo) *sect
if mw.Receipt.ExitCode != 0 { if mw.Receipt.ExitCode != 0 {
log.Error("sector precommit failed: ", mw.Receipt.ExitCode) log.Error("sector precommit failed: ", mw.Receipt.ExitCode)
err := xerrors.Errorf("sector precommit failed: %d", mw.Receipt.ExitCode)
return sector.upd().to(api.PreCommitFailed).error(err) return sector.upd().to(api.PreCommitFailed).error(err)
} }
log.Info("precommit message landed on chain: ", sector.SectorID) log.Info("precommit message landed on chain: ", sector.SectorID)
@ -157,6 +158,7 @@ func (m *Miner) handlePreCommitted(ctx context.Context, sector SectorInfo) *sect
return nil return nil
}, func(ctx context.Context, ts *types.TipSet) error { }, func(ctx context.Context, ts *types.TipSet) error {
log.Warn("revert in interactive commit sector step") log.Warn("revert in interactive commit sector step")
// TODO: need to cancel running process and restart...
return nil return nil
}, 3, mw.TipSet.Height()+build.InteractivePoRepDelay) }, 3, mw.TipSet.Height()+build.InteractivePoRepDelay)
if err != nil { if err != nil {
@ -203,20 +205,29 @@ func (m *Miner) handleCommitting(ctx context.Context, sector SectorInfo) *sector
} }
// TODO: Separate state before this wait, so we persist message cid? // TODO: Separate state before this wait, so we persist message cid?
return sector.upd().to(api.CommitWait).state(func(info *SectorInfo) {
mw, err := m.api.StateWaitMsg(ctx, smsg.Cid())
if err != nil {
return sector.upd().to(api.CommitFailed).error(xerrors.Errorf("failed to wait for porep inclusion: %w", err))
}
if mw.Receipt.ExitCode != 0 {
log.Errorf("UNHANDLED: submitting sector proof failed (exit=%d, msg=%s) (t:%x; s:%x(%d); p:%x)", mw.Receipt.ExitCode, smsg.Cid(), sector.Ticket.TicketBytes, sector.Seed.TicketBytes, sector.Seed.BlockHeight, params.Proof)
return sector.upd().fatal(xerrors.New("UNHANDLED: submitting sector proof failed"))
}
return sector.upd().to(api.Proving).state(func(info *SectorInfo) {
mcid := smsg.Cid() mcid := smsg.Cid()
info.CommitMessage = &mcid info.CommitMessage = &mcid
info.Proof = proof info.Proof = proof
}) })
} }
func (m *Miner) handleCommitWait(ctx context.Context, sector SectorInfo) *sectorUpdate {
if sector.CommitMessage == nil {
log.Errorf("sector %d entered commit wait state without a message cid", sector.SectorID)
return sector.upd().to(api.CommitFailed).error(xerrors.Errorf("entered commit wait with no commit cid"))
}
mw, err := m.api.StateWaitMsg(ctx, *sector.CommitMessage)
if err != nil {
return sector.upd().to(api.CommitFailed).error(xerrors.Errorf("failed to wait for porep inclusion: %w", err))
}
if mw.Receipt.ExitCode != 0 {
log.Errorf("UNHANDLED: submitting sector proof failed (exit=%d, msg=%s) (t:%x; s:%x(%d); p:%x)", mw.Receipt.ExitCode, sector.CommitMessage, sector.Ticket.TicketBytes, sector.Seed.TicketBytes, sector.Seed.BlockHeight, sector.Proof)
return sector.upd().fatal(xerrors.New("UNHANDLED: submitting sector proof failed"))
}
return sector.upd().to(api.Proving).state(func(info *SectorInfo) {
})
}

View File

@ -229,6 +229,8 @@ func (m *Miner) onSectorUpdated(ctx context.Context, update sectorUpdate) {
m.handleSectorUpdate(ctx, sector, m.handlePreCommitted) m.handleSectorUpdate(ctx, sector, m.handlePreCommitted)
case api.Committing: case api.Committing:
m.handleSectorUpdate(ctx, sector, m.handleCommitting) m.handleSectorUpdate(ctx, sector, m.handleCommitting)
case api.CommitWait:
m.handleSectorUpdate(ctx, sector, m.handleCommitWait)
case api.Proving: case api.Proving:
// TODO: track sector health / expiration // TODO: track sector health / expiration
log.Infof("Proving sector %d", update.id) log.Infof("Proving sector %d", update.id)