Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use a consistent tipset in commands #6142

Merged
merged 1 commit into from
Apr 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We now always do this.

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