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

merge: merge a head #216

Merged
merged 17 commits into from
Jul 18, 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
36 changes: 23 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 @@ -173,4 +173,14 @@ jobs:
--data-urlencode "link=$link" \
--data-urlencode "description=message:${{steps.vars.outputs.git_message}}, branch:${{steps.vars.outputs.branch}}, commit:${{steps.vars.outputs.short}}, tag:${{steps.vars.outputs.github_tag}}" \
--data-urlencode "version=${{steps.vars.outputs.short}}"
set -e
set -e

- name: Publish the Docker image
id: docker
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}}
docker login --username=filvenus --password ${{ secrets.DOCKER_PASSWORD }}
docker push filvenus/venus-messager:${{steps.vars.outputs.github_tag}}
docker push filvenus/venus-messager:latest
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
15 changes: 13 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 All @@ -28,3 +32,10 @@ test:
rm -rf models/test_sqlite_db*
go test -race ./...


.PHONY: docker



docker:
docker build --build-arg https_proxy=$(BUILD_DOCKER_PROXY) -t venus-messager .
54 changes: 43 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ messager is a component used to manage local messages, with the purpose of savin

Use [Venus Issues](https://github.com/filecoin-project/venus/issues) for reporting issues about this repository.

## Work
### Work

- ✅ Remote wallet support: One messenger support multiple wallets to manage their keys separately
- ✅ Message pool for multiple miners: As a service, Messenger provides API for miners to put messages on chain
Expand All @@ -20,15 +20,53 @@ Use [Venus Issues](https://github.com/filecoin-project/venus/issues) for reporti
- 🔲 Rich and flexible message sorting options


## Getting Start
### Getting Start

build binary
```sh
git clone https://github.com/filecoin-project/venus-messager.git
make
```

## Config
### Set repo path

> The default path is ~/.venus-messager.
```
./venus-messager --repo=path_to_repo run
```

### Run

```sh
./venus-messager run \
--node-url=/ip4/127.0.0.1/tcp/3453 \
--gateway-url=/ip4/127.0.0.1/tcp/45132 \
--auth-url=http://127.0.0.1:8989 \
--auth-token=<auth-token> \
--db-type=sqlite
```

We will find three files in ~/.venus-messager

* message.db
* message.db-shm
* message.db-wal

#### db use mysql

```sh
./venus-messager run \
--node-url=/ip4/127.0.0.1/tcp/3453 \
--gateway-url=/ip4/127.0.0.1/tcp/45132 \
--auth-url=http://127.0.0.1:8989 \
--auth-token=<auth-token> \
--db-type=mysql \
--mysql-dsn="user:password@(127.0.0.1:3306)/messager?parseTime=true&loc=Local"
```

### Config

> The configuration file is saved in ~/.venus-messager/config.toml

```
[api]
Expand All @@ -40,14 +78,14 @@ make

[db.mysql]
connMaxLifeTime = "1m0s"
connectionString = "" # eg. root:password@(127.0.0.1:3306)/messager?parseTime=true&loc=Local
connectionString = ""
debug = false
maxIdleConn = 10
maxOpenConn = 10

[db.sqlite]
debug = false
file = "./message.db"
file = ""

[gateway]
# gateway token, generate by auth server
Expand Down Expand Up @@ -104,9 +142,3 @@ make
ProbabilitySampler = 1.0
ServerName = "venus-messenger"
```

## Run

```sh
./venus-messager run --auth-url=http://127.0.0.1:8989 --node-url=/ip4/127.0.0.1/tcp/3453 --gateway-url=/ip4/127.0.0.1/tcp/45132 --auth-token=<auth-token>
```
11 changes: 6 additions & 5 deletions api/jwt/jwt.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
package jwt

import (
"fmt"

"github.com/filecoin-project/venus-auth/cmd/jwtclient"
"golang.org/x/xerrors"

"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 {
return nil, xerrors.Errorf("new local jwt client failed %v", err)
return nil, fmt.Errorf("new local jwt client failed %v", err)
}

return jc, nil
Expand Down
6 changes: 3 additions & 3 deletions api/jwt/local_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"crypto/rand"
"encoding/hex"
"fmt"
"io"
"io/ioutil"

Expand All @@ -13,7 +14,6 @@ import (
"github.com/filecoin-project/venus-auth/auth"
"github.com/filecoin-project/venus-auth/core"
jwt3 "github.com/gbrlsnchs/jwt/v3"
"golang.org/x/xerrors"

"github.com/filecoin-project/venus-messager/config"
)
Expand All @@ -26,11 +26,11 @@ func newLocalJWTClient(cfg *config.JWTConfig) (jwtclient.IJwtAuthClient, error)
lc := &localJwtClient{}

if len(cfg.Local.Secret) == 0 {
return nil, xerrors.Errorf("secret is empty")
return nil, fmt.Errorf("secret is empty")
}
b, err := hex.DecodeString(cfg.Local.Secret)
if err != nil {
return nil, xerrors.Errorf("failed to decode secret %v", err)
return nil, fmt.Errorf("failed to decode secret %v", err)
}
lc.alg = jwt3.NewHS256(b)

Expand Down
4 changes: 2 additions & 2 deletions api/jwt/remote_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package jwt

import (
"context"
"errors"

"github.com/filecoin-project/go-jsonrpc/auth"
"github.com/filecoin-project/venus-auth/cmd/jwtclient"
"github.com/filecoin-project/venus-auth/core"
"golang.org/x/xerrors"

"github.com/filecoin-project/venus-messager/config"
)
Expand Down Expand Up @@ -35,5 +35,5 @@ func (c *RemoteAuthClient) Verify(ctx context.Context, token string) ([]auth.Per
return core.AdaptOldStrategy(res.Perm), nil
}

return nil, xerrors.New("remote client is nil")
return nil, errors.New("remote client is nil")
}
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
6 changes: 3 additions & 3 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,12 +41,12 @@ 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()
handler.Handle("/rpc/v0", srv)
authMux := jwtclient.NewAuthMux(jwtCli.Local, jwtCli.Remote, handler, log)
authMux := jwtclient.NewAuthMux(jwtCli.Local, jwtCli.Remote, handler)
authMux.TrustHandle("/debug/pprof/", http.DefaultServeMux)

apiserv := &http.Server{
Expand Down
Loading