Bugfix: Begin walkback when lookback target's height is too low
This commit is contained in:
parent
86083531c6
commit
656b285195
@ -30,6 +30,7 @@ func NewChainIndex(lts loadTipSetFunc) *ChainIndex {
|
|||||||
type lbEntry struct {
|
type lbEntry struct {
|
||||||
ts *types.TipSet
|
ts *types.TipSet
|
||||||
parentHeight abi.ChainEpoch
|
parentHeight abi.ChainEpoch
|
||||||
|
targetHeight abi.ChainEpoch
|
||||||
target types.TipSetKey
|
target types.TipSetKey
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,7 +58,7 @@ func (ci *ChainIndex) GetTipsetByHeight(ctx context.Context, from *types.TipSet,
|
|||||||
lbe := cval.(*lbEntry)
|
lbe := cval.(*lbEntry)
|
||||||
if lbe.ts.Height() == to || lbe.parentHeight < to {
|
if lbe.ts.Height() == to || lbe.parentHeight < to {
|
||||||
return lbe.ts, nil
|
return lbe.ts, nil
|
||||||
} else if to > lbe.ts.Height()-ci.skipLength {
|
} else if to > lbe.targetHeight {
|
||||||
return ci.walkBack(lbe.ts, to)
|
return ci.walkBack(lbe.ts, to)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,6 +66,10 @@ func (ci *ChainIndex) GetTipsetByHeight(ctx context.Context, from *types.TipSet,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ci *ChainIndex) GetTipsetByHeightWithoutCache(from *types.TipSet, to abi.ChainEpoch) (*types.TipSet, error) {
|
||||||
|
return ci.walkBack(from, to)
|
||||||
|
}
|
||||||
|
|
||||||
func (ci *ChainIndex) fillCache(tsk types.TipSetKey) (*lbEntry, error) {
|
func (ci *ChainIndex) fillCache(tsk types.TipSetKey) (*lbEntry, error) {
|
||||||
ts, err := ci.loadTipSet(tsk)
|
ts, err := ci.loadTipSet(tsk)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -100,6 +105,7 @@ func (ci *ChainIndex) fillCache(tsk types.TipSetKey) (*lbEntry, error) {
|
|||||||
lbe := &lbEntry{
|
lbe := &lbEntry{
|
||||||
ts: ts,
|
ts: ts,
|
||||||
parentHeight: parent.Height(),
|
parentHeight: parent.Height(),
|
||||||
|
targetHeight: skipTarget.Height(),
|
||||||
target: skipTarget.Key(),
|
target: skipTarget.Key(),
|
||||||
}
|
}
|
||||||
ci.skipCache.Add(tsk, lbe)
|
ci.skipCache.Add(tsk, lbe)
|
||||||
|
@ -962,6 +962,14 @@ func (cs *ChainStore) GetTipsetByHeight(ctx context.Context, h abi.ChainEpoch, t
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if lbts.Height() < h {
|
||||||
|
log.Warnf("chain index returned the wrong tipset at height %d, using slow retrieval", h)
|
||||||
|
lbts, err = cs.cindex.GetTipsetByHeightWithoutCache(ts, h)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if lbts.Height() == h || !prev {
|
if lbts.Height() == h || !prev {
|
||||||
return lbts, nil
|
return lbts, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user