Merge pull request #6635 from llifezou/fix_checkTicketExpired
fix ticket expiration check
This commit is contained in:
commit
60ecbdee8f
71
extern/storage-sealing/states_sealing.go
vendored
71
extern/storage-sealing/states_sealing.go
vendored
@ -105,48 +105,66 @@ func checkTicketExpired(ticket, head abi.ChainEpoch) bool {
|
|||||||
return head-ticket > MaxTicketAge // TODO: allow configuring expected seal durations
|
return head-ticket > MaxTicketAge // TODO: allow configuring expected seal durations
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Sealing) getTicket(ctx statemachine.Context, sector SectorInfo) (abi.SealRandomness, abi.ChainEpoch, error) {
|
func checkProveCommitExpired(preCommitEpoch, msd abi.ChainEpoch, currEpoch abi.ChainEpoch) bool {
|
||||||
|
return currEpoch > preCommitEpoch+msd
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Sealing) getTicket(ctx statemachine.Context, sector SectorInfo) (abi.SealRandomness, abi.ChainEpoch, bool, error) {
|
||||||
tok, epoch, err := m.api.ChainHead(ctx.Context())
|
tok, epoch, err := m.api.ChainHead(ctx.Context())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("handlePreCommit1: api error, not proceeding: %+v", err)
|
log.Errorf("getTicket: api error, not proceeding: %+v", err)
|
||||||
return nil, 0, nil
|
return nil, 0, false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// the reason why the StateMinerSectorAllocated function is placed here, if it is outside,
|
||||||
|
// if the MarshalCBOR function and StateSectorPreCommitInfo function return err, it will be executed
|
||||||
|
allocated, aerr := m.api.StateMinerSectorAllocated(ctx.Context(), m.maddr, sector.SectorNumber, nil)
|
||||||
|
if aerr != nil {
|
||||||
|
log.Errorf("getTicket: api error, checking if sector is allocated: %+v", aerr)
|
||||||
|
return nil, 0, false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
ticketEpoch := epoch - policy.SealRandomnessLookback
|
ticketEpoch := epoch - policy.SealRandomnessLookback
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
if err := m.maddr.MarshalCBOR(buf); err != nil {
|
if err := m.maddr.MarshalCBOR(buf); err != nil {
|
||||||
return nil, 0, err
|
return nil, 0, allocated, err
|
||||||
}
|
}
|
||||||
|
|
||||||
pci, err := m.api.StateSectorPreCommitInfo(ctx.Context(), m.maddr, sector.SectorNumber, tok)
|
pci, err := m.api.StateSectorPreCommitInfo(ctx.Context(), m.maddr, sector.SectorNumber, tok)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, xerrors.Errorf("getting precommit info: %w", err)
|
return nil, 0, allocated, xerrors.Errorf("getting precommit info: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if pci != nil {
|
if pci != nil {
|
||||||
ticketEpoch = pci.Info.SealRandEpoch
|
ticketEpoch = pci.Info.SealRandEpoch
|
||||||
|
|
||||||
if checkTicketExpired(ticketEpoch, epoch) {
|
nv, err := m.api.StateNetworkVersion(ctx.Context(), tok)
|
||||||
return nil, 0, xerrors.Errorf("ticket expired for precommitted sector")
|
if err != nil {
|
||||||
|
return nil, 0, allocated, xerrors.Errorf("getTicket: StateNetworkVersion: api error, not proceeding: %+v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
msd := policy.GetMaxProveCommitDuration(actors.VersionForNetwork(nv), sector.SectorType)
|
||||||
|
|
||||||
|
if checkProveCommitExpired(pci.PreCommitEpoch, msd, epoch) {
|
||||||
|
return nil, 0, allocated, xerrors.Errorf("ticket expired for precommitted sector")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if pci == nil && allocated { // allocated is true, sector precommitted but expired, will SectorCommitFailed or SectorRemove
|
||||||
|
return nil, 0, allocated, xerrors.Errorf("sector %s precommitted but expired", sector.SectorNumber)
|
||||||
}
|
}
|
||||||
|
|
||||||
rand, err := m.api.ChainGetRandomnessFromTickets(ctx.Context(), tok, crypto.DomainSeparationTag_SealRandomness, ticketEpoch, buf.Bytes())
|
rand, err := m.api.ChainGetRandomnessFromTickets(ctx.Context(), tok, crypto.DomainSeparationTag_SealRandomness, ticketEpoch, buf.Bytes())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, err
|
return nil, 0, allocated, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return abi.SealRandomness(rand), ticketEpoch, nil
|
return abi.SealRandomness(rand), ticketEpoch, allocated, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Sealing) handleGetTicket(ctx statemachine.Context, sector SectorInfo) error {
|
func (m *Sealing) handleGetTicket(ctx statemachine.Context, sector SectorInfo) error {
|
||||||
ticketValue, ticketEpoch, err := m.getTicket(ctx, sector)
|
ticketValue, ticketEpoch, allocated, err := m.getTicket(ctx, sector)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
allocated, aerr := m.api.StateMinerSectorAllocated(ctx.Context(), m.maddr, sector.SectorNumber, nil)
|
|
||||||
if aerr != nil {
|
|
||||||
log.Errorf("error checking if sector is allocated: %+v", aerr)
|
|
||||||
}
|
|
||||||
|
|
||||||
if allocated {
|
if allocated {
|
||||||
if sector.CommitMessage != nil {
|
if sector.CommitMessage != nil {
|
||||||
// Some recovery paths with unfortunate timing lead here
|
// Some recovery paths with unfortunate timing lead here
|
||||||
@ -182,16 +200,37 @@ func (m *Sealing) handlePreCommit1(ctx statemachine.Context, sector SectorInfo)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_, height, err := m.api.ChainHead(ctx.Context())
|
tok, height, err := m.api.ChainHead(ctx.Context())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("handlePreCommit1: api error, not proceeding: %+v", err)
|
log.Errorf("handlePreCommit1: api error, not proceeding: %+v", err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if checkTicketExpired(sector.TicketEpoch, height) {
|
if checkTicketExpired(sector.TicketEpoch, height) {
|
||||||
|
pci, err := m.api.StateSectorPreCommitInfo(ctx.Context(), m.maddr, sector.SectorNumber, tok)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("handlePreCommit1: StateSectorPreCommitInfo: api error, not proceeding: %+v", err)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if pci == nil {
|
||||||
return ctx.Send(SectorOldTicket{}) // go get new ticket
|
return ctx.Send(SectorOldTicket{}) // go get new ticket
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nv, err := m.api.StateNetworkVersion(ctx.Context(), tok)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("handlePreCommit1: StateNetworkVersion: api error, not proceeding: %+v", err)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
msd := policy.GetMaxProveCommitDuration(actors.VersionForNetwork(nv), sector.SectorType)
|
||||||
|
|
||||||
|
// if height > PreCommitEpoch + msd, there is no need to recalculate
|
||||||
|
if checkProveCommitExpired(pci.PreCommitEpoch, msd, height) {
|
||||||
|
return ctx.Send(SectorOldTicket{}) // will be removed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pc1o, err := m.sealer.SealPreCommit1(sector.sealingCtx(ctx.Context()), m.minerSector(sector.SectorType, sector.SectorNumber), sector.TicketValue, sector.pieceInfos())
|
pc1o, err := m.sealer.SealPreCommit1(sector.sealingCtx(ctx.Context()), m.minerSector(sector.SectorType, sector.SectorNumber), sector.TicketValue, sector.pieceInfos())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ctx.Send(SectorSealPreCommit1Failed{xerrors.Errorf("seal pre commit(1) failed: %w", err)})
|
return ctx.Send(SectorSealPreCommit1Failed{xerrors.Errorf("seal pre commit(1) failed: %w", err)})
|
||||||
|
Loading…
Reference in New Issue
Block a user