Teach shed/sim to understand --tipset=@nnn notation
This commit is contained in:
parent
e74838f024
commit
ce65cdd1e5
23
cli/state.go
23
cli/state.go
@ -44,6 +44,7 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/chain/consensus/filcns"
|
"github.com/filecoin-project/lotus/chain/consensus/filcns"
|
||||||
"github.com/filecoin-project/lotus/chain/state"
|
"github.com/filecoin-project/lotus/chain/state"
|
||||||
"github.com/filecoin-project/lotus/chain/stmgr"
|
"github.com/filecoin-project/lotus/chain/stmgr"
|
||||||
|
"github.com/filecoin-project/lotus/chain/store"
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -294,6 +295,28 @@ func ParseTipSetRef(ctx context.Context, api v0api.FullNode, tss string) (*types
|
|||||||
return ts, nil
|
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{
|
var StatePowerCmd = &cli.Command{
|
||||||
Name: "power",
|
Name: "power",
|
||||||
Usage: "Query network or miner power",
|
Usage: "Query network or miner power",
|
||||||
|
@ -32,7 +32,6 @@ import (
|
|||||||
|
|
||||||
"github.com/filecoin-project/lotus/blockstore"
|
"github.com/filecoin-project/lotus/blockstore"
|
||||||
"github.com/filecoin-project/lotus/chain/store"
|
"github.com/filecoin-project/lotus/chain/store"
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
|
||||||
lcli "github.com/filecoin-project/lotus/cli"
|
lcli "github.com/filecoin-project/lotus/cli"
|
||||||
"github.com/filecoin-project/lotus/cmd/lotus-shed/shedgen"
|
"github.com/filecoin-project/lotus/cmd/lotus-shed/shedgen"
|
||||||
"github.com/filecoin-project/lotus/node/repo"
|
"github.com/filecoin-project/lotus/node/repo"
|
||||||
@ -125,22 +124,9 @@ var exportChainCmd = &cli.Command{
|
|||||||
fullstate := cctx.Bool("full-state")
|
fullstate := cctx.Bool("full-state")
|
||||||
skipoldmsgs := cctx.Bool("skip-old-msgs")
|
skipoldmsgs := cctx.Bool("skip-old-msgs")
|
||||||
|
|
||||||
var ts *types.TipSet
|
ts, err := lcli.ParseTipSetRefOffline(ctx, cs, cctx.String("tipset"))
|
||||||
if tss := cctx.String("tipset"); tss != "" {
|
if err != nil {
|
||||||
cids, err := lcli.ParseTipSetString(tss)
|
return err
|
||||||
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()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if fullstate {
|
if fullstate {
|
||||||
|
@ -31,12 +31,7 @@ var createSimCommand = &cli.Command{
|
|||||||
}
|
}
|
||||||
ts = node.Chainstore.GetHeaviestTipSet()
|
ts = node.Chainstore.GetHeaviestTipSet()
|
||||||
case 1:
|
case 1:
|
||||||
cids, err := lcli.ParseTipSetString(cctx.Args().Get(1))
|
ts, err = lcli.ParseTipSetRefOffline(cctx.Context, node.Chainstore, cctx.Args().Get(1))
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
tsk := types.NewTipSetKey(cids...)
|
|
||||||
ts, err = node.Chainstore.LoadTipSet(cctx.Context, tsk)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user