Skip to content

Commit

Permalink
storagefsm: Fix expired ticket retry loop
Browse files Browse the repository at this point in the history
  • Loading branch information
magik6k authored and codefather-filestar committed Jun 17, 2021
1 parent 1b0b2ab commit bda65cc
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions extern/storage-sealing/states_sealing.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ func (m *Sealing) handlePacking(ctx statemachine.Context, sector SectorInfo) err
return ctx.Send(SectorPacked{FillerPieces: fillerPieces})
}

func checkTicketExpired(sector SectorInfo, epoch abi.ChainEpoch) bool {
return epoch-sector.TicketEpoch > MaxTicketAge // TODO: allow configuring expected seal durations
}

func (m *Sealing) getTicket(ctx statemachine.Context, sector SectorInfo) (abi.SealRandomness, abi.ChainEpoch, error) {
tok, epoch, err := m.api.ChainHead(ctx.Context())
if err != nil {
Expand All @@ -76,6 +80,10 @@ func (m *Sealing) getTicket(ctx statemachine.Context, sector SectorInfo) (abi.Se
ticketEpoch = pci.Info.SealRandEpoch
}

if checkTicketExpired(sector, ticketEpoch) {
return nil, 0, xerrors.Errorf("ticket expired for precommitted sector")
}

rand, err := m.api.ChainGetRandomnessFromTickets(ctx.Context(), tok, crypto.DomainSeparationTag_SealRandomness, ticketEpoch, buf.Bytes())
if err != nil {
return nil, 0, err
Expand Down Expand Up @@ -127,25 +135,14 @@ func (m *Sealing) handlePreCommit1(ctx statemachine.Context, sector SectorInfo)
}
}

tok, height, err := m.api.ChainHead(ctx.Context())
_, height, err := m.api.ChainHead(ctx.Context())
if err != nil {
log.Errorf("handlePreCommit1: api error, not proceeding: %+v", err)
return nil
}

if height-sector.TicketEpoch > MaxTicketAge {
pci, err := m.api.StateSectorPreCommitInfo(ctx.Context(), m.maddr, sector.SectorNumber, tok)
if err != nil {
log.Errorf("getting precommit info: %+v", err)
}

if pci == nil {
return ctx.Send(SectorOldTicket{}) // go get new ticket
}

// TODO: allow configuring expected seal durations, if we're here, it's
// pretty unlikely that we'll precommit on time (unless the miner
// process has just restarted and the worker had the result ready)
if checkTicketExpired(sector, height) {
return ctx.Send(SectorOldTicket{}) // go get new ticket
}

pc1o, err := m.sealer.SealPreCommit1(sector.sealingCtx(ctx.Context()), m.minerSector(sector.SectorNumber), sector.TicketValue, sector.pieceInfos())
Expand Down

0 comments on commit bda65cc

Please sign in to comment.