Merge pull request #1673 from filecoin-project/fix/lookback-tipset

add flag to choose what to do when looking back tipsets in null rounds
This commit is contained in:
Łukasz Magiera 2020-05-05 19:10:18 +02:00 committed by GitHub
commit 50291408c7
4 changed files with 11 additions and 4 deletions

View File

@ -426,7 +426,7 @@ func GetLookbackTipSetForRound(ctx context.Context, sm *StateManager, ts *types.
return ts, nil return ts, nil
} }
lbts, err := sm.ChainStore().GetTipsetByHeight(ctx, lbr, ts) lbts, err := sm.ChainStore().GetTipsetByHeight(ctx, lbr, ts, true)
if err != nil { if err != nil {
return nil, xerrors.Errorf("failed to get lookback tipset: %w", err) return nil, xerrors.Errorf("failed to get lookback tipset: %w", err)
} }

View File

@ -930,7 +930,11 @@ func (cs *ChainStore) GetRandomness(ctx context.Context, blks []cid.Cid, pers cr
} }
} }
func (cs *ChainStore) GetTipsetByHeight(ctx context.Context, h abi.ChainEpoch, ts *types.TipSet) (*types.TipSet, error) { // GetTipsetByHeight returns the tipset on the chain behind 'ts' at the given
// height. In the case that the given height is a null round, the 'prev' flag
// selects the tipset before the null round if true, and the tipset following
// the null round if false.
func (cs *ChainStore) GetTipsetByHeight(ctx context.Context, h abi.ChainEpoch, ts *types.TipSet, prev bool) (*types.TipSet, error) {
if ts == nil { if ts == nil {
ts = cs.GetHeaviestTipSet() ts = cs.GetHeaviestTipSet()
} }
@ -954,6 +958,9 @@ func (cs *ChainStore) GetTipsetByHeight(ctx context.Context, h abi.ChainEpoch, t
} }
if h > pts.Height() { if h > pts.Height() {
if prev {
return pts, nil
}
return ts, nil return ts, nil
} }
if h == pts.Height() { if h == pts.Height() {

View File

@ -85,7 +85,7 @@ var importBenchCmd = &cli.Command{
} }
if h := cctx.Int64("height"); h != 0 { if h := cctx.Int64("height"); h != 0 {
tsh, err := cs.GetTipsetByHeight(context.TODO(), abi.ChainEpoch(h), head) tsh, err := cs.GetTipsetByHeight(context.TODO(), abi.ChainEpoch(h), head, true)
if err != nil { if err != nil {
return err return err
} }

View File

@ -174,7 +174,7 @@ func (a *ChainAPI) ChainGetTipSetByHeight(ctx context.Context, h abi.ChainEpoch,
if err != nil { if err != nil {
return nil, xerrors.Errorf("loading tipset %s: %w", tsk, err) return nil, xerrors.Errorf("loading tipset %s: %w", tsk, err)
} }
return a.Chain.GetTipsetByHeight(ctx, h, ts) return a.Chain.GetTipsetByHeight(ctx, h, ts, true)
} }
func (a *ChainAPI) ChainReadObj(ctx context.Context, obj cid.Cid) ([]byte, error) { func (a *ChainAPI) ChainReadObj(ctx context.Context, obj cid.Cid) ([]byte, error) {