Skip to content

Commit

Permalink
fix: eth: log on unexpected events
Browse files Browse the repository at this point in the history
We can remove these later as we add more event types, but this will aid
in debugging.
  • Loading branch information
Stebalien committed Feb 10, 2023
1 parent ece8f25 commit cc302dd
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions node/impl/full/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -1365,23 +1365,25 @@ 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.
idx := int(entry.Key[1] - '1')

// 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
Expand All @@ -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
Expand Down

0 comments on commit cc302dd

Please sign in to comment.