diff --git a/chain/events/events.go b/chain/events/events.go index 9f19b1691..c3934fe4d 100644 --- a/chain/events/events.go +++ b/chain/events/events.go @@ -142,6 +142,8 @@ func (e *Events) listenHeadChangesOnce(ctx context.Context) error { } e.readyOnce.Do(func() { + e.at = cur[0].Val.Height() + e.ready.Done() }) diff --git a/chain/events/events_called.go b/chain/events/events_called.go index e2c81a004..228781f2e 100644 --- a/chain/events/events_called.go +++ b/chain/events/events_called.go @@ -62,6 +62,8 @@ type calledEvents struct { ctx context.Context gcConfidence uint64 + at abi.ChainEpoch + lk sync.Mutex ctr triggerId @@ -83,14 +85,16 @@ type calledEvents struct { func (e *calledEvents) headChangeCalled(rev, app []*types.TipSet) error { for _, ts := range rev { e.handleReverts(ts) + e.at = ts.Height() } for _, ts := range app { // called triggers - e.checkNewCalls(ts) - e.applyWithConfidence(ts) - e.applyTimeouts(ts) + for ; e.at <= ts.Height(); e.at++ { + e.applyWithConfidence(ts, e.at) + e.applyTimeouts(ts) + } } return nil @@ -170,8 +174,8 @@ func (e *calledEvents) queueForConfidence(triggerId uint64, msg *types.Message, e.revertQueue[appliedH] = append(e.revertQueue[appliedH], triggerH) } -func (e *calledEvents) applyWithConfidence(ts *types.TipSet) { - byOrigH, ok := e.confQueue[ts.Height()] +func (e *calledEvents) applyWithConfidence(ts *types.TipSet, height abi.ChainEpoch) { + byOrigH, ok := e.confQueue[height] if !ok { return // no triggers at thin height } @@ -179,7 +183,7 @@ func (e *calledEvents) applyWithConfidence(ts *types.TipSet) { for origH, events := range byOrigH { triggerTs, err := e.tsc.get(origH) if err != nil { - log.Errorf("events: applyWithConfidence didn't find tipset for event; wanted %d; current %d", origH, ts.Height()) + log.Errorf("events: applyWithConfidence didn't find tipset for event; wanted %d; current %d", origH, height) } for _, event := range events { @@ -198,9 +202,9 @@ func (e *calledEvents) applyWithConfidence(ts *types.TipSet) { return } - more, err := trigger.handle(event.msg, rec, triggerTs, ts.Height()) + more, err := trigger.handle(event.msg, rec, triggerTs, height) if err != nil { - log.Errorf("chain trigger (call %s.%d() @H %d, called @ %d) failed: %s", event.msg.To, event.msg.Method, origH, ts.Height(), err) + log.Errorf("chain trigger (call %s.%d() @H %d, called @ %d) failed: %s", event.msg.To, event.msg.Method, origH, height, err) continue // don't revert failed calls } diff --git a/chain/events/events_test.go b/chain/events/events_test.go index faf2d3863..10c418d4a 100644 --- a/chain/events/events_test.go +++ b/chain/events/events_test.go @@ -942,4 +942,10 @@ func TestCalledNull(t *testing.T) { require.Equal(t, true, applied) require.Equal(t, false, reverted) + applied = false + + fcs.advance(5, 1, nil, 10) + + require.Equal(t, false, applied) + require.Equal(t, true, reverted) }