fix: eth: log on unexpected events
We can remove these later as we add more event types, but this will aid in debugging.
This commit is contained in:
parent
ece8f25511
commit
cc302dd68b
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user