Merge pull request #1985 from filecoin-project/fix/chain-idx-nulls

chainstore index: Drop wrong check
This commit is contained in:
Łukasz Magiera 2020-06-11 16:01:05 +02:00 committed by GitHub
commit 9457df9ddd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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
}
if parent.Height() > rheight {
return nil, xerrors.Errorf("cache is inconsistent")
}
rheight -= ci.skipLength
var skipTarget *types.TipSet
if parent.Height() < rheight {
skipTarget = parent
} else {
skipTarget, err = ci.walkBack(parent, rheight)
if err != nil {
@ -119,8 +114,9 @@ func (ci *ChainIndex) fillCache(tsk types.TipSetKey) (*lbEntry, error) {
return lbe, nil
}
// floors to nearest skipLength multiple
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) {
@ -152,6 +148,8 @@ func (ci *ChainIndex) walkBack(from *types.TipSet, to abi.ChainEpoch) (*types.Ti
}
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
}
if to == pts.Height() {

View File

@ -44,7 +44,8 @@ func TestIndexSeeks(t *testing.T) {
}
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))
if err := cs.PutTipSet(ctx, nextts); err != nil {
@ -53,6 +54,7 @@ func TestIndexSeeks(t *testing.T) {
cur = nextts
}
// Put 50 null epochs + 1 block
skip := mock.MkBlock(cur, 1, 1)
skip.Height += 50
@ -66,9 +68,9 @@ func TestIndexSeeks(t *testing.T) {
if err != nil {
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)
if err != nil {
t.Fatal(err)