Make sure that tipsetcache get works when tail ts in null

This commit is contained in:
Łukasz Magiera 2019-10-05 01:26:36 +02:00
parent 7170e1893f
commit 1cfe67cb59
2 changed files with 14 additions and 1 deletions

View File

@ -88,7 +88,13 @@ func (tsc *tipSetCache) get(height uint64) (*types.TipSet, error) {
}
clen := len(tsc.cache)
tail := tsc.cache[normalModulo(tsc.start-tsc.len+1, clen)]
var tail *types.TipSet
for i := 1; i <= tsc.len; i++ {
tail = tsc.cache[normalModulo(tsc.start-tsc.len+i, clen)]
if tail != nil {
break
}
}
if height < tail.Height() {
log.Warnf("tipSetCache.get: requested tipset not in cache, requesting from storage (h=%d; tail=%d)", height, tail.Height())

View File

@ -99,4 +99,11 @@ func TestTsCacheNulls(t *testing.T) {
require.NoError(t, tsc.revert(tsc.best()))
require.NoError(t, tsc.revert(tsc.best()))
require.Equal(t, h-8, tsc.best().Height())
h += 50
add()
ts, err = tsc.get(h - 1)
require.NoError(t, err)
require.Equal(t, h-1, ts.Height())
}