From 739d61c6987587b0ab0cd9942e8f3520a2ba2270 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Mon, 12 Jun 2023 09:48:30 -0700 Subject: [PATCH] fix: eth: ensure that the event topics are non-nil Even when empty. fixes #10910 --- node/impl/full/eth.go | 2 ++ node/impl/full/eth_test.go | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/node/impl/full/eth.go b/node/impl/full/eth.go index 2f1b30fad..38c3a88d1 100644 --- a/node/impl/full/eth.go +++ b/node/impl/full/eth.go @@ -1537,6 +1537,8 @@ func ethLogFromEvent(entries []types.EventEntry) (data []byte, topics []ethtypes topicsFoundCount int dataFound bool ) + // Topics must be non-nil, even if empty. So we might as well pre-allocate for 4 (the max). + topics = make([]ethtypes.EthHash, 0, 4) for _, entry := range entries { // Drop events with non-raw topics to avoid mistakes. if entry.Codec != cid.Raw { diff --git a/node/impl/full/eth_test.go b/node/impl/full/eth_test.go index 63dbb447e..903c2c1d8 100644 --- a/node/impl/full/eth_test.go +++ b/node/impl/full/eth_test.go @@ -17,7 +17,8 @@ func TestEthLogFromEvent(t *testing.T) { data, topics, ok := ethLogFromEvent(nil) require.True(t, ok) require.Nil(t, data) - require.Nil(t, topics) + require.Empty(t, topics) + require.NotNil(t, topics) // basic topic data, topics, ok = ethLogFromEvent([]types.EventEntry{{