Terminate SubscribeActorEvents chan when at max height

This commit is contained in:
Rod Vagg 2024-02-26 19:04:25 +11:00 committed by Phi-rjan
parent eaf2cd672b
commit eff2762348
2 changed files with 14 additions and 6 deletions

View File

@ -444,15 +444,11 @@ func TestOnboardRawPieceVerified_WithActorEvents(t *testing.T) {
// check that our `ToHeight` filter works as expected // check that our `ToHeight` filter works as expected
var initialEvents []*types.ActorEvent var initialEvents []*types.ActorEvent
// TODO: this should probably close the channel when it knows it's done
for evt := range initialEventsChan { for evt := range initialEventsChan {
initialEvents = append(initialEvents, evt) initialEvents = append(initialEvents, evt)
// sector-precommitted, sector-activated, verifier-balance, verifier-balance
if len(initialEvents) == 4 {
break
} }
} // sector-precommitted, sector-activated, verifier-balance, verifier-balance, allocation
require.Equal(t, eventsFromMessages[0:4], initialEvents) require.Equal(t, eventsFromMessages[0:5], initialEvents)
// construct ActorEvents from subscription channel for all actor events // construct ActorEvents from subscription channel for all actor events
allEvtsChan, err := miner.FullNode.SubscribeActorEvents(ctx, &types.ActorEventFilter{ allEvtsChan, err := miner.FullNode.SubscribeActorEvents(ctx, &types.ActorEventFilter{

View File

@ -284,6 +284,14 @@ func (a *ActorEventHandler) SubscribeActorEvents(ctx context.Context, evtFilter
return true 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 { for ctx.Err() == nil {
if len(buffer) > 0 { if len(buffer) > 0 {
// check if we need to disconnect the client because they've fallen behind, always allow at // 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(): case <-ctx.Done():
return return
case <-ticker.C:
if params.MaxHeight > 0 && a.Chain.GetHeaviestTipSet().Height() > params.MaxHeight {
return
}
} }
} }
} }