Skip to content

Commit e587881

Browse files
[EVM] add tx hash to evm info (#488)
## Describe your changes and provide context - add tx hash to evm info ## Testing performed to validate your change - unit test
1 parent 6f71ccb commit e587881

File tree

5 files changed

+35
-4
lines changed

5 files changed

+35
-4
lines changed

baseapp/abci.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ func (app *BaseApp) DeliverTx(ctx sdk.Context, req abci.RequestDeliverTx, tx sdk
317317
res.EvmTxInfo = &abci.EvmTxInfo{
318318
SenderAddress: resCtx.EVMSenderAddress(),
319319
Nonce: resCtx.EVMNonce(),
320+
TxHash: resCtx.EVMTxHash(),
320321
}
321322
}
322323
return

baseapp/deliver_tx_test.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1498,19 +1498,39 @@ func TestDeliverTx(t *testing.T) {
14981498
app.BeginBlock(app.deliverState.ctx, abci.RequestBeginBlock{Header: header})
14991499

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

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

15071509
decoded, _ := app.txDecoder(txBytes)
1508-
res := app.DeliverTx(app.deliverState.ctx, abci.RequestDeliverTx{Tx: txBytes}, decoded, sha256.Sum256(txBytes))
1510+
1511+
ctx := app.deliverState.ctx
1512+
1513+
if isEvm {
1514+
ctx = ctx.WithIsEVM(true)
1515+
ctx = ctx.WithEVMNonce(12345)
1516+
ctx = ctx.WithEVMTxHash("hash")
1517+
ctx = ctx.WithEVMSenderAddress("address")
1518+
}
1519+
1520+
res := app.DeliverTx(ctx, abci.RequestDeliverTx{Tx: txBytes}, decoded, sha256.Sum256(txBytes))
15091521
require.True(t, res.IsOK(), fmt.Sprintf("%v", res))
15101522
events := res.GetEvents()
15111523
require.Len(t, events, 3, "should contain ante handler, message type and counter events respectively")
15121524
require.Equal(t, sdk.MarkEventsToIndex(counterEvent("ante_handler", counter).ToABCIEvents(), map[string]struct{}{})[0], events[0], "ante handler event")
15131525
require.Equal(t, sdk.MarkEventsToIndex(counterEvent(sdk.EventTypeMessage, counter).ToABCIEvents(), map[string]struct{}{})[0], events[2], "msg handler update counter event")
1526+
1527+
if isEvm {
1528+
require.Equal(t, uint64(12345), res.EvmTxInfo.Nonce)
1529+
require.Equal(t, "hash", res.EvmTxInfo.TxHash)
1530+
require.Equal(t, "address", res.EvmTxInfo.SenderAddress)
1531+
} else {
1532+
require.Nil(t, res.EvmTxInfo)
1533+
}
15141534
}
15151535

15161536
app.EndBlock(app.deliverState.ctx, abci.RequestEndBlock{})

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ replace (
187187
github.com/sei-protocol/sei-db => github.com/sei-protocol/sei-db v0.0.31
188188
// Latest goleveldb is broken, we have to stick to this version
189189
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
190-
github.com/tendermint/tendermint => github.com/sei-protocol/sei-tendermint v0.2.38-evm-rebase-2
190+
github.com/tendermint/tendermint => github.com/sei-protocol/sei-tendermint v0.2.43-seiv2
191191
// latest grpc doesn't work with with our modified proto compiler, so we need to enforce
192192
// the following version across all dependencies.
193193
google.golang.org/grpc => google.golang.org/grpc v1.33.2

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -954,8 +954,8 @@ github.com/sei-protocol/sei-db v0.0.31 h1:UW9skaXnaXfi9mp60EbAJ2ijyr1Hnu9WYatMNr
954954
github.com/sei-protocol/sei-db v0.0.31/go.mod h1:F/ZKZA8HJPcUzSZPA8yt6pfwlGriJ4RDR4eHKSGLStI=
955955
github.com/sei-protocol/sei-iavl v0.1.9 h1:y4mVYftxLNRs6533zl7N0/Ch+CzRQc04JDfHolIxgBE=
956956
github.com/sei-protocol/sei-iavl v0.1.9/go.mod h1:7PfkEVT5dcoQE+s/9KWdoXJ8VVVP1QpYYPLdxlkSXFk=
957-
github.com/sei-protocol/sei-tendermint v0.2.38-evm-rebase-2 h1:y740HdzTehlJaBrwy/T1ncwJ9D10xu4r6gSHtNRzqF0=
958-
github.com/sei-protocol/sei-tendermint v0.2.38-evm-rebase-2/go.mod h1:4LSlJdhl3nf3OmohliwRNUFLOB1XWlrmSodrIP7fLh4=
957+
github.com/sei-protocol/sei-tendermint v0.2.43-seiv2 h1:aSyMTWLcj3xsqMhIndipy9NJSgwwODmXnqmbnsab+nc=
958+
github.com/sei-protocol/sei-tendermint v0.2.43-seiv2/go.mod h1:4LSlJdhl3nf3OmohliwRNUFLOB1XWlrmSodrIP7fLh4=
959959
github.com/sei-protocol/sei-tm-db v0.0.5 h1:3WONKdSXEqdZZeLuWYfK5hP37TJpfaUa13vAyAlvaQY=
960960
github.com/sei-protocol/sei-tm-db v0.0.5/go.mod h1:Cpa6rGyczgthq7/0pI31jys2Fw0Nfrc+/jKdP1prVqY=
961961
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=

types/context.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ type Context struct {
5353
evm bool // EVM transaction flag
5454
evmNonce uint64 // EVM Transaction nonce
5555
evmSenderAddress string // EVM Sender address
56+
evmTxHash string // EVM TX hash
5657

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

141+
func (c Context) EVMTxHash() string {
142+
return c.evmTxHash
143+
}
144+
140145
func (c Context) IsEVM() bool {
141146
return c.evm
142147
}
@@ -397,6 +402,11 @@ func (c Context) WithIsEVM(isEVM bool) Context {
397402
return c
398403
}
399404

405+
func (c Context) WithEVMTxHash(txHash string) Context {
406+
c.evmTxHash = txHash
407+
return c
408+
}
409+
400410
func (c Context) WithPendingTxChecker(checker abci.PendingTxChecker) Context {
401411
c.pendingTxChecker = checker
402412
return c

0 commit comments

Comments
 (0)