Skip to content

Commit

Permalink
Problem: ethermint json-rpc fixes are not backported (#932)
Browse files Browse the repository at this point in the history
* Problem: tx delivery performance is not benchmarked (#916)

Solution:
- add the first benchmark for tx delivery

* Problem: go 1.20.2 is not used (#926)

* Problem: go 1.20.2 is not used

Solution:
- update nixpkgs to recent master
- re-enable coverage report for integration tests

* enlarge timeout

---------

Co-authored-by: mmsqe <mavis@crypto.com>

* Problem: eth tx sender recovery is slow (#928)

* Problem: eth tx sender recovery is slow

Solution:
- update ethermint dependency, do it once in ante handler and cache the result

* fix build

* update upstream

* fix lint

* fix versiondb

* fix memiavl

* fix upgrade integration test

---------

Co-authored-by: mmsqe <mavis@crypto.com>

* fix lint

* fix test

* point to rpc fix only

* no report coverage

---------

Co-authored-by: yihuang <huang@crypto.com>
  • Loading branch information
mmsqe and yihuang committed Mar 16, 2023
1 parent 9cc7127 commit efd570d
Show file tree
Hide file tree
Showing 8 changed files with 277 additions and 102 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Expand Up @@ -15,7 +15,7 @@ concurrency:
jobs:
integration_tests:
runs-on: ubuntu-latest
timeout-minutes: 180
timeout-minutes: 240
steps:
- uses: actions/checkout@v3
with:
Expand Down
154 changes: 154 additions & 0 deletions app/bench_test.go
@@ -0,0 +1,154 @@
package app

import (
"encoding/binary"
"encoding/json"
"math/big"
"testing"

sdkmath "cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/testutil/mock"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/crypto-org-chain/cronos/x/cronos/types"
"github.com/ethereum/go-ethereum/common"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/evmos/ethermint/crypto/ethsecp256k1"
"github.com/evmos/ethermint/tests"
evmtypes "github.com/evmos/ethermint/x/evm/types"
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
tmtypes "github.com/tendermint/tendermint/types"
dbm "github.com/tendermint/tm-db"
)

// BenchmarkERC20Transfer benchmarks execution of standard erc20 token transfer transactions
func BenchmarkERC20Transfer(b *testing.B) {
b.Run("memdb", func(b *testing.B) {
db := dbm.NewMemDB()
benchmarkERC20Transfer(b, db)
})
b.Run("leveldb", func(b *testing.B) {
db, err := dbm.NewGoLevelDB("application", b.TempDir())
require.NoError(b, err)
benchmarkERC20Transfer(b, db)
})
}

func benchmarkERC20Transfer(b *testing.B, db dbm.DB) {
txsPerBlock := 1000
gasPrice := big.NewInt(100000000000)

encodingConfig := MakeEncodingConfig()
app := New(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, encodingConfig, EmptyAppOptions{})

priv, err := ethsecp256k1.GenerateKey()
address := common.BytesToAddress(priv.PubKey().Address().Bytes())
signer := tests.NewSigner(priv)
chainID := big.NewInt(777)
ethSigner := ethtypes.LatestSignerForChainID(chainID)

signTx := func(msg *evmtypes.MsgEthereumTx) ([]byte, error) {
msg.From = address.String()
if err := msg.Sign(ethSigner, signer); err != nil {
return nil, err
}
require.NoError(b, err)
tx, err := msg.BuildTx(encodingConfig.TxConfig.NewTxBuilder(), evmtypes.DefaultEVMDenom)
if err != nil {
return nil, err
}
return encodingConfig.TxConfig.TxEncoder()(tx)
}

privVal := mock.NewPV()
pubKey, err := privVal.GetPubKey()
consAddress := sdk.ConsAddress(pubKey.Address())
require.NoError(b, err)
validator := tmtypes.NewValidator(pubKey, 1)
valSet := tmtypes.NewValidatorSet([]*tmtypes.Validator{validator})
acc := authtypes.NewBaseAccount(priv.PubKey().Address().Bytes(), priv.PubKey(), 0, 0)
balance := banktypes.Balance{
Address: acc.GetAddress().String(),
Coins: sdk.NewCoins(sdk.NewCoin(evmtypes.DefaultEVMDenom, sdkmath.NewIntWithDecimal(10000000, 18))),
}
genesisState := NewDefaultGenesisState(encodingConfig.Codec, true)
genesisState = genesisStateWithValSet(b, app, genesisState, valSet, []authtypes.GenesisAccount{acc}, balance)

appState, err := json.MarshalIndent(genesisState, "", " ")
require.NoError(b, err)
app.InitChain(abci.RequestInitChain{
ChainId: SimAppChainID,
AppStateBytes: appState,
ConsensusParams: DefaultConsensusParams,
})
app.BeginBlock(abci.RequestBeginBlock{
Header: tmproto.Header{
Height: 1,
ChainID: SimAppChainID,
ProposerAddress: consAddress,
},
})

// deploy contract
ctx := app.GetContextForDeliverTx(nil)
contractAddr, err := app.CronosKeeper.DeployModuleCRC21(ctx, "test")
require.NoError(b, err)

// mint to sender
amount := int64(100000000)
_, err = app.CronosKeeper.CallModuleCRC21(ctx, contractAddr, "mint_by_cronos_module", address, big.NewInt(amount))
require.NoError(b, err)

// check balance
ret, err := app.CronosKeeper.CallModuleCRC21(ctx, contractAddr, "balanceOf", address)
require.NoError(b, err)
require.Equal(b, uint64(amount), binary.BigEndian.Uint64(ret[32-8:]))

app.EndBlock(abci.RequestEndBlock{})
app.Commit()

// prepare transactions
var transferTxs [][]byte
for i := 0; i < b.N; i++ {
for j := 0; j < txsPerBlock; j++ {
idx := int64(i*txsPerBlock + j)
recipient := common.BigToAddress(big.NewInt(idx))
data, err := types.ModuleCRC21Contract.ABI.Pack("transfer", recipient, big.NewInt(1))
require.NoError(b, err)
bz, err := signTx(evmtypes.NewTx(chainID, uint64(idx), &contractAddr, big.NewInt(0), 210000, gasPrice, nil, nil, data, nil))
require.NoError(b, err)
transferTxs = append(transferTxs, bz)
}
}

b.ResetTimer()
for i := 0; i < b.N; i++ {
app.BeginBlock(abci.RequestBeginBlock{
Header: tmproto.Header{
Height: int64(i) + 2,
ChainID: SimAppChainID,
ProposerAddress: consAddress,
},
})
for j := 0; j < txsPerBlock; j++ {
idx := i*txsPerBlock + j
res := app.DeliverTx(abci.RequestDeliverTx{
Tx: transferTxs[idx],
})
require.Equal(b, 0, int(res.Code))
}

// check remaining balance
ctx := app.GetContextForDeliverTx(nil)
ret, err = app.CronosKeeper.CallModuleCRC21(ctx, contractAddr, "balanceOf", address)
require.NoError(b, err)
require.Equal(b, uint64(amount)-uint64((i+1)*txsPerBlock), binary.BigEndian.Uint64(ret[32-8:]))

app.EndBlock(abci.RequestEndBlock{})
app.Commit()
}
}
4 changes: 2 additions & 2 deletions app/test_helpers.go
Expand Up @@ -51,7 +51,7 @@ const (
var DefaultConsensusParams = &abci.ConsensusParams{
Block: &abci.BlockParams{
MaxBytes: 200000,
MaxGas: 2000000,
MaxGas: 200000000,
},
Evidence: &tmproto.EvidenceParams{
MaxAgeNumBlocks: 302400,
Expand Down Expand Up @@ -149,7 +149,7 @@ func SetupWithGenesisValSet(t *testing.T, cronosAdmin string, experimental bool,
return app
}

func genesisStateWithValSet(t *testing.T,
func genesisStateWithValSet(t require.TestingT,
app *App, genesisState GenesisState,
valSet *tmtypes.ValidatorSet, genAccs []authtypes.GenesisAccount,
balances ...banktypes.Balance,
Expand Down
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 22 additions & 22 deletions go.mod
Expand Up @@ -9,7 +9,7 @@ require (
github.com/cosmos/cosmos-sdk v0.46.11
github.com/cosmos/ibc-go/v5 v5.2.0
github.com/crypto-org-chain/cronos/versiondb v0.0.0
github.com/ethereum/go-ethereum v1.10.19
github.com/ethereum/go-ethereum v1.10.26
github.com/evmos/ethermint v0.6.1-0.20221101220534-a8ea4eceb6d9
github.com/gogo/protobuf v1.3.3
github.com/golang/protobuf v1.5.2
Expand All @@ -24,19 +24,19 @@ require (
github.com/stretchr/testify v1.8.2
github.com/tendermint/tendermint v0.34.27
github.com/tendermint/tm-db v0.6.7
golang.org/x/exp v0.0.0-20230118134722-a68e582fa157
google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f
golang.org/x/exp v0.0.0-20230206171751-46f607a40771
google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4
google.golang.org/grpc v1.53.0
google.golang.org/protobuf v1.28.2-0.20220831092852-f930b1dc76e8
gopkg.in/yaml.v2 v2.4.0
)

require (
cloud.google.com/go v0.107.0 // indirect
cloud.google.com/go/compute v1.15.1 // indirect
cloud.google.com/go v0.110.0 // indirect
cloud.google.com/go/compute v1.18.0 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v0.8.0 // indirect
cloud.google.com/go/storage v1.27.0 // indirect
cloud.google.com/go/iam v0.12.0 // indirect
cloud.google.com/go/storage v1.28.1 // indirect
filippo.io/edwards25519 v1.0.0-rc.1 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/99designs/keyring v1.2.1 // indirect
Expand All @@ -46,7 +46,7 @@ require (
github.com/Workiva/go-datastructures v1.0.53 // indirect
github.com/alitto/pond v1.8.2 // indirect
github.com/allegro/bigcache v1.2.1 // indirect
github.com/aws/aws-sdk-go v1.40.45 // indirect
github.com/aws/aws-sdk-go v1.44.122 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 // indirect
Expand All @@ -63,7 +63,7 @@ require (
github.com/cometbft/cometbft-db v0.7.0 // indirect
github.com/confio/ics23/go v0.9.0 // indirect
github.com/cosmos/btcutil v1.0.5 // indirect
github.com/cosmos/cosmos-proto v1.0.0-alpha8 // indirect
github.com/cosmos/cosmos-proto v1.0.0-beta.1 // indirect
github.com/cosmos/go-bip39 v1.0.0 // indirect
github.com/cosmos/iavl v0.19.5 // indirect
github.com/cosmos/ledger-cosmos-go v0.12.2 // indirect
Expand Down Expand Up @@ -99,7 +99,7 @@ require (
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/orderedcode v0.0.1 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect
github.com/googleapis/gax-go/v2 v2.7.0 // indirect
github.com/gorilla/handlers v1.5.1 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
Expand All @@ -109,7 +109,7 @@ require (
github.com/gtank/ristretto255 v0.1.2 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-getter v1.6.1 // indirect
github.com/hashicorp/go-getter v1.7.0 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-safetemp v1.0.0 // indirect
Expand All @@ -127,7 +127,7 @@ require (
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/jmhodges/levigo v1.0.0 // indirect
github.com/klauspost/compress v1.15.11 // indirect
github.com/ledgerwatch/erigon-lib v0.0.0-20230130172141-b594e6cdbf76 // indirect
github.com/ledgerwatch/erigon-lib v0.0.0-20230210071639-db0e7ed11263 // indirect
github.com/lib/pq v1.10.6 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/magiconair/properties v1.8.6 // indirect
Expand All @@ -139,7 +139,7 @@ require (
github.com/mimoo/StrobeGo v0.0.0-20210601165009-122bf33a46e0 // indirect
github.com/minio/highwayhash v1.0.2 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/go-testing-interface v1.0.0 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mtibben/percent v0.2.1 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
Expand Down Expand Up @@ -171,20 +171,20 @@ require (
github.com/tklauser/go-sysconf v0.3.10 // indirect
github.com/tklauser/numcpus v0.4.0 // indirect
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
github.com/ulikunitz/xz v0.5.8 // indirect
github.com/ulikunitz/xz v0.5.10 // indirect
github.com/zondax/hid v0.9.1 // indirect
github.com/zondax/ledger-go v0.14.1 // indirect
go.etcd.io/bbolt v1.3.7 // indirect
go.opencensus.io v0.24.0 // indirect
golang.org/x/crypto v0.5.0 // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/oauth2 v0.4.0 // indirect
golang.org/x/crypto v0.7.0 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/oauth2 v0.5.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/term v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/term v0.6.0 // indirect
golang.org/x/text v0.8.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/api v0.103.0 // indirect
google.golang.org/api v0.110.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
Expand All @@ -201,7 +201,7 @@ replace (
github.com/cosmos/cosmos-sdk => github.com/cosmos/cosmos-sdk v0.46.11
github.com/crypto-org-chain/cronos/versiondb => ./versiondb
github.com/ethereum/go-ethereum => github.com/crypto-org-chain/go-ethereum v1.10.19-deepcopy-jumptable
github.com/evmos/ethermint => github.com/crypto-org-chain/ethermint v0.20.8-cronos
github.com/evmos/ethermint => github.com/crypto-org-chain/ethermint v0.20.8-cronos.0.20230314071400-c5e93382c318
// Fix upstream GHSA-h395-qcrw-5vmq vulnerability.
// TODO Remove it: https://github.com/cosmos/cosmos-sdk/issues/10409
github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.7.0
Expand Down

0 comments on commit efd570d

Please sign in to comment.