Skip to content

Commit

Permalink
Merge pull request #6142 from filecoin-project/fix/tipset-cli
Browse files Browse the repository at this point in the history
fix: use a consistent tipset in commands
  • Loading branch information
magik6k authored Apr 29, 2021
2 parents 492b026 + 2857f6c commit 002eb4e
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 55 deletions.
6 changes: 0 additions & 6 deletions cli/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -723,12 +723,6 @@ var ChainGetCmd = &cli.Command{
return err
}

if ts == nil {
ts, err = api.ChainHead(ctx)
if err != nil {
return err
}
}
p = "/ipfs/" + ts.ParentState().String() + p
if cctx.Bool("verbose") {
fmt.Println(p)
Expand Down
27 changes: 4 additions & 23 deletions cli/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,13 @@ func ParseTipSetString(ts string) ([]cid.Cid, error) {
return cids, nil
}

// LoadTipSet gets the tipset from the context, or the head from the API.
//
// It always gets the head from the API so commands use a consistent tipset even if time pases.
func LoadTipSet(ctx context.Context, cctx *cli.Context, api v0api.FullNode) (*types.TipSet, error) {
tss := cctx.String("tipset")
if tss == "" {
return nil, nil
return api.ChainHead(ctx)
}

return ParseTipSetRef(ctx, api, tss)
Expand Down Expand Up @@ -850,14 +853,6 @@ var StateListMessagesCmd = &cli.Command{
return err
}

if ts == nil {
head, err := api.ChainHead(ctx)
if err != nil {
return err
}
ts = head
}

windowSize := abi.ChainEpoch(100)

cur := ts
Expand Down Expand Up @@ -957,13 +952,6 @@ var StateComputeStateCmd = &cli.Command{
}

h := abi.ChainEpoch(cctx.Uint64("vm-height"))
if ts == nil {
head, err := api.ChainHead(ctx)
if err != nil {
return err
}
ts = head
}
if h == 0 {
h = ts.Height()
}
Expand Down Expand Up @@ -1765,13 +1753,6 @@ var StateSectorCmd = &cli.Command{
return err
}

if ts == nil {
ts, err = api.ChainHead(ctx)
if err != nil {
return err
}
}

maddr, err := address.NewFromString(cctx.Args().Get(0))
if err != nil {
return err
Expand Down
6 changes: 0 additions & 6 deletions cmd/lotus-shed/frozen-miners.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ var frozenMinersCmd = &cli.Command{
if err != nil {
return err
}
if ts == nil {
ts, err = api.ChainHead(ctx)
if err != nil {
return err
}
}

queryEpoch := ts.Height()

Expand Down
6 changes: 0 additions & 6 deletions cmd/lotus-shed/postfind.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,6 @@ var postFindCmd = &cli.Command{
if err != nil {
return err
}
if startTs == nil {
startTs, err = api.ChainHead(ctx)
if err != nil {
return err
}
}
stopEpoch := startTs.Height() - abi.ChainEpoch(c.Int("lookback"))
if verbose {
fmt.Printf("Collecting messages between %d and %d\n", startTs.Height(), stopEpoch)
Expand Down
14 changes: 0 additions & 14 deletions cmd/lotus-shed/stateroot-stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,6 @@ var staterootDiffsCmd = &cli.Command{
return err
}

if ts == nil {
ts, err = api.ChainHead(ctx)
if err != nil {
return err
}
}

fn := func(ts *types.TipSet) (cid.Cid, []cid.Cid) {
blk := ts.Blocks()[0]
strt := blk.ParentStateRoot
Expand Down Expand Up @@ -134,13 +127,6 @@ var staterootStatCmd = &cli.Command{
return err
}

if ts == nil {
ts, err = api.ChainHead(ctx)
if err != nil {
return err
}
}

var addrs []address.Address

for _, inp := range cctx.Args().Slice() {
Expand Down

0 comments on commit 002eb4e

Please sign in to comment.