From 3cb469e7ee44c664c52b4f00f8f9245a1bfd8fff Mon Sep 17 00:00:00 2001 From: Jongwhan Lee <51560997+leejw51crypto@users.noreply.github.com> Date: Fri, 16 Jul 2021 14:07:13 +0900 Subject: [PATCH 1/5] fix: remove redundant log option (#304) --- cmd/ethermintd/flags.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/cmd/ethermintd/flags.go b/cmd/ethermintd/flags.go index ef228e2965..c863aa6fc5 100644 --- a/cmd/ethermintd/flags.go +++ b/cmd/ethermintd/flags.go @@ -39,8 +39,6 @@ var ( statsdAddress string statsdStuckFunc string evmDebug bool - logJSON bool - logLevel string ) // addTxFlags adds common flags for commands to post tx @@ -59,10 +57,7 @@ func addTxFlags(cmd *cobra.Command) *cobra.Command { cmd.PersistentFlags().String(flags.FlagNode, "tcp://localhost:26657", ": to tendermint rpc interface for this chain") cmd.PersistentFlags().Float64(flags.FlagGasAdjustment, flags.DefaultGasAdjustment, "adjustment factor to be multiplied against the estimate returned by the tx simulation; if the gas limit is set manually this flag is ignored ") cmd.PersistentFlags().StringP(flags.FlagBroadcastMode, "b", flags.BroadcastSync, "Transaction broadcasting mode (sync|async|block)") - cmd.PersistentFlags().BoolVar(&logJSON, "log-json", false, "Use JSON as the output format of the own logger (default: text)") cmd.PersistentFlags().BoolVar(&evmDebug, "evm-debug", false, "Enable EVM debug traces") - cmd.PersistentFlags().StringVar(&logLevel, "log-level", "info", "Sets the level of the own logger (error, warn, info, debug)") - // cmd.PersistentFlags().Bool(flags.FlagTrustNode, true, "Trust connected full node (don't verify proofs for responses)") cmd.PersistentFlags().String(flags.FlagKeyringBackend, keyring.BackendFile, "Select keyring's backend") // --gas can accept integers and "simulate" From c8ddb503c1ca94a1a9600231cd3a415979c4f9f2 Mon Sep 17 00:00:00 2001 From: yihuang Date: Fri, 16 Jul 2021 17:30:34 +0800 Subject: [PATCH 2/5] ci: add goreleaser workflow (#295) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #305 patch panicwrap to fix build issue Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> --- .github/workflows/goreleaser.yml | 26 ++++++++ .goreleaser.yml | 109 +++++++++++++++++++++++++++++++ Makefile | 33 ++++++++++ go.mod | 3 + go.sum | 4 +- 5 files changed, 173 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/goreleaser.yml create mode 100644 .goreleaser.yml diff --git a/.github/workflows/goreleaser.yml b/.github/workflows/goreleaser.yml new file mode 100644 index 0000000000..70365ef179 --- /dev/null +++ b/.github/workflows/goreleaser.yml @@ -0,0 +1,26 @@ +name: Release +# This workflow helps with creating releases. +# This job will only be triggered when a tag (vX.X.x) is pushed +on: + push: + # Sequence of patterns matched against refs/tags + tags: + - "v[0-9]+.[0-9]+.[0-9]+" # Push events to matching v*, i.e. v1.0, v20.15.10 + +jobs: + release: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Install Go + uses: actions/setup-go@v2.1.3 + with: + go-version: 1.16 + - name: Unshallow + run: git fetch --prune --unshallow + - name: Create release + uses: goreleaser/goreleaser-action@v2.6.1 + with: + args: release --rm-dist --release-notes ./RELEASE_CHANGELOG.md + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000000..e63e016b3a --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,109 @@ +before: + hooks: + - go mod download + +builds: + - id: "ethermintd-darwin" + main: ./cmd/ethermintd + binary: bin/ethermintd + env: + - CGO_ENABLED=1 + - CC=o64-clang + - CXX=o64-clang++ + goos: + - darwin + goarch: + - amd64 + flags: + - -tags=cgo + ldflags: + - -s -w -X github.com/cosmos/cosmos-sdk/version.Name=ethermint -X github.com/cosmos/cosmos-sdk/version.AppName=ethermintd -X github.com/cosmos/cosmos-sdk/version.Version={{.Version}} -X github.com/cosmos/cosmos-sdk/version.Commit={{.Commit}} + - id: "ethermintd-darwin-arm64" + main: ./cmd/ethermintd + binary: bin/ethermintd + env: + - CGO_ENABLED=1 + - CC=oa64-clang + - CXX=oa64-clang++ + goos: + - darwin + goarch: + - arm64 + flags: + - -tags=cgo + ldflags: + - -s -w -X github.com/cosmos/cosmos-sdk/version.Name=ethermint -X github.com/cosmos/cosmos-sdk/version.AppName=ethermintd -X github.com/cosmos/cosmos-sdk/version.Version={{.Version}} -X github.com/cosmos/cosmos-sdk/version.Commit={{.Commit}} + - id: "ethermintd-linux" + main: ./cmd/ethermintd + binary: bin/ethermintd + env: + - CGO_ENABLED=1 + - CC=gcc + - CXX=g++ + goos: + - linux + goarch: + - amd64 + flags: + - -tags=cgo + ldflags: + - -s -w -X github.com/cosmos/cosmos-sdk/version.Name=ethermint -X github.com/cosmos/cosmos-sdk/version.AppName=ethermintd -X github.com/cosmos/cosmos-sdk/version.Version={{.Version}} -X github.com/cosmos/cosmos-sdk/version.Commit={{.Commit}} + - id: "ethermintd-linux-arm64" + main: ./cmd/ethermintd + binary: bin/ethermintd + env: + - CGO_ENABLED=1 + - CC=aarch64-linux-gnu-gcc + - CXX=aarch64-linux-gnu-g++ + goos: + - linux + goarch: + - arm64 + flags: + - -tags=cgo + ldflags: + - -s -w -X github.com/cosmos/cosmos-sdk/version.Name=ethermint -X github.com/cosmos/cosmos-sdk/version.AppName=ethermintd -X github.com/cosmos/cosmos-sdk/version.Version={{.Version}} -X github.com/cosmos/cosmos-sdk/version.Commit={{.Commit}} + - id: "ethermintd-windows" + main: ./cmd/ethermintd + binary: bin/ethermintd + env: + - CGO_ENABLED=1 + - CC=x86_64-w64-mingw32-gcc + - CXX=x86_64-w64-mingw32-g++ + goos: + - windows + goarch: + - amd64 + flags: + - -tags=cgo + - -buildmode=exe + ldflags: + - -s -w -X github.com/cosmos/cosmos-sdk/version.Name=ethermint -X github.com/cosmos/cosmos-sdk/version.AppName=ethermintd -X github.com/cosmos/cosmos-sdk/version.Version={{.Version}} -X github.com/cosmos/cosmos-sdk/version.Commit={{.Commit}} + +archives: +- name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}' + replacements: + darwin: Darwin + linux: Linux + windows: Windows + amd64: x86_64 + format_overrides: + - goos: windows + format: zip + builds: + - ethermintd-darwin + - ethermintd-darwin-arm64 + - ethermintd-windows + - ethermintd-linux + - ethermintd-linux-arm64 + +checksum: + name_template: 'checksums.txt' +changelog: + sort: asc + filters: + exclude: + - '^docs:' + - '^test:' +snapshot: + name_template: "{{ .Tag }}-next" diff --git a/Makefile b/Makefile index b1a58a2859..47d496012d 100755 --- a/Makefile +++ b/Makefile @@ -519,3 +519,36 @@ else endif .PHONY: build-docker-local-ethermint localnet-start localnet-stop + +# release +PACKAGE_NAME:=github.com/tharsis/ethermint +GOLANG_CROSS_VERSION = v1.16.4 +release-dry-run: + docker run \ + --rm \ + --privileged \ + -e CGO_ENABLED=1 \ + -v /var/run/docker.sock:/var/run/docker.sock \ + -v `pwd`:/go/src/$(PACKAGE_NAME) \ + -v ${GOPATH}/pkg:/go/pkg \ + -w /go/src/$(PACKAGE_NAME) \ + troian/golang-cross:${GOLANG_CROSS_VERSION} \ + --rm-dist --skip-validate --skip-publish + +release: + @if [ ! -f ".release-env" ]; then \ + echo "\033[91m.release-env is required for release\033[0m";\ + exit 1;\ + fi + docker run \ + --rm \ + --privileged \ + -e CGO_ENABLED=1 \ + --env-file .release-env \ + -v /var/run/docker.sock:/var/run/docker.sock \ + -v `pwd`:/go/src/$(PACKAGE_NAME) \ + -w /go/src/$(PACKAGE_NAME) \ + troian/golang-cross:${GOLANG_CROSS_VERSION} \ + release --rm-dist --skip-validate + +.PHONY: release-dry-run release diff --git a/go.mod b/go.mod index e421c3a132..e9d317e9f6 100644 --- a/go.mod +++ b/go.mod @@ -54,3 +54,6 @@ require ( replace google.golang.org/grpc => google.golang.org/grpc v1.33.2 replace github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 + +// FIXME: update after PR merged: https://github.com/bugsnag/panicwrap/pull/23 +replace github.com/bugsnag/panicwrap => github.com/yihuang/panicwrap v1.3.4-0.20210716032932-61c0a7c0cd05 diff --git a/go.sum b/go.sum index 0c9fe20604..543e0eb049 100644 --- a/go.sum +++ b/go.sum @@ -165,8 +165,6 @@ github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46f github.com/bugsnag/bugsnag-go v1.5.3/go.mod h1:2oa8nejYd4cQ/b0hMIopN0lCRxU0bueqREvZLWFrtK8= github.com/bugsnag/bugsnag-go v2.1.0+incompatible h1:SuqsBHDutts2rZh4swHEWTexxi0F/JZ/6j1rR9BFe7I= github.com/bugsnag/bugsnag-go v2.1.0+incompatible/go.mod h1:2oa8nejYd4cQ/b0hMIopN0lCRxU0bueqREvZLWFrtK8= -github.com/bugsnag/panicwrap v1.3.2 h1:pNcbtPtH4Y6VwK+oZVNV/2H6Hh3jOL0ZNVFZEfd/eA4= -github.com/bugsnag/panicwrap v1.3.2/go.mod h1:D/8v3kj0zr8ZAKg1AQ6crr+5VwKN5eIywRkfhyM/+dE= github.com/c-bata/go-prompt v0.2.2/go.mod h1:VzqtzE2ksDBcdln8G7mk2RX9QyGjH+OVqOCSiVIqS34= github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ= github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM= @@ -1014,6 +1012,8 @@ github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1: github.com/xtaci/kcp-go v5.4.20+incompatible/go.mod h1:bN6vIwHQbfHaHtFpEssmWsN45a+AZwO7eyRCmEIbtvE= github.com/xtaci/lossyconn v0.0.0-20190602105132-8df528c0c9ae/go.mod h1:gXtu8J62kEgmN++bm9BVICuT/e8yiLI2KFobd/TRFsE= github.com/ybbus/jsonrpc v2.1.2+incompatible/go.mod h1:XJrh1eMSzdIYFbM08flv0wp5G35eRniyeGut1z+LSiE= +github.com/yihuang/panicwrap v1.3.4-0.20210716032932-61c0a7c0cd05 h1:pAujDEt8f+lZIOOfVXpkoMemkOi0e6On1aaZWK4dxSM= +github.com/yihuang/panicwrap v1.3.4-0.20210716032932-61c0a7c0cd05/go.mod h1:AeUysGSIOPvhV1BZNplN56n5EEm3YfgYc/X3mhpjRiA= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= From 333a76bdf81cd00254ced0b970b7bbca081cdfd1 Mon Sep 17 00:00:00 2001 From: Jongwhan Lee <51560997+leejw51crypto@users.noreply.github.com> Date: Fri, 16 Jul 2021 18:40:33 +0900 Subject: [PATCH 3/5] build: refactor `init.sh` (#294) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> --- init.sh | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/init.sh b/init.sh index bf3d432810..ab72c201db 100755 --- a/init.sh +++ b/init.sh @@ -2,17 +2,20 @@ KEY="mykey" CHAINID="ethermint-2" MONIKER="localtestnet" +KEYRING="test" +KEYALGO="eth_secp256k1" +LOGLEVEL="info" # remove existing daemon and client rm -rf ~/.ethermintd* make install -ethermintd config keyring-backend test +ethermintd config keyring-backend $KEYRING ethermintd config chain-id $CHAINID # if $KEY exists it should be deleted -ethermintd keys add $KEY --keyring-backend test --algo "eth_secp256k1" +ethermintd keys add $KEY --keyring-backend $KEYRING --algo $KEYALGO # Set moniker and chain-id for Ethermint (Moniker can be anything, chain-id must be an integer) ethermintd init $MONIKER --chain-id $CHAINID @@ -58,10 +61,10 @@ if [[ $1 == "pending" ]]; then fi # Allocate genesis accounts (cosmos formatted addresses) -ethermintd add-genesis-account $KEY 100000000000000000000000000aphoton --keyring-backend test +ethermintd add-genesis-account $KEY 100000000000000000000000000aphoton --keyring-backend $KEYRING # Sign genesis transaction -ethermintd gentx $KEY 1000000000000000000000aphoton --keyring-backend test --chain-id $CHAINID +ethermintd gentx $KEY 1000000000000000000000aphoton --keyring-backend $KEYRING --chain-id $CHAINID # Collect genesis tx ethermintd collect-gentxs @@ -74,4 +77,4 @@ if [[ $1 == "pending" ]]; then fi # Start the node (remove the --pruning=nothing flag if historical queries are not needed) -ethermintd start --pruning=nothing --trace --log_level info --minimum-gas-prices=0.0001aphoton +ethermintd start --pruning=nothing --trace --log_level $LOGLEVEL --minimum-gas-prices=0.0001aphoton From 071ae3f618a10bbe5c4204692cbd2b770acbf0d2 Mon Sep 17 00:00:00 2001 From: Calvin Lau <38898718+calvinaco@users.noreply.github.com> Date: Fri, 16 Jul 2021 18:13:15 +0800 Subject: [PATCH 4/5] rpc: fix `eth_getBlockTransactionCountByNumber` crash on block not found (#254) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix GetBlockTransactionCountByNumber crashed on block not found * Fix getTransactionByBlock* * Update log based on review * Apply suggestions from code review * Update ethereum/rpc/namespaces/eth/api.go * Apply suggestions from code review Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> --- ethereum/rpc/namespaces/eth/api.go | 24 +++++++++- tests/rpc/rpc_test.go | 75 ++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+), 1 deletion(-) diff --git a/ethereum/rpc/namespaces/eth/api.go b/ethereum/rpc/namespaces/eth/api.go index 3b8d4334b3..9136661569 100644 --- a/ethereum/rpc/namespaces/eth/api.go +++ b/ethereum/rpc/namespaces/eth/api.go @@ -273,6 +273,12 @@ func (e *PublicAPI) GetBlockTransactionCountByHash(hash common.Hash) *hexutil.Ui resBlock, err := e.clientCtx.Client.BlockByHash(e.ctx, hash.Bytes()) if err != nil { + e.logger.Debug("block not found", "hash", hash.Hex(), "error", err.Error()) + return nil + } + + if resBlock.Block == nil { + e.logger.Debug("block not found", "hash", hash.Hex()) return nil } @@ -282,9 +288,15 @@ func (e *PublicAPI) GetBlockTransactionCountByHash(hash common.Hash) *hexutil.Ui // GetBlockTransactionCountByNumber returns the number of transactions in the block identified by number. func (e *PublicAPI) GetBlockTransactionCountByNumber(blockNum rpctypes.BlockNumber) *hexutil.Uint { - e.logger.Debug("eth_getBlockTransactionCountByNumber", "block number", blockNum) + e.logger.Debug("eth_getBlockTransactionCountByNumber", "height", blockNum.Int64()) resBlock, err := e.clientCtx.Client.Block(e.ctx, blockNum.TmHeight()) if err != nil { + e.logger.Debug("block not found", "height", blockNum.Int64(), "error", err.Error()) + return nil + } + + if resBlock.Block == nil { + e.logger.Debug("block not found", "height", blockNum.Int64()) return nil } @@ -668,6 +680,11 @@ func (e *PublicAPI) GetTransactionByBlockHashAndIndex(hash common.Hash, idx hexu return nil, nil } + if resBlock.Block == nil { + e.logger.Debug("block not found", "hash", hash.Hex()) + return nil, nil + } + i := int(idx) if i >= len(resBlock.Block.Txs) { e.logger.Debug("block txs index out of bound", "index", i) @@ -706,6 +723,11 @@ func (e *PublicAPI) GetTransactionByBlockNumberAndIndex(blockNum rpctypes.BlockN return nil, nil } + if resBlock.Block == nil { + e.logger.Debug("block not found", "height", blockNum.Int64()) + return nil, nil + } + i := int(idx) if i >= len(resBlock.Block.Txs) { e.logger.Debug("block txs index out of bound", "index", i) diff --git a/tests/rpc/rpc_test.go b/tests/rpc/rpc_test.go index c446679231..5f6a4b83df 100644 --- a/tests/rpc/rpc_test.go +++ b/tests/rpc/rpc_test.go @@ -214,6 +214,81 @@ func TestEth_GetTransactionCount(t *testing.T) { require.Equal(t, prev, post-1) } +func TestETH_GetBlockTransactionCountByHash(t *testing.T) { + txHash := sendTestTransaction(t) + + time.Sleep(time.Second * 5) + + param := []string{txHash.String()} + rpcRes := call(t, "eth_getTransactionReceipt", param) + require.Nil(t, rpcRes.Error) + + receipt := make(map[string]interface{}) + err := json.Unmarshal(rpcRes.Result, &receipt) + require.NoError(t, err) + require.NotEmpty(t, receipt) + + blockHash := receipt["blockHash"].(string) + + param = []string{blockHash} + rpcRes = call(t, "eth_getBlockTransactionCountByHash", param) + + var res hexutil.Uint + err = res.UnmarshalJSON(rpcRes.Result) + require.NoError(t, err) + require.Equal(t, "0x1", res.String()) +} + +func TestETH_GetBlockTransactionCountByHash_BlockHashNotFound(t *testing.T) { + anyBlockHash := "0xb3b20624f8f0f86eb50dd04688409e5cea4bd02d700bf6e79e9384d47d6a5a35" + param := []string{anyBlockHash} + rpcRes := call(t, "eth_getBlockTransactionCountByHash", param) + + var result interface{} + err := json.Unmarshal(rpcRes.Result, &result) + require.NoError(t, err) + require.Nil(t, result) +} + +func TestETH_GetTransactionByBlockHashAndIndex(t *testing.T) { + txHash := sendTestTransaction(t) + + time.Sleep(time.Second * 5) + + param := []string{txHash.String()} + rpcRes := call(t, "eth_getTransactionReceipt", param) + require.Nil(t, rpcRes.Error) + + receipt := make(map[string]interface{}) + err := json.Unmarshal(rpcRes.Result, &receipt) + require.NoError(t, err) + require.NotEmpty(t, receipt) + + blockHash := receipt["blockHash"].(string) + + param = []string{blockHash, "0x0"} + rpcRes = call(t, "eth_getTransactionByBlockHashAndIndex", param) + + tx := make(map[string]interface{}) + err = json.Unmarshal(rpcRes.Result, &tx) + require.NoError(t, err) + require.NotNil(t, tx) + require.Equal(t, blockHash, tx["blockHash"].(string)) + require.Equal(t, "0x0", tx["transactionIndex"].(string)) +} + +func TestETH_GetTransactionByBlockHashAndIndex_BlockHashNotFound(t *testing.T) { + anyBlockHash := "0xb3b20624f8f0f86eb50dd04688409e5cea4bd02d700bf6e79e9384d47d6a5a35" + + param := []string{anyBlockHash, "0x0"} + rpcRes := call(t, "eth_getTransactionByBlockHashAndIndex", param) + + var result interface{} + err := json.Unmarshal(rpcRes.Result, &result) + require.NoError(t, err) + require.Nil(t, result) +} + func TestEth_GetTransactionLogs(t *testing.T) { // TODO: this test passes on when run on its own, but fails when run with the other tests if testing.Short() { From 0a8f02e0676e1cab260c622fd96fd997d160ae32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Federico=20Kunze=20K=C3=BCllmer?= <31522760+fedekunze@users.noreply.github.com> Date: Fri, 16 Jul 2021 06:54:43 -0400 Subject: [PATCH 5/5] update README.md (#223) --- README.md | 28 +++------------------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index a1f4fc61bb..1262c4a534 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,9 @@ parent: Go report card + + +
@@ -49,31 +52,6 @@ To learn how the Ethermint works from a high-level perspective, go to the [Intro For more, please refer to the [Ethermint Docs](./docs/), which are also hosted on [docs.ethermint.zone](https://docs.ethermint.zone/). -## Tests - -Unit tests are invoked via: - -```bash -make test -``` - -To run JSON-RPC tests, execute: - -```bash -make test-rpc -``` - -There is also an included Ethereum mainnet exported blockchain file in `importer/blockchain` -that includes blocks up to height `97638`. To execute and test a full import of -these blocks using the EVM module, execute: - -```bash -make test-import -``` - -You may also provide a custom blockchain export file to test importing more blocks -via the `--blockchain` flag. See `TestImportBlocks` for further documentation. - ### Community The following chat channels and forums are a great spot to ask questions about Ethermint: