events: Give non-null tipsets in handlers
This commit is contained in:
parent
d0850b8c2f
commit
27411f7e3a
@ -77,7 +77,7 @@ func (e *heightEvents) headChangeAt(rev, app []*types.TipSet) error {
|
|||||||
hnd := e.heightTriggers[tid]
|
hnd := e.heightTriggers[tid]
|
||||||
triggerH := h - uint64(hnd.confidence)
|
triggerH := h - uint64(hnd.confidence)
|
||||||
|
|
||||||
incTs, err := e.tsc.get(triggerH)
|
incTs, err := e.tsc.getNonNull(triggerH)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -241,7 +241,7 @@ func TestAtNullTrigger(t *testing.T) {
|
|||||||
var reverted bool
|
var reverted bool
|
||||||
|
|
||||||
err := events.ChainAt(func(ts *types.TipSet, curH uint64) error {
|
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))
|
require.Equal(t, 8, int(curH))
|
||||||
applied = true
|
applied = true
|
||||||
return nil
|
return nil
|
||||||
|
@ -76,6 +76,19 @@ func (tsc *tipSetCache) revert(ts *types.TipSet) error {
|
|||||||
return nil
|
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) {
|
func (tsc *tipSetCache) get(height uint64) (*types.TipSet, error) {
|
||||||
if tsc.len == 0 {
|
if tsc.len == 0 {
|
||||||
return nil, xerrors.New("tipSetCache.get: cache is empty")
|
return nil, xerrors.New("tipSetCache.get: cache is empty")
|
||||||
|
Loading…
Reference in New Issue
Block a user