Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

evm keeper benchmark #577

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions x/evm/keeper/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,21 @@ func BenchmarkEmitLogs(b *testing.B) {
return types.NewTx(suite.app.EvmKeeper.ChainID(), nonce, &contract, big.NewInt(0), 4100000, big.NewInt(1), input, nil)
})
}

func BenchmarkTokenTransferForm(b *testing.B) {
JayT106 marked this conversation as resolved.
Show resolved Hide resolved
DoBenchmark(b, func(suite *KeeperTestSuite, contract common.Address) *types.MsgEthereumTx {
input, err := ContractABI.Pack("transferFrom", suite.address, common.HexToAddress("0x378c50D9264C63F3F92B806d4ee56E9D86FfB3Ec"), big.NewInt(0))
require.NoError(b, err)
nonce := suite.app.EvmKeeper.GetNonce(suite.address)
return types.NewTx(suite.app.EvmKeeper.ChainID(), nonce, &contract, big.NewInt(0), 410000, big.NewInt(1), input, nil)
})
}

func BenchmarkTokenMint(b *testing.B) {
DoBenchmark(b, func(suite *KeeperTestSuite, contract common.Address) *types.MsgEthereumTx {
input, err := ContractABI.Pack("mint", common.HexToAddress("0x378c50D9264C63F3F92B806d4ee56E9D86FfB3Ec"), big.NewInt(1000))
require.NoError(b, err)
nonce := suite.app.EvmKeeper.GetNonce(suite.address)
return types.NewTx(suite.app.EvmKeeper.ChainID(), nonce, &contract, big.NewInt(0), 410000, big.NewInt(1), input, nil)
})
}
62 changes: 62 additions & 0 deletions x/evm/keeper/state_transition_benchmark_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package keeper_test

import (
"math/big"
"testing"

"github.com/ethereum/go-ethereum/common"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/stretchr/testify/require"
evmtypes "github.com/tharsis/ethermint/x/evm/types"
)

func BenchmarkApplyTransaction(b *testing.B) {
suite := KeeperTestSuite{}
suite.DoSetupTest(b)

b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
b.StopTimer()
nonce := suite.app.EvmKeeper.GetNonce(suite.address)
msg := evmtypes.NewTx(suite.app.EvmKeeper.ChainID(), nonce, &common.Address{}, big.NewInt(100), 21000, big.NewInt(1), nil, nil)
JayT106 marked this conversation as resolved.
Show resolved Hide resolved
msg.From = suite.address.Hex()
err := msg.Sign(ethtypes.LatestSignerForChainID(suite.app.EvmKeeper.ChainID()), suite.signer)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can move the LatestSignerForChainID outside the for loop

require.NoError(b, err)

b.StartTimer()
_, err = suite.app.EvmKeeper.ApplyTransaction(msg.AsTransaction())
b.StopTimer()
require.NoError(b, err)
}
}

func BenchmarkApplyNativeMessage(b *testing.B) {
suite := KeeperTestSuite{}
suite.DoSetupTest(b)

params := suite.app.EvmKeeper.GetParams(suite.ctx)
ethCfg := params.ChainConfig.EthereumConfig(suite.app.EvmKeeper.ChainID())

b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
b.StopTimer()
nonce := suite.app.EvmKeeper.GetNonce(suite.address)
msg := evmtypes.NewTx(suite.app.EvmKeeper.ChainID(), nonce, &common.Address{}, big.NewInt(100), 21000, big.NewInt(1), nil, nil)
JayT106 marked this conversation as resolved.
Show resolved Hide resolved
msg.From = suite.address.Hex()
err := msg.Sign(ethtypes.LatestSignerForChainID(suite.app.EvmKeeper.ChainID()), suite.signer)
JayT106 marked this conversation as resolved.
Show resolved Hide resolved
require.NoError(b, err)

blockNum := big.NewInt(suite.ctx.BlockHeight())
signer := ethtypes.MakeSigner(ethCfg, blockNum)

m, err := msg.AsMessage(signer)
require.NoError(b, err)

b.StartTimer()
_, err = suite.app.EvmKeeper.ApplyNativeMessage(m)
b.StopTimer()
require.NoError(b, err)
}
}
54 changes: 54 additions & 0 deletions x/evm/keeper/statedb_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,57 @@ func BenchmarkSnapshot(b *testing.B) {
})
}
}

func BenchmarkSubBalance(b *testing.B) {
suite := KeeperTestSuite{}
suite.DoSetupTest(b)

amt := big.NewInt(10)

b.ResetTimer()
b.ReportAllocs()

for i := 0; i < b.N; i++ {
suite.app.EvmKeeper.SubBalance(suite.address, amt)
}
}

func BenchmarkSetNonce(b *testing.B) {
suite := KeeperTestSuite{}
suite.DoSetupTest(b)

b.ResetTimer()
b.ReportAllocs()

for i := 0; i < b.N; i++ {
suite.app.EvmKeeper.SetNonce(suite.address, 1)
}
}

func BenchmarkAddRefund(b *testing.B) {
suite := KeeperTestSuite{}
suite.DoSetupTest(b)

b.ResetTimer()
b.ReportAllocs()

for i := 0; i < b.N; i++ {
suite.app.EvmKeeper.AddRefund(1)
}
}

func BenchmarkSuicide(b *testing.B) {
suite := KeeperTestSuite{}
suite.DoSetupTest(b)

b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
b.StopTimer()
addr := tests.GenerateAddress()
suite.app.EvmKeeper.CreateAccount(addr)
b.StartTimer()

suite.app.EvmKeeper.Suicide(addr)
}
}