From cc302dd68b21bf694579416f18c34134f4d76e7e Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Fri, 10 Feb 2023 07:59:47 -0800 Subject: [PATCH] fix: eth: log on unexpected events We can remove these later as we add more event types, but this will aid in debugging. --- node/impl/full/eth.go | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/node/impl/full/eth.go b/node/impl/full/eth.go index 7f010c4d0..a740d32fa 100644 --- a/node/impl/full/eth.go +++ b/node/impl/full/eth.go @@ -1365,6 +1365,11 @@ func ethLogFromEvent(entries []types.EventEntry) (data []byte, topics []ethtypes dataFound bool ) for _, entry := range entries { + // Drop events with non-raw topics to avoid mistakes. + if entry.Codec != cid.Raw { + log.Warnw("did not expect an event entry with a non-raw codec", "codec", entry.Codec, "key", entry.Key) + return nil, nil, false + } // Check if the key is t1..t4 if len(entry.Key) == 2 && "t1" <= entry.Key && entry.Key <= "t4" { // '1' - '1' == 0, etc. @@ -1372,16 +1377,13 @@ func ethLogFromEvent(entries []types.EventEntry) (data []byte, topics []ethtypes // Drop events with mis-sized topics. if len(entry.Value) != 32 { - return nil, nil, false - } - - // Drop events with non-raw topics to avoid mistakes. - if entry.Codec != cid.Raw { + log.Warnw("got an EVM event topic with an invalid size", "key", entry.Key, "size", len(entry.Value)) return nil, nil, false } // Drop events with duplicate topics. if topicsFound[idx] { + log.Warnw("got a duplicate EVM event topic", "key", entry.Key) return nil, nil, false } topicsFound[idx] = true @@ -1393,25 +1395,25 @@ func ethLogFromEvent(entries []types.EventEntry) (data []byte, topics []ethtypes } copy(topics[idx][:], entry.Value) } else if entry.Key == "d" { - // Drop events with non-raw data to avoid mistakes. - if entry.Codec != cid.Raw { - return nil, nil, false - } - // Drop events with duplicate data fields. if dataFound { + log.Warnw("got duplicate EVM event data") return nil, nil, false } dataFound = true data = entry.Value + } else { + // Skip entries we don't understand (makes it easier to extend things). + // But we warn for now because we don't expect them. + log.Warnw("unexpected event entry", "key", entry.Key) } - // Skip entries we don't understand (makes it easier to extend things). } // Drop events with skipped topics. if len(topics) != topicsFoundCount { + log.Warnw("EVM event topic length mismatch", "expected", len(topics), "actual", topicsFoundCount) return nil, nil, false } return data, topics, true