From d92ba5fbba88163d0b1f12bbf872bdcd1a64e638 Mon Sep 17 00:00:00 2001 From: whyrusleeping Date: Thu, 5 Dec 2019 18:40:57 -0800 Subject: [PATCH] Add separate state for waiting for commit message --- api/api_storage.go | 1 + storage/sector_states.go | 35 +++++++++++++++++++++++------------ storage/sectors.go | 2 ++ 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/api/api_storage.go b/api/api_storage.go index 56b718420..3e69a726d 100644 --- a/api/api_storage.go +++ b/api/api_storage.go @@ -20,6 +20,7 @@ const ( PreCommitting // on chain pre-commit PreCommitted // waiting for seed Committing + CommitWait // waiting for message to land on chain Proving SealFailed diff --git a/storage/sector_states.go b/storage/sector_states.go index 4790447e9..8369a5722 100644 --- a/storage/sector_states.go +++ b/storage/sector_states.go @@ -131,6 +131,7 @@ func (m *Miner) handlePreCommitted(ctx context.Context, sector SectorInfo) *sect if mw.Receipt.ExitCode != 0 { 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) } 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 }, func(ctx context.Context, ts *types.TipSet) error { log.Warn("revert in interactive commit sector step") + // TODO: need to cancel running process and restart... return nil }, 3, mw.TipSet.Height()+build.InteractivePoRepDelay) 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? - - 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) { + return sector.upd().to(api.CommitWait).state(func(info *SectorInfo) { mcid := smsg.Cid() info.CommitMessage = &mcid 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) { + }) +} diff --git a/storage/sectors.go b/storage/sectors.go index ea9d3dbb9..72f380a81 100644 --- a/storage/sectors.go +++ b/storage/sectors.go @@ -229,6 +229,8 @@ func (m *Miner) onSectorUpdated(ctx context.Context, update sectorUpdate) { m.handleSectorUpdate(ctx, sector, m.handlePreCommitted) case api.Committing: m.handleSectorUpdate(ctx, sector, m.handleCommitting) + case api.CommitWait: + m.handleSectorUpdate(ctx, sector, m.handleCommitWait) case api.Proving: // TODO: track sector health / expiration log.Infof("Proving sector %d", update.id)