Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Hybrid StateDB for precompile support #47

Closed
wants to merge 100 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
d86f20c
refactor(evm): Move StateDB types, use StateDB interface in keeper
drklee3 Jan 8, 2024
a8af130
Update statedb usage in app
drklee3 Jan 8, 2024
e308b80
fix: Resolve importer test Statedb types
drklee3 Feb 8, 2024
13380af
Resolve multi import
drklee3 Feb 8, 2024
b72084e
Remove unused allow-leading-space nolintlint option
drklee3 Feb 8, 2024
e43f080
ci: Run workflows on kava/release/** branches
drklee3 Feb 8, 2024
f198860
Add basic benchmark
drklee3 Jan 12, 2024
0cdc7e3
Add ctx snapshots and state commits
drklee3 Jan 12, 2024
d3b2dee
Create access list with sdk store
drklee3 Jan 12, 2024
ed99657
Add prototype store for logs and refund
drklee3 Jan 12, 2024
b8343f9
Reuse journal for logs and refund, update account methods
drklee3 Jan 13, 2024
6d1a398
refactor: Move snapshottable ctx to separate struct
drklee3 Jan 18, 2024
9905d05
Store suicided state in store, use transient store
drklee3 Jan 18, 2024
9eb2dbd
Fix reflect test error
drklee3 Jan 18, 2024
d307e30
Update StateDBTestSuite.TestBalance to use real keeper
drklee3 Jan 19, 2024
3203321
Fix tests with real keeper
drklee3 Jan 19, 2024
9ab0793
Update all tests to work
drklee3 Jan 19, 2024
757dcfa
no-op when AddBalance with negative amounts
drklee3 Jan 19, 2024
2cd187b
Remove unused journal types
drklee3 Jan 19, 2024
7b38d90
fix: Include journal index in snapshot
drklee3 Jan 22, 2024
09e83b4
Start actual snapshots at id 0
drklee3 Jan 22, 2024
6a080c9
Handle keeper errors, fix lints, remove use of MockKeeper
drklee3 Jan 22, 2024
a663cce
Fix statedb benchmarks
drklee3 Jan 22, 2024
9ee1710
Delete mock keeper
drklee3 Jan 22, 2024
5e7efa3
Keep logs in slice instead of sdk store
drklee3 Jan 25, 2024
28264f0
feat: Return error on Commit() instead of panic on individual methods
drklee3 Jan 29, 2024
ffa7ead
Update db error test
drklee3 Jan 29, 2024
74be945
Preserve initial sdk error instead of replacing
drklee3 Jan 29, 2024
af601e0
Remove use of transient store, use in memory slices instead
drklee3 Jan 29, 2024
7b86df3
Remove GetTransientKey()
drklee3 Jan 29, 2024
4e1d905
reorganize statedb fields
drklee3 Jan 29, 2024
31abe8d
Move logs to ephemeral store, add tests
drklee3 Jan 30, 2024
d6fc799
Remove GetLogsCount method
drklee3 Jan 30, 2024
fb02fbf
Increase BenchmarkNestedSnapshot iterations, time Commit() instead of…
drklee3 Feb 6, 2024
32c1c52
Update benchmarks to use subbenchmarks instead of parent calls
drklee3 Feb 6, 2024
39fd812
fix GetRevertKey test to use actual test cases
drklee3 Feb 8, 2024
cd9012c
refactor: Use testutil test Suite for keeper tests
drklee3 Feb 8, 2024
546476f
rename testutil suite
drklee3 Feb 8, 2024
50dfcb5
resolve lint errors
drklee3 Feb 8, 2024
1949b92
Manually revert statedb type migration changes
drklee3 Feb 9, 2024
2159176
Temporary Revert "update to latest cometbft and cosmos-sdk forks w/ i…
drklee3 Feb 9, 2024
f4f3311
Add temp test for logging tracing state
drklee3 Feb 13, 2024
38f5b3f
temp: Prevent trace in snapshots, deploy test contract & log commit hash
drklee3 Feb 13, 2024
517f356
Make tests deterministic for consistent output hash, use fixed val keys
drklee3 Feb 13, 2024
048500d
Add hash check
drklee3 Feb 13, 2024
e0f741c
Create reverted tx
drklee3 Feb 14, 2024
4a1938f
Skip noop state changes on SetState
drklee3 Feb 21, 2024
829a121
Also skip dirty noop state changes on SetState
drklee3 Feb 21, 2024
6f47ac9
fix: Delete state on empty common.Hash{}
drklee3 Feb 22, 2024
49442ff
test: Add case for non-empty noop state change
drklee3 Feb 22, 2024
3ee8238
test: Update apphash test for suspected issue
drklee3 Mar 4, 2024
c1ac022
temp disable account clearning
drklee3 Mar 5, 2024
f3ff456
add journal based statedb for comparison testing
drklee3 Mar 6, 2024
b556f10
test: Add test for comparing statedb output iavl hashes
drklee3 Mar 6, 2024
4c20773
Remove tracing
drklee3 Mar 6, 2024
8f3eb66
feat: Add test for noop SetState unmodified iavl hash
drklee3 Mar 8, 2024
096320e
test: Skip noop state change
drklee3 Mar 8, 2024
15910b0
fix: Re-add SetAccount on SetState
drklee3 Mar 9, 2024
2d2a38e
test: Add additional test cases for noop SetState changes
drklee3 Mar 11, 2024
57853c2
test: Add account number tests, extend hash test
drklee3 Mar 12, 2024
8c5b485
feat: Skip no-op contract state changes
drklee3 Mar 12, 2024
ea916aa
fix: Avoid skip on 0 value SubBalance
drklee3 Mar 12, 2024
68ebc1a
test: Add account number legacy statedb tests for test correctness
drklee3 Mar 12, 2024
57acd0a
test: Enable reverse/random addr tests
drklee3 Mar 12, 2024
1618b47
test: Skip account number cachectx tests
drklee3 Mar 12, 2024
ea3d440
refactor: Rename legacy statedb package
drklee3 Mar 13, 2024
a33384f
remove key logging
drklee3 Mar 13, 2024
1a1491d
style: Fix lint issues
drklee3 Feb 28, 2024
8d995d3
test: Run unmodified IAVL tree test on legacy statedb
drklee3 Mar 13, 2024
9ed0fd3
feat: Prototype to align account numbers behavior with legacy statedb
drklee3 Mar 13, 2024
ccf72b2
feat: Update ReassignAccountNumbers docs
drklee3 Mar 13, 2024
a35847e
feat: Add initial hybrid design
drklee3 Mar 14, 2024
d2482be
feat: Store balances only in bank, remove from state object
drklee3 Mar 15, 2024
fd2e4d5
refactor: Move ctx statedb to separate package, rename hybridstatedb …
drklee3 Mar 16, 2024
724be12
refactor: Disable ctx statedb
drklee3 Mar 18, 2024
fdcbec9
feat: Add legacy keeper methods and update tests
drklee3 Mar 18, 2024
8a46133
feat: Set and return sdk error if ocurrs
drklee3 Mar 18, 2024
d200cc1
fix: Mark balance changes as dirty, ensure account is set if only bal…
drklee3 Mar 19, 2024
a840701
feat: Include ctx snapshots and rollbacks
drklee3 Mar 20, 2024
ec883d0
Revert "fix: Delete state on empty common.Hash{}"
drklee3 Mar 20, 2024
0fe3d3b
fix: Only reassign account numbers for those created
drklee3 Mar 22, 2024
42d2634
fix: Skip bank balance no-op and IAVL version changes with denom mapping
drklee3 Apr 4, 2024
0a43c6b
wip: ctx balance bug
drklee3 Apr 9, 2024
6a5e5ee
deps: Revert go.mod go.sum to main
drklee3 Apr 15, 2024
7ca959b
fix: Remove unset store methods
drklee3 Apr 15, 2024
3d79e1c
Revert "wip: ctx balance bug"
drklee3 Apr 15, 2024
95b2dd2
test: Update DBError balance error text
drklee3 Apr 15, 2024
e10527a
Resolve lint errors
drklee3 Apr 15, 2024
3bf0202
Resolve .golangci.yml config lint errors
drklee3 Apr 15, 2024
23e65f8
Remove account number reassignment
drklee3 Apr 15, 2024
de1cd8d
fix: Use versioned go-bindata install
drklee3 Apr 15, 2024
c96a449
test: Skip tests for state compatibility
drklee3 Apr 16, 2024
fb3a2e5
fix: Delete state on empty common.Hash{}
drklee3 Feb 22, 2024
bc3352c
Remove unused UnsetState
drklee3 Apr 16, 2024
c4fd460
test: Add SetState delete test
drklee3 Apr 16, 2024
6539ed2
chore: Delete ctxstatedb
drklee3 Apr 16, 2024
0933480
chore: Remove unused evmkeeper.New params
drklee3 Apr 16, 2024
72de35e
chore: Remove legacystatedb
drklee3 Apr 17, 2024
1684639
chore: Remove account number statedb methods
drklee3 Apr 18, 2024
5030d2e
fix: Remove GetAccountNumber from Keeper interface
drklee3 Apr 18, 2024
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
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on:
pull_request:
branches:
- main
- kava/release/**

jobs:
cleanup-runs:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ jobs:
triage:
runs-on: ubuntu-latest
steps:
- uses: actions/labeler@v4
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
- uses: actions/labeler@v4
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
3 changes: 2 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
push:
branches:
- main
- kava/release/**
jobs:
golangci:
name: Run golangci-lint
Expand All @@ -25,7 +26,7 @@ jobs:
**/**.go
go.mod
go.sum
- uses: golangci/golangci-lint-action@v3.3.1
- uses: golangci/golangci-lint-action@v3.7.0
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: latest
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- main
- kava/release/**

jobs:
Gosec:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches:
- main
- release/**
- kava/release/**

jobs:
cleanup-runs:
Expand Down
15 changes: 7 additions & 8 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,16 @@ linters-settings:
locale: US
nolintlint:
allow-unused: false
allow-leading-space: true
require-explanation: false
require-specific: false
gofumpt:
lang-version: "1.19"
gomodguard:
blocked:
versions: # List of blocked module version constraints
- https://github.com/etcd-io/etcd: # Blocked module with version constraint
version: ">= 3.4.10 || ~3.3.23" # Version constraint, see https://github.com/Masterminds/semver#basic-comparisons
reason: "CVE-2020-15114; CVE-2020-15136; CVE-2020-15115" # Reason why the version constraint exists. (Optional)
- https://github.com/dgrijalva/jwt-go: # Blocked module with version constraint
version: ">= 4.0.0-preview1" # Version constraint, see https://github.com/Masterminds/semver#basic-comparisons
reason: "CVE-2020-26160" # Reason why the version constraint exists. (Optional)
versions: # List of blocked module version constraints
- https://github.com/etcd-io/etcd: # Blocked module with version constraint
version: ">= 3.4.10 || ~3.3.23" # Version constraint, see https://github.com/Masterminds/semver#basic-comparisons
reason: "CVE-2020-15114; CVE-2020-15136; CVE-2020-15115" # Reason why the version constraint exists. (Optional)
- https://github.com/dgrijalva/jwt-go: # Blocked module with version constraint
version: ">= 4.0.0-preview1" # Version constraint, see https://github.com/Masterminds/semver#basic-comparisons
reason: "CVE-2020-26160" # Reason why the version constraint exists. (Optional)
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ endif

ifeq (, $(shell which go-bindata))
@echo "Installing go-bindata..."
@go get github.com/kevinburke/go-bindata/v4/go-bindata
@go get github.com/kevinburke/go-bindata/v4
else
@echo "go-bindata already installed; skipping..."
endif
Expand Down
5 changes: 3 additions & 2 deletions app/ante/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,14 @@ func (avd EthAccountVerificationDecorator) AnteHandle(
if acct == nil {
acc := avd.ak.NewAccountWithAddress(ctx, from)
avd.ak.SetAccount(ctx, acc)
acct = statedb.NewEmptyAccount()
} else if acct.IsContract() {
return ctx, errorsmod.Wrapf(errortypes.ErrInvalidType,
"the sender is not EOA: address %s, codeHash <%s>", fromAddr, acct.CodeHash)
}

if err := keeper.CheckSenderBalance(sdkmath.NewIntFromBigInt(acct.Balance), txData); err != nil {
bal := avd.evmKeeper.GetBalance(ctx, fromAddr)

if err := keeper.CheckSenderBalance(sdkmath.NewIntFromBigInt(bal), txData); err != nil {
return ctx, errorsmod.Wrap(err, "failed to check sender balance")
}
}
Expand Down
3 changes: 2 additions & 1 deletion app/ante/sigs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ func (suite AnteTestSuite) TestSignatures() {

acc := statedb.NewEmptyAccount()
acc.Nonce = 1
acc.Balance = big.NewInt(10000000000)

suite.app.EvmKeeper.SetAccount(suite.ctx, addr, *acc)
suite.app.EvmKeeper.SetBalance(suite.ctx, addr, big.NewInt(10000000000))

msgEthereumTx := evmtypes.NewTx(suite.app.EvmKeeper.ChainID(), 1, &to, big.NewInt(10), 100000, big.NewInt(1), nil, nil, nil, nil)
msgEthereumTx.From = addr.Hex()

Expand Down
10 changes: 9 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,8 @@ func NewEthermintApp(
// Set authority to x/gov module account to only expect the module account to update params
evmSs := app.GetSubspace(evmtypes.ModuleName)
app.EvmKeeper = evmkeeper.NewKeeper(
appCodec, keys[evmtypes.StoreKey], tkeys[evmtypes.TransientKey],
appCodec,
keys[evmtypes.StoreKey], tkeys[evmtypes.TransientKey],
authtypes.NewModuleAddress(govtypes.ModuleName),
app.AccountKeeper, app.BankKeeper, stakingKeeper, app.FeeMarketKeeper,
vm.NewEVM, tracer, evmSs,
Expand Down Expand Up @@ -766,6 +767,13 @@ func (app *EthermintApp) InterfaceRegistry() types.InterfaceRegistry {
return app.interfaceRegistry
}

// GetKeys returns all KVStoreKeys
//
// NOTE: This is solely to be used for testing purposes.
func (app *EthermintApp) GetKeys() map[string]*storetypes.KVStoreKey {
return app.keys
}

// GetKey returns the KVStoreKey for the provided store key.
//
// NOTE: This is solely to be used for testing purposes.
Expand Down
10 changes: 8 additions & 2 deletions app/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
"github.com/cosmos/cosmos-sdk/testutil/mock"
simutils "github.com/cosmos/cosmos-sdk/testutil/sims"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/ethereum/go-ethereum/common"

dbm "github.com/cometbft/cometbft-db"
abci "github.com/cometbft/cometbft/abci/types"
Expand Down Expand Up @@ -105,7 +107,9 @@ func SetupWithDB(isCheckTx bool, patchGenesis func(*EthermintApp, simapp.Genesis

// NewTestGenesisState generate genesis state with single validator
func NewTestGenesisState(codec codec.Codec) simapp.GenesisState {
privVal := mock.NewPV()
key := ed25519.GenPrivKeyFromSecret([]byte("constant seed"))
privVal := mock.PV{PrivKey: key}

pubKey, err := privVal.GetPubKey()
if err != nil {
panic(err)
Expand All @@ -115,7 +119,9 @@ func NewTestGenesisState(codec codec.Codec) simapp.GenesisState {
valSet := tmtypes.NewValidatorSet([]*tmtypes.Validator{validator})

// generate genesis account
senderPrivKey := secp256k1.GenPrivKey()
senderPrivKey := secp256k1.PrivKey{
Key: common.Hex2Bytes("6b65793a225c745c3337355c33363627365c333735476c5c3331375f5c323530305c3031375c303237375c3337365c3234315c3336355c323136247d475c3237316a3c5c3336365f785c3337353b5c3336305c3031362220"), //nolint:lll
}
acc := authtypes.NewBaseAccount(senderPrivKey.PubKey().Address().Bytes(), senderPrivKey.PubKey(), 0, 0)
balance := banktypes.Balance{
Address: acc.GetAddress().String(),
Expand Down
2 changes: 1 addition & 1 deletion x/evm/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func InitGenesis(
k.SetCode(ctx, codeHash.Bytes(), code)

for _, storage := range account.Storage {
k.SetState(ctx, address, common.HexToHash(storage.Key), common.HexToHash(storage.Value).Bytes())
k.SetState(ctx, address, common.HexToHash(storage.Key), common.HexToHash(storage.Value))
}
}

Expand Down
4 changes: 2 additions & 2 deletions x/evm/keeper/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
)

func (suite *KeeperTestSuite) TestEndBlock() {
em := suite.ctx.EventManager()
em := suite.Ctx.EventManager()
suite.Require().Equal(0, len(em.Events()))

res := suite.app.EvmKeeper.EndBlock(suite.ctx, types.RequestEndBlock{})
res := suite.App.EvmKeeper.EndBlock(suite.Ctx, types.RequestEndBlock{})
suite.Require().Equal([]types.ValidatorUpdate{}, res)

// should emit 1 EventTypeBlockBloom event on EndBlock
Expand Down
52 changes: 26 additions & 26 deletions x/evm/keeper/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ func SetupContract(b *testing.B) (*KeeperTestSuite, common.Address) {
suite.SetupTestWithT(b)

amt := sdk.Coins{ethermint.NewPhotonCoinInt64(1000000000000000000)}
err := suite.app.BankKeeper.MintCoins(suite.ctx, types.ModuleName, amt)
err := suite.App.BankKeeper.MintCoins(suite.Ctx, types.ModuleName, amt)
require.NoError(b, err)
err = suite.app.BankKeeper.SendCoinsFromModuleToAccount(suite.ctx, types.ModuleName, suite.address.Bytes(), amt)
err = suite.App.BankKeeper.SendCoinsFromModuleToAccount(suite.Ctx, types.ModuleName, suite.Address.Bytes(), amt)
require.NoError(b, err)

contractAddr := suite.DeployTestContract(b, suite.address, sdkmath.NewIntWithDecimal(1000, 18).BigInt())
contractAddr := suite.DeployTestContract(b, suite.Address, sdkmath.NewIntWithDecimal(1000, 18).BigInt())
suite.Commit()

return &suite, contractAddr
Expand All @@ -37,9 +37,9 @@ func SetupTestMessageCall(b *testing.B) (*KeeperTestSuite, common.Address) {
suite.SetupTestWithT(b)

amt := sdk.Coins{ethermint.NewPhotonCoinInt64(1000000000000000000)}
err := suite.app.BankKeeper.MintCoins(suite.ctx, types.ModuleName, amt)
err := suite.App.BankKeeper.MintCoins(suite.Ctx, types.ModuleName, amt)
require.NoError(b, err)
err = suite.app.BankKeeper.SendCoinsFromModuleToAccount(suite.ctx, types.ModuleName, suite.address.Bytes(), amt)
err = suite.App.BankKeeper.SendCoinsFromModuleToAccount(suite.Ctx, types.ModuleName, suite.Address.Bytes(), amt)
require.NoError(b, err)

contractAddr := suite.DeployTestMessageCall(b)
Expand All @@ -54,24 +54,24 @@ func DoBenchmark(b *testing.B, txBuilder TxBuilder) {
suite, contractAddr := SetupContract(b)

msg := txBuilder(suite, contractAddr)
msg.From = suite.address.Hex()
err := msg.Sign(ethtypes.LatestSignerForChainID(suite.app.EvmKeeper.ChainID()), suite.signer)
msg.From = suite.Address.Hex()
err := msg.Sign(ethtypes.LatestSignerForChainID(suite.App.EvmKeeper.ChainID()), suite.Signer)
require.NoError(b, err)

b.ResetTimer()
b.StartTimer()
for i := 0; i < b.N; i++ {
ctx, _ := suite.ctx.CacheContext()
ctx, _ := suite.Ctx.CacheContext()

// deduct fee first
txData, err := types.UnpackTxData(msg.Data)
require.NoError(b, err)

fees := sdk.Coins{sdk.NewCoin(suite.EvmDenom(), sdkmath.NewIntFromBigInt(txData.Fee()))}
err = authante.DeductFees(suite.app.BankKeeper, suite.ctx, suite.app.AccountKeeper.GetAccount(ctx, msg.GetFrom()), fees)
err = authante.DeductFees(suite.App.BankKeeper, suite.Ctx, suite.App.AccountKeeper.GetAccount(ctx, msg.GetFrom()), fees)
require.NoError(b, err)

rsp, err := suite.app.EvmKeeper.EthereumTx(sdk.WrapSDKContext(ctx), msg)
rsp, err := suite.App.EvmKeeper.EthereumTx(sdk.WrapSDKContext(ctx), msg)
require.NoError(b, err)
require.False(b, rsp.Failed())
}
Expand All @@ -81,35 +81,35 @@ func BenchmarkTokenTransfer(b *testing.B) {
DoBenchmark(b, func(suite *KeeperTestSuite, contract common.Address) *types.MsgEthereumTx {
input, err := types.ERC20Contract.ABI.Pack("transfer", common.HexToAddress("0x378c50D9264C63F3F92B806d4ee56E9D86FfB3Ec"), big.NewInt(1000))
require.NoError(b, err)
nonce := suite.app.EvmKeeper.GetNonce(suite.ctx, suite.address)
return types.NewTx(suite.app.EvmKeeper.ChainID(), nonce, &contract, big.NewInt(0), 410000, big.NewInt(1), nil, nil, input, nil)
nonce := suite.App.EvmKeeper.GetNonce(suite.Ctx, suite.Address)
return types.NewTx(suite.App.EvmKeeper.ChainID(), nonce, &contract, big.NewInt(0), 410000, big.NewInt(1), nil, nil, input, nil)
})
}

func BenchmarkEmitLogs(b *testing.B) {
DoBenchmark(b, func(suite *KeeperTestSuite, contract common.Address) *types.MsgEthereumTx {
input, err := types.ERC20Contract.ABI.Pack("benchmarkLogs", big.NewInt(1000))
require.NoError(b, err)
nonce := suite.app.EvmKeeper.GetNonce(suite.ctx, suite.address)
return types.NewTx(suite.app.EvmKeeper.ChainID(), nonce, &contract, big.NewInt(0), 4100000, big.NewInt(1), nil, nil, input, nil)
nonce := suite.App.EvmKeeper.GetNonce(suite.Ctx, suite.Address)
return types.NewTx(suite.App.EvmKeeper.ChainID(), nonce, &contract, big.NewInt(0), 4100000, big.NewInt(1), nil, nil, input, nil)
})
}

func BenchmarkTokenTransferFrom(b *testing.B) {
DoBenchmark(b, func(suite *KeeperTestSuite, contract common.Address) *types.MsgEthereumTx {
input, err := types.ERC20Contract.ABI.Pack("transferFrom", suite.address, common.HexToAddress("0x378c50D9264C63F3F92B806d4ee56E9D86FfB3Ec"), big.NewInt(0))
input, err := types.ERC20Contract.ABI.Pack("transferFrom", suite.Address, common.HexToAddress("0x378c50D9264C63F3F92B806d4ee56E9D86FfB3Ec"), big.NewInt(0))
require.NoError(b, err)
nonce := suite.app.EvmKeeper.GetNonce(suite.ctx, suite.address)
return types.NewTx(suite.app.EvmKeeper.ChainID(), nonce, &contract, big.NewInt(0), 410000, big.NewInt(1), nil, nil, input, nil)
nonce := suite.App.EvmKeeper.GetNonce(suite.Ctx, suite.Address)
return types.NewTx(suite.App.EvmKeeper.ChainID(), nonce, &contract, big.NewInt(0), 410000, big.NewInt(1), nil, nil, input, nil)
})
}

func BenchmarkTokenMint(b *testing.B) {
DoBenchmark(b, func(suite *KeeperTestSuite, contract common.Address) *types.MsgEthereumTx {
input, err := types.ERC20Contract.ABI.Pack("mint", common.HexToAddress("0x378c50D9264C63F3F92B806d4ee56E9D86FfB3Ec"), big.NewInt(1000))
require.NoError(b, err)
nonce := suite.app.EvmKeeper.GetNonce(suite.ctx, suite.address)
return types.NewTx(suite.app.EvmKeeper.ChainID(), nonce, &contract, big.NewInt(0), 410000, big.NewInt(1), nil, nil, input, nil)
nonce := suite.App.EvmKeeper.GetNonce(suite.Ctx, suite.Address)
return types.NewTx(suite.App.EvmKeeper.ChainID(), nonce, &contract, big.NewInt(0), 410000, big.NewInt(1), nil, nil, input, nil)
})
}

Expand All @@ -118,27 +118,27 @@ func BenchmarkMessageCall(b *testing.B) {

input, err := types.TestMessageCall.ABI.Pack("benchmarkMessageCall", big.NewInt(10000))
require.NoError(b, err)
nonce := suite.app.EvmKeeper.GetNonce(suite.ctx, suite.address)
msg := types.NewTx(suite.app.EvmKeeper.ChainID(), nonce, &contract, big.NewInt(0), 25000000, big.NewInt(1), nil, nil, input, nil)
nonce := suite.App.EvmKeeper.GetNonce(suite.Ctx, suite.Address)
msg := types.NewTx(suite.App.EvmKeeper.ChainID(), nonce, &contract, big.NewInt(0), 25000000, big.NewInt(1), nil, nil, input, nil)

msg.From = suite.address.Hex()
err = msg.Sign(ethtypes.LatestSignerForChainID(suite.app.EvmKeeper.ChainID()), suite.signer)
msg.From = suite.Address.Hex()
err = msg.Sign(ethtypes.LatestSignerForChainID(suite.App.EvmKeeper.ChainID()), suite.Signer)
require.NoError(b, err)

b.ResetTimer()
b.StartTimer()
for i := 0; i < b.N; i++ {
ctx, _ := suite.ctx.CacheContext()
ctx, _ := suite.Ctx.CacheContext()

// deduct fee first
txData, err := types.UnpackTxData(msg.Data)
require.NoError(b, err)

fees := sdk.Coins{sdk.NewCoin(suite.EvmDenom(), sdkmath.NewIntFromBigInt(txData.Fee()))}
err = authante.DeductFees(suite.app.BankKeeper, suite.ctx, suite.app.AccountKeeper.GetAccount(ctx, msg.GetFrom()), fees)
err = authante.DeductFees(suite.App.BankKeeper, suite.Ctx, suite.App.AccountKeeper.GetAccount(ctx, msg.GetFrom()), fees)
require.NoError(b, err)

rsp, err := suite.app.EvmKeeper.EthereumTx(sdk.WrapSDKContext(ctx), msg)
rsp, err := suite.App.EvmKeeper.EthereumTx(sdk.WrapSDKContext(ctx), msg)
require.NoError(b, err)
require.False(b, rsp.Failed())
}
Expand Down
4 changes: 3 additions & 1 deletion x/evm/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ func (k Keeper) Account(c context.Context, req *types.QueryAccountRequest) (*typ
ctx := sdk.UnwrapSDKContext(c)
acct := k.GetAccountOrEmpty(ctx, addr)

bal := k.GetBalance(ctx, addr)

return &types.QueryAccountResponse{
Balance: acct.Balance.String(),
Balance: bal.String(),
CodeHash: common.BytesToHash(acct.CodeHash).Hex(),
Nonce: acct.Nonce,
}, nil
Expand Down
Loading
Loading