From 152ebdc18048c7ee577a6f4e0ae7f83d7fe26876 Mon Sep 17 00:00:00 2001 From: HuangYi Date: Tue, 14 Dec 2021 15:03:15 +0800 Subject: [PATCH 1/3] Problem: empty topics shouldn't be encoded as nil Closes: #839 Solution: - encode it as empty array --- x/evm/types/logs.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/x/evm/types/logs.go b/x/evm/types/logs.go index 75cea38896..4cf73c94dc 100644 --- a/x/evm/types/logs.go +++ b/x/evm/types/logs.go @@ -70,9 +70,9 @@ func (log *Log) Validate() error { // ToEthereum returns the Ethereum type Log from a Ethermint proto compatible Log. func (log *Log) ToEthereum() *ethtypes.Log { - var topics []common.Hash // nolint: prealloc - for i := range log.Topics { - topics = append(topics, common.HexToHash(log.Topics[i])) + topics := make([]common.Hash, len(log.Topics)) + for i, topic := range log.Topics { + topics[i] = common.HexToHash(topic) } return ðtypes.Log{ @@ -108,9 +108,9 @@ func LogsToEthereum(logs []*Log) []*ethtypes.Log { // NewLogFromEth creates a new Log instance from a Ethereum type Log. func NewLogFromEth(log *ethtypes.Log) *Log { - var topics []string // nolint: prealloc - for _, topic := range log.Topics { - topics = append(topics, topic.String()) + topics := make([]string, len(log.Topics)) + for i, topic := range log.Topics { + topics[i] = topic.String() } return &Log{ From cb7c3d7c99a6d9592f3b75314e67dd7d00cdee9c Mon Sep 17 00:00:00 2001 From: HuangYi Date: Tue, 14 Dec 2021 15:45:18 +0800 Subject: [PATCH 2/3] fix unit tests --- x/evm/keeper/statedb_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/x/evm/keeper/statedb_test.go b/x/evm/keeper/statedb_test.go index 7c69072b45..a3cb8cafdf 100644 --- a/x/evm/keeper/statedb_test.go +++ b/x/evm/keeper/statedb_test.go @@ -592,6 +592,7 @@ func (suite *KeeperTestSuite) TestAddLog() { ðtypes.Log{ Address: addr, TxHash: txHash, + Topics: make([]common.Hash, 0), }, func() {}, }, @@ -606,6 +607,7 @@ func (suite *KeeperTestSuite) TestAddLog() { TxHash: txHash2, TxIndex: 1, Index: 1, + Topics: make([]common.Hash, 0), }, func() { suite.app.EvmKeeper.SetTxHashTransient(txHash) @@ -624,6 +626,7 @@ func (suite *KeeperTestSuite) TestAddLog() { ðtypes.Log{ Address: addr, TxHash: txHash3, + Topics: make([]common.Hash, 0), }, func() {}, }, @@ -638,6 +641,7 @@ func (suite *KeeperTestSuite) TestAddLog() { TxHash: txHash4, TxIndex: 1, Index: 1, + Topics: make([]common.Hash, 0), }, func() { suite.app.EvmKeeper.SetTxHashTransient(txHash) From 42b3a14f6c30388c34dcd271c2511af478151786 Mon Sep 17 00:00:00 2001 From: HuangYi Date: Tue, 14 Dec 2021 20:44:39 +0800 Subject: [PATCH 3/3] changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b39a9c52e3..77ef6f4c33 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,10 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## Unreleased +### State Machine Breaking + +- (evm) [tharsis#840](https://github.com/tharsis/ethermint/pull/840) Store empty topics as empty array rather than nil. + ## [v0.9.0] - 2021-12-01 ### State Machine Breaking