Skip to content

Commit

Permalink
Merge pull request #30 from filecoin-project/fix/no-precommit-recover
Browse files Browse the repository at this point in the history
checkCommit: handle missing precommits
  • Loading branch information
magik6k authored Jun 17, 2020
2 parents 494c3bc + b2d1438 commit 77fc23c
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 2 deletions.
5 changes: 5 additions & 0 deletions checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type ErrPrecommitOnChain struct{ error }

type ErrBadSeed struct{ error }
type ErrInvalidProof struct{ error }
type ErrNoPrecommit struct{ error }

func checkPieces(ctx context.Context, si SectorInfo, api SealingAPI) error {
tok, height, err := api.ChainHead(ctx)
Expand Down Expand Up @@ -109,6 +110,10 @@ func (m *Sealing) checkCommit(ctx context.Context, si SectorInfo, proof []byte,
return xerrors.Errorf("getting precommit info: %w", err)
}

if pci == nil {
return &ErrNoPrecommit{xerrors.Errorf("precommit info not found on-chain")}
}

if pci.PreCommitEpoch+miner.PreCommitChallengeDelay != si.SeedEpoch {
return &ErrBadSeed{xerrors.Errorf("seed epoch doesn't match on chain info: %d != %d", pci.PreCommitEpoch+miner.PreCommitChallengeDelay, si.SeedEpoch)}
}
Expand Down
1 change: 1 addition & 0 deletions fsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ var fsmPlanners = map[SectorState]func(events []statemachine.Event, state *Secto
on(SectorRetryWaitSeed{}, WaitSeed),
on(SectorRetryComputeProof{}, Committing),
on(SectorRetryInvalidProof{}, Committing),
on(SectorRetryPreCommitWait{}, PreCommitWait),
),
FinalizeFailed: planOne(
on(SectorRetryFinalize{}, FinalizeSector),
Expand Down
4 changes: 4 additions & 0 deletions fsm_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ type SectorRetryWaitSeed struct{}

func (evt SectorRetryWaitSeed) apply(state *SectorInfo) {}

type SectorRetryPreCommitWait struct{}

func (evt SectorRetryPreCommitWait) apply(state *SectorInfo) {}

type SectorRetryComputeProof struct{}

func (evt SectorRetryComputeProof) apply(state *SectorInfo) {
Expand Down
4 changes: 2 additions & 2 deletions states.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,9 @@ func (m *Sealing) handleWaitSeed(ctx statemachine.Context, sector SectorInfo) er
}
rand, err := m.api.ChainGetRandomness(ectx, tok, crypto.DomainSeparationTag_InteractiveSealChallengeSeed, randHeight, buf.Bytes())
if err != nil {
err = xerrors.Errorf("failed to get randomness for computing seal proof: %w", err)
err = xerrors.Errorf("failed to get randomness for computing seal proof (ch %d; rh %d; tsk %x): %w", curH, randHeight, tok, err)

_ = ctx.Send(SectorFatalError{error: err})
_ = ctx.Send(SectorChainPreCommitFailed{error: err})
return err
}

Expand Down
3 changes: 3 additions & 0 deletions states_failed.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ func (m *Sealing) handleCommitFailed(ctx statemachine.Context, sector SectorInfo
}

return ctx.Send(SectorRetryInvalidProof{})
case *ErrPrecommitOnChain:
log.Errorf("no precommit on chain, will retry: %+v", err)
return ctx.Send(SectorRetryPreCommitWait{})
default:
return xerrors.Errorf("checkCommit sanity check error: %w", err)
}
Expand Down

0 comments on commit 77fc23c

Please sign in to comment.