From 1cdefeaa9286a0942a6f7025f41d0c345ba9987f Mon Sep 17 00:00:00 2001 From: Yongwoo Lee Date: Thu, 14 May 2020 10:08:37 +0900 Subject: [PATCH 1/7] feat: add codespace to broadcast response (#6) --- types/result_test.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/types/result_test.go b/types/result_test.go index 03a6b61875..faeb353799 100644 --- a/types/result_test.go +++ b/types/result_test.go @@ -215,3 +215,25 @@ func TestWrapServiceResult(t *testing.T) { require.NoError(t, err) require.Equal(t, spot, spot2) } + +func TestNewResponseFormatBroadcastTx(t *testing.T) { + hash, err := hex.DecodeString("00000000000000000000000000000000") + require.NoError(t, err) + result := ctypes.ResultBroadcastTx{ + Code: 1, + Data: []byte("some data"), + Log: `[{"log":"","msg_index":1,"success":true}]`, + Codespace: "codespace", + Hash: hash, + } + + txResponse := sdk.NewResponseFormatBroadcastTx(&result) + + require.NoError(t, err) + require.Equal(t, result.Code, txResponse.Code) + require.Equal(t, result.Data.String(), txResponse.Data) + require.NotEmpty(t, txResponse.Logs) + require.Equal(t, result.Log, txResponse.RawLog) + require.Equal(t, result.Codespace, txResponse.Codespace) + require.Equal(t, result.Hash.String(), txResponse.TxHash) +} From d4ad0390319b84cc1e64062c9924b6ccac90772e Mon Sep 17 00:00:00 2001 From: Marshall Kim Date: Thu, 14 May 2020 18:38:56 +0900 Subject: [PATCH 2/7] chore: expose usedCodes for document (#7) --- types/errors/errors_doc.go | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 types/errors/errors_doc.go diff --git a/types/errors/errors_doc.go b/types/errors/errors_doc.go new file mode 100644 index 0000000000..6b7db89060 --- /dev/null +++ b/types/errors/errors_doc.go @@ -0,0 +1,9 @@ +package errors + +func RegisteredErrors() []*Error { + es := make([]*Error, 0, len(usedCodes)) + for _, e := range usedCodes { + es = append(es, e) + } + return es +} From d3e8ed696232d973d149630f788227889d6428b3 Mon Sep 17 00:00:00 2001 From: Marshall Kim Date: Thu, 21 May 2020 11:47:45 +0900 Subject: [PATCH 3/7] fix: query error (#9) --- client/errors_query.go | 31 +++++++++++++++++++++++++++++++ client/query.go | 2 +- 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 client/errors_query.go diff --git a/client/errors_query.go b/client/errors_query.go new file mode 100644 index 0000000000..b2e68ea89f --- /dev/null +++ b/client/errors_query.go @@ -0,0 +1,31 @@ +package client + +import ( + "bytes" + "encoding/json" + "strings" + + "github.com/pkg/errors" +) + +type Error struct { + Codespace string `json:"codespace"` + Code uint32 `json:"code"` + Message string `json:"message"` +} + +func NewQueryError(codespace string, code uint32, desc string) *Error { + return &Error{Codespace: codespace, Code: code, Message: desc} +} + +func (err Error) Error() string { + var buff bytes.Buffer + enc := json.NewEncoder(&buff) + enc.SetEscapeHTML(false) + + if err := enc.Encode(err); err != nil { + panic(errors.Wrap(err, "failed to encode Query error log")) + } + + return strings.TrimSpace(buff.String()) +} diff --git a/client/query.go b/client/query.go index 8d1c98e5a3..277c740d16 100644 --- a/client/query.go +++ b/client/query.go @@ -79,7 +79,7 @@ func (ctx Context) queryABCI(req abci.RequestQuery) (abci.ResponseQuery, error) } if !result.Response.IsOK() { - return abci.ResponseQuery{}, errors.New(result.Response.Log) + return abci.ResponseQuery{}, NewQueryError(result.Response.Codespace, result.Response.Code, result.Response.Log) } // data from trusted node or subspace query doesn't need verification From ffc1a8b7bebdf00ad81b4bc1b2645d9831037a36 Mon Sep 17 00:00:00 2001 From: Marshall Kim Date: Thu, 21 May 2020 13:29:38 +0900 Subject: [PATCH 4/7] fix: check internalABCICodespace (#10) * fix: check UndefinedCodespace too * Update types/errors/abci.go Co-authored-by: Yongwoo Lee Co-authored-by: Yongwoo Lee --- types/errors/abci.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/errors/abci.go b/types/errors/abci.go index accbd35210..19c0f7c9fe 100644 --- a/types/errors/abci.go +++ b/types/errors/abci.go @@ -160,7 +160,7 @@ func Redact(err error) error { if ErrPanic.Is(err) { return errPanicWithMsg } - if abciCode(err) == internalABCICode { + if abciCode(err) == internalABCICode && abciCodespace(err) == internalABCICodespace { return errInternal } From 4d92d7ff6afbc049e2392999aa0f9625b33c9a35 Mon Sep 17 00:00:00 2001 From: wonkuk_seo Date: Fri, 10 Jul 2020 10:34:17 +0900 Subject: [PATCH 5/7] fix: Send response with 404 status when quering non-exist account (#14) --- types/rest/http_status_table.go | 48 +++++++++++++++++++++++++++++++++ x/auth/client/rest/query.go | 4 +-- 2 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 types/rest/http_status_table.go diff --git a/types/rest/http_status_table.go b/types/rest/http_status_table.go new file mode 100644 index 0000000000..0cfce82058 --- /dev/null +++ b/types/rest/http_status_table.go @@ -0,0 +1,48 @@ +package rest + +// TODO : Intergrate http status mapping for every REST API +import ( + "net/http" + + "github.com/line/lbm-sdk/v2/client" + "github.com/line/lbm-sdk/v2/types/errors" +) + +// HTTPStatusMappingTable is map to mapping an error type and a http status +type HTTPStatusMappingTable map[string]map[uint32]int + +var ( + table = HTTPStatusMappingTable{ + errors.RootCodespace: { + 9: http.StatusNotFound, + }, + } +) + +func parsingError(rawErr error) *errors.Error { + if rawErr == nil { + return nil + } + if err, ok := rawErr.(client.Error); ok { + return errors.New(err.Codespace, err.Code, err.Message) + } + if err, ok := rawErr.(*errors.Error); ok { + return err + } + return errors.New(errors.UndefinedCodespace, 1, "internal") +} + +// GetHTTPStatus is method to get http status for given error +func GetHTTPStatusWithError(err error) int { + abciErr := parsingError(err) + if abciErr == nil { + return http.StatusOK + } + result := http.StatusInternalServerError + if codeTable, ok := table[abciErr.Codespace()]; ok { + if status, ok := codeTable[abciErr.ABCICode()]; ok { + result = status + } + } + return result +} diff --git a/x/auth/client/rest/query.go b/x/auth/client/rest/query.go index b5a74b93dc..790ca532fa 100644 --- a/x/auth/client/rest/query.go +++ b/x/auth/client/rest/query.go @@ -38,15 +38,13 @@ func QueryAccountRequestHandlerFn(storeName string, clientCtx client.Context) ht account, height, err := accGetter.GetAccountWithHeight(clientCtx, addr) if err != nil { - // TODO: Handle more appropriately based on the error type. - // Ref: https://github.com/cosmos/cosmos-sdk/issues/4923 if err := accGetter.EnsureExists(clientCtx, addr); err != nil { clientCtx = clientCtx.WithHeight(height) rest.PostProcessResponse(w, clientCtx, types.BaseAccount{}) return } - rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) + rest.WriteErrorResponse(w, rest.GetHTTPStatusWithError(err), err.Error()) return } From bcd1aca936dd1ba5d3314bfd4d06a23caefff942 Mon Sep 17 00:00:00 2001 From: Woosang Son Date: Mon, 22 Mar 2021 20:40:22 +0900 Subject: [PATCH 6/7] chore: enable github action ci --- .github/workflows/lint.yml | 6 ++ .github/workflows/release-sims.yml | 2 +- .github/workflows/sims.yml | 26 ++++- .github/workflows/stale.yml | 2 +- .github/workflows/tag.yml | 2 +- .github/workflows/test.yml | 93 ++++++++++++------ Dockerfile | 6 +- cosmovisor/go.mod | 2 +- cosmovisor/process_test.go | 4 +- cosmovisor/testdata/repo/zip_binary/autod.zip | Bin 511 -> 483 bytes cosmovisor/upgrade_test.go | 2 +- 11 files changed, 100 insertions(+), 45 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 157f0d2178..f1de2542ce 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -2,6 +2,8 @@ name: Lint # Lint runs golangci-lint over the entire cosmos-sdk repository # This workflow is run on every pull request and push to master # The `golangci` will pass without running if no *.{go, mod, sum} files have been changed. +env: + GOPRIVATE: "github.com/line/*" on: pull_request: push: @@ -13,6 +15,10 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 6 steps: + - name: Configure git for private modules + env: + TOKEN: ${{ secrets.TOKEN }} + run: git config --global url."https://${TOKEN}:x-oauth-basic@github.com".insteadOf "https://github.com" - uses: actions/checkout@v2 - uses: technote-space/get-diff-action@v4 with: diff --git a/.github/workflows/release-sims.yml b/.github/workflows/release-sims.yml index 68ca310511..fdacf42874 100644 --- a/.github/workflows/release-sims.yml +++ b/.github/workflows/release-sims.yml @@ -12,7 +12,7 @@ jobs: steps: - uses: rokroskar/workflow-run-cleanup-action@master env: - GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + GITHUB_TOKEN: "${{ secrets.TOKEN }}" if: "!startsWith(github.ref, 'refs/tags/') && github.ref != 'refs/heads/master'" build: diff --git a/.github/workflows/sims.yml b/.github/workflows/sims.yml index d50ddb63a2..78fa786172 100644 --- a/.github/workflows/sims.yml +++ b/.github/workflows/sims.yml @@ -1,11 +1,15 @@ name: Sims # Sims workflow runs multiple types of simulations (nondeterminism, import-export, after-import, multi-seed-short) # This workflow will run on all Pull Requests, if a .go, .mod or .sum file have been changed +env: + GOPRIVATE: "github.com/line/*" + +# TODO ebony: fix sim test failure on: - pull_request: - push: - branches: - - master +# pull_request: +# push: +# branches: +# - master jobs: cleanup-runs: @@ -14,12 +18,16 @@ jobs: steps: - uses: rokroskar/workflow-run-cleanup-action@master env: - GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + GITHUB_TOKEN: "${{ secrets.TOKEN }}" build: runs-on: ubuntu-latest if: "!contains(github.event.head_commit.message, 'skip-sims')" steps: + - name: Configure git for private modules + env: + TOKEN: ${{ secrets.TOKEN }} + run: git config --global url."https://${TOKEN}:x-oauth-basic@github.com".insteadOf "https://github.com" - uses: actions/checkout@v2 - uses: actions/setup-go@v2.1.3 with: @@ -48,6 +56,10 @@ jobs: runs-on: ubuntu-latest needs: [build, install-runsim] steps: + - name: Configure git for private modules + env: + TOKEN: ${{ secrets.TOKEN }} + run: git config --global url."https://${TOKEN}:x-oauth-basic@github.com".insteadOf "https://github.com" - uses: actions/checkout@v2 - uses: actions/setup-go@v2.1.3 with: @@ -74,6 +86,10 @@ jobs: runs-on: ubuntu-latest needs: [build, install-runsim] steps: + - name: Configure git for private modules + env: + TOKEN: ${{ secrets.TOKEN }} + run: git config --global url."https://${TOKEN}:x-oauth-basic@github.com".insteadOf "https://github.com" - uses: actions/checkout@v2 - uses: actions/setup-go@v2.1.3 with: diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 79b54186ee..e4eb648e0d 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -9,7 +9,7 @@ jobs: steps: - uses: actions/stale@v3 with: - repo-token: ${{ secrets.GITHUB_TOKEN }} + repo-token: ${{ secrets.TOKEN }} stale-pr-message: "This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions." diff --git a/.github/workflows/tag.yml b/.github/workflows/tag.yml index 7e1068f303..a29dfef49f 100644 --- a/.github/workflows/tag.yml +++ b/.github/workflows/tag.yml @@ -23,4 +23,4 @@ jobs: with: args: release --rm-dist --release-notes ./RELEASE_CHANGELOG.md env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ secrets.TOKEN }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0bea630422..26abdb2054 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,6 +1,9 @@ name: Tests / Code Coverage # Tests / Code Coverage workflow runs unit tests and uploads a code coverage report # This workflow is run on pushes to master & every Pull Requests where a .go, .mod, .sum have been changed +env: + GOPRIVATE: "github.com/line/*" + on: pull_request: push: @@ -12,7 +15,7 @@ jobs: steps: - uses: rokroskar/workflow-run-cleanup-action@master env: - GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + GITHUB_TOKEN: "${{ secrets.TOKEN }}" if: "!startsWith(github.ref, 'refs/tags/') && github.ref != 'refs/heads/master'" install-tparse: @@ -37,6 +40,10 @@ jobs: matrix: go-arch: ["amd64", "arm", "arm64"] steps: + - name: Configure git for private modules + env: + TOKEN: ${{ secrets.TOKEN }} + run: git config --global url."https://${TOKEN}:x-oauth-basic@github.com".insteadOf "https://github.com" - uses: actions/checkout@v2 - uses: actions/setup-go@v2.1.3 with: @@ -54,6 +61,10 @@ jobs: test-cosmovisor: runs-on: ubuntu-latest steps: + - name: Configure git for private modules + env: + TOKEN: ${{ secrets.TOKEN }} + run: git config --global url."https://${TOKEN}:x-oauth-basic@github.com".insteadOf "https://github.com" - uses: actions/checkout@v2 - uses: actions/setup-go@v2.1.3 with: @@ -76,6 +87,10 @@ jobs: split-test-files: runs-on: ubuntu-latest steps: + - name: Configure git for private modules + env: + TOKEN: ${{ secrets.TOKEN }} + run: git config --global url."https://${TOKEN}:x-oauth-basic@github.com".insteadOf "https://github.com" - uses: actions/checkout@v2 - name: Create a file with all the pkgs run: go list ./... > pkgs.txt @@ -107,6 +122,10 @@ jobs: matrix: part: ["00", "01", "02", "03"] steps: + - name: Configure git for private modules + env: + TOKEN: ${{ secrets.TOKEN }} + run: git config --global url."https://${TOKEN}:x-oauth-basic@github.com".insteadOf "https://github.com" - uses: actions/checkout@v2 - uses: actions/setup-go@v2.1.3 with: @@ -185,6 +204,10 @@ jobs: matrix: part: ["00", "01", "02", "03"] steps: + - name: Configure git for private modules + env: + TOKEN: ${{ secrets.TOKEN }} + run: git config --global url."https://${TOKEN}:x-oauth-basic@github.com".insteadOf "https://github.com" - uses: actions/checkout@v2 - uses: actions/setup-go@v2.1.3 with: @@ -246,35 +269,41 @@ jobs: run: cat ./*-race-output.txt | ~/go/bin/tparse if: env.GIT_DIFF - liveness-test: - runs-on: ubuntu-latest - timeout-minutes: 10 - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-go@v2.1.3 - with: - go-version: 1.15 - - uses: technote-space/get-diff-action@v4 - id: git_diff - with: - PATTERNS: | - **/**.go - go.mod - go.sum - - name: start localnet - run: | - make clean build-simd-linux localnet-start - if: env.GIT_DIFF - - name: test liveness - run: | - ./contrib/localnet_liveness.sh 100 5 50 localhost - if: env.GIT_DIFF +# TODO ebony: enable this test +# liveness-test: +# runs-on: ubuntu-latest +# timeout-minutes: 10 +# steps: +# - name: Configure git for private modules +# env: +# TOKEN: ${{ secrets.TOKEN }} +# run: git config --global url."https://${TOKEN}:x-oauth-basic@github.com".insteadOf "https://github.com" +# - uses: actions/checkout@v2 +# - uses: actions/setup-go@v2.1.3 +# with: +# go-version: 1.15 +# - uses: technote-space/get-diff-action@v4 +# id: git_diff +# with: +# PATTERNS: | +# **/**.go +# go.mod +# go.sum +# - name: start localnet +# run: | +# make clean build-simd-linux localnet-start +# if: env.GIT_DIFF +# - name: test liveness +# run: | +# ./contrib/localnet_liveness.sh 100 5 50 localhost +# if: env.GIT_DIFF - docker-build: - runs-on: ubuntu-latest - timeout-minutes: 10 - steps: - - uses: actions/checkout@v2 - - name: build docker image - run: | - docker build --pull --rm -f "Dockerfile" -t simapp:latest "." +# TODO ebony: fix module download error in docker +# docker-build: +# runs-on: ubuntu-latest +# timeout-minutes: 10 +# steps: +# - uses: actions/checkout@v2 +# - name: build docker image +# run: | +# docker build --pull --rm -f "Dockerfile" -t simapp:latest "." diff --git a/Dockerfile b/Dockerfile index 72349483bc..391c6d446b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,7 +23,11 @@ WORKDIR /go/src/github.com/line/lbm-sdk COPY . . # install simapp, remove packages -RUN make build-linux +# TODO ebony: fix module download error in docker +RUN export GO111MODULE=on && \ + export GOPROXY=direct && \ + git config --global url."https://53e246813dc517348d0f87dfc21a12f70e4e81de:x-oauth-basic@github.com".insteadOf "https://github.com" && \ + make build-linux # Final image diff --git a/cosmovisor/go.mod b/cosmovisor/go.mod index c472fd05f9..034fe08b36 100644 --- a/cosmovisor/go.mod +++ b/cosmovisor/go.mod @@ -1,4 +1,4 @@ -module github.com/line/lbm-sdk/cosmovisor +module github.com/line/lbm-sdk/v2/cosmovisor go 1.14 diff --git a/cosmovisor/process_test.go b/cosmovisor/process_test.go index 0d1b6fb10c..ddb6f1796c 100644 --- a/cosmovisor/process_test.go +++ b/cosmovisor/process_test.go @@ -78,7 +78,7 @@ func (s *processTestSuite) TestLaunchProcessWithDownloads() { s.Require().NoError(err) s.Require().True(doUpgrade) s.Require().Equal("", stderr.String()) - s.Require().Equal("Preparing auto-download some args\n"+`ERROR: UPGRADE "chain2" NEEDED at height: 49: {"binaries":{"linux/amd64":"https://github.com/line/lbm-sdk/v2/raw/51249cb93130810033408934454841c98423ed4b/cosmovisor/testdata/repo/zip_binary/autod.zip?checksum=sha256:dc48829b4126ae95bc0db316c66d4e9da5f3db95e212665b6080638cca77e998"}} module=main`+"\n", stdout.String()) + s.Require().Equal("Preparing auto-download some args\n"+`ERROR: UPGRADE "chain2" NEEDED at height: 49: {"binaries":{"linux/amd64":"https://github.com/cosmos/cosmos-sdk/raw/51249cb93130810033408934454841c98423ed4b/cosmovisor/testdata/repo/zip_binary/autod.zip?checksum=sha256:dc48829b4126ae95bc0db316c66d4e9da5f3db95e212665b6080638cca77e998"}} module=main`+"\n", stdout.String()) // ensure this is upgraded now and produces new output currentBin, err = cfg.CurrentBin() @@ -91,7 +91,7 @@ func (s *processTestSuite) TestLaunchProcessWithDownloads() { s.Require().NoError(err) s.Require().True(doUpgrade) s.Require().Equal("", stderr.String()) - s.Require().Equal("Chain 2 from zipped binary link to referral\nArgs: run --fast\n"+`ERROR: UPGRADE "chain3" NEEDED at height: 936: https://github.com/line/lbm-sdk/v2/raw/0eae1a50612b8bf803336d35055896fbddaa1ddd/cosmovisor/testdata/repo/ref_zipped?checksum=sha256:0a428575de718ed3cf0771c9687eefaf6f19359977eca4d94a0abd0e11ef8e64 module=main`+"\n", stdout.String()) + s.Require().Equal("Chain 2 from zipped binary link to referral\nArgs: run --fast\n"+`ERROR: UPGRADE "chain3" NEEDED at height: 936: https://github.com/cosmos/cosmos-sdk/raw/0eae1a50612b8bf803336d35055896fbddaa1ddd/cosmovisor/testdata/repo/ref_zipped?checksum=sha256:0a428575de718ed3cf0771c9687eefaf6f19359977eca4d94a0abd0e11ef8e64 module=main`+"\n", stdout.String()) // ended with one more upgrade currentBin, err = cfg.CurrentBin() diff --git a/cosmovisor/testdata/repo/zip_binary/autod.zip b/cosmovisor/testdata/repo/zip_binary/autod.zip index 0fe45f18f6250f631b3596eebacd7ae1ab15957d..19cc593ab8dbf3d4108f2203477627661ff022b8 100644 GIT binary patch delta 131 zcmey*{FvDwz?+#xgn@y9gF$jhS-GB9iaVpawjhQ!j6{FKlTP6p=0hKK|Z t-e?lSXvN4R$Bavp1kf-B2B3b1w~Zhc)Cg9H5tDB*N^^Mwg_}Ss7yyHr9&i8v delta 159 zcmaFN{GZt*z?+#xgnI8K7VTBLf2~g91ZhX-R%cXb3L@d%+y7co^Pj5W*P5 x&hh8&k@?O*g&@TN-i%Bl%m{;! Date: Tue, 23 Mar 2021 08:59:22 +0900 Subject: [PATCH 7/7] chore: remove github access token from Dockerfile --- Dockerfile | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 391c6d446b..2c88a2c23c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,10 +24,7 @@ COPY . . # install simapp, remove packages # TODO ebony: fix module download error in docker -RUN export GO111MODULE=on && \ - export GOPROXY=direct && \ - git config --global url."https://53e246813dc517348d0f87dfc21a12f70e4e81de:x-oauth-basic@github.com".insteadOf "https://github.com" && \ - make build-linux +RUN make build-linux # Final image