Skip to content

Commit

Permalink
[EVM] add tx hash to evm info (#488)
Browse files Browse the repository at this point in the history
## Describe your changes and provide context
- add tx hash to evm info

## Testing performed to validate your change
- unit test
  • Loading branch information
stevenlanders authored and udpatil committed Apr 19, 2024
1 parent 771a3fd commit 2d7bc49
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 4 deletions.
1 change: 1 addition & 0 deletions baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ func (app *BaseApp) DeliverTx(ctx sdk.Context, req abci.RequestDeliverTx, tx sdk
res.EvmTxInfo = &abci.EvmTxInfo{
SenderAddress: resCtx.EVMSenderAddress(),
Nonce: resCtx.EVMNonce(),
TxHash: resCtx.EVMTxHash(),
}
}
return
Expand Down
22 changes: 21 additions & 1 deletion baseapp/deliver_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1498,19 +1498,39 @@ func TestDeliverTx(t *testing.T) {
app.BeginBlock(app.deliverState.ctx, abci.RequestBeginBlock{Header: header})

for i := 0; i < txPerHeight; i++ {
// every even i is an evm tx
isEvm := i%2 == 0
counter := int64(blockN*txPerHeight + i)
tx := newTxCounter(counter, counter)

txBytes, err := codec.Marshal(tx)
require.NoError(t, err)

decoded, _ := app.txDecoder(txBytes)
res := app.DeliverTx(app.deliverState.ctx, abci.RequestDeliverTx{Tx: txBytes}, decoded, sha256.Sum256(txBytes))

ctx := app.deliverState.ctx

if isEvm {
ctx = ctx.WithIsEVM(true)
ctx = ctx.WithEVMNonce(12345)
ctx = ctx.WithEVMTxHash("hash")
ctx = ctx.WithEVMSenderAddress("address")
}

res := app.DeliverTx(ctx, abci.RequestDeliverTx{Tx: txBytes}, decoded, sha256.Sum256(txBytes))
require.True(t, res.IsOK(), fmt.Sprintf("%v", res))
events := res.GetEvents()
require.Len(t, events, 3, "should contain ante handler, message type and counter events respectively")
require.Equal(t, sdk.MarkEventsToIndex(counterEvent("ante_handler", counter).ToABCIEvents(), map[string]struct{}{})[0], events[0], "ante handler event")
require.Equal(t, sdk.MarkEventsToIndex(counterEvent(sdk.EventTypeMessage, counter).ToABCIEvents(), map[string]struct{}{})[0], events[2], "msg handler update counter event")

if isEvm {
require.Equal(t, uint64(12345), res.EvmTxInfo.Nonce)
require.Equal(t, "hash", res.EvmTxInfo.TxHash)
require.Equal(t, "address", res.EvmTxInfo.SenderAddress)
} else {
require.Nil(t, res.EvmTxInfo)
}
}

app.EndBlock(app.deliverState.ctx, abci.RequestEndBlock{})
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ replace (
github.com/sei-protocol/sei-db => github.com/sei-protocol/sei-db v0.0.31
// Latest goleveldb is broken, we have to stick to this version
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
github.com/tendermint/tendermint => github.com/sei-protocol/sei-tendermint v0.2.38-evm-rebase-2
github.com/tendermint/tendermint => github.com/sei-protocol/sei-tendermint v0.2.43-seiv2
// latest grpc doesn't work with with our modified proto compiler, so we need to enforce
// the following version across all dependencies.
google.golang.org/grpc => google.golang.org/grpc v1.33.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -954,8 +954,8 @@ github.com/sei-protocol/sei-db v0.0.31 h1:UW9skaXnaXfi9mp60EbAJ2ijyr1Hnu9WYatMNr
github.com/sei-protocol/sei-db v0.0.31/go.mod h1:F/ZKZA8HJPcUzSZPA8yt6pfwlGriJ4RDR4eHKSGLStI=
github.com/sei-protocol/sei-iavl v0.1.9 h1:y4mVYftxLNRs6533zl7N0/Ch+CzRQc04JDfHolIxgBE=
github.com/sei-protocol/sei-iavl v0.1.9/go.mod h1:7PfkEVT5dcoQE+s/9KWdoXJ8VVVP1QpYYPLdxlkSXFk=
github.com/sei-protocol/sei-tendermint v0.2.38-evm-rebase-2 h1:y740HdzTehlJaBrwy/T1ncwJ9D10xu4r6gSHtNRzqF0=
github.com/sei-protocol/sei-tendermint v0.2.38-evm-rebase-2/go.mod h1:4LSlJdhl3nf3OmohliwRNUFLOB1XWlrmSodrIP7fLh4=
github.com/sei-protocol/sei-tendermint v0.2.43-seiv2 h1:aSyMTWLcj3xsqMhIndipy9NJSgwwODmXnqmbnsab+nc=
github.com/sei-protocol/sei-tendermint v0.2.43-seiv2/go.mod h1:4LSlJdhl3nf3OmohliwRNUFLOB1XWlrmSodrIP7fLh4=
github.com/sei-protocol/sei-tm-db v0.0.5 h1:3WONKdSXEqdZZeLuWYfK5hP37TJpfaUa13vAyAlvaQY=
github.com/sei-protocol/sei-tm-db v0.0.5/go.mod h1:Cpa6rGyczgthq7/0pI31jys2Fw0Nfrc+/jKdP1prVqY=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
Expand Down
10 changes: 10 additions & 0 deletions types/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type Context struct {
evm bool // EVM transaction flag
evmNonce uint64 // EVM Transaction nonce
evmSenderAddress string // EVM Sender address
evmTxHash string // EVM TX hash

msgValidator *acltypes.MsgValidator
messageIndex int // Used to track current message being processed
Expand Down Expand Up @@ -137,6 +138,10 @@ func (c Context) EVMNonce() uint64 {
return c.evmNonce
}

func (c Context) EVMTxHash() string {
return c.evmTxHash
}

func (c Context) IsEVM() bool {
return c.evm
}
Expand Down Expand Up @@ -397,6 +402,11 @@ func (c Context) WithIsEVM(isEVM bool) Context {
return c
}

func (c Context) WithEVMTxHash(txHash string) Context {
c.evmTxHash = txHash
return c
}

func (c Context) WithPendingTxChecker(checker abci.PendingTxChecker) Context {
c.pendingTxChecker = checker
return c
Expand Down

0 comments on commit 2d7bc49

Please sign in to comment.