Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
- [\#774](https://github.com/cosmos/evm/pull/774) Emit proper allowance amount in erc20 event.
- [\#790](https://github.com/cosmos/evm/pull/790) fix panic in historical query due to missing EvmCoinInfo.
- [\#800](https://github.com/cosmos/evm/pull/800) Fix denom exponent validation in virtual fee deduct in vm module.
- [\#812](https://github.com/cosmos/evm/pull/812) Patch evm tx index and log indexes, cleanup EmitTxHashEvent and ResetTransientGasUsed.
- [\#817](https://github.com/cosmos/evm/pull/817) Align GetCoinbaseAddress to handle empty proposer address in contexts like CheckTx where proposer doesn't exist.
- [\#814](https://github.com/cosmos/evm/pull/814) Fix duplicated events in post tx processor.
- [\#816](https://github.com/cosmos/evm/pull/816) Avoid nil pointer when RPC requests execute before evmCoinInfo initialization in PreBlock with defaultEvmCoinInfo fallback.
Expand Down
25 changes: 0 additions & 25 deletions ante/evm/11_emit_event.go

This file was deleted.

3 changes: 0 additions & 3 deletions ante/evm/mono_decorator.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,6 @@ func (md MonoDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, ne
return ctx, err
}

// Emit event unconditionally - ctx.TxIndex() will be valid during block execution
EmitTxHashEvent(ctx, ethMsg, uint64(ctx.TxIndex())) // #nosec G115 -- no overlfow here

if err := CheckTxFee(txFeeInfo, decUtils.TxFee, decUtils.TxGasLimit); err != nil {
return ctx, err
}
Expand Down
37 changes: 34 additions & 3 deletions evmd/app.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
package evmd

import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"os"

goruntime "runtime"

Check notice

Code scanning / CodeQL

Sensitive package import Note

Certain system packages contain functions which may be a possible source of non-determinism

cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"

"github.com/spf13/cast"

// Force-load the tracer engines to trigger registration due to Go-Ethereum v1.10.15 changes
"github.com/ethereum/go-ethereum/common"
"github.com/spf13/cast"

_ "github.com/ethereum/go-ethereum/eth/tracers/js"
_ "github.com/ethereum/go-ethereum/eth/tracers/native"
Expand Down Expand Up @@ -73,6 +79,7 @@
upgradetypes "cosmossdk.io/x/upgrade/types"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/blockstm"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/grpc/cmtservice"
Expand Down Expand Up @@ -199,6 +206,18 @@
configurator module.Configurator
}

type customRunner struct {
*blockstm.STMRunner
}

func (r *customRunner) Run(ctx context.Context, ms storetypes.MultiStore, txs [][]byte, deliverTx sdk.DeliverTxFunc) ([]*abci.ExecTxResult, error) {
results, err := r.STMRunner.Run(ctx, ms, txs, deliverTx)
if err != nil {
return nil, err
}
return evmtypes.PatchTxResponses(results), nil
}

// NewExampleApp returns a reference to an initialized EVMD.
func NewExampleApp(
logger log.Logger,
Expand All @@ -215,13 +234,13 @@
legacyAmino := encodingConfig.Amino
interfaceRegistry := encodingConfig.InterfaceRegistry
txConfig := encodingConfig.TxConfig

txDecoder := encodingConfig.TxConfig.TxDecoder()
bApp := baseapp.NewBaseApp(
appName,
logger,
db,
// use transaction decoder to support the sdk.Tx interface instead of sdk.StdTx
encodingConfig.TxConfig.TxDecoder(),
txDecoder,
baseAppOptions...,
)
bApp.SetCommitMultiStoreTracer(traceStore)
Expand Down Expand Up @@ -775,6 +794,18 @@
}
}

bApp.SetBlockSTMTxRunner(&customRunner{
STMRunner: blockstm.NewSTMRunner(
encodingConfig.TxConfig.TxDecoder(),
nonTransientKeys,
min(goruntime.GOMAXPROCS(0), goruntime.NumCPU()),
true,
func(ms storetypes.MultiStore) string {
return app.EVMKeeper.GetParams(sdk.NewContext(ms, cmtproto.Header{}, false, log.NewNopLogger())).EvmDenom
},
),
})

return app
}

Expand Down
2 changes: 2 additions & 0 deletions evmd/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,8 @@ github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc=
github.com/tendermint/go-amino v0.16.0 h1:GyhmgQKvqF82e2oZeuMSp9JTN0N09emoSZlb2lyGa2E=
github.com/tendermint/go-amino v0.16.0/go.mod h1:TQU0M1i/ImAo+tYpZi73AU3V/dKeCoMC9Sphe2ZwGME=
github.com/test-go/testify v1.1.4 h1:Tf9lntrKUMHiXQ07qBScBTSA0dhYQlu83hswqelv1iE=
github.com/test-go/testify v1.1.4/go.mod h1:rH7cfJo/47vWGdi4GPj16x3/t1xGOj2YxzmNQzk2ghU=
github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/gjson v1.18.0 h1:FIDeeyB800efLX89e5a8Y0BNH+LOngJyGrIWxG2FKQY=
github.com/tidwall/gjson v1.18.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
Expand Down
1 change: 0 additions & 1 deletion local_node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,6 @@ if [[ $overwrite == "y" || $overwrite == "Y" ]]; then
sed -i.bak 's/prometheus-retention-time = "0"/prometheus-retention-time = "1000000000000"/g' "$APP_TOML"
sed -i.bak 's/enabled = false/enabled = true/g' "$APP_TOML"
sed -i.bak 's/enable = false/enable = true/g' "$APP_TOML"
sed -i.bak 's/enable-indexer = false/enable-indexer = true/g' "$APP_TOML"

# --------- maybe generate additional users ---------
# start with provided/default list
Expand Down
9 changes: 9 additions & 0 deletions rpc/backend/comet_to_eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,15 @@ func (b *Backend) ReceiptsFromCometBlock(
return nil, fmt.Errorf("failed to convert tx result to eth receipt: %w", err)
}

if txResult.EthTxIndex == -1 {
var err error
// Fallback to find tx index by iterating all valid eth transactions
txResult.EthTxIndex, err = FindEthTxIndexByHash(ctx, ethMsg.Hash(), resBlock, blockRes, b)
if err != nil {
return nil, err
}
}

bloom := ethtypes.CreateBloom(&ethtypes.Receipt{Logs: logs})

receipt := &ethtypes.Receipt{
Expand Down
18 changes: 4 additions & 14 deletions rpc/backend/tx_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"encoding/json"
"fmt"
"math"
"math/big"
"time"

Expand Down Expand Up @@ -66,22 +65,13 @@ func (b *Backend) GetTransactionByHash(ctx context.Context, txHash common.Hash)
}

if res.EthTxIndex == -1 {
var err error
// Fallback to find tx index by iterating all valid eth transactions
msgs := b.EthMsgsFromCometBlock(ctx, block, blockRes)
for i := range msgs {
if msgs[i].Hash() == txHash {
if i > math.MaxInt32 {
return nil, errors.New("tx index overflow")
}
res.EthTxIndex = int32(i) //#nosec G115 -- checked for int overflow already
break
}
res.EthTxIndex, err = FindEthTxIndexByHash(ctx, txHash, block, blockRes, b)
if err != nil {
return nil, err
}
}
// if we still unable to find the eth tx index, return error, shouldn't happen.
if res.EthTxIndex == -1 {
return nil, errors.New("can't find index of ethereum tx")
}

baseFee, err := b.BaseFee(ctx, blockRes)
if err != nil {
Expand Down
14 changes: 14 additions & 0 deletions rpc/backend/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,3 +355,17 @@ func unwrapBlockNOrHash(blockNOrHash types.BlockNumberOrHash) string {
}
return ""
}

// Fallback to find tx index by iterating all valid eth transactions for legacy blocks that don't have AttributeKeyTxIndex in events
func FindEthTxIndexByHash(ctx context.Context, txHash common.Hash, block *cmtrpctypes.ResultBlock, blockRes *cmtrpctypes.ResultBlockResults, b *Backend) (int32, error) {
msgs := b.EthMsgsFromCometBlock(ctx, block, blockRes)
for i := range msgs {
if msgs[i].Hash() == txHash {
if i > math.MaxInt32 {
return -1, fmt.Errorf("tx index overflow")
}
return int32(i), nil //#nosec G115 -- checked for int overflow already
}
}
return -1, fmt.Errorf("can't find index of ethereum tx")
}
4 changes: 4 additions & 0 deletions rpc/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ func (p *ParsedTxs) updateTx(eventIndex int, attrs []abci.EventAttribute) error
// if hash is different, index the new one too
p.TxHashes[tx.Hash] = eventIndex
}
// preserve EthTxIndex from the first event set by PatchTxResponses if not set in the second event from msg_server
if tx.EthTxIndex == -1 {
tx.EthTxIndex = p.Txs[eventIndex].EthTxIndex
}
// override the tx because the second event is more trustworthy
p.Txs[eventIndex] = tx
return nil
Expand Down
Loading
Loading