Skip to content

Commit

Permalink
feat: fix cli
Browse files Browse the repository at this point in the history
  • Loading branch information
hunjixin committed Jan 5, 2023
1 parent 6ed0766 commit 74f5a75
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 45 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
*.txt
tipset.json
test_sqlite_db
./cmds/cfg_example/cfg_example
cmds/cfg_example/cfg_example
cmds/client_example/client_example
venus-messager
*.log
./venus-messager-tools
Expand Down
124 changes: 100 additions & 24 deletions cli/actor_cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ package cli
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"os"
"sort"
"strconv"

"github.com/filecoin-project/go-state-types/big"

actors2 "github.com/filecoin-project/venus/venus-shared/actors"

Expand All @@ -23,7 +27,7 @@ import (
)

var ActorCfgCmds = &cli.Command{
Name: "actor-cfg",
Name: "actor",
Usage: "actor config",
Subcommands: []*cli.Command{
listActorCfgCmd,
Expand All @@ -47,6 +51,16 @@ var listActorCfgCmd = &cli.Command{
}
defer closer()

nodeAPI, nodeAPICloser, err := getNodeAPI(ctx)
if err != nil {
return err
}
defer nodeAPICloser()

if err := LoadBuiltinActors(ctx.Context, nodeAPI); err != nil {
return err
}

actorCfgs, err := client.ListActorCfg(ctx.Context)
if err != nil {
return err
Expand Down Expand Up @@ -83,68 +97,82 @@ var updateActorCfgCmd = &cli.Command{
}
defer closer()

nodeAPI, nodeAPICloser, err := getNodeAPI(ctx)
if err != nil {
return err
}
defer nodeAPICloser()

if err := LoadBuiltinActors(ctx.Context, nodeAPI); err != nil {
return err
}

if ctx.NArg() != 1 {
return errors.New("must specify one uid argument")
}
uuidStr := ctx.Args().Get(0)
id, err := types2.ParseUUID(uuidStr)
if err != nil {
return err
}

hasUpdate := false
changeGasSpecParams := &types.ChangeGasSpecParams{}
if ctx.IsSet(gasOverEstimationFlag.Name) {
hasUpdate = true
gasOverEstimation := ctx.Float64(gasOverEstimationFlag.Name)
changeGasSpecParams.GasOverEstimation = &gasOverEstimation
}

if ctx.IsSet(GasOverPremiumFlag.Name) {
hasUpdate = true
gasOverPremium := ctx.Float64(GasOverPremiumFlag.Name)
changeGasSpecParams.GasOverPremium = &gasOverPremium
}

if ctx.IsSet(gasFeeCapFlag.Name) {
hasUpdate = true
gasFeeCap, err := types2.BigFromString(ctx.String(gasFeeCapFlag.Name))
if err != nil {
return fmt.Errorf("parsing feecap failed %v", err)
}
changeGasSpecParams.GasFeeCap = gasFeeCap
changeGasSpecParams.GasFeeCap = big.Int(gasFeeCap)
}

if ctx.IsSet(maxFeeFlag.Name) {
hasUpdate = true
maxfee, err := types2.BigFromString(ctx.String(maxFeeFlag.Name))
if err != nil {
return fmt.Errorf("parsing maxfee failed %v", err)
}
changeGasSpecParams.MaxFee = maxfee
changeGasSpecParams.MaxFee = big.Int(maxfee)
}

if ctx.IsSet(basefeeFlag.Name) {
hasUpdate = true
basefee, err := types2.BigFromString(ctx.String(basefeeFlag.Name))
if err != nil {
return fmt.Errorf("parsing maxfee failed %v", err)
}
changeGasSpecParams.BaseFee = basefee
changeGasSpecParams.BaseFee = big.Int(basefee)
}
if !hasUpdate {
return errors.New("no new params to update")
}
return client.UpdateActorCfg(ctx.Context, id, changeGasSpecParams)
},
}

var addActorCfgCmd = &cli.Command{
Name: "add",
Usage: "add new actor config",
Name: "add",
Usage: "add new actor config",
ArgsUsage: "<code> <method>",
Flags: []cli.Flag{
gasOverEstimationFlag,
gasFeeCapFlag,
maxFeeFlag,
basefeeFlag,
GasOverPremiumFlag,

&cli.StringFlag{
Name: "code",
Required: true,
},
&cli.Uint64Flag{
Name: "method",
Required: true,
},
&cli.IntFlag{
Name: "version",
},
Expand All @@ -156,16 +184,33 @@ var addActorCfgCmd = &cli.Command{
}
defer closer()

codeCid, err := cid.Decode(ctx.String("code"))
nodeAPI, nodeAPICloser, err := getNodeAPI(ctx)
if err != nil {
return err
}
defer nodeAPICloser()

if err := LoadBuiltinActors(ctx.Context, nodeAPI); err != nil {
return err
}

if ctx.NArg() != 2 {
return errors.New("must specify code and method argument")
}
codeCid, err := cid.Decode(ctx.Args().Get(0))
if err != nil {
return err
}

method, err := strconv.ParseUint(ctx.Args().Get(1), 10, 64)
if err != nil {
return err
}
newActorCfg := &types.ActorCfg{
ID: types2.NewUUID(),
MethodType: types.MethodType{
Code: codeCid,
Method: abi.MethodNum(ctx.Uint64("method")),
Method: abi.MethodNum(method),
},
FeeSpec: types.FeeSpec{},
}
Expand All @@ -181,46 +226,56 @@ var addActorCfgCmd = &cli.Command{
newActorCfg.ActorVersion = methodMeta.Version
}

hasArgument := false
if ctx.IsSet(gasOverEstimationFlag.Name) {
hasArgument = true
gasOverEstimation := ctx.Float64(gasOverEstimationFlag.Name)
newActorCfg.GasOverEstimation = gasOverEstimation
}

if ctx.IsSet(GasOverPremiumFlag.Name) {
hasArgument = true
gasOverPremium := ctx.Float64(GasOverPremiumFlag.Name)
newActorCfg.GasOverPremium = gasOverPremium
}

if ctx.IsSet(gasFeeCapFlag.Name) {
hasArgument = true
gasFeeCap, err := types2.BigFromString(ctx.String(gasFeeCapFlag.Name))
if err != nil {
return fmt.Errorf("parsing feecap failed %v", err)
}
newActorCfg.GasFeeCap = gasFeeCap
newActorCfg.GasFeeCap = big.Int(gasFeeCap)
}

if ctx.IsSet(maxFeeFlag.Name) {
hasArgument = true
maxfee, err := types2.BigFromString(ctx.String(maxFeeFlag.Name))
if err != nil {
return fmt.Errorf("parsing maxfee failed %v", err)
}
newActorCfg.MaxFee = maxfee
newActorCfg.MaxFee = big.Int(maxfee)
}

if ctx.IsSet(basefeeFlag.Name) {
hasArgument = true
basefee, err := types2.BigFromString(ctx.String(basefeeFlag.Name))
if err != nil {
return fmt.Errorf("parsing maxfee failed %v", err)
}
newActorCfg.BaseFee = basefee
newActorCfg.BaseFee = big.Int(basefee)
}
if !hasArgument {
return errors.New("no argument to save")
}
return client.SaveActorCfg(ctx.Context, newActorCfg)
},
}

var getActorCfgCmd = &cli.Command{
Name: "list",
Usage: "list actor config",
Name: "get",
Usage: "get actor config",
ArgsUsage: "<uid>",
Flags: []cli.Flag{
outputTypeFlag,
},
Expand All @@ -231,6 +286,19 @@ var getActorCfgCmd = &cli.Command{
}
defer closer()

nodeAPI, nodeAPICloser, err := getNodeAPI(ctx)
if err != nil {
return err
}
defer nodeAPICloser()

if err := LoadBuiltinActors(ctx.Context, nodeAPI); err != nil {
return err
}

if ctx.NArg() != 1 {
return errors.New("must specific one uid argument")
}
uuidStr := ctx.Args().Get(0)
id, err := types2.ParseUUID(uuidStr)
if err != nil {
Expand Down Expand Up @@ -263,7 +331,6 @@ var listBuiltinActorCmd = &cli.Command{
Name: "version",
},
},

Action: func(ctx *cli.Context) error {
type MethodMeta struct {
Name string
Expand All @@ -272,6 +339,16 @@ var listBuiltinActorCmd = &cli.Command{
Version actors.Version
}

nodeAPI, nodeAPICloser, err := getNodeAPI(ctx)
if err != nil {
return err
}
defer nodeAPICloser()

if err := LoadBuiltinActors(ctx.Context, nodeAPI); err != nil {
return err
}

methodsByActorsVersion := make(map[actors.Version]map[cid.Cid][]MethodMeta)
var maxVersion actors.Version
for codeCid, methodMap := range utils.MethodsMap {
Expand Down Expand Up @@ -329,7 +406,6 @@ var listBuiltinActorCmd = &cli.Command{
}
actorCfgTw.Write(row)
}

}
return actorCfgTw.Flush(os.Stdout)
},
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/filecoin-project/go-jsonrpc v0.1.5
github.com/filecoin-project/go-state-types v0.9.8
github.com/filecoin-project/specs-actors/v5 v5.0.6
github.com/filecoin-project/venus v1.9.0-rc1.0.20230104064901-387e152c1d91
github.com/filecoin-project/venus v1.9.0-rc1.0.20230105013945-4a030c5cb47e
github.com/filecoin-project/venus-auth v1.9.0
github.com/golang/mock v1.6.0
github.com/google/uuid v1.3.0
Expand Down Expand Up @@ -233,7 +233,7 @@ require (
github.com/go-logr/stdr v1.2.2 // indirect
github.com/hraban/lrucache v0.0.0-20201130153820-17052bf09781 // indirect
github.com/ipfs/go-block-format v0.0.3 // indirect
github.com/libp2p/go-libp2p-core v0.20.0 // indirect
github.com/libp2p/go-libp2p-core v0.20.1 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/marten-seemann/qtls-go1-19 v0.1.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,8 @@ github.com/filecoin-project/specs-storage v0.4.1/go.mod h1:Z2eK6uMwAOSLjek6+sy0j
github.com/filecoin-project/storetheindex v0.3.5/go.mod h1:0r3d0kSpK63O6AvLr1CjAINLi+nWD49clzcnKV+GLpI=
github.com/filecoin-project/test-vectors/schema v0.0.5/go.mod h1:iQ9QXLpYWL3m7warwvK1JC/pTri8mnfEmKygNDqqY6E=
github.com/filecoin-project/venus v1.2.4/go.mod h1:hJULXHGAnWuq5S5KRtPkwbT8DqgM9II7NwyNU7t59D0=
github.com/filecoin-project/venus v1.9.0-rc1.0.20230104064901-387e152c1d91 h1:4chMUNd3Ty5N9T2hU81oqkoEmcYVkJqISF7EplgHh5U=
github.com/filecoin-project/venus v1.9.0-rc1.0.20230104064901-387e152c1d91/go.mod h1:BJn0TSnkDTX8R3duiCpgPKDYU5ybrPCgJlkxZi/wmTs=
github.com/filecoin-project/venus v1.9.0-rc1.0.20230105013945-4a030c5cb47e h1:oPfZqAEzwmRjLaAUjYXu/hyCnxWrx1Zet01CN+Kge3M=
github.com/filecoin-project/venus v1.9.0-rc1.0.20230105013945-4a030c5cb47e/go.mod h1:BJn0TSnkDTX8R3duiCpgPKDYU5ybrPCgJlkxZi/wmTs=
github.com/filecoin-project/venus-auth v1.3.2/go.mod h1:m5Jog2GYxztwP7w3m/iJdv/V1/bTcAVU9rm/CbhxRQU=
github.com/filecoin-project/venus-auth v1.9.0 h1:GH0o/jPdF55/U/uLoMzrqR9+DOsMf5oWM/X4UPuyWPA=
github.com/filecoin-project/venus-auth v1.9.0/go.mod h1:Ckj8F/iuSgXnCb9LvH0IiPR7swJZQAhabDOxVycLGWs=
Expand Down Expand Up @@ -1175,8 +1175,8 @@ github.com/libp2p/go-libp2p-core v0.11.0/go.mod h1:ECdxehoYosLYHgDDFa2N4yE8Y7aQR
github.com/libp2p/go-libp2p-core v0.12.0/go.mod h1:ECdxehoYosLYHgDDFa2N4yE8Y7aQRAMf0sX9mf2sbGg=
github.com/libp2p/go-libp2p-core v0.13.0/go.mod h1:ECdxehoYosLYHgDDFa2N4yE8Y7aQRAMf0sX9mf2sbGg=
github.com/libp2p/go-libp2p-core v0.14.0/go.mod h1:tLasfcVdTXnixsLB0QYaT1syJOhsbrhG7q6pGrHtBg8=
github.com/libp2p/go-libp2p-core v0.20.0 h1:PGKM74+T+O/FaZNARNW32i90RMBHCcgd/hkum2UQ5eY=
github.com/libp2p/go-libp2p-core v0.20.0/go.mod h1:6zR8H7CvQWgYLsbG4on6oLNSGcyKaYFSEYyDt51+bIY=
github.com/libp2p/go-libp2p-core v0.20.1 h1:fQz4BJyIFmSZAiTbKV8qoYhEH5Dtv/cVhZbG3Ib/+Cw=
github.com/libp2p/go-libp2p-core v0.20.1/go.mod h1:6zR8H7CvQWgYLsbG4on6oLNSGcyKaYFSEYyDt51+bIY=
github.com/libp2p/go-libp2p-crypto v0.0.1/go.mod h1:yJkNyDmO341d5wwXxDUGO0LykUVT72ImHNUqh5D/dBE=
github.com/libp2p/go-libp2p-crypto v0.0.2/go.mod h1:eETI5OUfBnvARGOHrJz2eWNyTUxEGZnBxMcbUjfIj4I=
github.com/libp2p/go-libp2p-crypto v0.1.0/go.mod h1:sPUokVISZiy+nNuTTH/TY+leRSxnFj/2GLjtOTW90hI=
Expand Down
8 changes: 4 additions & 4 deletions models/mysql/actor_cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (
type mysqlActorCfg struct {
ID shared.UUID `gorm:"column:id;type:varchar(256);primary_key;"` // 主键
ActorVersion int `gorm:"column:actor_v;type:unsigned int;NOT NULL"`
Code mtypes.DBCid `gorm:"column:code;type:varchar(256);index:idx_code_cid_method,unique;NOT NULL;"`
Method uint64 `gorm:"column:method;type:unsigned bigint;index:idx_code_cid_method,unique;NOT NULL"`
Code mtypes.DBCid `gorm:"column:code;type:varchar(256);index:idx_code_method,unique;NOT NULL;"`
Method uint64 `gorm:"column:method;type:unsigned bigint;index:idx_code_method,unique;NOT NULL"`

FeeSpec

Expand Down Expand Up @@ -88,7 +88,7 @@ func (s *mysqlActorCfgRepo) SaveActorCfg(ctx context.Context, actorCfg *types.Ac

func (s *mysqlActorCfgRepo) GetActorCfgByMethodType(ctx context.Context, methodType *types.MethodType) (*types.ActorCfg, error) {
var a mysqlActorCfg
if err := s.DB.Take(&a, "code_cid = ? and method = ?", methodType.Code.String(), methodType.Method).Error; err != nil {
if err := s.DB.Take(&a, "code = ? and method = ?", methodType.Code.String(), methodType.Method).Error; err != nil {
return nil, err
}

Expand Down Expand Up @@ -119,7 +119,7 @@ func (s *mysqlActorCfgRepo) ListActorCfg(ctx context.Context) ([]*types.ActorCfg
}

func (s *mysqlActorCfgRepo) DelActorCfgByMethodType(ctx context.Context, methodType *types.MethodType) error {
return s.DB.Delete(mysqlActorCfg{}, "code_cid = ? and method = ?", methodType.Code.String(), methodType.Method).Error
return s.DB.Delete(mysqlActorCfg{}, "code = ? and method = ?", methodType.Code.String(), methodType.Method).Error
}

func (s *mysqlActorCfgRepo) DelActorCfgById(ctx context.Context, id shared.UUID) error {
Expand Down
Loading

0 comments on commit 74f5a75

Please sign in to comment.