Skip to content

Commit d594fff

Browse files
authored
Merge branch 'main' into bank-precompile
2 parents 82ba9c1 + ec57b96 commit d594fff

File tree

16 files changed

+451
-160
lines changed

16 files changed

+451
-160
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@
1010
- [\#492](https://github.com/cosmos/evm/pull/492) Duplicate case switch to avoid empty execution block
1111
- [\#509](https://github.com/cosmos/evm/pull/509) Allow value with slashes when query token_pairs
1212
- [\#495](https://github.com/cosmos/evm/pull/495) Allow immediate SIGINT interrupt when mempool is not empty
13+
- [\#416](https://github.com/cosmos/evm/pull/416) Fix regression in CometBlockResultByNumber when height is 0 to use the latest block. This fixes eth_getFilterLogs RPC.
14+
- [\#545](https://github.com/cosmos/evm/pull/545) Check if mempool is not nil before accepting nonce gap error tx.
1315

1416
### IMPROVEMENTS
1517

18+
- [\#538](https://github.com/cosmos/evm/pull/538) Optimize `eth_estimateGas` gRPC path: short-circuit plain transfers, add optimistic gas bound based on `MaxUsedGas`.
1619
- [\#513](https://github.com/cosmos/evm/pull/513) Replace `TestEncodingConfig` with production `EncodingConfig` in encoding package to remove test dependencies from production code.
1720
- [\#467](https://github.com/cosmos/evm/pull/467) Replace GlobalEVMMempool by passing to JSONRPC on initiate.
1821
- [\#352](https://github.com/cosmos/evm/pull/352) Remove the creation of a Geth EVM instance, stateDB during the AnteHandler balance check.
1922
- [\#496](https://github.com/cosmos/evm/pull/496) Simplify mempool instantiation by using configs instead of objects.
23+
- [\#511](https://github.com/cosmos/evm/pull/511) Minor code cleanup for `AddPrecompileFn`.
2024

2125
### FEATURES
2226

api/cosmos/evm/vm/v1/tx.pulsar.go

Lines changed: 128 additions & 69 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# Cosmos EVM v0.4.0 → v0.5.0 Migration (UNRELEASED)
2+
3+
## 0) Prep
4+
5+
- Create a branch: `git switch -c upgrade/evm-v0.5`.
6+
- Ensure a clean build + tests green pre-upgrade.
7+
- Snapshot your current params/genesis for comparison later.
8+
9+
---
10+
11+
## 1) Dependency bumps (go.mod)
12+
13+
- Bump `github.com/cosmos/evm` to v0.5.0 and run:
14+
15+
```bash
16+
go mod tidy
17+
```
18+
19+
---
20+
21+
## 2) App wiring in `app.go`
22+
23+
### Mempool
24+
25+
#### Minimal setups: nothing to change
26+
27+
If you use the default mempool wiring (no custom pools), your existing code continues to work. If `BlockGasLimit` is 0, it defaults to `100_000_000`. If `BroadCastTxFn` is not set, it's also set to a default value.
28+
29+
```go
30+
mempoolConfig := &evmmempool.EVMMempoolConfig{
31+
AnteHandler: app.GetAnteHandler(),
32+
BlockGasLimit: 100_000_000, // or 0 to use default
33+
}
34+
evmMempool := evmmempool.NewExperimentalEVMMempool(
35+
app.CreateQueryContext, logger, app.EVMKeeper, app.FeeMarketKeeper, app.txConfig, app.clientCtx, mempoolConfig
36+
)
37+
```
38+
39+
#### Advanced setups: migrate your customizations
40+
41+
PR [#496](https://github.com/cosmos/evm/pull/496) replaced pre-built pools with configs in `EVMMempoolConfig`:
42+
43+
- Replace pools with configs
44+
- Removed: `TxPool *txpool.TxPool`, `CosmosPool sdkmempool.ExtMempool`
45+
- Added: `LegacyPoolConfig *legacypool.Config`, `CosmosPoolConfig *sdkmempool.PriorityNonceMempoolConfig[math.Int]`
46+
47+
If you built custom pools yourself:
48+
49+
```diff
50+
mempoolConfig := &evmmempool.EVMMempoolConfig{
51+
- TxPool: customTxPool,
52+
- CosmosPool: customCosmosPool,
53+
+ LegacyPoolConfig: &legacyCfg, // or nil for defaults
54+
+ CosmosPoolConfig: &cosmosCfg, // or nil for defaults
55+
AnteHandler: app.GetAnteHandler(),
56+
BroadCastTxFn: myBroadcast, // optional
57+
}
58+
```
59+
60+
Example custom configs:
61+
62+
```go
63+
// EVM legacy txpool tuning
64+
legacyCfg := legacypool.DefaultConfig
65+
legacyCfg.PriceLimit = 2
66+
mempoolConfig.LegacyPoolConfig = &legacyCfg
67+
68+
// Cosmos priority mempool tuning
69+
cosmosCfg := sdkmempool.PriorityNonceMempoolConfig[math.Int]{}
70+
cosmosCfg.TxPriority = sdkmempool.TxPriority[math.Int]{
71+
GetTxPriority: func(goCtx context.Context, tx sdk.Tx) math.Int {
72+
// Custom priority function
73+
},
74+
Compare: func(a, b math.Int) int { return a.BigInt().Cmp(b.BigInt()) },
75+
MinValue: math.ZeroInt(),
76+
}
77+
mempoolConfig.CosmosPoolConfig = &cosmosCfg
78+
79+
// Custom EVM broadcast (optional)
80+
mempoolConfig.BroadCastTxFn = func(txs []*ethtypes.Transaction) error { return nil }
81+
```
82+
83+
---
84+
85+
## 3) Build & quick tests
86+
87+
```bash
88+
go build ./...
89+
```
90+
91+
Smoke test on a single node:
92+
- Send a few EVM txs; confirm promotion/broadcast (or your `BroadCastTxFn`).
93+
- Send Cosmos txs; confirm ordering reflects your `CosmosPoolConfig` (if customized).
94+

evmd/go.mod

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ require (
7474
github.com/cncf/xds/go v0.0.0-20250501225837-2ac532fd4443 // indirect
7575
github.com/cockroachdb/apd/v2 v2.0.2 // indirect
7676
github.com/cockroachdb/errors v1.12.0 // indirect
77+
github.com/cockroachdb/fifo v0.0.0-20240616162244-4768e80dfb9a // indirect
7778
github.com/cockroachdb/logtags v0.0.0-20241215232642-bb51bb14a506 // indirect
7879
github.com/cockroachdb/pebble v1.1.5 // indirect
7980
github.com/cockroachdb/redact v1.1.6 // indirect
@@ -275,8 +276,6 @@ require (
275276
replace (
276277
// use cosmos fork of keyring
277278
github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0
278-
// Pin this pebble version to avoid breaking compilation of geth
279-
github.com/cockroachdb/pebble => github.com/cockroachdb/pebble v0.0.0-20230928194634-aa077af62593
280279
github.com/cosmos/evm => ../
281280
github.com/cosmos/evm/evmd => ./evmd
282281
// use Cosmos geth fork

evmd/go.sum

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -826,10 +826,12 @@ github.com/cockroachdb/datadriven v1.0.3-0.20230413201302-be42291fc80f h1:otljaY
826826
github.com/cockroachdb/datadriven v1.0.3-0.20230413201302-be42291fc80f/go.mod h1:a9RdTaap04u637JoCzcUoIcDmvwSUtcUFtT/C3kJlTU=
827827
github.com/cockroachdb/errors v1.12.0 h1:d7oCs6vuIMUQRVbi6jWWWEJZahLCfJpnJSVobd1/sUo=
828828
github.com/cockroachdb/errors v1.12.0/go.mod h1:SvzfYNNBshAVbZ8wzNc/UPK3w1vf0dKDUP41ucAIf7g=
829+
github.com/cockroachdb/fifo v0.0.0-20240616162244-4768e80dfb9a h1:f52TdbU4D5nozMAhO9TvTJ2ZMCXtN4VIAmfrrZ0JXQ4=
830+
github.com/cockroachdb/fifo v0.0.0-20240616162244-4768e80dfb9a/go.mod h1:9/y3cnZ5GKakj/H4y9r9GTjCvAFta7KLgSHPJJYc52M=
829831
github.com/cockroachdb/logtags v0.0.0-20241215232642-bb51bb14a506 h1:ASDL+UJcILMqgNeV5jiqR4j+sTuvQNHdf2chuKj1M5k=
830832
github.com/cockroachdb/logtags v0.0.0-20241215232642-bb51bb14a506/go.mod h1:Mw7HqKr2kdtu6aYGn3tPmAftiP3QPX63LdK/zcariIo=
831-
github.com/cockroachdb/pebble v0.0.0-20230928194634-aa077af62593 h1:aPEJyR4rPBvDmeyi+l/FS/VtA00IWvjeFvjen1m1l1A=
832-
github.com/cockroachdb/pebble v0.0.0-20230928194634-aa077af62593/go.mod h1:6hk1eMY/u5t+Cf18q5lFMUA1Rc+Sm5I6Ra1QuPyxXCo=
833+
github.com/cockroachdb/pebble v1.1.5 h1:5AAWCBWbat0uE0blr8qzufZP5tBjkRyy/jWe1QWLnvw=
834+
github.com/cockroachdb/pebble v1.1.5/go.mod h1:17wO9el1YEigxkP/YtV8NtCivQDgoCyBg5c4VR/eOWo=
833835
github.com/cockroachdb/redact v1.1.6 h1:zXJBwDZ84xJNlHl1rMyCojqyIxv+7YUpQiJLQ7n4314=
834836
github.com/cockroachdb/redact v1.1.6/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg=
835837
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 h1:zuQyyAKVxetITBuuhv3BI9cMrmStnpT18zmgmTxunpo=

evmd/tests/integration/x_vm_test.go

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,87 @@
11
package integration
22

33
import (
4+
"encoding/json"
45
"testing"
56

6-
"github.com/stretchr/testify/suite"
7-
7+
"github.com/cosmos/evm/server/config"
88
"github.com/cosmos/evm/tests/integration/x/vm"
9+
"github.com/cosmos/evm/testutil/integration/evm/network"
10+
"github.com/cosmos/evm/testutil/keyring"
11+
feemarkettypes "github.com/cosmos/evm/x/feemarket/types"
12+
"github.com/cosmos/evm/x/vm/types"
13+
"github.com/ethereum/go-ethereum/common"
14+
15+
"github.com/stretchr/testify/require"
16+
"github.com/stretchr/testify/suite"
917
)
1018

19+
func BenchmarkGasEstimation(b *testing.B) {
20+
// Setup benchmark test environment
21+
keys := keyring.New(2)
22+
// Set custom balance based on test params
23+
customGenesis := network.CustomGenesisState{}
24+
feemarketGenesis := feemarkettypes.DefaultGenesisState()
25+
feemarketGenesis.Params.NoBaseFee = true
26+
customGenesis[feemarkettypes.ModuleName] = feemarketGenesis
27+
opts := []network.ConfigOption{
28+
network.WithPreFundedAccounts(keys.GetAllAccAddrs()...),
29+
network.WithCustomGenesis(customGenesis),
30+
}
31+
nw := network.NewUnitTestNetwork(CreateEvmd, opts...)
32+
// gh := grpc.NewIntegrationHandler(nw)
33+
// tf := factory.New(nw, gh)
34+
35+
chainConfig := types.DefaultChainConfig(nw.GetEIP155ChainID().Uint64())
36+
// get the denom and decimals set on chain initialization
37+
// because we'll need to set them again when resetting the chain config
38+
denom := types.GetEVMCoinDenom()
39+
extendedDenom := types.GetEVMCoinExtendedDenom()
40+
displayDenom := types.GetEVMCoinDisplayDenom()
41+
decimals := types.GetEVMCoinDecimals()
42+
43+
configurator := types.NewEVMConfigurator()
44+
configurator.ResetTestConfig()
45+
err := configurator.
46+
WithChainConfig(chainConfig).
47+
WithEVMCoinInfo(types.EvmCoinInfo{
48+
Denom: denom,
49+
ExtendedDenom: extendedDenom,
50+
DisplayDenom: displayDenom,
51+
Decimals: decimals,
52+
}).
53+
Configure()
54+
require.NoError(b, err)
55+
56+
// Use simple transaction args for consistent benchmarking
57+
args := types.TransactionArgs{
58+
To: &common.Address{},
59+
}
60+
61+
marshalArgs, err := json.Marshal(args)
62+
require.NoError(b, err)
63+
64+
req := types.EthCallRequest{
65+
Args: marshalArgs,
66+
GasCap: config.DefaultGasCap,
67+
ProposerAddress: nw.GetContext().BlockHeader().ProposerAddress,
68+
}
69+
70+
// Reset timer to exclude setup time
71+
b.ResetTimer()
72+
73+
// Run the benchmark
74+
for i := 0; i < b.N; i++ {
75+
_, err := nw.GetEvmClient().EstimateGas(
76+
nw.GetContext(),
77+
&req,
78+
)
79+
if err != nil {
80+
b.Fatal(err)
81+
}
82+
}
83+
}
84+
1185
func TestKeeperTestSuite(t *testing.T) {
1286
s := vm.NewKeeperTestSuite(CreateEvmd)
1387
s.EnableFeemarket = false

precompiles/common/precompile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func (p Precompile) RunSetup(
7373

7474
// add precompileCall entry on the stateDB journal
7575
// this allows to revert the changes within an evm tx
76-
err = stateDB.AddPrecompileFn(p.Address(), snapshot, events)
76+
err = stateDB.AddPrecompileFn(snapshot, events)
7777
if err != nil {
7878
return sdk.Context{}, nil, nil, uint64(0), nil, err
7979
}

proto/cosmos/evm/vm/v1/tx.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ message MsgEthereumTxResponse {
7171
string vm_error = 4;
7272
// gas_used specifies how much gas was consumed by the transaction
7373
uint64 gas_used = 5;
74+
// max_used_gas specifies the gas consumed by the transaction, not including refunds
75+
uint64 max_used_gas = 6;
7476
}
7577

7678
// MsgUpdateParams defines a Msg for updating the x/vm module parameters.

rpc/backend/blocks.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ func (b *Backend) CometHeaderByNumber(blockNum rpctypes.BlockNumber) (*cmtrpctyp
203203
// CometBlockResultByNumber returns a CometBFT-formatted block result
204204
// by block number
205205
func (b *Backend) CometBlockResultByNumber(height *int64) (*cmtrpctypes.ResultBlockResults, error) {
206+
if height != nil && *height == 0 {
207+
height = nil
208+
}
206209
res, err := b.RPCClient.BlockResults(b.Ctx, height)
207210
if err != nil {
208211
return nil, fmt.Errorf("failed to fetch block result from CometBFT %d: %w", *height, err)

rpc/backend/call_tx.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func (b *Backend) SendRawTransaction(data hexutil.Bytes) (common.Hash, error) {
155155
}
156156
if err != nil {
157157
// Check if this is a nonce gap error that was successfully queued
158-
if strings.Contains(err.Error(), mempool.ErrNonceGap.Error()) {
158+
if b.Mempool != nil && strings.Contains(err.Error(), mempool.ErrNonceGap.Error()) {
159159
// Transaction was successfully queued due to nonce gap, return success to client
160160
b.Logger.Debug("transaction queued due to nonce gap", "hash", txHash.Hex())
161161
return txHash, nil

0 commit comments

Comments
 (0)