From cabdf67ed3ee31e5fe991aaf74a4094b3c9dc703 Mon Sep 17 00:00:00 2001 From: "Jieyi Long (THETA Network)" Date: Tue, 7 Nov 2023 10:56:41 -0800 Subject: [PATCH 1/4] Parser error handling --- go.sum | 1 + rpc/ethrpc/eth_get_transaction_by_hash.go | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/go.sum b/go.sum index 538d62f..209e242 100644 --- a/go.sum +++ b/go.sum @@ -1021,6 +1021,7 @@ golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220328115105-d36c6a25d886/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220412071739-889880a91fd5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220502124256-b6088ccd6cba/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k= diff --git a/rpc/ethrpc/eth_get_transaction_by_hash.go b/rpc/ethrpc/eth_get_transaction_by_hash.go index 5b31b26..c4a7b7b 100644 --- a/rpc/ethrpc/eth_get_transaction_by_hash.go +++ b/rpc/ethrpc/eth_get_transaction_by_hash.go @@ -34,7 +34,12 @@ func (e *EthRPCService) GetTransactionByHash(ctx context.Context, hashStr string logger.Warnf("eth_getTransactionByHash failed, err: %v", rpcErr) } - parse := func(jsonBytes []byte) (interface{}, error) { + parse := func(jsonBytes []byte) (interface{}, error err) { + err = fmt.Errorf("Failed to parse the transaction") + defer func() { + recover() // recover from parsing exception. + }() + trpcResult := trpc.GetTransactionResult{} json.Unmarshal(jsonBytes, &trpcResult) if (trpcResult.BlockHash == tcommon.Hash{}) { From 96b6c28305291c850fb7e1c4ef3cfe2f3727ae0c Mon Sep 17 00:00:00 2001 From: "Jieyi Long (THETA Network)" Date: Tue, 7 Nov 2023 12:11:20 -0800 Subject: [PATCH 2/4] Minor fixes --- rpc/ethrpc/eth_get_transaction_by_hash.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpc/ethrpc/eth_get_transaction_by_hash.go b/rpc/ethrpc/eth_get_transaction_by_hash.go index c4a7b7b..1dca2a5 100644 --- a/rpc/ethrpc/eth_get_transaction_by_hash.go +++ b/rpc/ethrpc/eth_get_transaction_by_hash.go @@ -34,7 +34,7 @@ func (e *EthRPCService) GetTransactionByHash(ctx context.Context, hashStr string logger.Warnf("eth_getTransactionByHash failed, err: %v", rpcErr) } - parse := func(jsonBytes []byte) (interface{}, error err) { + parse := func(jsonBytes []byte) (resultIntf interface{}, err error) { err = fmt.Errorf("Failed to parse the transaction") defer func() { recover() // recover from parsing exception. From f88c3c5d57bbe77d9fcdfc7b4a313b5f68de204e Mon Sep 17 00:00:00 2001 From: "Jieyi Long (THETA Network)" Date: Wed, 8 Nov 2023 13:50:56 -0800 Subject: [PATCH 3/4] Update go.mod --- go.mod | 9 +++++++++ go.sum | 3 --- integration/docker/build/Dockerfile | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index c1db1a8..12d698d 100644 --- a/go.mod +++ b/go.mod @@ -1,13 +1,21 @@ module github.com/thetatoken/theta-eth-rpc-adaptor require ( + cloud.google.com/go/datastore v1.1.0 // indirect + cloud.google.com/go/pubsub v1.3.1 // indirect + github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect github.com/dgraph-io/badger v1.6.1 // indirect github.com/ethereum/go-ethereum v1.9.23 + github.com/go-kit/kit v0.9.0 // indirect + github.com/golang/mock v1.6.0 // indirect + github.com/google/btree v1.0.0 // indirect + github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 // indirect github.com/gorilla/mux v1.8.0 // indirect github.com/gorilla/websocket v1.4.2 // indirect github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d // indirect github.com/mitchellh/go-homedir v1.1.0 github.com/pborman/uuid v1.2.0 // indirect + github.com/prometheus/tsdb v0.7.1 // indirect github.com/sirupsen/logrus v1.6.0 github.com/spf13/cobra v1.5.0 github.com/spf13/viper v1.13.0 @@ -16,6 +24,7 @@ require ( github.com/thetatoken/theta v0.0.0 github.com/thetatoken/theta/common v0.0.0 github.com/ybbus/jsonrpc v1.1.1 + golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6 // indirect ) replace github.com/thetatoken/theta v0.0.0 => ../theta diff --git a/go.sum b/go.sum index 209e242..12a0830 100644 --- a/go.sum +++ b/go.sum @@ -188,7 +188,6 @@ github.com/fatih/color v1.3.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5Kwzbycv github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= -github.com/fd/go-nat v1.0.0 h1:DPyQ97sxA9ThrWYRPcWUz/z9TnpTIGRYODIQc/dy64M= github.com/fd/go-nat v1.0.0/go.mod h1:BTBu/CKvMmOMUPkKVef1pngt2WFH/lg7E6yQnulfp6E= github.com/fjl/memsize v0.0.0-20180418122429-ca190fb6ffbc/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0= github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE= @@ -1026,8 +1025,6 @@ golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220502124256-b6088ccd6cba/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220829200755-d48e67d00261 h1:v6hYoSR9T5oet+pMXwUWkbiVqx/63mlHjefrHmxwfeY= -golang.org/x/sys v0.0.0-20220829200755-d48e67d00261/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= diff --git a/integration/docker/build/Dockerfile b/integration/docker/build/Dockerfile index f29e3b3..3073429 100644 --- a/integration/docker/build/Dockerfile +++ b/integration/docker/build/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.11 +FROM golang:1.18 VOLUME ["/go"] From 37d037b7b93f5cab2e1e365333d8d9a0d7913815 Mon Sep 17 00:00:00 2001 From: "Jieyi Long (THETA Network)" Date: Wed, 8 Nov 2023 14:09:36 -0800 Subject: [PATCH 4/4] Fixes for Linux cross-compilation on Apple Silicon --- integration/docker/build/Dockerfile | 9 +++++++-- integration/docker/build/start.sh | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/integration/docker/build/Dockerfile b/integration/docker/build/Dockerfile index 3073429..423ff75 100644 --- a/integration/docker/build/Dockerfile +++ b/integration/docker/build/Dockerfile @@ -1,3 +1,6 @@ +# Cross-compilation issue on Apple Silicon +# https://github.com/mattn/go-sqlite3/issues/992#issuecomment-1002559704 + FROM golang:1.18 VOLUME ["/go"] @@ -6,9 +9,11 @@ WORKDIR /go/src/github.com/thetatoken/theta-eth-rpc-adaptor/ ENV GOPATH=/go -ENV CGO_ENABLED=1 +RUN dpkg --add-architecture amd64 \ + && apt-get update \ + && apt-get install -y --no-install-recommends gcc-x86-64-linux-gnu g++-x86-64-linux-gnu libc6-dev-amd64-cross -ENV GO111MODULE=on +COPY . . CMD ["/go/src/github.com/thetatoken/theta-eth-rpc-adaptor/integration/docker/build/start.sh"] diff --git a/integration/docker/build/start.sh b/integration/docker/build/start.sh index bb1dd99..f4881ce 100755 --- a/integration/docker/build/start.sh +++ b/integration/docker/build/start.sh @@ -7,7 +7,7 @@ set -x GOBIN=/usr/local/go/bin/go -$GOBIN build -o ./build/linux/theta-eth-rpc-adaptor ./cmd/theta-eth-rpc-adaptor +CGO_ENABLED=1 GOARCH=amd64 CC=x86_64-linux-gnu-gcc CXX=g++-x86-64-linux-gnu $GOBIN build -o ./build/linux/theta-eth-rpc-adaptor ./cmd/theta-eth-rpc-adaptor set +x