events: Give non-null tipsets in handlers

This commit is contained in:
Łukasz Magiera 2019-10-06 01:43:10 +02:00
parent d0850b8c2f
commit 27411f7e3a
3 changed files with 15 additions and 2 deletions

View File

@ -77,7 +77,7 @@ func (e *heightEvents) headChangeAt(rev, app []*types.TipSet) error {
hnd := e.heightTriggers[tid]
triggerH := h - uint64(hnd.confidence)
incTs, err := e.tsc.get(triggerH)
incTs, err := e.tsc.getNonNull(triggerH)
if err != nil {
return err
}

View File

@ -241,7 +241,7 @@ func TestAtNullTrigger(t *testing.T) {
var reverted bool
err := events.ChainAt(func(ts *types.TipSet, curH uint64) error {
require.Nil(t, ts)
require.Equal(t, uint64(6), ts.Height())
require.Equal(t, 8, int(curH))
applied = true
return nil

View File

@ -76,6 +76,19 @@ func (tsc *tipSetCache) revert(ts *types.TipSet) error {
return nil
}
func (tsc *tipSetCache) getNonNull(height uint64) (*types.TipSet, error) {
for {
ts, err := tsc.get(height)
if err != nil {
return nil, err
}
if ts != nil {
return ts, nil
}
height++
}
}
func (tsc *tipSetCache) get(height uint64) (*types.TipSet, error) {
if tsc.len == 0 {
return nil, xerrors.New("tipSetCache.get: cache is empty")