2019-08-07 06:35:57 +00:00
|
|
|
package cli
|
|
|
|
|
|
|
|
import (
|
2020-01-15 21:24:01 +00:00
|
|
|
"bytes"
|
2019-12-11 16:53:31 +00:00
|
|
|
"context"
|
2021-05-10 15:28:17 +00:00
|
|
|
"encoding/base64"
|
|
|
|
"encoding/hex"
|
2019-12-11 16:53:31 +00:00
|
|
|
"encoding/json"
|
2019-08-07 06:35:57 +00:00
|
|
|
"fmt"
|
2020-06-12 12:46:50 +00:00
|
|
|
"html/template"
|
2020-07-21 17:23:25 +00:00
|
|
|
"io"
|
2020-10-06 23:38:31 +00:00
|
|
|
"io/ioutil"
|
2020-06-12 11:24:38 +00:00
|
|
|
"os"
|
2020-01-15 21:24:01 +00:00
|
|
|
"reflect"
|
2020-05-21 22:52:20 +00:00
|
|
|
"sort"
|
2020-01-15 21:24:01 +00:00
|
|
|
"strconv"
|
2019-12-11 16:53:31 +00:00
|
|
|
"strings"
|
2022-05-18 05:52:32 +00:00
|
|
|
"text/tabwriter"
|
2020-05-04 17:19:23 +00:00
|
|
|
"time"
|
2019-08-07 06:35:57 +00:00
|
|
|
|
2020-10-28 23:04:03 +00:00
|
|
|
"github.com/fatih/color"
|
2020-05-04 16:48:50 +00:00
|
|
|
"github.com/ipfs/go-cid"
|
2020-09-24 21:30:11 +00:00
|
|
|
cbor "github.com/ipfs/go-ipld-cbor"
|
2020-10-28 23:04:03 +00:00
|
|
|
"github.com/multiformats/go-multiaddr"
|
2020-05-04 16:48:50 +00:00
|
|
|
"github.com/multiformats/go-multihash"
|
2020-06-05 22:59:01 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
2020-05-04 16:48:50 +00:00
|
|
|
cbg "github.com/whyrusleeping/cbor-gen"
|
|
|
|
"golang.org/x/xerrors"
|
2020-03-08 02:31:36 +00:00
|
|
|
|
2019-12-19 20:13:17 +00:00
|
|
|
"github.com/filecoin-project/go-address"
|
2020-09-07 03:49:10 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
2022-09-06 15:49:29 +00:00
|
|
|
actorstypes "github.com/filecoin-project/go-state-types/actors"
|
2022-06-14 15:00:51 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/big"
|
2020-09-07 03:49:10 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/exitcode"
|
2022-06-14 15:00:51 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/network"
|
2020-02-08 02:18:32 +00:00
|
|
|
|
2019-12-11 16:53:31 +00:00
|
|
|
"github.com/filecoin-project/lotus/api"
|
2020-10-06 23:38:31 +00:00
|
|
|
lapi "github.com/filecoin-project/lotus/api"
|
2022-06-14 15:00:51 +00:00
|
|
|
"github.com/filecoin-project/lotus/api/v0api"
|
2021-01-29 20:01:00 +00:00
|
|
|
"github.com/filecoin-project/lotus/blockstore"
|
2020-06-04 02:34:57 +00:00
|
|
|
"github.com/filecoin-project/lotus/build"
|
2022-06-14 15:00:51 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/actors"
|
|
|
|
"github.com/filecoin-project/lotus/chain/actors/builtin"
|
2022-09-27 10:21:42 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/consensus"
|
2020-09-24 21:30:11 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/state"
|
2020-07-03 16:57:58 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/stmgr"
|
2022-10-05 19:10:19 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/store"
|
2019-10-18 04:47:41 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
2022-10-31 12:32:00 +00:00
|
|
|
cliutil "github.com/filecoin-project/lotus/cli/util"
|
2019-08-07 06:35:57 +00:00
|
|
|
)
|
|
|
|
|
2021-03-23 23:21:04 +00:00
|
|
|
var StateCmd = &cli.Command{
|
2019-08-07 06:35:57 +00:00
|
|
|
Name: "state",
|
|
|
|
Usage: "Interact with and query filecoin chain state",
|
2019-12-11 16:53:31 +00:00
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "tipset",
|
|
|
|
Usage: "specify tipset to call method on (pass comma separated array of cids)",
|
|
|
|
},
|
|
|
|
},
|
2019-08-07 06:35:57 +00:00
|
|
|
Subcommands: []*cli.Command{
|
2021-03-23 23:21:04 +00:00
|
|
|
StatePowerCmd,
|
|
|
|
StateSectorsCmd,
|
|
|
|
StateActiveSectorsCmd,
|
|
|
|
StateListActorsCmd,
|
|
|
|
StateListMinersCmd,
|
|
|
|
StateCircSupplyCmd,
|
|
|
|
StateSectorCmd,
|
|
|
|
StateGetActorCmd,
|
|
|
|
StateLookupIDCmd,
|
|
|
|
StateReplayCmd,
|
|
|
|
StateSectorSizeCmd,
|
|
|
|
StateReadStateCmd,
|
|
|
|
StateListMessagesCmd,
|
|
|
|
StateComputeStateCmd,
|
|
|
|
StateCallCmd,
|
|
|
|
StateGetDealSetCmd,
|
|
|
|
StateWaitMsgCmd,
|
|
|
|
StateSearchMsgCmd,
|
|
|
|
StateMinerInfo,
|
|
|
|
StateMarketCmd,
|
|
|
|
StateExecTraceCmd,
|
|
|
|
StateNtwkVersionCmd,
|
2021-04-28 23:33:40 +00:00
|
|
|
StateMinerProvingDeadlineCmd,
|
2022-05-18 05:52:32 +00:00
|
|
|
StateSysActorCIDsCmd,
|
2021-04-28 23:33:40 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var StateMinerProvingDeadlineCmd = &cli.Command{
|
|
|
|
Name: "miner-proving-deadline",
|
|
|
|
Usage: "Retrieve information about a given miner's proving deadline",
|
|
|
|
ArgsUsage: "[minerAddress]",
|
|
|
|
Action: func(cctx *cli.Context) error {
|
|
|
|
api, closer, err := GetFullNodeAPI(cctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer closer()
|
|
|
|
|
|
|
|
ctx := ReqContext(cctx)
|
|
|
|
|
2023-01-25 12:13:56 +00:00
|
|
|
if cctx.NArg() != 1 {
|
|
|
|
return IncorrectNumArgs(cctx)
|
2021-04-28 23:33:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
addr, err := address.NewFromString(cctx.Args().First())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
ts, err := LoadTipSet(ctx, cctx, api)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
cd, err := api.StateMinerProvingDeadline(ctx, addr, ts.Key())
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("getting miner info: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("Period Start:\t%s\n", cd.PeriodStart)
|
|
|
|
fmt.Printf("Index:\t\t%d\n", cd.Index)
|
|
|
|
fmt.Printf("Open:\t\t%s\n", cd.Open)
|
|
|
|
fmt.Printf("Close:\t\t%s\n", cd.Close)
|
|
|
|
fmt.Printf("Challenge:\t%s\n", cd.Challenge)
|
|
|
|
fmt.Printf("FaultCutoff:\t%s\n", cd.FaultCutoff)
|
|
|
|
|
|
|
|
return nil
|
2020-02-18 19:02:52 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-03-23 23:21:04 +00:00
|
|
|
var StateMinerInfo = &cli.Command{
|
2020-03-06 19:01:28 +00:00
|
|
|
Name: "miner-info",
|
|
|
|
Usage: "Retrieve miner information",
|
2020-03-04 21:46:00 +00:00
|
|
|
ArgsUsage: "[minerAddress]",
|
2020-02-18 19:02:52 +00:00
|
|
|
Action: func(cctx *cli.Context) error {
|
|
|
|
api, closer, err := GetFullNodeAPI(cctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer closer()
|
|
|
|
|
|
|
|
ctx := ReqContext(cctx)
|
|
|
|
|
2023-01-25 12:13:56 +00:00
|
|
|
if cctx.NArg() != 1 {
|
|
|
|
return IncorrectNumArgs(cctx)
|
2020-02-18 19:02:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
addr, err := address.NewFromString(cctx.Args().First())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-03-07 00:46:20 +00:00
|
|
|
ts, err := LoadTipSet(ctx, cctx, api)
|
2020-02-18 19:02:52 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-06-09 01:03:44 +00:00
|
|
|
mi, err := api.StateMinerInfo(ctx, addr, ts.Key())
|
2020-02-18 19:02:52 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-10-28 23:04:03 +00:00
|
|
|
availableBalance, err := api.StateMinerAvailableBalance(ctx, addr, ts.Key())
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("getting miner available balance: %w", err)
|
|
|
|
}
|
2020-10-29 09:33:08 +00:00
|
|
|
fmt.Printf("Available Balance: %s\n", types.FIL(availableBalance))
|
2020-02-18 19:02:52 +00:00
|
|
|
fmt.Printf("Owner:\t%s\n", mi.Owner)
|
|
|
|
fmt.Printf("Worker:\t%s\n", mi.Worker)
|
2020-08-19 20:08:04 +00:00
|
|
|
for i, controlAddress := range mi.ControlAddresses {
|
|
|
|
fmt.Printf("Control %d: \t%s\n", i, controlAddress)
|
|
|
|
}
|
2022-09-14 05:04:15 +00:00
|
|
|
if mi.Beneficiary != address.Undef {
|
|
|
|
fmt.Printf("Beneficiary:\t%s\n", mi.Beneficiary)
|
|
|
|
if mi.Beneficiary != mi.Owner {
|
|
|
|
fmt.Printf("Beneficiary Quota:\t%s\n", mi.BeneficiaryTerm.Quota)
|
|
|
|
fmt.Printf("Beneficiary Used Quota:\t%s\n", mi.BeneficiaryTerm.UsedQuota)
|
|
|
|
fmt.Printf("Beneficiary Expiration:\t%s\n", mi.BeneficiaryTerm.Expiration)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if mi.PendingBeneficiaryTerm != nil {
|
|
|
|
fmt.Printf("Pending Beneficiary Term:\n")
|
|
|
|
fmt.Printf("New Beneficiary:\t%s\n", mi.PendingBeneficiaryTerm.NewBeneficiary)
|
|
|
|
fmt.Printf("New Quota:\t%s\n", mi.PendingBeneficiaryTerm.NewQuota)
|
|
|
|
fmt.Printf("New Expiration:\t%s\n", mi.PendingBeneficiaryTerm.NewExpiration)
|
|
|
|
fmt.Printf("Approved By Beneficiary:\t%t\n", mi.PendingBeneficiaryTerm.ApprovedByBeneficiary)
|
|
|
|
fmt.Printf("Approved By Nominee:\t%t\n", mi.PendingBeneficiaryTerm.ApprovedByNominee)
|
|
|
|
}
|
2020-10-28 23:04:03 +00:00
|
|
|
|
2020-02-24 17:45:25 +00:00
|
|
|
fmt.Printf("PeerID:\t%s\n", mi.PeerId)
|
2020-11-13 20:21:24 +00:00
|
|
|
fmt.Printf("Multiaddrs:\t")
|
2020-07-29 20:34:01 +00:00
|
|
|
for _, addr := range mi.Multiaddrs {
|
|
|
|
a, err := multiaddr.NewMultiaddrBytes(addr)
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("undecodable listen address: %w", err)
|
|
|
|
}
|
|
|
|
fmt.Printf("%s ", a)
|
|
|
|
}
|
2020-11-27 07:14:58 +00:00
|
|
|
fmt.Println()
|
2020-11-13 20:21:24 +00:00
|
|
|
fmt.Printf("Consensus Fault End:\t%d\n", mi.ConsensusFaultElapsed)
|
2020-10-28 23:04:03 +00:00
|
|
|
|
|
|
|
fmt.Printf("SectorSize:\t%s (%d)\n", types.SizeStr(types.NewInt(uint64(mi.SectorSize))), mi.SectorSize)
|
|
|
|
pow, err := api.StateMinerPower(ctx, addr, ts.Key())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("Byte Power: %s / %s (%0.4f%%)\n",
|
|
|
|
color.BlueString(types.SizeStr(pow.MinerPower.RawBytePower)),
|
|
|
|
types.SizeStr(pow.TotalPower.RawBytePower),
|
2021-05-21 11:03:45 +00:00
|
|
|
types.BigDivFloat(
|
|
|
|
types.BigMul(pow.MinerPower.RawBytePower, big.NewInt(100)),
|
|
|
|
pow.TotalPower.RawBytePower,
|
|
|
|
),
|
|
|
|
)
|
2020-10-28 23:04:03 +00:00
|
|
|
|
|
|
|
fmt.Printf("Actual Power: %s / %s (%0.4f%%)\n",
|
|
|
|
color.GreenString(types.DeciStr(pow.MinerPower.QualityAdjPower)),
|
|
|
|
types.DeciStr(pow.TotalPower.QualityAdjPower),
|
2021-05-21 11:03:45 +00:00
|
|
|
types.BigDivFloat(
|
|
|
|
types.BigMul(pow.MinerPower.QualityAdjPower, big.NewInt(100)),
|
|
|
|
pow.TotalPower.QualityAdjPower,
|
|
|
|
),
|
|
|
|
)
|
2020-10-28 23:04:03 +00:00
|
|
|
|
2020-07-29 20:34:01 +00:00
|
|
|
fmt.Println()
|
2020-02-18 19:02:52 +00:00
|
|
|
|
2020-09-14 23:36:36 +00:00
|
|
|
cd, err := api.StateMinerProvingDeadline(ctx, addr, ts.Key())
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("getting miner info: %w", err)
|
|
|
|
}
|
|
|
|
|
2022-10-31 12:32:00 +00:00
|
|
|
fmt.Printf("Proving Period Start:\t%s\n", cliutil.EpochTime(cd.CurrentEpoch, cd.PeriodStart))
|
2020-09-14 23:36:36 +00:00
|
|
|
|
2020-02-18 19:02:52 +00:00
|
|
|
return nil
|
2019-08-07 06:35:57 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-09-11 00:32:30 +00:00
|
|
|
func ParseTipSetString(ts string) ([]cid.Cid, error) {
|
2019-12-11 16:53:31 +00:00
|
|
|
strs := strings.Split(ts, ",")
|
|
|
|
|
|
|
|
var cids []cid.Cid
|
|
|
|
for _, s := range strs {
|
|
|
|
c, err := cid.Parse(strings.TrimSpace(s))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
cids = append(cids, c)
|
|
|
|
}
|
|
|
|
|
|
|
|
return cids, nil
|
|
|
|
}
|
|
|
|
|
2023-01-06 23:02:36 +00:00
|
|
|
type TipSetResolver interface {
|
|
|
|
ChainHead(context.Context) (*types.TipSet, error)
|
|
|
|
ChainGetTipSetByHeight(context.Context, abi.ChainEpoch, types.TipSetKey) (*types.TipSet, error)
|
|
|
|
ChainGetTipSet(context.Context, types.TipSetKey) (*types.TipSet, error)
|
|
|
|
}
|
|
|
|
|
2021-04-29 15:46:38 +00:00
|
|
|
// 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.
|
2023-01-06 23:02:36 +00:00
|
|
|
func LoadTipSet(ctx context.Context, cctx *cli.Context, api TipSetResolver) (*types.TipSet, error) {
|
2020-04-21 15:06:54 +00:00
|
|
|
tss := cctx.String("tipset")
|
|
|
|
if tss == "" {
|
2021-04-29 15:46:38 +00:00
|
|
|
return api.ChainHead(ctx)
|
2020-04-21 15:06:54 +00:00
|
|
|
}
|
|
|
|
|
2020-07-23 22:32:28 +00:00
|
|
|
return ParseTipSetRef(ctx, api, tss)
|
|
|
|
}
|
|
|
|
|
2023-01-06 23:02:36 +00:00
|
|
|
func ParseTipSetRef(ctx context.Context, api TipSetResolver, tss string) (*types.TipSet, error) {
|
2020-04-21 15:06:54 +00:00
|
|
|
if tss[0] == '@' {
|
2020-07-23 22:32:28 +00:00
|
|
|
if tss == "@head" {
|
|
|
|
return api.ChainHead(ctx)
|
|
|
|
}
|
|
|
|
|
2020-04-21 15:06:54 +00:00
|
|
|
var h uint64
|
|
|
|
if _, err := fmt.Sscanf(tss, "@%d", &h); err != nil {
|
|
|
|
return nil, xerrors.Errorf("parsing height tipset ref: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return api.ChainGetTipSetByHeight(ctx, abi.ChainEpoch(h), types.EmptyTSK)
|
|
|
|
}
|
|
|
|
|
2020-09-11 00:32:30 +00:00
|
|
|
cids, err := ParseTipSetString(tss)
|
2019-12-11 16:53:31 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(cids) == 0 {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
k := types.NewTipSetKey(cids...)
|
|
|
|
ts, err := api.ChainGetTipSet(ctx, k)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return ts, nil
|
|
|
|
}
|
|
|
|
|
2022-10-05 19:10:19 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-23 23:21:04 +00:00
|
|
|
var StatePowerCmd = &cli.Command{
|
2020-03-06 19:01:28 +00:00
|
|
|
Name: "power",
|
|
|
|
Usage: "Query network or miner power",
|
2020-03-04 21:46:00 +00:00
|
|
|
ArgsUsage: "[<minerAddress> (optional)]",
|
2019-08-07 06:35:57 +00:00
|
|
|
Action: func(cctx *cli.Context) error {
|
2019-10-03 18:12:30 +00:00
|
|
|
api, closer, err := GetFullNodeAPI(cctx)
|
2019-08-07 06:35:57 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-10-03 18:12:30 +00:00
|
|
|
defer closer()
|
2019-08-07 06:35:57 +00:00
|
|
|
|
|
|
|
ctx := ReqContext(cctx)
|
|
|
|
|
2021-06-08 22:46:21 +00:00
|
|
|
ts, err := LoadTipSet(ctx, cctx, api)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-08-21 22:14:58 +00:00
|
|
|
var maddr address.Address
|
2019-08-07 06:35:57 +00:00
|
|
|
if cctx.Args().Present() {
|
2019-08-21 22:14:58 +00:00
|
|
|
maddr, err = address.NewFromString(cctx.Args().First())
|
2019-08-07 06:35:57 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-12-11 16:53:31 +00:00
|
|
|
|
2021-06-08 22:46:21 +00:00
|
|
|
ma, err := api.StateGetActor(ctx, maddr, ts.Key())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if !builtin.IsStorageMinerActor(ma.Code) {
|
|
|
|
return xerrors.New("provided address does not correspond to a miner actor")
|
|
|
|
}
|
2019-12-11 16:53:31 +00:00
|
|
|
}
|
|
|
|
|
2020-02-11 23:29:45 +00:00
|
|
|
power, err := api.StateMinerPower(ctx, maddr, ts.Key())
|
2019-08-07 06:35:57 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-08-21 22:14:58 +00:00
|
|
|
|
2020-02-06 06:25:30 +00:00
|
|
|
tp := power.TotalPower
|
2019-08-21 22:14:58 +00:00
|
|
|
if cctx.Args().Present() {
|
2020-02-06 06:25:30 +00:00
|
|
|
mp := power.MinerPower
|
2021-05-21 11:03:45 +00:00
|
|
|
fmt.Printf(
|
|
|
|
"%s(%s) / %s(%s) ~= %0.4f%%\n",
|
|
|
|
mp.QualityAdjPower.String(), types.SizeStr(mp.QualityAdjPower),
|
|
|
|
tp.QualityAdjPower.String(), types.SizeStr(tp.QualityAdjPower),
|
|
|
|
types.BigDivFloat(
|
|
|
|
types.BigMul(mp.QualityAdjPower, big.NewInt(100)),
|
|
|
|
tp.QualityAdjPower,
|
|
|
|
),
|
|
|
|
)
|
2020-02-06 06:25:30 +00:00
|
|
|
} else {
|
2020-04-17 22:02:04 +00:00
|
|
|
fmt.Printf("%s(%s)\n", tp.QualityAdjPower.String(), types.SizeStr(tp.QualityAdjPower))
|
2019-08-07 06:35:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-03-23 23:21:04 +00:00
|
|
|
var StateSectorsCmd = &cli.Command{
|
2020-03-06 19:01:28 +00:00
|
|
|
Name: "sectors",
|
|
|
|
Usage: "Query the sector set of a miner",
|
2020-03-04 21:46:00 +00:00
|
|
|
ArgsUsage: "[minerAddress]",
|
2019-08-07 06:35:57 +00:00
|
|
|
Action: func(cctx *cli.Context) error {
|
2019-10-03 18:12:30 +00:00
|
|
|
api, closer, err := GetFullNodeAPI(cctx)
|
2019-08-07 06:35:57 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-10-03 18:12:30 +00:00
|
|
|
defer closer()
|
2019-08-07 06:35:57 +00:00
|
|
|
|
|
|
|
ctx := ReqContext(cctx)
|
|
|
|
|
2023-01-25 12:13:56 +00:00
|
|
|
if cctx.NArg() != 1 {
|
|
|
|
return IncorrectNumArgs(cctx)
|
2019-08-07 06:35:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
maddr, err := address.NewFromString(cctx.Args().First())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-03-07 00:46:20 +00:00
|
|
|
ts, err := LoadTipSet(ctx, cctx, api)
|
2019-12-11 16:53:31 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-09-21 19:05:01 +00:00
|
|
|
sectors, err := api.StateMinerSectors(ctx, maddr, nil, ts.Key())
|
2019-08-07 06:35:57 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, s := range sectors {
|
2021-06-07 22:05:48 +00:00
|
|
|
fmt.Printf("%d: %s\n", s.SectorNumber, s.SealedCID)
|
2019-08-07 06:35:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-03-23 23:21:04 +00:00
|
|
|
var StateActiveSectorsCmd = &cli.Command{
|
2020-07-17 14:26:48 +00:00
|
|
|
Name: "active-sectors",
|
|
|
|
Usage: "Query the active sector set of a miner",
|
2020-03-04 21:46:00 +00:00
|
|
|
ArgsUsage: "[minerAddress]",
|
2019-08-07 06:35:57 +00:00
|
|
|
Action: func(cctx *cli.Context) error {
|
2020-07-17 14:21:00 +00:00
|
|
|
api, closer, err := GetFullNodeAPI(cctx)
|
2019-08-07 06:35:57 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-10-03 18:12:30 +00:00
|
|
|
defer closer()
|
2019-08-07 06:35:57 +00:00
|
|
|
|
2020-07-17 14:21:00 +00:00
|
|
|
ctx := ReqContext(cctx)
|
2019-08-07 06:35:57 +00:00
|
|
|
|
2023-01-25 12:13:56 +00:00
|
|
|
if cctx.NArg() != 1 {
|
|
|
|
return IncorrectNumArgs(cctx)
|
2019-08-07 06:35:57 +00:00
|
|
|
}
|
|
|
|
|
2020-07-17 14:21:00 +00:00
|
|
|
maddr, err := address.NewFromString(cctx.Args().First())
|
2019-08-07 06:35:57 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-03-07 00:46:20 +00:00
|
|
|
ts, err := LoadTipSet(ctx, cctx, api)
|
2019-12-11 16:53:31 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-07-17 14:26:48 +00:00
|
|
|
sectors, err := api.StateMinerActiveSectors(ctx, maddr, ts.Key())
|
2019-08-07 06:35:57 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, s := range sectors {
|
2021-06-07 22:05:48 +00:00
|
|
|
fmt.Printf("%d: %s\n", s.SectorNumber, s.SealedCID)
|
2020-07-17 14:21:00 +00:00
|
|
|
}
|
2019-08-07 06:35:57 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
2019-09-19 20:25:18 +00:00
|
|
|
|
2021-03-23 23:21:04 +00:00
|
|
|
var StateExecTraceCmd = &cli.Command{
|
2020-10-06 23:06:24 +00:00
|
|
|
Name: "exec-trace",
|
|
|
|
Usage: "Get the execution trace of a given message",
|
|
|
|
ArgsUsage: "<messageCid>",
|
|
|
|
Action: func(cctx *cli.Context) error {
|
2023-01-25 12:13:56 +00:00
|
|
|
if cctx.NArg() != 1 {
|
|
|
|
return IncorrectNumArgs(cctx)
|
2020-10-06 23:06:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mcid, err := cid.Decode(cctx.Args().First())
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("message cid was invalid: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
capi, closer, err := GetFullNodeAPI(cctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer closer()
|
|
|
|
|
|
|
|
ctx := ReqContext(cctx)
|
|
|
|
|
|
|
|
msg, err := capi.ChainGetMessage(ctx, mcid)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
lookup, err := capi.StateSearchMsg(ctx, mcid)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-07-20 18:28:27 +00:00
|
|
|
if lookup == nil {
|
|
|
|
return fmt.Errorf("failed to find message: %s", mcid)
|
|
|
|
}
|
2020-10-06 23:06:24 +00:00
|
|
|
|
|
|
|
ts, err := capi.ChainGetTipSet(ctx, lookup.TipSet)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
pts, err := capi.ChainGetTipSet(ctx, ts.Parents())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
cso, err := capi.StateCompute(ctx, pts.Height(), nil, pts.Key())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
var trace *api.InvocResult
|
|
|
|
for _, t := range cso.Trace {
|
|
|
|
if t.Msg.From == msg.From && t.Msg.Nonce == msg.Nonce {
|
|
|
|
trace = t
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if trace == nil {
|
|
|
|
return fmt.Errorf("failed to find message in tipset trace output")
|
|
|
|
}
|
|
|
|
|
|
|
|
out, err := json.MarshalIndent(trace, "", " ")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println(string(out))
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-03-23 23:21:04 +00:00
|
|
|
var StateReplayCmd = &cli.Command{
|
2020-10-15 23:47:02 +00:00
|
|
|
Name: "replay",
|
|
|
|
Usage: "Replay a particular message",
|
|
|
|
ArgsUsage: "<messageCid>",
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "show-trace",
|
|
|
|
Usage: "print out full execution trace for given message",
|
|
|
|
},
|
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "detailed-gas",
|
|
|
|
Usage: "print out detailed gas costs for given message",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: func(cctx *cli.Context) error {
|
2022-09-14 18:33:29 +00:00
|
|
|
if cctx.NArg() != 1 {
|
2022-09-14 19:38:15 +00:00
|
|
|
return IncorrectNumArgs(cctx)
|
2020-10-15 23:47:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mcid, err := cid.Decode(cctx.Args().First())
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("message cid was invalid: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
fapi, closer, err := GetFullNodeAPI(cctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer closer()
|
|
|
|
|
|
|
|
ctx := ReqContext(cctx)
|
|
|
|
|
2020-10-16 02:45:11 +00:00
|
|
|
res, err := fapi.StateReplay(ctx, types.EmptyTSK, mcid)
|
2020-10-15 23:47:02 +00:00
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("replay call failed: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println("Replay receipt:")
|
|
|
|
fmt.Printf("Exit code: %d\n", res.MsgRct.ExitCode)
|
|
|
|
fmt.Printf("Return: %x\n", res.MsgRct.Return)
|
|
|
|
fmt.Printf("Gas Used: %d\n", res.MsgRct.GasUsed)
|
|
|
|
|
|
|
|
if cctx.Bool("detailed-gas") {
|
|
|
|
fmt.Printf("Base Fee Burn: %d\n", res.GasCost.BaseFeeBurn)
|
|
|
|
fmt.Printf("Overestimaton Burn: %d\n", res.GasCost.OverEstimationBurn)
|
|
|
|
fmt.Printf("Miner Penalty: %d\n", res.GasCost.MinerPenalty)
|
|
|
|
fmt.Printf("Miner Tip: %d\n", res.GasCost.MinerTip)
|
|
|
|
fmt.Printf("Refund: %d\n", res.GasCost.Refund)
|
|
|
|
}
|
|
|
|
fmt.Printf("Total Message Cost: %d\n", res.GasCost.TotalCost)
|
|
|
|
|
2020-03-03 23:32:17 +00:00
|
|
|
if res.MsgRct.ExitCode != 0 {
|
2019-12-05 05:02:14 +00:00
|
|
|
fmt.Printf("Error message: %q\n", res.Error)
|
|
|
|
}
|
2019-09-19 20:25:18 +00:00
|
|
|
|
2020-10-15 23:47:02 +00:00
|
|
|
if cctx.Bool("show-trace") {
|
|
|
|
fmt.Printf("%s\t%s\t%s\t%d\t%x\t%d\t%x\n", res.Msg.From, res.Msg.To, res.Msg.Value, res.Msg.Method, res.Msg.Params, res.MsgRct.ExitCode, res.MsgRct.Return)
|
|
|
|
printInternalExecutions("\t", res.ExecutionTrace.Subcalls)
|
|
|
|
}
|
|
|
|
|
2019-09-19 20:25:18 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
2019-09-27 14:53:34 +00:00
|
|
|
|
2021-03-23 23:21:04 +00:00
|
|
|
var StateGetDealSetCmd = &cli.Command{
|
2020-03-06 19:01:28 +00:00
|
|
|
Name: "get-deal",
|
|
|
|
Usage: "View on-chain deal info",
|
2020-03-04 21:46:00 +00:00
|
|
|
ArgsUsage: "[dealId]",
|
2020-01-25 10:41:17 +00:00
|
|
|
Action: func(cctx *cli.Context) error {
|
|
|
|
api, closer, err := GetFullNodeAPI(cctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer closer()
|
|
|
|
|
|
|
|
ctx := ReqContext(cctx)
|
|
|
|
|
2023-01-25 12:13:56 +00:00
|
|
|
if cctx.NArg() != 1 {
|
|
|
|
return IncorrectNumArgs(cctx)
|
2020-01-25 10:41:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dealid, err := strconv.ParseUint(cctx.Args().First(), 10, 64)
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("parsing deal ID: %w", err)
|
|
|
|
}
|
|
|
|
|
2020-03-07 00:46:20 +00:00
|
|
|
ts, err := LoadTipSet(ctx, cctx, api)
|
2020-01-25 10:41:17 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-02-24 17:32:02 +00:00
|
|
|
deal, err := api.StateMarketStorageDeal(ctx, abi.DealID(dealid), ts.Key())
|
2020-01-25 10:41:17 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
data, err := json.MarshalIndent(deal, "", " ")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
fmt.Println(string(data))
|
|
|
|
|
|
|
|
return nil
|
2019-09-27 14:53:34 +00:00
|
|
|
},
|
|
|
|
}
|
2019-10-12 06:45:48 +00:00
|
|
|
|
2021-03-23 23:21:04 +00:00
|
|
|
var StateListMinersCmd = &cli.Command{
|
2019-10-12 06:45:48 +00:00
|
|
|
Name: "list-miners",
|
|
|
|
Usage: "list all miners in the network",
|
2020-05-21 22:52:20 +00:00
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "sort-by",
|
|
|
|
Usage: "criteria to sort miners by (none, num-deals)",
|
|
|
|
},
|
|
|
|
},
|
2019-10-12 06:45:48 +00:00
|
|
|
Action: func(cctx *cli.Context) error {
|
|
|
|
api, closer, err := GetFullNodeAPI(cctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer closer()
|
|
|
|
|
|
|
|
ctx := ReqContext(cctx)
|
|
|
|
|
2020-03-07 00:46:20 +00:00
|
|
|
ts, err := LoadTipSet(ctx, cctx, api)
|
2019-12-11 16:53:31 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-02-11 23:29:45 +00:00
|
|
|
miners, err := api.StateListMiners(ctx, ts.Key())
|
2019-10-12 06:45:48 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-05-21 22:52:20 +00:00
|
|
|
switch cctx.String("sort-by") {
|
|
|
|
case "num-deals":
|
|
|
|
ndm, err := getDealsCounts(ctx, api)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
sort.Slice(miners, func(i, j int) bool {
|
|
|
|
return ndm[miners[i]] > ndm[miners[j]]
|
|
|
|
})
|
|
|
|
|
|
|
|
for i := 0; i < 50 && i < len(miners); i++ {
|
|
|
|
fmt.Printf("%s %d\n", miners[i], ndm[miners[i]])
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
default:
|
|
|
|
return fmt.Errorf("unrecognized sorting order")
|
|
|
|
case "", "none":
|
|
|
|
}
|
|
|
|
|
2019-10-12 06:45:48 +00:00
|
|
|
for _, m := range miners {
|
|
|
|
fmt.Println(m.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-04-03 10:55:29 +00:00
|
|
|
func getDealsCounts(ctx context.Context, lapi v0api.FullNode) (map[address.Address]int, error) {
|
2020-05-21 22:52:20 +00:00
|
|
|
allDeals, err := lapi.StateMarketDeals(ctx, types.EmptyTSK)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
out := make(map[address.Address]int)
|
|
|
|
for _, d := range allDeals {
|
|
|
|
if d.State.SectorStartEpoch != -1 {
|
|
|
|
out[d.Proposal.Provider]++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return out, nil
|
|
|
|
}
|
|
|
|
|
2021-03-23 23:21:04 +00:00
|
|
|
var StateListActorsCmd = &cli.Command{
|
2019-10-12 06:45:48 +00:00
|
|
|
Name: "list-actors",
|
|
|
|
Usage: "list all actors in the network",
|
|
|
|
Action: func(cctx *cli.Context) error {
|
|
|
|
api, closer, err := GetFullNodeAPI(cctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer closer()
|
|
|
|
|
|
|
|
ctx := ReqContext(cctx)
|
|
|
|
|
2020-03-07 00:46:20 +00:00
|
|
|
ts, err := LoadTipSet(ctx, cctx, api)
|
2019-12-11 16:53:31 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-02-11 23:29:45 +00:00
|
|
|
actors, err := api.StateListActors(ctx, ts.Key())
|
2019-10-12 06:45:48 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, a := range actors {
|
|
|
|
fmt.Println(a.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
2019-11-01 18:28:12 +00:00
|
|
|
|
2021-03-23 23:21:04 +00:00
|
|
|
var StateGetActorCmd = &cli.Command{
|
2020-03-06 19:01:28 +00:00
|
|
|
Name: "get-actor",
|
|
|
|
Usage: "Print actor information",
|
2021-07-05 14:44:06 +00:00
|
|
|
ArgsUsage: "[actorAddress]",
|
2019-11-01 18:28:12 +00:00
|
|
|
Action: func(cctx *cli.Context) error {
|
|
|
|
api, closer, err := GetFullNodeAPI(cctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer closer()
|
|
|
|
|
|
|
|
ctx := ReqContext(cctx)
|
|
|
|
|
2023-01-25 12:13:56 +00:00
|
|
|
if cctx.NArg() != 1 {
|
|
|
|
return IncorrectNumArgs(cctx)
|
2019-11-01 18:28:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
addr, err := address.NewFromString(cctx.Args().First())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-03-07 00:46:20 +00:00
|
|
|
ts, err := LoadTipSet(ctx, cctx, api)
|
2019-12-11 16:53:31 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-02-11 23:29:45 +00:00
|
|
|
a, err := api.StateGetActor(ctx, addr, ts.Key())
|
2019-11-01 18:28:12 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-09-04 00:22:18 +00:00
|
|
|
strtype := builtin.ActorNameByCode(a.Code)
|
2020-08-19 20:10:07 +00:00
|
|
|
|
2019-11-01 18:28:12 +00:00
|
|
|
fmt.Printf("Address:\t%s\n", addr)
|
|
|
|
fmt.Printf("Balance:\t%s\n", types.FIL(a.Balance))
|
|
|
|
fmt.Printf("Nonce:\t\t%d\n", a.Nonce)
|
2020-08-19 20:10:07 +00:00
|
|
|
fmt.Printf("Code:\t\t%s (%s)\n", a.Code, strtype)
|
2019-11-01 18:28:12 +00:00
|
|
|
fmt.Printf("Head:\t\t%s\n", a.Head)
|
2023-01-20 21:45:06 +00:00
|
|
|
if a.Address != nil {
|
|
|
|
fmt.Printf("Delegated address:\t\t%s\n", a.Address)
|
|
|
|
}
|
2019-11-01 18:28:12 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
2019-11-15 16:39:43 +00:00
|
|
|
|
2021-03-23 23:21:04 +00:00
|
|
|
var StateLookupIDCmd = &cli.Command{
|
2020-03-06 19:01:28 +00:00
|
|
|
Name: "lookup",
|
|
|
|
Usage: "Find corresponding ID address",
|
2020-03-04 21:46:00 +00:00
|
|
|
ArgsUsage: "[address]",
|
2020-04-22 16:38:01 +00:00
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "reverse",
|
|
|
|
Aliases: []string{"r"},
|
|
|
|
Usage: "Perform reverse lookup",
|
|
|
|
},
|
|
|
|
},
|
2019-11-15 16:39:43 +00:00
|
|
|
Action: func(cctx *cli.Context) error {
|
|
|
|
api, closer, err := GetFullNodeAPI(cctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer closer()
|
|
|
|
|
|
|
|
ctx := ReqContext(cctx)
|
|
|
|
|
2023-01-25 12:13:56 +00:00
|
|
|
if cctx.NArg() != 1 {
|
|
|
|
return IncorrectNumArgs(cctx)
|
2019-11-15 16:39:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
addr, err := address.NewFromString(cctx.Args().First())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-03-07 00:46:20 +00:00
|
|
|
ts, err := LoadTipSet(ctx, cctx, api)
|
2019-12-11 16:53:31 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-04-22 16:38:01 +00:00
|
|
|
var a address.Address
|
|
|
|
if !cctx.Bool("reverse") {
|
|
|
|
a, err = api.StateLookupID(ctx, addr, ts.Key())
|
|
|
|
} else {
|
|
|
|
a, err = api.StateAccountKey(ctx, addr, ts.Key())
|
|
|
|
}
|
|
|
|
|
2019-11-15 16:39:43 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("%s\n", a)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
2019-12-12 11:31:22 +00:00
|
|
|
|
2021-03-23 23:21:04 +00:00
|
|
|
var StateSectorSizeCmd = &cli.Command{
|
2020-03-06 19:01:28 +00:00
|
|
|
Name: "sector-size",
|
|
|
|
Usage: "Look up miners sector size",
|
2020-03-04 21:46:00 +00:00
|
|
|
ArgsUsage: "[minerAddress]",
|
2019-12-12 11:31:22 +00:00
|
|
|
Action: func(cctx *cli.Context) error {
|
|
|
|
api, closer, err := GetFullNodeAPI(cctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer closer()
|
|
|
|
|
|
|
|
ctx := ReqContext(cctx)
|
|
|
|
|
2023-01-25 12:13:56 +00:00
|
|
|
if cctx.NArg() != 1 {
|
|
|
|
return IncorrectNumArgs(cctx)
|
2019-12-12 11:31:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
addr, err := address.NewFromString(cctx.Args().First())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-03-07 00:46:20 +00:00
|
|
|
ts, err := LoadTipSet(ctx, cctx, api)
|
2019-12-11 16:53:31 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-04-16 17:36:36 +00:00
|
|
|
mi, err := api.StateMinerInfo(ctx, addr, ts.Key())
|
2019-12-12 11:31:22 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-06-09 18:04:17 +00:00
|
|
|
fmt.Printf("%s (%d)\n", types.SizeStr(types.NewInt(uint64(mi.SectorSize))), mi.SectorSize)
|
2019-12-11 16:53:31 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-03-23 23:21:04 +00:00
|
|
|
var StateReadStateCmd = &cli.Command{
|
2020-03-06 19:01:28 +00:00
|
|
|
Name: "read-state",
|
|
|
|
Usage: "View a json representation of an actors state",
|
2020-03-04 21:46:00 +00:00
|
|
|
ArgsUsage: "[actorAddress]",
|
2019-12-11 16:53:31 +00:00
|
|
|
Action: func(cctx *cli.Context) error {
|
|
|
|
api, closer, err := GetFullNodeAPI(cctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer closer()
|
|
|
|
|
|
|
|
ctx := ReqContext(cctx)
|
|
|
|
|
2023-01-25 12:13:56 +00:00
|
|
|
if cctx.NArg() != 1 {
|
|
|
|
return IncorrectNumArgs(cctx)
|
2019-12-11 16:53:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
addr, err := address.NewFromString(cctx.Args().First())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-03-07 00:46:20 +00:00
|
|
|
ts, err := LoadTipSet(ctx, cctx, api)
|
2019-12-11 16:53:31 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-06-17 05:10:29 +00:00
|
|
|
as, err := api.StateReadState(ctx, addr, ts.Key())
|
2019-12-11 16:53:31 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
data, err := json.MarshalIndent(as.State, "", " ")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
fmt.Println(string(data))
|
2019-12-12 11:31:22 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
2020-01-07 19:03:11 +00:00
|
|
|
|
2021-03-23 23:21:04 +00:00
|
|
|
var StateListMessagesCmd = &cli.Command{
|
2020-01-07 19:03:11 +00:00
|
|
|
Name: "list-messages",
|
|
|
|
Usage: "list messages on chain matching given criteria",
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "to",
|
|
|
|
Usage: "return messages to a given address",
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "from",
|
|
|
|
Usage: "return messages from a given address",
|
|
|
|
},
|
|
|
|
&cli.Uint64Flag{
|
|
|
|
Name: "toheight",
|
|
|
|
Usage: "don't look before given block height",
|
|
|
|
},
|
2020-01-21 22:53:23 +00:00
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "cids",
|
|
|
|
Usage: "print message CIDs instead of messages",
|
|
|
|
},
|
2020-01-07 19:03:11 +00:00
|
|
|
},
|
|
|
|
Action: func(cctx *cli.Context) error {
|
|
|
|
api, closer, err := GetFullNodeAPI(cctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer closer()
|
|
|
|
|
|
|
|
ctx := ReqContext(cctx)
|
|
|
|
|
|
|
|
var toa, froma address.Address
|
|
|
|
if tos := cctx.String("to"); tos != "" {
|
|
|
|
a, err := address.NewFromString(tos)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("given 'to' address %q was invalid: %w", tos, err)
|
|
|
|
}
|
|
|
|
toa = a
|
|
|
|
}
|
|
|
|
|
|
|
|
if froms := cctx.String("from"); froms != "" {
|
|
|
|
a, err := address.NewFromString(froms)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("given 'from' address %q was invalid: %w", froms, err)
|
|
|
|
}
|
|
|
|
froma = a
|
|
|
|
}
|
|
|
|
|
2020-10-15 16:38:27 +00:00
|
|
|
toh := abi.ChainEpoch(cctx.Uint64("toheight"))
|
2020-01-07 19:03:11 +00:00
|
|
|
|
2020-03-07 00:46:20 +00:00
|
|
|
ts, err := LoadTipSet(ctx, cctx, api)
|
2020-01-07 19:03:11 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-10-15 16:38:27 +00:00
|
|
|
windowSize := abi.ChainEpoch(100)
|
|
|
|
|
|
|
|
cur := ts
|
|
|
|
for cur.Height() > toh {
|
|
|
|
if ctx.Err() != nil {
|
|
|
|
return ctx.Err()
|
2020-01-21 22:53:23 +00:00
|
|
|
}
|
|
|
|
|
2020-10-15 16:38:27 +00:00
|
|
|
end := toh
|
|
|
|
if cur.Height()-windowSize > end {
|
|
|
|
end = cur.Height() - windowSize
|
2020-01-21 22:53:23 +00:00
|
|
|
}
|
|
|
|
|
2020-10-15 16:38:27 +00:00
|
|
|
msgs, err := api.StateListMessages(ctx, &lapi.MessageMatch{To: toa, From: froma}, cur.Key(), end)
|
2020-01-07 19:03:11 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-10-15 16:38:27 +00:00
|
|
|
|
|
|
|
for _, c := range msgs {
|
|
|
|
if cctx.Bool("cids") {
|
|
|
|
fmt.Println(c.String())
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
m, err := api.ChainGetMessage(ctx, c)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
b, err := json.MarshalIndent(m, "", " ")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
fmt.Println(string(b))
|
|
|
|
}
|
|
|
|
|
|
|
|
if end <= 0 {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
next, err := api.ChainGetTipSetByHeight(ctx, end-1, cur.Key())
|
2020-01-07 19:03:11 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-10-15 16:38:27 +00:00
|
|
|
|
|
|
|
cur = next
|
2020-01-07 19:03:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
2020-01-17 02:33:43 +00:00
|
|
|
|
2021-03-23 23:21:04 +00:00
|
|
|
var StateComputeStateCmd = &cli.Command{
|
2020-01-17 02:33:43 +00:00
|
|
|
Name: "compute-state",
|
|
|
|
Usage: "Perform state computations",
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.Uint64Flag{
|
2020-07-07 21:40:57 +00:00
|
|
|
Name: "vm-height",
|
|
|
|
Usage: "set the height that the vm will see",
|
2020-01-17 02:33:43 +00:00
|
|
|
},
|
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "apply-mpool-messages",
|
|
|
|
Usage: "apply messages from the mempool to the computed state",
|
|
|
|
},
|
2020-03-08 02:31:36 +00:00
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "show-trace",
|
|
|
|
Usage: "print out full execution trace for given tipset",
|
|
|
|
},
|
2020-05-04 16:03:54 +00:00
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "html",
|
|
|
|
Usage: "generate html report",
|
|
|
|
},
|
2020-09-26 06:47:59 +00:00
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "json",
|
|
|
|
Usage: "generate json output",
|
|
|
|
},
|
2020-10-06 23:38:31 +00:00
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "compute-state-output",
|
|
|
|
Usage: "a json file containing pre-existing compute-state output, to generate html reports without rerunning state changes",
|
|
|
|
},
|
2021-01-28 17:15:22 +00:00
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "no-timing",
|
|
|
|
Usage: "don't show timing information in html traces",
|
|
|
|
},
|
2020-01-17 02:33:43 +00:00
|
|
|
},
|
|
|
|
Action: func(cctx *cli.Context) error {
|
|
|
|
api, closer, err := GetFullNodeAPI(cctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer closer()
|
|
|
|
|
|
|
|
ctx := ReqContext(cctx)
|
|
|
|
|
2020-03-07 00:46:20 +00:00
|
|
|
ts, err := LoadTipSet(ctx, cctx, api)
|
2020-01-17 02:33:43 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-07-07 21:40:57 +00:00
|
|
|
h := abi.ChainEpoch(cctx.Uint64("vm-height"))
|
2020-09-24 21:30:11 +00:00
|
|
|
if h == 0 {
|
2020-01-17 02:33:43 +00:00
|
|
|
h = ts.Height()
|
|
|
|
}
|
|
|
|
|
|
|
|
var msgs []*types.Message
|
|
|
|
if cctx.Bool("apply-mpool-messages") {
|
2020-08-11 11:05:04 +00:00
|
|
|
pmsgs, err := api.MpoolSelect(ctx, ts.Key(), 1)
|
2020-01-17 03:36:54 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-01-17 02:33:43 +00:00
|
|
|
for _, sm := range pmsgs {
|
|
|
|
msgs = append(msgs, &sm.Message)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-06 23:38:31 +00:00
|
|
|
var stout *lapi.ComputeStateOutput
|
|
|
|
if csofile := cctx.String("compute-state-output"); csofile != "" {
|
|
|
|
data, err := ioutil.ReadFile(csofile)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
var o lapi.ComputeStateOutput
|
|
|
|
if err := json.Unmarshal(data, &o); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
stout = &o
|
|
|
|
} else {
|
|
|
|
o, err := api.StateCompute(ctx, h, msgs, ts.Key())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
stout = o
|
2020-01-17 02:33:43 +00:00
|
|
|
}
|
|
|
|
|
2020-09-26 06:47:59 +00:00
|
|
|
if cctx.Bool("json") {
|
|
|
|
out, err := json.Marshal(stout)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
fmt.Println(string(out))
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-05-04 16:03:54 +00:00
|
|
|
if cctx.Bool("html") {
|
2021-01-29 20:01:00 +00:00
|
|
|
st, err := state.LoadStateTree(cbor.NewCborStore(blockstore.NewAPIBlockstore(api)), stout.Root)
|
2020-09-24 21:30:11 +00:00
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("loading state tree: %w", err)
|
|
|
|
}
|
|
|
|
|
2020-05-04 16:48:50 +00:00
|
|
|
codeCache := map[address.Address]cid.Cid{}
|
|
|
|
getCode := func(addr address.Address) (cid.Cid, error) {
|
|
|
|
if c, found := codeCache[addr]; found {
|
|
|
|
return c, nil
|
|
|
|
}
|
|
|
|
|
2020-09-24 21:30:11 +00:00
|
|
|
c, err := st.GetActor(addr)
|
2020-05-04 16:48:50 +00:00
|
|
|
if err != nil {
|
|
|
|
return cid.Cid{}, err
|
|
|
|
}
|
|
|
|
|
|
|
|
codeCache[addr] = c.Code
|
|
|
|
return c.Code, nil
|
|
|
|
}
|
|
|
|
|
2021-01-28 17:15:22 +00:00
|
|
|
_, _ = fmt.Fprintln(os.Stderr, "computed state cid: ", stout.Root)
|
|
|
|
|
|
|
|
return ComputeStateHTMLTempl(os.Stdout, ts, stout, !cctx.Bool("no-timing"), getCode)
|
2020-05-04 16:03:54 +00:00
|
|
|
}
|
|
|
|
|
2020-03-08 02:31:36 +00:00
|
|
|
fmt.Println("computed state cid: ", stout.Root)
|
|
|
|
if cctx.Bool("show-trace") {
|
|
|
|
for _, ir := range stout.Trace {
|
|
|
|
fmt.Printf("%s\t%s\t%s\t%d\t%x\t%d\t%x\n", ir.Msg.From, ir.Msg.To, ir.Msg.Value, ir.Msg.Method, ir.Msg.Params, ir.MsgRct.ExitCode, ir.MsgRct.Return)
|
2020-06-11 00:47:28 +00:00
|
|
|
printInternalExecutions("\t", ir.ExecutionTrace.Subcalls)
|
2020-03-08 02:31:36 +00:00
|
|
|
}
|
|
|
|
}
|
2020-01-17 02:33:43 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
2020-01-15 21:24:01 +00:00
|
|
|
|
2020-06-11 00:47:28 +00:00
|
|
|
func printInternalExecutions(prefix string, trace []types.ExecutionTrace) {
|
2020-03-10 04:38:31 +00:00
|
|
|
for _, im := range trace {
|
|
|
|
fmt.Printf("%s%s\t%s\t%s\t%d\t%x\t%d\t%x\n", prefix, im.Msg.From, im.Msg.To, im.Msg.Value, im.Msg.Method, im.Msg.Params, im.MsgRct.ExitCode, im.MsgRct.Return)
|
|
|
|
printInternalExecutions(prefix+"\t", im.Subcalls)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-12 11:24:38 +00:00
|
|
|
var compStateTemplate = `
|
|
|
|
<html>
|
2020-05-04 16:03:54 +00:00
|
|
|
<head>
|
2020-08-12 14:38:32 +00:00
|
|
|
<meta charset="UTF-8">
|
2020-05-04 16:03:54 +00:00
|
|
|
<style>
|
|
|
|
html, body { font-family: monospace; }
|
2020-05-04 16:48:50 +00:00
|
|
|
a:link, a:visited { color: #004; }
|
2020-05-04 16:03:54 +00:00
|
|
|
pre { background: #ccc; }
|
2020-05-04 18:19:01 +00:00
|
|
|
small { color: #444; }
|
2020-05-04 18:12:31 +00:00
|
|
|
.call { color: #00a; }
|
|
|
|
.params { background: #dfd; }
|
|
|
|
.ret { background: #ddf; }
|
2020-05-04 16:03:54 +00:00
|
|
|
.error { color: red; }
|
|
|
|
.exit0 { color: green; }
|
|
|
|
.exec {
|
2020-05-04 18:12:31 +00:00
|
|
|
padding-left: 15px;
|
|
|
|
border-left: 2.5px solid;
|
|
|
|
margin-bottom: 45px;
|
2020-05-04 16:03:54 +00:00
|
|
|
}
|
2020-05-04 16:48:50 +00:00
|
|
|
.exec:hover {
|
2020-05-04 18:12:31 +00:00
|
|
|
background: #eee;
|
2020-05-04 16:48:50 +00:00
|
|
|
}
|
2020-05-04 17:19:23 +00:00
|
|
|
.slow-true-false { color: #660; }
|
|
|
|
.slow-true-true { color: #f80; }
|
2020-06-15 14:18:05 +00:00
|
|
|
.deemp { color: #444; }
|
2020-06-11 20:25:24 +00:00
|
|
|
table {
|
|
|
|
font-size: 12px;
|
2020-06-12 16:49:29 +00:00
|
|
|
border-collapse: collapse;
|
|
|
|
}
|
2020-08-05 20:17:14 +00:00
|
|
|
tr {
|
2020-06-12 16:49:29 +00:00
|
|
|
border-top: 1px solid black;
|
|
|
|
border-bottom: 1px solid black;
|
|
|
|
}
|
|
|
|
tr.sum { border-top: 2px solid black; }
|
|
|
|
tr:first-child { border-top: none; }
|
|
|
|
tr:last-child { border-bottom: none; }
|
|
|
|
|
|
|
|
|
|
|
|
.ellipsis-content,
|
|
|
|
.ellipsis-toggle input {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
.ellipsis-toggle {
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
Checked State
|
|
|
|
**/
|
2020-08-05 20:17:14 +00:00
|
|
|
|
2020-06-12 16:49:29 +00:00
|
|
|
.ellipsis-toggle input:checked + .ellipsis {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
.ellipsis-toggle input:checked ~ .ellipsis-content {
|
|
|
|
display: inline;
|
|
|
|
background-color: #ddd;
|
|
|
|
}
|
2020-06-12 18:46:04 +00:00
|
|
|
hr {
|
|
|
|
border: none;
|
|
|
|
height: 1px;
|
|
|
|
background-color: black;
|
|
|
|
margin: 0;
|
|
|
|
}
|
2020-05-04 16:03:54 +00:00
|
|
|
</style>
|
|
|
|
</head>
|
|
|
|
<body>
|
2020-06-12 11:24:38 +00:00
|
|
|
<div>Tipset: <b>{{.TipSet.Key}}</b></div>
|
|
|
|
<div>Epoch: {{.TipSet.Height}}</div>
|
|
|
|
<div>State CID: <b>{{.Comp.Root}}</b></div>
|
|
|
|
<div>Calls</div>
|
|
|
|
{{range .Comp.Trace}}
|
|
|
|
{{template "message" (Call .ExecutionTrace false .Msg.Cid.String)}}
|
|
|
|
{{end}}
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
`
|
|
|
|
|
|
|
|
var compStateMsg = `
|
|
|
|
<div class="exec" id="{{.Hash}}">
|
|
|
|
{{$code := GetCode .Msg.To}}
|
2020-06-12 12:46:50 +00:00
|
|
|
<div>
|
|
|
|
<a href="#{{.Hash}}">
|
|
|
|
{{if not .Subcall}}
|
|
|
|
<h2 class="call">
|
|
|
|
{{else}}
|
|
|
|
<h4 class="call">
|
|
|
|
{{end}}
|
|
|
|
{{- CodeStr $code}}:{{GetMethod ($code) (.Msg.Method)}}
|
|
|
|
{{if not .Subcall}}
|
|
|
|
</h2>
|
|
|
|
{{else}}
|
|
|
|
</h4>
|
|
|
|
{{end}}
|
|
|
|
</a>
|
|
|
|
</div>
|
2020-06-12 11:24:38 +00:00
|
|
|
|
|
|
|
<div><b>{{.Msg.From}}</b> -> <b>{{.Msg.To}}</b> ({{ToFil .Msg.Value}} FIL), M{{.Msg.Method}}</div>
|
|
|
|
{{if not .Subcall}}<div><small>Msg CID: {{.Msg.Cid}}</small></div>{{end}}
|
|
|
|
{{if gt (len .Msg.Params) 0}}
|
|
|
|
<div><pre class="params">{{JsonParams ($code) (.Msg.Method) (.Msg.Params) | html}}</pre></div>
|
|
|
|
{{end}}
|
2021-01-28 17:15:22 +00:00
|
|
|
{{if PrintTiming}}
|
|
|
|
<div><span class="slow-{{IsSlow .Duration}}-{{IsVerySlow .Duration}}">Took {{.Duration}}</span>, <span class="exit{{IntExit .MsgRct.ExitCode}}">Exit: <b>{{.MsgRct.ExitCode}}</b></span>{{if gt (len .MsgRct.Return) 0}}, Return{{end}}</div>
|
|
|
|
{{else}}
|
|
|
|
<div><span class="exit{{IntExit .MsgRct.ExitCode}}">Exit: <b>{{.MsgRct.ExitCode}}</b></span>{{if gt (len .MsgRct.Return) 0}}, Return{{end}}</div>
|
|
|
|
{{end}}
|
2020-06-12 11:24:38 +00:00
|
|
|
{{if gt (len .MsgRct.Return) 0}}
|
|
|
|
<div><pre class="ret">{{JsonReturn ($code) (.Msg.Method) (.MsgRct.Return) | html}}</pre></div>
|
|
|
|
{{end}}
|
|
|
|
|
|
|
|
{{if ne .MsgRct.ExitCode 0}}
|
|
|
|
<div class="error">Error: <pre>{{.Error}}</pre></div>
|
|
|
|
{{end}}
|
|
|
|
|
2020-06-12 18:46:04 +00:00
|
|
|
<details>
|
|
|
|
<summary>Gas Trace</summary>
|
|
|
|
<table>
|
2022-09-20 15:40:24 +00:00
|
|
|
<tr><th>Name</th><th>Total/Compute/Storage</th><th>Time Taken</th><th>Location</th></tr>
|
2020-06-15 14:18:05 +00:00
|
|
|
{{define "virt" -}}
|
|
|
|
{{- if . -}}
|
|
|
|
<span class="deemp">+({{.}})</span>
|
|
|
|
{{- end -}}
|
|
|
|
{{- end}}
|
|
|
|
|
|
|
|
{{define "gasC" -}}
|
|
|
|
<td>{{.TotalGas}}{{template "virt" .TotalVirtualGas }}/{{.ComputeGas}}{{template "virt" .VirtualComputeGas}}/{{.StorageGas}}{{template "virt" .VirtualStorageGas}}</td>
|
|
|
|
{{- end}}
|
|
|
|
|
2020-06-12 18:46:04 +00:00
|
|
|
{{range .GasCharges}}
|
2022-09-20 15:40:24 +00:00
|
|
|
<tr><td>{{.Name}}{{if .Extra}}:{{.Extra}}{{end}}</td>
|
2020-06-15 14:18:05 +00:00
|
|
|
{{template "gasC" .}}
|
2021-01-28 17:15:22 +00:00
|
|
|
<td>{{if PrintTiming}}{{.TimeTaken}}{{end}}</td>
|
2020-06-12 18:46:04 +00:00
|
|
|
<td>
|
|
|
|
{{ $fImp := FirstImportant .Location }}
|
|
|
|
{{ if $fImp }}
|
|
|
|
<details>
|
|
|
|
<summary>{{ $fImp }}</summary><hr />
|
|
|
|
{{ $elipOn := false }}
|
|
|
|
{{ range $index, $ele := .Location -}}
|
|
|
|
{{- if $index }}<br />{{end -}}
|
|
|
|
{{- if .Show -}}
|
|
|
|
{{ if $elipOn }}
|
|
|
|
{{ $elipOn = false }}
|
|
|
|
</span></label>
|
|
|
|
{{end}}
|
|
|
|
|
|
|
|
{{- if .Important }}<b>{{end -}}
|
|
|
|
{{- . -}}
|
|
|
|
{{if .Important }}</b>{{end}}
|
|
|
|
{{else}}
|
|
|
|
{{ if not $elipOn }}
|
|
|
|
{{ $elipOn = true }}
|
|
|
|
<label class="ellipsis-toggle"><input type="checkbox" /><span class="ellipsis">[…]<br /></span>
|
|
|
|
<span class="ellipsis-content">
|
|
|
|
{{end}}
|
|
|
|
{{- "" -}}
|
|
|
|
{{- . -}}
|
|
|
|
{{end}}
|
|
|
|
{{end}}
|
|
|
|
{{ if $elipOn }}
|
|
|
|
{{ $elipOn = false }}
|
|
|
|
</span></label>
|
2020-06-12 16:49:29 +00:00
|
|
|
{{end}}
|
2020-06-12 18:46:04 +00:00
|
|
|
</details>
|
|
|
|
{{end}}
|
|
|
|
</td></tr>
|
|
|
|
{{end}}
|
2022-11-16 20:07:23 +00:00
|
|
|
{{with sumGas .GasCharges}}
|
2020-06-15 14:18:05 +00:00
|
|
|
<tr class="sum"><td><b>Sum</b></td>
|
|
|
|
{{template "gasC" .}}
|
2021-01-28 17:15:22 +00:00
|
|
|
<td>{{if PrintTiming}}{{.TimeTaken}}{{end}}</td>
|
2020-06-15 14:18:05 +00:00
|
|
|
<td></td></tr>
|
2020-06-12 18:46:04 +00:00
|
|
|
{{end}}
|
|
|
|
</table>
|
|
|
|
</details>
|
|
|
|
|
|
|
|
|
2020-06-12 11:24:38 +00:00
|
|
|
{{if gt (len .Subcalls) 0}}
|
|
|
|
<div>Subcalls:</div>
|
|
|
|
{{$hash := .Hash}}
|
|
|
|
{{range .Subcalls}}
|
|
|
|
{{template "message" (Call . true (printf "%s-%s" $hash .Msg.Cid.String))}}
|
|
|
|
{{end}}
|
|
|
|
{{end}}
|
|
|
|
</div>`
|
|
|
|
|
2020-06-12 14:25:55 +00:00
|
|
|
type compStateHTMLIn struct {
|
2020-06-12 11:24:38 +00:00
|
|
|
TipSet *types.TipSet
|
|
|
|
Comp *api.ComputeStateOutput
|
|
|
|
}
|
2020-05-04 16:03:54 +00:00
|
|
|
|
2021-01-28 17:15:22 +00:00
|
|
|
func ComputeStateHTMLTempl(w io.Writer, ts *types.TipSet, o *api.ComputeStateOutput, printTiming bool, getCode func(addr address.Address) (cid.Cid, error)) error {
|
2020-06-12 11:24:38 +00:00
|
|
|
t, err := template.New("compute_state").Funcs(map[string]interface{}{
|
2021-01-28 17:15:22 +00:00
|
|
|
"GetCode": getCode,
|
|
|
|
"GetMethod": getMethod,
|
|
|
|
"ToFil": toFil,
|
|
|
|
"JsonParams": JsonParams,
|
2023-02-01 21:44:44 +00:00
|
|
|
"JsonReturn": JsonReturn,
|
2021-01-28 17:15:22 +00:00
|
|
|
"IsSlow": isSlow,
|
|
|
|
"IsVerySlow": isVerySlow,
|
|
|
|
"IntExit": func(i exitcode.ExitCode) int64 { return int64(i) },
|
2022-11-16 20:07:23 +00:00
|
|
|
"sumGas": types.SumGas,
|
2021-01-28 17:15:22 +00:00
|
|
|
"CodeStr": codeStr,
|
|
|
|
"Call": call,
|
|
|
|
"PrintTiming": func() bool { return printTiming },
|
2020-06-12 18:46:04 +00:00
|
|
|
"FirstImportant": func(locs []types.Loc) *types.Loc {
|
|
|
|
if len(locs) != 0 {
|
|
|
|
for _, l := range locs {
|
|
|
|
if l.Important() {
|
|
|
|
return &l
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return &locs[0]
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
2020-06-12 11:24:38 +00:00
|
|
|
}).Parse(compStateTemplate)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
t, err = t.New("message").Parse(compStateMsg)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2020-05-04 16:03:54 +00:00
|
|
|
}
|
|
|
|
|
2020-07-21 17:23:25 +00:00
|
|
|
return t.ExecuteTemplate(w, "compute_state", &compStateHTMLIn{
|
2020-06-12 11:24:38 +00:00
|
|
|
TipSet: ts,
|
|
|
|
Comp: o,
|
|
|
|
})
|
2020-05-04 16:03:54 +00:00
|
|
|
}
|
|
|
|
|
2020-06-12 11:24:38 +00:00
|
|
|
type callMeta struct {
|
|
|
|
types.ExecutionTrace
|
|
|
|
Subcall bool
|
|
|
|
Hash string
|
|
|
|
}
|
2020-06-05 12:57:37 +00:00
|
|
|
|
2020-06-12 11:24:38 +00:00
|
|
|
func call(e types.ExecutionTrace, subcall bool, hash string) callMeta {
|
|
|
|
return callMeta{
|
|
|
|
ExecutionTrace: e,
|
|
|
|
Subcall: subcall,
|
|
|
|
Hash: hash,
|
2020-05-04 16:03:54 +00:00
|
|
|
}
|
|
|
|
}
|
2020-05-04 16:48:50 +00:00
|
|
|
|
2020-06-12 11:24:38 +00:00
|
|
|
func codeStr(c cid.Cid) string {
|
|
|
|
cmh, err := multihash.Decode(c.Hash())
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return string(cmh.Digest)
|
|
|
|
}
|
2020-05-04 18:12:31 +00:00
|
|
|
|
2020-06-12 11:24:38 +00:00
|
|
|
func getMethod(code cid.Cid, method abi.MethodNum) string {
|
2022-11-22 09:28:18 +00:00
|
|
|
return consensus.NewActorRegistry().Methods[code][method].Name // todo: use remote
|
2020-06-12 11:24:38 +00:00
|
|
|
}
|
2020-05-04 18:12:31 +00:00
|
|
|
|
2020-06-12 11:24:38 +00:00
|
|
|
func toFil(f types.BigInt) types.FIL {
|
|
|
|
return types.FIL(f)
|
|
|
|
}
|
2020-05-04 18:12:31 +00:00
|
|
|
|
2020-06-12 11:24:38 +00:00
|
|
|
func isSlow(t time.Duration) bool {
|
|
|
|
return t > 10*time.Millisecond
|
|
|
|
}
|
2020-05-04 18:12:31 +00:00
|
|
|
|
2020-06-12 11:24:38 +00:00
|
|
|
func isVerySlow(t time.Duration) bool {
|
|
|
|
return t > 50*time.Millisecond
|
|
|
|
}
|
2020-06-02 20:06:03 +00:00
|
|
|
|
2020-10-23 19:51:10 +00:00
|
|
|
func JsonParams(code cid.Cid, method abi.MethodNum, params []byte) (string, error) {
|
2022-09-27 10:21:42 +00:00
|
|
|
p, err := stmgr.GetParamType(consensus.NewActorRegistry(), code, method) // todo use api for correct actor registry
|
2020-09-29 07:01:52 +00:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
2020-09-04 03:28:42 +00:00
|
|
|
}
|
2020-09-29 07:01:52 +00:00
|
|
|
|
2020-05-04 18:12:31 +00:00
|
|
|
if err := p.UnmarshalCBOR(bytes.NewReader(params)); err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
b, err := json.MarshalIndent(p, "", " ")
|
|
|
|
return string(b), err
|
|
|
|
}
|
|
|
|
|
2023-02-01 21:44:44 +00:00
|
|
|
func JsonReturn(code cid.Cid, method abi.MethodNum, ret []byte) (string, error) {
|
2022-09-27 10:21:42 +00:00
|
|
|
methodMeta, found := consensus.NewActorRegistry().Methods[code][method] // TODO: use remote
|
2020-09-04 03:28:42 +00:00
|
|
|
if !found {
|
|
|
|
return "", fmt.Errorf("method %d not found on actor %s", method, code)
|
|
|
|
}
|
|
|
|
re := reflect.New(methodMeta.Ret.Elem())
|
2020-05-04 18:12:31 +00:00
|
|
|
p := re.Interface().(cbg.CBORUnmarshaler)
|
|
|
|
if err := p.UnmarshalCBOR(bytes.NewReader(ret)); err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
b, err := json.MarshalIndent(p, "", " ")
|
|
|
|
return string(b), err
|
|
|
|
}
|
|
|
|
|
2021-03-23 23:21:04 +00:00
|
|
|
var StateWaitMsgCmd = &cli.Command{
|
2020-03-06 19:01:28 +00:00
|
|
|
Name: "wait-msg",
|
2022-05-03 18:35:06 +00:00
|
|
|
Aliases: []string{"wait-message"},
|
2020-03-06 19:01:28 +00:00
|
|
|
Usage: "Wait for a message to appear on chain",
|
2020-03-04 21:46:00 +00:00
|
|
|
ArgsUsage: "[messageCid]",
|
2020-02-11 00:38:02 +00:00
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "timeout",
|
|
|
|
Value: "10m",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: func(cctx *cli.Context) error {
|
2023-01-25 12:13:56 +00:00
|
|
|
if cctx.NArg() != 1 {
|
|
|
|
return IncorrectNumArgs(cctx)
|
2020-02-11 00:38:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
api, closer, err := GetFullNodeAPI(cctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer closer()
|
|
|
|
|
|
|
|
ctx := ReqContext(cctx)
|
|
|
|
|
|
|
|
msg, err := cid.Decode(cctx.Args().First())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-06-03 21:42:06 +00:00
|
|
|
mw, err := api.StateWaitMsg(ctx, msg, build.MessageConfidence)
|
2020-02-11 00:38:02 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-05-13 17:53:02 +00:00
|
|
|
m, err := api.ChainGetMessage(ctx, msg)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-02-22 18:08:58 +00:00
|
|
|
return printMsg(ctx, api, msg, mw, m)
|
2020-02-11 00:38:02 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-03-23 23:21:04 +00:00
|
|
|
var StateSearchMsgCmd = &cli.Command{
|
2020-03-18 23:06:53 +00:00
|
|
|
Name: "search-msg",
|
2022-05-03 18:35:06 +00:00
|
|
|
Aliases: []string{"search-message"},
|
2020-03-18 23:06:53 +00:00
|
|
|
Usage: "Search to see whether a message has appeared on chain",
|
|
|
|
ArgsUsage: "[messageCid]",
|
|
|
|
Action: func(cctx *cli.Context) error {
|
2023-01-25 12:13:56 +00:00
|
|
|
if cctx.NArg() != 1 {
|
|
|
|
return IncorrectNumArgs(cctx)
|
2020-03-18 23:06:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
api, closer, err := GetFullNodeAPI(cctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer closer()
|
|
|
|
|
|
|
|
ctx := ReqContext(cctx)
|
|
|
|
|
|
|
|
msg, err := cid.Decode(cctx.Args().First())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
mw, err := api.StateSearchMsg(ctx, msg)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-07-20 18:28:27 +00:00
|
|
|
if mw == nil {
|
|
|
|
return fmt.Errorf("failed to find message: %s", msg)
|
|
|
|
}
|
|
|
|
|
2021-02-22 18:08:58 +00:00
|
|
|
m, err := api.ChainGetMessage(ctx, msg)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2020-03-18 23:06:53 +00:00
|
|
|
}
|
2021-02-22 18:08:58 +00:00
|
|
|
|
|
|
|
return printMsg(ctx, api, msg, mw, m)
|
2020-03-18 23:06:53 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-04-03 10:55:29 +00:00
|
|
|
func printReceiptReturn(ctx context.Context, api v0api.FullNode, m *types.Message, r types.MessageReceipt) error {
|
2021-02-22 18:08:58 +00:00
|
|
|
if len(r.Return) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
act, err := api.StateGetActor(ctx, m.To, types.EmptyTSK)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-02-01 21:44:44 +00:00
|
|
|
jret, err := JsonReturn(act.Code, m.Method, r.Return)
|
2021-02-22 18:08:58 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println("Decoded return value: ", jret)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-04-03 10:55:29 +00:00
|
|
|
func printMsg(ctx context.Context, api v0api.FullNode, msg cid.Cid, mw *lapi.MsgLookup, m *types.Message) error {
|
2021-04-04 02:54:57 +00:00
|
|
|
if mw == nil {
|
2021-02-22 18:08:58 +00:00
|
|
|
fmt.Println("message was not found on chain")
|
2021-04-04 02:54:57 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if mw.Message != msg {
|
|
|
|
fmt.Printf("Message was replaced: %s\n", mw.Message)
|
2021-02-22 18:08:58 +00:00
|
|
|
}
|
|
|
|
|
2021-04-04 02:54:57 +00:00
|
|
|
fmt.Printf("Executed in tipset: %s\n", mw.TipSet.Cids())
|
|
|
|
fmt.Printf("Exit Code: %d\n", mw.Receipt.ExitCode)
|
|
|
|
fmt.Printf("Gas Used: %d\n", mw.Receipt.GasUsed)
|
|
|
|
fmt.Printf("Return: %x\n", mw.Receipt.Return)
|
2021-02-22 18:08:58 +00:00
|
|
|
if err := printReceiptReturn(ctx, api, m, mw.Receipt); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-03-23 23:21:04 +00:00
|
|
|
var StateCallCmd = &cli.Command{
|
2020-03-06 19:01:28 +00:00
|
|
|
Name: "call",
|
|
|
|
Usage: "Invoke a method on an actor locally",
|
2021-05-10 15:28:17 +00:00
|
|
|
ArgsUsage: "[toAddress methodId params (optional)]",
|
2020-01-15 21:24:01 +00:00
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "from",
|
|
|
|
Usage: "",
|
2020-02-25 20:54:58 +00:00
|
|
|
Value: builtin.SystemActorAddr.String(),
|
2020-01-15 21:24:01 +00:00
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "value",
|
|
|
|
Usage: "specify value field for invocation",
|
|
|
|
Value: "0",
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "ret",
|
2021-05-10 15:28:17 +00:00
|
|
|
Usage: "specify how to parse output (raw, decoded, base64, hex)",
|
|
|
|
Value: "decoded",
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "encoding",
|
|
|
|
Value: "base64",
|
|
|
|
Usage: "specify params encoding to parse (base64, hex)",
|
2020-01-15 21:24:01 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: func(cctx *cli.Context) error {
|
2022-09-14 18:33:29 +00:00
|
|
|
if cctx.NArg() < 2 {
|
2022-09-14 19:38:15 +00:00
|
|
|
return ShowHelp(cctx, fmt.Errorf("must specify at least actor and method to invoke"))
|
2020-01-15 21:24:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
api, closer, err := GetFullNodeAPI(cctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer closer()
|
|
|
|
|
|
|
|
ctx := ReqContext(cctx)
|
|
|
|
|
|
|
|
toa, err := address.NewFromString(cctx.Args().First())
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("given 'to' address %q was invalid: %w", cctx.Args().First(), err)
|
|
|
|
}
|
|
|
|
|
|
|
|
froma, err := address.NewFromString(cctx.String("from"))
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("given 'from' address %q was invalid: %w", cctx.String("from"), err)
|
|
|
|
}
|
|
|
|
|
2020-03-07 00:46:20 +00:00
|
|
|
ts, err := LoadTipSet(ctx, cctx, api)
|
2020-01-15 21:24:01 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
method, err := strconv.ParseUint(cctx.Args().Get(1), 10, 64)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("must pass method as a number")
|
|
|
|
}
|
|
|
|
|
|
|
|
value, err := types.ParseFIL(cctx.String("value"))
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to parse 'value': %s", err)
|
|
|
|
}
|
|
|
|
|
2021-05-10 15:28:17 +00:00
|
|
|
var params []byte
|
|
|
|
// If params were passed in, decode them
|
2022-09-14 18:33:29 +00:00
|
|
|
if cctx.NArg() > 2 {
|
2021-05-10 15:28:17 +00:00
|
|
|
switch cctx.String("encoding") {
|
|
|
|
case "base64":
|
|
|
|
params, err = base64.StdEncoding.DecodeString(cctx.Args().Get(2))
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("decoding base64 value: %w", err)
|
|
|
|
}
|
|
|
|
case "hex":
|
|
|
|
params, err = hex.DecodeString(cctx.Args().Get(2))
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("decoding hex value: %w", err)
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return xerrors.Errorf("unrecognized encoding: %s", cctx.String("encoding"))
|
|
|
|
}
|
2020-01-15 21:24:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret, err := api.StateCall(ctx, &types.Message{
|
2020-08-06 21:08:42 +00:00
|
|
|
From: froma,
|
|
|
|
To: toa,
|
|
|
|
Value: types.BigInt(value),
|
|
|
|
Method: abi.MethodNum(method),
|
|
|
|
Params: params,
|
2020-02-11 23:29:45 +00:00
|
|
|
}, ts.Key())
|
2020-01-15 21:24:01 +00:00
|
|
|
if err != nil {
|
2021-05-10 15:28:17 +00:00
|
|
|
return fmt.Errorf("state call failed: %w", err)
|
2020-01-15 21:24:01 +00:00
|
|
|
}
|
|
|
|
|
2020-03-03 23:32:17 +00:00
|
|
|
if ret.MsgRct.ExitCode != 0 {
|
2020-09-11 00:32:30 +00:00
|
|
|
return fmt.Errorf("invocation failed (exit: %d, gasUsed: %d): %s", ret.MsgRct.ExitCode, ret.MsgRct.GasUsed, ret.Error)
|
2020-01-15 21:24:01 +00:00
|
|
|
}
|
|
|
|
|
2021-05-10 15:28:17 +00:00
|
|
|
fmt.Println("Call receipt:")
|
|
|
|
fmt.Printf("Exit code: %d\n", ret.MsgRct.ExitCode)
|
|
|
|
fmt.Printf("Gas Used: %d\n", ret.MsgRct.GasUsed)
|
2020-01-15 21:24:01 +00:00
|
|
|
|
2021-05-10 15:28:17 +00:00
|
|
|
switch cctx.String("ret") {
|
|
|
|
case "decoded":
|
|
|
|
act, err := api.StateGetActor(ctx, toa, ts.Key())
|
2020-01-15 21:24:01 +00:00
|
|
|
if err != nil {
|
2021-05-10 15:28:17 +00:00
|
|
|
return xerrors.Errorf("getting actor: %w", err)
|
2020-01-15 21:24:01 +00:00
|
|
|
}
|
2021-05-10 15:28:17 +00:00
|
|
|
|
2023-02-01 21:44:44 +00:00
|
|
|
retStr, err := JsonReturn(act.Code, abi.MethodNum(method), ret.MsgRct.Return)
|
2020-01-16 00:05:49 +00:00
|
|
|
if err != nil {
|
2021-05-10 15:28:17 +00:00
|
|
|
return xerrors.Errorf("decoding return: %w", err)
|
2020-01-16 00:05:49 +00:00
|
|
|
}
|
2021-05-10 15:28:17 +00:00
|
|
|
|
|
|
|
fmt.Printf("Return:\n%s\n", retStr)
|
|
|
|
case "raw":
|
|
|
|
fmt.Printf("Return: \n%s\n", ret.MsgRct.Return)
|
|
|
|
case "hex":
|
|
|
|
fmt.Printf("Return: \n%x\n", ret.MsgRct.Return)
|
|
|
|
case "base64":
|
|
|
|
fmt.Printf("Return: \n%s\n", base64.StdEncoding.EncodeToString(ret.MsgRct.Return))
|
2020-01-15 21:24:01 +00:00
|
|
|
}
|
|
|
|
|
2021-05-10 15:28:17 +00:00
|
|
|
return nil
|
|
|
|
},
|
2020-01-15 21:24:01 +00:00
|
|
|
}
|
2020-08-07 19:57:03 +00:00
|
|
|
|
2021-03-23 23:21:04 +00:00
|
|
|
var StateCircSupplyCmd = &cli.Command{
|
2020-08-07 19:57:03 +00:00
|
|
|
Name: "circulating-supply",
|
2020-10-11 22:17:28 +00:00
|
|
|
Usage: "Get the exact current circulating supply of Filecoin",
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "vm-supply",
|
|
|
|
Usage: "calculates the approximation of the circulating supply used internally by the VM (instead of the exact amount)",
|
|
|
|
Value: false,
|
|
|
|
},
|
|
|
|
},
|
2020-08-07 19:57:03 +00:00
|
|
|
Action: func(cctx *cli.Context) error {
|
|
|
|
api, closer, err := GetFullNodeAPI(cctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer closer()
|
|
|
|
|
|
|
|
ctx := ReqContext(cctx)
|
|
|
|
|
|
|
|
ts, err := LoadTipSet(ctx, cctx, api)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-10-11 22:17:28 +00:00
|
|
|
if cctx.IsSet("vm-supply") {
|
2020-10-12 20:41:27 +00:00
|
|
|
circ, err := api.StateVMCirculatingSupplyInternal(ctx, ts.Key())
|
2020-10-11 22:17:28 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println("Circulating supply: ", types.FIL(circ.FilCirculating))
|
|
|
|
fmt.Println("Mined: ", types.FIL(circ.FilMined))
|
|
|
|
fmt.Println("Vested: ", types.FIL(circ.FilVested))
|
|
|
|
fmt.Println("Burnt: ", types.FIL(circ.FilBurnt))
|
|
|
|
fmt.Println("Locked: ", types.FIL(circ.FilLocked))
|
|
|
|
} else {
|
|
|
|
circ, err := api.StateCirculatingSupply(ctx, ts.Key())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-08-07 19:57:03 +00:00
|
|
|
|
2020-10-11 22:17:28 +00:00
|
|
|
fmt.Println("Exact circulating supply: ", types.FIL(circ))
|
|
|
|
return nil
|
|
|
|
}
|
2020-08-07 19:57:03 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
2020-08-14 18:22:54 +00:00
|
|
|
|
2021-03-23 23:21:04 +00:00
|
|
|
var StateSectorCmd = &cli.Command{
|
2020-09-14 23:36:36 +00:00
|
|
|
Name: "sector",
|
2022-05-03 18:35:06 +00:00
|
|
|
Aliases: []string{"sector-info"},
|
2020-09-14 23:36:36 +00:00
|
|
|
Usage: "Get miner sector info",
|
2021-04-04 02:56:39 +00:00
|
|
|
ArgsUsage: "[minerAddress] [sectorNumber]",
|
2020-09-14 23:36:36 +00:00
|
|
|
Action: func(cctx *cli.Context) error {
|
|
|
|
api, closer, err := GetFullNodeAPI(cctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer closer()
|
|
|
|
|
|
|
|
ctx := ReqContext(cctx)
|
|
|
|
|
2022-09-14 18:33:29 +00:00
|
|
|
if cctx.NArg() != 2 {
|
2022-09-14 19:38:15 +00:00
|
|
|
return IncorrectNumArgs(cctx)
|
2020-09-14 23:36:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ts, err := LoadTipSet(ctx, cctx, api)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
maddr, err := address.NewFromString(cctx.Args().Get(0))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
sid, err := strconv.ParseInt(cctx.Args().Get(1), 10, 64)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
si, err := api.StateSectorGetInfo(ctx, maddr, abi.SectorNumber(sid), ts.Key())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-11-23 16:00:14 +00:00
|
|
|
if si == nil {
|
|
|
|
return xerrors.Errorf("sector %d for miner %s not found", sid, maddr)
|
|
|
|
}
|
2020-09-14 23:36:36 +00:00
|
|
|
|
|
|
|
fmt.Println("SectorNumber: ", si.SectorNumber)
|
|
|
|
fmt.Println("SealProof: ", si.SealProof)
|
|
|
|
fmt.Println("SealedCID: ", si.SealedCID)
|
2022-03-08 21:57:11 +00:00
|
|
|
if si.SectorKeyCID != nil {
|
|
|
|
fmt.Println("SectorKeyCID: ", si.SectorKeyCID)
|
|
|
|
}
|
2020-09-14 23:36:36 +00:00
|
|
|
fmt.Println("DealIDs: ", si.DealIDs)
|
|
|
|
fmt.Println()
|
2022-10-31 12:32:00 +00:00
|
|
|
fmt.Println("Activation: ", cliutil.EpochTimeTs(ts.Height(), si.Activation, ts))
|
|
|
|
fmt.Println("Expiration: ", cliutil.EpochTimeTs(ts.Height(), si.Expiration, ts))
|
2020-09-14 23:36:36 +00:00
|
|
|
fmt.Println()
|
|
|
|
fmt.Println("DealWeight: ", si.DealWeight)
|
|
|
|
fmt.Println("VerifiedDealWeight: ", si.VerifiedDealWeight)
|
|
|
|
fmt.Println("InitialPledge: ", types.FIL(si.InitialPledge))
|
|
|
|
fmt.Println("ExpectedDayReward: ", types.FIL(si.ExpectedDayReward))
|
|
|
|
fmt.Println("ExpectedStoragePledge: ", types.FIL(si.ExpectedStoragePledge))
|
|
|
|
fmt.Println()
|
|
|
|
|
|
|
|
sp, err := api.StateSectorPartition(ctx, maddr, abi.SectorNumber(sid), ts.Key())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println("Deadline: ", sp.Deadline)
|
|
|
|
fmt.Println("Partition: ", sp.Partition)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-03-23 23:21:04 +00:00
|
|
|
var StateMarketCmd = &cli.Command{
|
2020-08-14 18:22:54 +00:00
|
|
|
Name: "market",
|
|
|
|
Usage: "Inspect the storage market actor",
|
|
|
|
Subcommands: []*cli.Command{
|
|
|
|
stateMarketBalanceCmd,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var stateMarketBalanceCmd = &cli.Command{
|
2023-01-25 12:13:56 +00:00
|
|
|
Name: "balance",
|
|
|
|
Usage: "Get the market balance (locked and escrowed) for a given account",
|
|
|
|
ArgsUsage: "[address]",
|
2020-08-14 18:22:54 +00:00
|
|
|
Action: func(cctx *cli.Context) error {
|
2023-01-25 12:13:56 +00:00
|
|
|
if cctx.NArg() != 1 {
|
|
|
|
return IncorrectNumArgs(cctx)
|
2020-08-14 18:22:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
api, closer, err := GetFullNodeAPI(cctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer closer()
|
|
|
|
|
|
|
|
ctx := ReqContext(cctx)
|
|
|
|
|
|
|
|
ts, err := LoadTipSet(ctx, cctx, api)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
addr, err := address.NewFromString(cctx.Args().First())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
balance, err := api.StateMarketBalance(ctx, addr, ts.Key())
|
2020-08-20 04:49:10 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-08-14 18:22:54 +00:00
|
|
|
|
|
|
|
fmt.Printf("Escrow: %s\n", types.FIL(balance.Escrow))
|
|
|
|
fmt.Printf("Locked: %s\n", types.FIL(balance.Locked))
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
2020-11-19 07:24:32 +00:00
|
|
|
|
2021-03-23 23:21:04 +00:00
|
|
|
var StateNtwkVersionCmd = &cli.Command{
|
2020-11-19 07:24:32 +00:00
|
|
|
Name: "network-version",
|
|
|
|
Usage: "Returns the network version",
|
|
|
|
Action: func(cctx *cli.Context) error {
|
|
|
|
if cctx.Args().Present() {
|
|
|
|
return ShowHelp(cctx, fmt.Errorf("doesn't expect any arguments"))
|
|
|
|
}
|
|
|
|
|
|
|
|
api, closer, err := GetFullNodeAPI(cctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer closer()
|
|
|
|
|
|
|
|
ctx := ReqContext(cctx)
|
|
|
|
|
|
|
|
ts, err := LoadTipSet(ctx, cctx, api)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
nv, err := api.StateNetworkVersion(ctx, ts.Key())
|
2020-11-19 16:08:14 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-11-19 07:24:32 +00:00
|
|
|
|
|
|
|
fmt.Printf("Network Version: %d\n", nv)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
2022-05-18 05:52:32 +00:00
|
|
|
|
|
|
|
var StateSysActorCIDsCmd = &cli.Command{
|
|
|
|
Name: "actor-cids",
|
|
|
|
Usage: "Returns the built-in actor bundle manifest ID & system actor cids",
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.UintFlag{
|
|
|
|
Name: "network-version",
|
|
|
|
Usage: "specify network version",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: func(cctx *cli.Context) error {
|
|
|
|
if cctx.Args().Present() {
|
|
|
|
return ShowHelp(cctx, fmt.Errorf("doesn't expect any arguments"))
|
|
|
|
}
|
|
|
|
|
|
|
|
api, closer, err := GetFullNodeAPI(cctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer closer()
|
|
|
|
|
|
|
|
ctx := ReqContext(cctx)
|
|
|
|
|
2022-09-15 14:42:44 +00:00
|
|
|
var nv network.Version
|
|
|
|
if cctx.IsSet("network-version") {
|
|
|
|
nv = network.Version(cctx.Uint64("network-version"))
|
|
|
|
} else {
|
|
|
|
nv, err = api.StateNetworkVersion(ctx, types.EmptyTSK)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2022-05-18 05:52:32 +00:00
|
|
|
|
|
|
|
fmt.Printf("Network Version: %d\n", nv)
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
actorVersion, err := actorstypes.VersionForNetwork(nv)
|
2022-05-18 05:52:32 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
fmt.Printf("Actor Version: %d\n", actorVersion)
|
|
|
|
|
2022-06-28 16:39:19 +00:00
|
|
|
manifestCid, ok := actors.GetManifest(actorVersion)
|
|
|
|
if ok {
|
|
|
|
fmt.Printf("Manifest CID: %v\n", manifestCid)
|
|
|
|
}
|
|
|
|
|
2022-05-18 05:52:32 +00:00
|
|
|
tw := tabwriter.NewWriter(os.Stdout, 2, 4, 2, ' ', 0)
|
|
|
|
_, _ = fmt.Fprintln(tw, "\nActor\tCID\t")
|
|
|
|
|
2022-06-23 18:05:20 +00:00
|
|
|
actorsCids, err := api.StateActorCodeCIDs(ctx, nv)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
for name, cid := range actorsCids {
|
|
|
|
_, _ = fmt.Fprintf(tw, "%v\t%v\n", name, cid)
|
2022-05-18 05:52:32 +00:00
|
|
|
}
|
|
|
|
return tw.Flush()
|
|
|
|
},
|
|
|
|
}
|