Skip to content

Commit

Permalink
Update go-ethereum's version to v1.13.14 (#118)
Browse files Browse the repository at this point in the history
* Update go-ethereum's version to the latest

* Fix lint errors and upgrade Go version to fix test errors

* Rerun go mod tidy

* Update Go verion to 1.21 in ci.yml

* Fix lint errors by replacing deprecated function calls
  • Loading branch information
songge-cb authored Mar 8, 2024
1 parent e305703 commit 0949ece
Show file tree
Hide file tree
Showing 14 changed files with 587 additions and 505 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
pull_request:

env:
go_version: 1.17
go_version: 1.21
GO111MODULE: on
COVERALLS_TOKEN: ${{ secrets.COVERALLS_TOKEN }}

Expand Down
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.PHONY: deps test mocks lint format check-license add-license \
shorten-lines salus check-format

GO_PACKAGES=./services/... ./client/... ./configuration/... ./utils/... ./examples/...
GO_PACKAGES=./services/... ./client/... ./configuration/... ./utils/... ./examples/... ./contracts/... ./types/...
TEST_SCRIPT=go test ${GO_PACKAGES}
LINT_CONFIG=.golangci.yml
GOIMPORTS_INSTALL=go install golang.org/x/tools/cmd/goimports@latest
Expand All @@ -17,6 +17,9 @@ GOLINES_CMD=golines
deps:
go get ./...

build:
go build ${GO_PACKAGES}

test:
${TEST_SCRIPT}

Expand Down Expand Up @@ -53,4 +56,4 @@ salus:
check-format:
! gofmt -s -l . | read;
${GOIMPORTS_INSTALL}
! ${GOIMPORTS_CMD} -l . | read;
! ${GOIMPORTS_CMD} -l . | read;
43 changes: 24 additions & 19 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"fmt"
"log"
"math/big"
"strconv"

"github.com/coinbase/rosetta-geth-sdk/configuration"
sdkTypes "github.com/coinbase/rosetta-geth-sdk/types"
Expand All @@ -30,15 +29,17 @@ import (

RosettaTypes "github.com/coinbase/rosetta-sdk-go/types"

"github.com/ethereum/go-ethereum"
goEthereum "github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/consensus/ethash"
"github.com/ethereum/go-ethereum/core"
EthTypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/eth/tracers"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rpc"
"github.com/holiman/uint256"
"golang.org/x/sync/semaphore"
)

Expand Down Expand Up @@ -294,7 +295,7 @@ func (ec *SDKClient) blockHeader(
}

if err == nil && header == nil {
return nil, ethereum.NotFound
return nil, goEthereum.NotFound
}
return header, err
}
Expand Down Expand Up @@ -573,18 +574,20 @@ func FlattenTraces(data *Call, flattened []*FlatCall) []*FlatCall {
// https://github.com/ethereum/go-ethereum/blob/master/consensus/ethash/consensus.go#L646-L653
func (ec *SDKClient) miningReward(
currentBlock *big.Int,
) int64 {
) *uint256.Int {
if currentBlock.Int64() == int64(0) {
return big.NewInt(0).Int64()
return uint256.NewInt(0)
}

blockReward := ethash.FrontierBlockReward.Int64()
blockReward := ethash.FrontierBlockReward

if ec.P.IsByzantium(currentBlock) {
blockReward = ethash.ByzantiumBlockReward.Int64()
blockReward = ethash.ByzantiumBlockReward
}
if ec.P.IsConstantinople(currentBlock) {
blockReward = ethash.ConstantinopleBlockReward.Int64()
blockReward = ethash.ConstantinopleBlockReward
}

return blockReward
}

Expand All @@ -607,12 +610,12 @@ func (ec *SDKClient) BlockRewardTransaction(
if len(uncles) > 0 {
reward := new(big.Float)
uncleReward := float64(numUncles) / sdkTypes.UnclesRewardMultiplier
rewardFloat := reward.Mul(big.NewFloat(uncleReward), big.NewFloat(float64(miningReward)))
rewardInt, _ := rewardFloat.Int64()
minerReward += rewardInt
rewardFloat := reward.Mul(big.NewFloat(uncleReward), big.NewFloat(miningReward.Float64()))
rewardInt := new(big.Int)
rewardFloat.Int(rewardInt)
minerReward.Add(minerReward, uint256.MustFromBig(rewardInt))
}

const base = 10
miningRewardOp := &RosettaTypes.Operation{
OperationIdentifier: &RosettaTypes.OperationIdentifier{
Index: 0,
Expand All @@ -623,7 +626,7 @@ func (ec *SDKClient) BlockRewardTransaction(
Address: MustChecksum(miner),
},
Amount: &RosettaTypes.Amount{
Value: strconv.FormatInt(minerReward, base),
Value: minerReward.Dec(),
Currency: ec.rosettaConfig.Currency,
},
}
Expand All @@ -633,11 +636,13 @@ func (ec *SDKClient) BlockRewardTransaction(
for _, b := range uncles {
uncleMiner := b.Coinbase.String()
uncleBlock := b.Number.Int64()
miningRewardPerUncle := minerReward.Clone()
miningRewardPerUncle.Div(miningRewardPerUncle, uint256.NewInt(sdkTypes.MaxUncleDepth))
uncleRewardBlock := new(
big.Int,
).Mul(
big.NewInt(uncleBlock+sdkTypes.MaxUncleDepth-blockIdentifier.Index),
big.NewInt(miningReward/sdkTypes.MaxUncleDepth),
miningRewardPerUncle.ToBig(),
)

uncleRewardOp := &RosettaTypes.Operation{
Expand Down Expand Up @@ -798,7 +803,7 @@ func (ec *SDKClient) GetBaseFee(ctx context.Context) (*big.Int, error) {
return nil, err
}
if head == nil {
return nil, ethereum.NotFound
return nil, goEthereum.NotFound
}
return head.BaseFee.ToInt(), nil
}
Expand All @@ -819,7 +824,7 @@ func (ec *SDKClient) GetErc20TransferGasLimit(
// the To address in EstimateGas is the contract address
contractAddress := common.HexToAddress(contract.(string))
data := GenerateErc20TransferData(toAddress, value)
gasLimit, err := ec.EstimateGas(ctx, ethereum.CallMsg{
gasLimit, err := ec.EstimateGas(ctx, goEthereum.CallMsg{
From: common.HexToAddress(fromAddress),
To: &contractAddress,
Data: data,
Expand All @@ -838,7 +843,7 @@ func (ec *SDKClient) GetContractCallGasLimit(
) (uint64, error) {
// ToAddress for contract address is the contract address
contractAddress := common.HexToAddress(toAddress)
gasLimit, err := ec.EstimateGas(ctx, ethereum.CallMsg{
gasLimit, err := ec.EstimateGas(ctx, goEthereum.CallMsg{
From: common.HexToAddress(fromAddress),
To: &contractAddress,
Data: data,
Expand Down Expand Up @@ -901,12 +906,12 @@ func (ec *SDKClient) GetLoadedTransaction(
}

signer := EthTypes.LatestSignerForChainID(ec.P.ChainID)
msg, err := tx.AsMessage(signer, header.BaseFee)
msg, err := core.TransactionToMessage(tx, signer, header.BaseFee)
if err != nil {
return nil, err
}
blockNumber := header.Number.String()
from := msg.From()
from := msg.From
txHash := tx.Hash()

txInfo := TxExtraInfo{
Expand Down
14 changes: 7 additions & 7 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"strconv"
"testing"

Expand Down Expand Up @@ -54,7 +54,7 @@ func TestOpenEthTraceAPI_EmptyTrace(t *testing.T) {
func(args mock.Arguments) {
r := args.Get(1).(*json.RawMessage)

file, err := ioutil.ReadFile(
file, err := os.ReadFile(
"testdata/trace_block_empty.json",
)
assert.NoError(t, err)
Expand Down Expand Up @@ -95,7 +95,7 @@ func TestTraceBlockByHash(t *testing.T) {
func(args mock.Arguments) {
r := args.Get(1).(*json.RawMessage)

file, err := ioutil.ReadFile(
file, err := os.ReadFile(
"testdata/block_trace_0xd88e8376ec3eef899d9fbc6349e8330ebfc102b245fef784a999ac854091cb64.json",
)
assert.NoError(t, err)
Expand Down Expand Up @@ -154,7 +154,7 @@ func TestOpenEthTraceAPI_1Txn(t *testing.T) {
func(args mock.Arguments) {
r := args.Get(1).(*json.RawMessage)

file, err := ioutil.ReadFile(
file, err := os.ReadFile(
"testdata/trace_block_1_tx.json",
)
assert.NoError(t, err)
Expand Down Expand Up @@ -206,7 +206,7 @@ func TestOpenEthTraceAPI_MultiTxns(t *testing.T) {
func(args mock.Arguments) {
r := args.Get(1).(*json.RawMessage)

file, err := ioutil.ReadFile(
file, err := os.ReadFile(
"testdata/trace_block_many_traces.json",
)
assert.NoError(t, err)
Expand Down Expand Up @@ -257,7 +257,7 @@ func TestBalance(t *testing.T) {
func(args mock.Arguments) {
r := args.Get(1).(**types.Header)

file, err := ioutil.ReadFile("testdata/block_10992.json")
file, err := os.ReadFile("testdata/block_10992.json")
assert.NoError(t, err)
err = json.Unmarshal(file, &r)
assert.NoError(t, err)
Expand Down Expand Up @@ -308,7 +308,7 @@ func TestBalance(t *testing.T) {
func(args mock.Arguments) {
r := args.Get(1).(*string)
var expected map[string]interface{}
file, err := ioutil.ReadFile("testdata/call_balance_token_10992.json")
file, err := os.ReadFile("testdata/call_balance_token_10992.json")
assert.NoError(t, err)

err = json.Unmarshal(file, &expected)
Expand Down
8 changes: 7 additions & 1 deletion client/rpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,16 @@ func NewRPCClient(endpoint string) (*RPCClient, error) {
defaultTransport.MaxIdleConns = DefaultMaxConnections
defaultTransport.MaxIdleConnsPerHost = DefaultMaxConnections

client, err := rpc.DialHTTPWithClient(endpoint, &http.Client{
clientOptions := rpc.WithHTTPClient(&http.Client{
Timeout: gethHTTPTimeout,
Transport: defaultTransport,
})
ctx := context.Background()
client, err := rpc.DialOptions(ctx, endpoint, clientOptions)
/*client, err := rpc.DialHTTPWithClient(endpoint, &http.Client{
Timeout: gethHTTPTimeout,
Transport: defaultTransport,
})*/
if err != nil {
return nil, fmt.Errorf("unable to dial node: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions client/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ package client
import (
"encoding/json"
"fmt"
"io/ioutil"
"math/big"
"os"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
Expand Down Expand Up @@ -47,7 +47,7 @@ func GetTraceConfig(useNative bool) (*tracers.TraceConfig, error) {
}

func loadTraceConfig() (*tracers.TraceConfig, error) {
loadedFile, err := ioutil.ReadFile(tracerPath)
loadedFile, err := os.ReadFile(tracerPath)
if err != nil {
return nil, fmt.Errorf("could not load tracer file: %w", err)
}
Expand Down
Loading

0 comments on commit 0949ece

Please sign in to comment.