Skip to content

Commit 285b9bb

Browse files
committed
feat: fill block hash in tx response
follow up for #576 (comment)
1 parent fedc27f commit 285b9bb

File tree

9 files changed

+238
-110
lines changed

9 files changed

+238
-110
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
- [\#496](https://github.com/cosmos/evm/pull/496) Simplify mempool instantiation by using configs instead of objects.
2323
- [\#568](https://github.com/cosmos/evm/pull/568) Avoid unnecessary block notifications when the event bus is already set up.
2424
- [\#511](https://github.com/cosmos/evm/pull/511) Minor code cleanup for `AddPrecompileFn`.
25-
- [\#544](https://github.com/cosmos/evm/pull/544) Parse logs from the txResult.Data and avoid emitting EVM events to cosmos-sdk events.
25+
- [\#576](https://github.com/cosmos/evm/pull/576) Parse logs from the txResult.Data and avoid emitting EVM events to cosmos-sdk events.
26+
- [\#585](https://github.com/cosmos/evm/pull/585) Add block hash for tx response.
2627

2728
### FEATURES
2829

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

Lines changed: 137 additions & 60 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ message MsgEthereumTxResponse {
7373
uint64 gas_used = 5;
7474
// max_used_gas specifies the gas consumed by the transaction, not including refunds
7575
uint64 max_used_gas = 6;
76+
// include the block hash for json-rpc to use
77+
bytes block_hash = 7;
7678
}
7779

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

tests/integration/x/vm/test_statedb.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,6 @@ func (s *KeeperTestSuite) TestAddLog() {
729729
},
730730
&ethtypes.Log{
731731
Address: addr,
732-
TxHash: txHash,
733732
Topics: make([]common.Hash, 0),
734733
},
735734
func(vm.StateDB) {},
@@ -743,7 +742,6 @@ func (s *KeeperTestSuite) TestAddLog() {
743742
},
744743
&ethtypes.Log{
745744
Address: addr,
746-
TxHash: txHash3,
747745
Topics: make([]common.Hash, 0),
748746
},
749747
func(vm.StateDB) {},

x/vm/keeper/state_transition.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,7 @@ func (k *Keeper) ApplyMessageWithConfig(ctx sdk.Context, msg core.Message, trace
515515
Ret: ret,
516516
Logs: types.NewLogsFromEth(logs),
517517
Hash: txConfig.TxHash.Hex(),
518+
BlockHash: ctx.HeaderHash(),
518519
}, nil
519520
}
520521

x/vm/statedb/statedb.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@ func (s *StateDB) cache() error {
218218
func (s *StateDB) AddLog(log *ethtypes.Log) {
219219
s.journal.append(addLogChange{})
220220

221-
log.TxHash = s.txConfig.TxHash
222221
log.TxIndex = s.txConfig.TxIndex
223222
log.Index = s.txConfig.LogIndex + uint(len(s.logs))
224223
s.logs = append(s.logs, log)

x/vm/statedb/statedb_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,6 @@ func (suite *StateDBTestSuite) TestLog() {
606606
BlockNumber: 1,
607607
BlockHash: blockHash,
608608
BlockTimestamp: 1,
609-
TxHash: txHash,
610609
TxIndex: 1,
611610
Index: 1,
612611
}

x/vm/types/tx.pb.go

Lines changed: 93 additions & 45 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x/vm/types/utils.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ func logsFromTxResponse(dst []*ethtypes.Log, rsp *MsgEthereumTxResponse, blockNu
8282
l := log.ToEthereum()
8383
l.TxHash = txHash
8484
l.BlockNumber = blockNumber
85+
if len(rsp.BlockHash) > 0 {
86+
l.BlockHash = common.BytesToHash(rsp.BlockHash)
87+
}
8588
dst = append(dst, l)
8689
}
8790
return dst

0 commit comments

Comments
 (0)