Terminate SubscribeActorEvents chan when at max height
This commit is contained in:
parent
dc0c8639df
commit
b12714f092
@ -444,15 +444,11 @@ func TestOnboardRawPieceVerified_WithActorEvents(t *testing.T) {
|
||||
|
||||
// check that our `ToHeight` filter works as expected
|
||||
var initialEvents []*types.ActorEvent
|
||||
// TODO: this should probably close the channel when it knows it's done
|
||||
for evt := range initialEventsChan {
|
||||
initialEvents = append(initialEvents, evt)
|
||||
// sector-precommitted, sector-activated, verifier-balance, verifier-balance
|
||||
if len(initialEvents) == 4 {
|
||||
break
|
||||
}
|
||||
}
|
||||
require.Equal(t, eventsFromMessages[0:4], initialEvents)
|
||||
// sector-precommitted, sector-activated, verifier-balance, verifier-balance, allocation
|
||||
require.Equal(t, eventsFromMessages[0:5], initialEvents)
|
||||
|
||||
// construct ActorEvents from subscription channel for all actor events
|
||||
allEvtsChan, err := miner.FullNode.SubscribeActorEvents(ctx, &types.ActorEventFilter{
|
||||
|
@ -284,6 +284,14 @@ func (a *ActorEventHandler) SubscribeActorEvents(ctx context.Context, evtFilter
|
||||
return true
|
||||
}
|
||||
|
||||
// for the case where we have a MaxHeight set, we don't get a signal from the filter when we
|
||||
// reach that height, so we need to check it ourselves, do it now but also in the loop
|
||||
if params.MaxHeight > 0 && a.Chain.GetHeaviestTipSet().Height() > params.MaxHeight {
|
||||
return
|
||||
}
|
||||
ticker := time.NewTicker(time.Duration(build.BlockDelaySecs) * time.Second)
|
||||
defer ticker.Stop()
|
||||
|
||||
for ctx.Err() == nil {
|
||||
if len(buffer) > 0 {
|
||||
// check if we need to disconnect the client because they've fallen behind, always allow at
|
||||
@ -312,6 +320,10 @@ func (a *ActorEventHandler) SubscribeActorEvents(ctx context.Context, evtFilter
|
||||
}
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case <-ticker.C:
|
||||
if params.MaxHeight > 0 && a.Chain.GetHeaviestTipSet().Height() > params.MaxHeight {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user