sealing: Use ChainAt in handleUpdateActivating

This commit is contained in:
Łukasz Magiera 2022-02-09 17:47:53 +01:00 committed by Jennifer Wang
parent 02c0fb7b65
commit 9e76a788e2

View File

@ -5,6 +5,7 @@ import (
"context" "context"
"time" "time"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/go-state-types/exitcode" "github.com/filecoin-project/go-state-types/exitcode"
statemachine "github.com/filecoin-project/go-statemachine" statemachine "github.com/filecoin-project/go-statemachine"
@ -235,7 +236,7 @@ func (m *Sealing) handleUpdateActivating(ctx statemachine.Context, sector Sector
return err return err
} }
tok, height, err := m.Api.ChainHead(ctx.Context()) tok, _, err := m.Api.ChainHead(ctx.Context())
if err != nil { if err != nil {
return err return err
} }
@ -248,30 +249,13 @@ func (m *Sealing) handleUpdateActivating(ctx statemachine.Context, sector Sector
lb := policy.GetWinningPoStSectorSetLookback(nv) lb := policy.GetWinningPoStSectorSetLookback(nv)
targetHeight := mw.Height + lb + InteractivePoRepConfidence targetHeight := mw.Height + lb + InteractivePoRepConfidence
delay := 50 * time.Millisecond
for { return m.events.ChainAt(func(context.Context, TipSetToken, abi.ChainEpoch) error {
if height >= targetHeight { return ctx.Send(SectorUpdateActive{})
break }, func(ctx context.Context, ts TipSetToken) error {
} log.Warn("revert in handleUpdateActivating")
return nil
wctx, cancel := context.WithTimeout(ctx.Context(), delay) }, InteractivePoRepConfidence, targetHeight)
<-wctx.Done()
cancel()
// increasing backoff; can't just calculate the correct time because integration tests do funny things with time
delay = delay * 10 / 3
if delay > 5*time.Minute {
delay = 5 * time.Minute
}
_, height, err = m.Api.ChainHead(ctx.Context())
if err != nil {
return err
}
}
return nil
} }
for { for {
@ -286,7 +270,7 @@ func (m *Sealing) handleUpdateActivating(ctx statemachine.Context, sector Sector
time.Sleep(time.Minute) time.Sleep(time.Minute)
} }
return ctx.Send(SectorUpdateActive{}) return nil
} }
func (m *Sealing) handleReleaseSectorKey(ctx statemachine.Context, sector SectorInfo) error { func (m *Sealing) handleReleaseSectorKey(ctx statemachine.Context, sector SectorInfo) error {