chainstore index: Drop wrong check

This commit is contained in:
Łukasz Magiera 2020-06-11 14:49:48 +02:00
parent 4f632c893c
commit 8b308972a4
2 changed files with 9 additions and 9 deletions

View File

@ -91,16 +91,11 @@ func (ci *ChainIndex) fillCache(tsk types.TipSetKey) (*lbEntry, error) {
return nil, err return nil, err
} }
if parent.Height() > rheight {
return nil, xerrors.Errorf("cache is inconsistent")
}
rheight -= ci.skipLength rheight -= ci.skipLength
var skipTarget *types.TipSet var skipTarget *types.TipSet
if parent.Height() < rheight { if parent.Height() < rheight {
skipTarget = parent skipTarget = parent
} else { } else {
skipTarget, err = ci.walkBack(parent, rheight) skipTarget, err = ci.walkBack(parent, rheight)
if err != nil { if err != nil {
@ -119,8 +114,9 @@ func (ci *ChainIndex) fillCache(tsk types.TipSetKey) (*lbEntry, error) {
return lbe, nil return lbe, nil
} }
// floors to nearest skipLength multiple
func (ci *ChainIndex) roundHeight(h abi.ChainEpoch) abi.ChainEpoch { func (ci *ChainIndex) roundHeight(h abi.ChainEpoch) abi.ChainEpoch {
return abi.ChainEpoch(h/ci.skipLength) * ci.skipLength return (h / ci.skipLength) * ci.skipLength
} }
func (ci *ChainIndex) roundDown(ts *types.TipSet) (*types.TipSet, error) { func (ci *ChainIndex) roundDown(ts *types.TipSet) (*types.TipSet, error) {
@ -152,6 +148,8 @@ func (ci *ChainIndex) walkBack(from *types.TipSet, to abi.ChainEpoch) (*types.Ti
} }
if to > pts.Height() { if to > pts.Height() {
// in case pts is lower than the epoch we're looking for (null blocks)
// return a tipset above that height
return ts, nil return ts, nil
} }
if to == pts.Height() { if to == pts.Height() {

View File

@ -44,7 +44,8 @@ func TestIndexSeeks(t *testing.T) {
} }
cs.SetGenesis(gen) cs.SetGenesis(gen)
for i := 0; i < 100; i++ { // Put 113 blocks from genesis
for i := 0; i < 113; i++ {
nextts := mock.TipSet(mock.MkBlock(cur, 1, 1)) nextts := mock.TipSet(mock.MkBlock(cur, 1, 1))
if err := cs.PutTipSet(ctx, nextts); err != nil { if err := cs.PutTipSet(ctx, nextts); err != nil {
@ -53,6 +54,7 @@ func TestIndexSeeks(t *testing.T) {
cur = nextts cur = nextts
} }
// Put 50 null epochs + 1 block
skip := mock.MkBlock(cur, 1, 1) skip := mock.MkBlock(cur, 1, 1)
skip.Height += 50 skip.Height += 50
@ -66,9 +68,9 @@ func TestIndexSeeks(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
assert.Equal(t, abi.ChainEpoch(151), ts.Height()) assert.Equal(t, abi.ChainEpoch(164), ts.Height())
for i := 0; i <= 100; i++ { for i := 0; i <= 113; i++ {
ts3, err := cs.GetTipsetByHeight(ctx, abi.ChainEpoch(i), skipts, false) ts3, err := cs.GetTipsetByHeight(ctx, abi.ChainEpoch(i), skipts, false)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)