events: Fix called with confidence on null round

This commit is contained in:
Łukasz Magiera 2020-05-08 10:24:17 +02:00
parent e5a0252126
commit 1ade0e7b92
3 changed files with 20 additions and 8 deletions

View File

@ -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()
})

View File

@ -62,6 +62,8 @@ type calledEvents struct {
ctx context.Context
gcConfidence uint64
at abi.ChainEpoch
lk sync.Mutex
ctr triggerId
@ -83,15 +85,17 @@ 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)
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
}

View File

@ -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)
}