Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

chore: backport: 201 & 203 & 206 ... #223

Merged
merged 12 commits into from
Jul 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions .github/workflows/build_upload.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
name: build for test/release

on:
create:
tags:
- '**'
pull_request:
branches:
- main
push:
branches:
- main
- incubation
branches: ['prep/**', 'release/**', 'test/**', master, main]
tags: ['**']
workflow_dispatch:
jobs:
build:
Expand All @@ -37,10 +30,15 @@ jobs:
export job_url=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID
export oss_exists=0
export ftp_exists=0
export rx='^v([0-9]+\.){0,2}(\*|[0-9]+)(-rc[0-9]*){0,1}$'
export is_tag_create=false

if [[ "${{github.ref_type}}" == "tag" ]] && [[ "${{github.event_name}}" == "create" ]] && [[ "$github_tag" =~ $rx ]]; then
export pub_method=pushRelease
export rx_tag='^refs\/tags\/.*'
export rx_version_tag='^v([0-9]+\.){0,2}(\*|[0-9]+)(-rc[0-9]*){0,1}$'
if [[ "${{github.ref}}" =~ $rx_tag ]]; then
export is_tag_create=true
if [[ "${{github.ref_name}}" =~ $rx_version_tag ]]; then
export pub_method=pushRelease
fi
fi

if [[ "${{secrets.OSS_KEY_ID}}" != "" && \
Expand All @@ -65,6 +63,7 @@ jobs:
echo "::set-output name=pub_method::$pub_method"
echo "::set-output name=oss_exists::$oss_exists"
echo "::set-output name=ftp_exists::$ftp_exists"
echo "::set-output name=is_tag_create:$is_tag_create"
- name: show environment
run: |
echo bin = ${{steps.vars.outputs.bin}}
Expand All @@ -86,6 +85,7 @@ jobs:
echo github.ref_name = ${{github.ref_name}}
echo vars.job_url = ${{steps.vars.outputs.job_url}}
echo ftp_url = ftp://${{secrets.FTP_HOST}}/${{steps.vars.outputs.repo_name}}/${{steps.vars.outputs.artifact_name}}
echo vars.is_tag_create = ${{steps.vars.outputs.is_tag_create}}
- name: Set up Go
uses: actions/setup-go@v2
with:
Expand Down Expand Up @@ -177,7 +177,7 @@ jobs:

- name: Publish the Docker image
id: docker
if: ${{ github.ref_type == 'tag' && github.event_name == 'create' }}
if: ${{ steps.vars.outputs.is_tag_create == 'true' }}
run: |
docker build . --file dockerfile --tag filvenus/venus-messager:latest
docker tag filvenus/venus-messager:latest filvenus/venus-messager:${{steps.vars.outputs.github_tag}}
Expand Down
16 changes: 9 additions & 7 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,9 @@ jobs:
go-version: 1.17

- name: Lint
uses: dominikh/staticcheck-action@v1.1.0
with:
install-go: false
version: "2021.1.1"

- name: Test
run: go test -v ./...
run: |
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.44.2
golangci-lint run --timeout 10m

- name: Build
env:
Expand All @@ -37,6 +33,12 @@ jobs:
run: |
make

- name: Detect changes
run: |
go mod tidy
git status --porcelain
test -z "$(git status --porcelain)"

- name: Run coverage
run: go test -coverpkg=./... -race -coverprofile=coverage.txt -covermode=atomic ./...

Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
.idea
.vscode
messager.toml.local
./venus-messager
./*.log
*.db
Expand All @@ -12,4 +11,5 @@ test_sqlite_db
./cmds/cfg_example/cfg_example
venus-messager
*.log
*.toml
./venus-messager-tools
venus-messager-tools
33 changes: 33 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
linters:
disable-all: true
enable:
- gofmt
- govet
- misspell
- goconst
- revive
- errcheck
- unconvert
- staticcheck
- varcheck
- structcheck
- deadcode
- unused
- stylecheck
- gosimple
- goimports

issues:
exclude:
- "should have( a package)? comment"
- "var-naming"
- "(ST1003)"

exclude-rules:
exclude-use-default: false

linters-settings:
goconst:
min-occurrences: 6
run:
skip-dirs-use-default: false
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ endif

GOFLAGS+=-ldflags="$(ldflags)"

build:
build: tools
rm -rf venus-messager
go build $(GOFLAGS) -o venus-messager .
./venus-messager --version

tools:
rm -rf venus-messager-tools
go build -o venus-messager-tools ./tools/main.go
.PHONY: tools

gen:
go run ./gen/gen.go > ./api/controller/auth_map.go
Expand Down
6 changes: 3 additions & 3 deletions api/jwt/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import (
"github.com/filecoin-project/venus-messager/config"
)

type JwtClient struct {
type Client struct {
Local jwtclient.IJwtAuthClient
Remote *RemoteAuthClient
}

func NewJwtClient(jwtCfg *config.JWTConfig) (*JwtClient, error) {
func NewJwtClient(jwtCfg *config.JWTConfig) (*Client, error) {
var err error
jc := &JwtClient{
jc := &Client{
Remote: newRemoteJwtClient(jwtCfg),
}
if jc.Local, err = newLocalJWTClient(jwtCfg); err != nil {
Expand Down
8 changes: 4 additions & 4 deletions api/messager_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ func (m MessageImp) UpdateFilledMessageByID(ctx context.Context, id string) (str
return m.MessageSrv.UpdateFilledMessageByID(ctx, id)
}

func (m MessageImp) ReplaceMessage(ctx context.Context, id string, auto bool, maxFee string, gasLimit int64, gasPremium string, gasFeecap string) (cid.Cid, error) {
return m.MessageSrv.ReplaceMessage(ctx, id, auto, maxFee, gasLimit, gasPremium, gasFeecap)
func (m MessageImp) ReplaceMessage(ctx context.Context, params *types.ReplacMessageParams) (cid.Cid, error) {
return m.MessageSrv.ReplaceMessage(ctx, params)
}

func (m MessageImp) RepublishMessage(ctx context.Context, id string) error {
Expand Down Expand Up @@ -159,8 +159,8 @@ func (m MessageImp) SetSelectMsgNum(ctx context.Context, addr address.Address, n
return m.AddressSrv.SetSelectMsgNum(ctx, addr, num)
}

func (m MessageImp) SetFeeParams(ctx context.Context, addr address.Address, gasOverEstimation float64, maxFee, maxFeeCap string) error {
return m.AddressSrv.SetFeeParams(ctx, addr, gasOverEstimation, maxFee, maxFeeCap)
func (m MessageImp) SetFeeParams(ctx context.Context, addr address.Address, gasOverEstimation, gasOverPremium float64, maxFee, maxFeeCap string) error {
return m.AddressSrv.SetFeeParams(ctx, addr, gasOverEstimation, gasOverPremium, maxFee, maxFeeCap)
}

func (m MessageImp) ClearUnFillMessage(ctx context.Context, addr address.Address) (int, error) {
Expand Down
4 changes: 2 additions & 2 deletions api/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"go.uber.org/fx"
)

func BindRateLimit(msgImp *MessageImp, jwtCli *jwt.JwtClient, log *log.Logger, rateLimitCfg *config.RateLimitConfig) (messager.IMessager, error) {
func BindRateLimit(msgImp *MessageImp, jwtCli *jwt.Client, log *log.Logger, rateLimitCfg *config.RateLimitConfig) (messager.IMessager, error) {
var msgAPI messager.IMessagerStruct
permission.PermissionProxy(msgImp, &msgAPI)

Expand All @@ -41,7 +41,7 @@ func BindRateLimit(msgImp *MessageImp, jwtCli *jwt.JwtClient, log *log.Logger, r

// RunAPI bind rpc call and start rpc
// todo
func RunAPI(lc fx.Lifecycle, jwtCli *jwt.JwtClient, lst net.Listener, log *log.Logger, msgImp messager.IMessager) error {
func RunAPI(lc fx.Lifecycle, jwtCli *jwt.Client, lst net.Listener, log *log.Logger, msgImp messager.IMessager) error {
srv := jsonrpc.NewServer()
srv.Register("Message", msgImp)
handler := http.NewServeMux()
Expand Down
4 changes: 2 additions & 2 deletions api/modules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ func TestLimitWrap(t *testing.T) {
fx.Supply(&config.RateLimitConfig{
Redis: "test url",
}),
fx.Provide(func() *jwt.JwtClient {
return &jwt.JwtClient{
fx.Provide(func() *jwt.Client {
return &jwt.Client{
Remote: &jwt.RemoteAuthClient{
Cli: &jwtclient.AuthClient{},
},
Expand Down
3 changes: 2 additions & 1 deletion cli/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ var setFeeParamsCmd = &cli.Command{
Name: "max-fee",
Usage: "Spend up to X attoFIL for message",
},
GasOverPremiumFlag,
},
Action: func(ctx *cli.Context) error {
client, closer, err := getAPI(ctx)
Expand All @@ -249,7 +250,7 @@ var setFeeParamsCmd = &cli.Command{
return err
}

err = client.SetFeeParams(ctx.Context, addr, ctx.Float64("gas-overestimation"), ctx.String("max-fee"), ctx.String("max-feecap"))
err = client.SetFeeParams(ctx.Context, addr, ctx.Float64("gas-overestimation"), ctx.Float64(GasOverPremiumFlag.Name), ctx.String("max-fee"), ctx.String("max-feecap"))

return err
},
Expand Down
21 changes: 16 additions & 5 deletions cli/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import (

"github.com/filecoin-project/go-jsonrpc"
"github.com/filecoin-project/venus-messager/filestore"
"github.com/filecoin-project/venus-messager/service"
v1 "github.com/filecoin-project/venus/venus-shared/api/chain/v1"
"github.com/filecoin-project/venus/venus-shared/utils"
"github.com/ipfs-force-community/venus-common-utils/apiinfo"
"github.com/mitchellh/go-homedir"
"github.com/urfave/cli/v2"

"github.com/filecoin-project/venus-messager/config"
utils2 "github.com/filecoin-project/venus-messager/utils"

"github.com/filecoin-project/venus/venus-shared/api/messager"
)
Expand All @@ -24,13 +24,17 @@ func getAPI(ctx *cli.Context) (messager.IMessager, jsonrpc.ClientCloser, error)
return nil, func() {}, err
}

apiInfo := apiinfo.NewAPIInfo(cfg.API.Address, cfg.JWT.Local.Token)
return NewMessagerAPI(ctx.Context, cfg.API.Address, cfg.JWT.Local.Token)
}

func NewMessagerAPI(ctx context.Context, addr, token string) (messager.IMessager, jsonrpc.ClientCloser, error) {
apiInfo := apiinfo.NewAPIInfo(addr, token)
addr, err := apiInfo.DialArgs("v0")
if err != nil {
return nil, nil, err
}

client, closer, err := messager.NewIMessagerRPC(ctx.Context, addr, apiInfo.AuthHeader())
client, closer, err := messager.NewIMessagerRPC(ctx, addr, apiInfo.AuthHeader())

return client, closer, err
}
Expand All @@ -40,16 +44,23 @@ func getNodeAPI(ctx *cli.Context) (v1.FullNode, jsonrpc.ClientCloser, error) {
if err != nil {
return nil, func() {}, err
}
return service.NewNodeClient(ctx.Context, &cfg.Node)
return v1.DialFullNodeRPC(ctx.Context, cfg.Node.Url, cfg.Node.Token, nil)
}

func NewNodeAPI(ctx context.Context, addr, token string) (v1.FullNode, jsonrpc.ClientCloser, error) {
return v1.DialFullNodeRPC(ctx, addr, token, nil)
}

func getConfig(ctx *cli.Context) (*config.Config, error) {
repoPath, err := homedir.Expand(ctx.String("repo"))
if err != nil {
return nil, err
}
cfg := new(config.Config)

err = utils2.ReadConfig(filepath.Join(repoPath, filestore.ConfigFile), cfg)

return config.ReadConfig(filepath.Join(repoPath, filestore.ConfigFile))
return cfg, err
}

func LoadBuiltinActors(ctx context.Context, nodeAPI v1.FullNode) error {
Expand Down
47 changes: 47 additions & 0 deletions cli/flag.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package cli

import (
"fmt"

"github.com/filecoin-project/go-state-types/big"
venusTypes "github.com/filecoin-project/venus/venus-shared/types"
"github.com/filecoin-project/venus/venus-shared/types/messager"
"github.com/urfave/cli/v2"
)

var GasOverPremiumFlag = &cli.Float64Flag{
Name: "gas-over-premium",
Usage: "",
}

func ParseFlagToReplaceMessaeParams(cctx *cli.Context) (*messager.ReplacMessageParams, error) {
params := messager.ReplacMessageParams{
Auto: cctx.Bool("auto"),
GasLimit: cctx.Int64("gas-limit"),
GasOverPremium: cctx.Float64(GasOverPremiumFlag.Name),
}

if cctx.IsSet("max-fee") {
maxFee, err := venusTypes.ParseFIL(cctx.String("max-fee"))
if err != nil {
return nil, fmt.Errorf("parse max fee failed: %v", err)
}
params.MaxFee = big.Int(maxFee)
}
if cctx.IsSet("gas-premium") {
gasPremium, err := venusTypes.BigFromString(cctx.String("gas-premium"))
if err != nil {
return nil, fmt.Errorf("parse gas premium failed: %v", err)
}
params.GasPremium = gasPremium
}
if cctx.IsSet("gas-feecap") {
gasFeecap, err := venusTypes.BigFromString(cctx.String("gas-feecap"))
if err != nil {
return nil, fmt.Errorf("parse gas feecap failed: %v", err)
}
params.GasFeecap = gasFeecap
}

return &params, nil
}
12 changes: 9 additions & 3 deletions cli/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ var waitMessagerCmd = &cli.Command{
}

id := cctx.Args().Get(0)
msg, err := client.WaitMessage(cctx.Context, id, uint64(constants.MessageConfidence))
msg, err := client.WaitMessage(cctx.Context, id, constants.MessageConfidence)
if err != nil {
return err
}
Expand Down Expand Up @@ -520,6 +520,7 @@ var replaceCmd = &cli.Command{
Name: "max-fee",
Usage: "Spend up to X attoFIL for this message (applicable for auto mode)",
},
GasOverPremiumFlag,
},
ArgsUsage: "<from nonce> | <id>",
Action: func(ctx *cli.Context) error {
Expand Down Expand Up @@ -552,8 +553,13 @@ var replaceCmd = &cli.Command{
return cli.ShowCommandHelp(ctx, ctx.Command.Name)
}

cid, err := client.ReplaceMessage(ctx.Context, id, ctx.Bool("auto"), ctx.String("max-fee"),
ctx.Int64("gas-limit"), ctx.String("gas-premium"), ctx.String("gas-feecap"))
params, err := ParseFlagToReplaceMessaeParams(ctx)
if err != nil {
return err
}
params.ID = id

cid, err := client.ReplaceMessage(ctx.Context, params)
if err != nil {
return err
}
Expand Down
Loading