Skip to content

Commit

Permalink
Merge pull request #9434 from ribasushi/chore/shed_at_notation
Browse files Browse the repository at this point in the history
chore:shed: Teach shed/sim to understand --tipset=@NNN notation
  • Loading branch information
magik6k authored Oct 5, 2022
2 parents e74838f + ce65cdd commit 80e99be
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 23 deletions.
23 changes: 23 additions & 0 deletions cli/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import (
"github.com/filecoin-project/lotus/chain/consensus/filcns"
"github.com/filecoin-project/lotus/chain/state"
"github.com/filecoin-project/lotus/chain/stmgr"
"github.com/filecoin-project/lotus/chain/store"
"github.com/filecoin-project/lotus/chain/types"
)

Expand Down Expand Up @@ -294,6 +295,28 @@ func ParseTipSetRef(ctx context.Context, api v0api.FullNode, tss string) (*types
return ts, nil
}

func ParseTipSetRefOffline(ctx context.Context, cs *store.ChainStore, tss string) (*types.TipSet, error) {
switch {

case tss == "" || tss == "@head":
return cs.GetHeaviestTipSet(), nil

case tss[0] != '@':
cids, err := ParseTipSetString(tss)
if err != nil {
return nil, xerrors.Errorf("failed to parse tipset (%q): %w", tss, err)
}
return cs.LoadTipSet(ctx, types.NewTipSetKey(cids...))

default:
var h uint64
if _, err := fmt.Sscanf(tss, "@%d", &h); err != nil {
return nil, xerrors.Errorf("parsing height tipset ref: %w", err)
}
return cs.GetTipsetByHeight(ctx, abi.ChainEpoch(h), cs.GetHeaviestTipSet(), true)
}
}

var StatePowerCmd = &cli.Command{
Name: "power",
Usage: "Query network or miner power",
Expand Down
20 changes: 3 additions & 17 deletions cmd/lotus-shed/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (

"github.com/filecoin-project/lotus/blockstore"
"github.com/filecoin-project/lotus/chain/store"
"github.com/filecoin-project/lotus/chain/types"
lcli "github.com/filecoin-project/lotus/cli"
"github.com/filecoin-project/lotus/cmd/lotus-shed/shedgen"
"github.com/filecoin-project/lotus/node/repo"
Expand Down Expand Up @@ -125,22 +124,9 @@ var exportChainCmd = &cli.Command{
fullstate := cctx.Bool("full-state")
skipoldmsgs := cctx.Bool("skip-old-msgs")

var ts *types.TipSet
if tss := cctx.String("tipset"); tss != "" {
cids, err := lcli.ParseTipSetString(tss)
if err != nil {
return xerrors.Errorf("failed to parse tipset (%q): %w", tss, err)
}

tsk := types.NewTipSetKey(cids...)

selts, err := cs.LoadTipSet(context.Background(), tsk)
if err != nil {
return xerrors.Errorf("loading tipset: %w", err)
}
ts = selts
} else {
ts = cs.GetHeaviestTipSet()
ts, err := lcli.ParseTipSetRefOffline(ctx, cs, cctx.String("tipset"))
if err != nil {
return err
}

if fullstate {
Expand Down
7 changes: 1 addition & 6 deletions cmd/lotus-sim/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,7 @@ var createSimCommand = &cli.Command{
}
ts = node.Chainstore.GetHeaviestTipSet()
case 1:
cids, err := lcli.ParseTipSetString(cctx.Args().Get(1))
if err != nil {
return err
}
tsk := types.NewTipSetKey(cids...)
ts, err = node.Chainstore.LoadTipSet(cctx.Context, tsk)
ts, err = lcli.ParseTipSetRefOffline(cctx.Context, node.Chainstore, cctx.Args().Get(1))
if err != nil {
return err
}
Expand Down

0 comments on commit 80e99be

Please sign in to comment.