Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: eth: harden event processing #10215

Merged
merged 4 commits into from
Feb 10, 2023
Merged

Conversation

Stebalien
Copy link
Member

This commit hardens event processing:

  1. Handles out of order topics.
  2. Ensures that topics are 32 bytes.
  3. Uses the correct type for topics.
  4. Detects duplicate topics/values.

)
for _, entry := range entries {
// Check if the key is t1..t4
if len(entry.Key) == 2 && "t1" <= entry.Key && entry.Key <= "t4" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would still like to hoist the key names as global vars. Can use EthTopicStart and EthTopicEnd, since we are now using range semantics. It just feels wrong to have constants buried inline here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be kind of dangerous. E.g., if someone decides to extend this to t12, it'll break.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean that the value being declared as a global variable will make it more prominent and subject to inadvertent changes? We can make it private to avoid programmatic mutations, but developer error can happen anywhere in the code. (not strongly held, we usually just define fixed arbitrary values as constants in most codebases)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I'm concerned about code distance. I want anyone changing them to read the code that uses them.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

node/impl/full/eth.go Outdated Show resolved Hide resolved
Comment on lines +1391 to +1395
for len(topics) <= idx {
topics = append(topics, ethtypes.EthHash{})
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: we can actually pre-initialize the slice as we expect exactly len(entries) - 1 topics. Then we can fail if we go beyond that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could probably also remove the topicsFoundCount counter.

Copy link
Member Author

@Stebalien Stebalien Feb 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm currently allowing for arbitrary entries.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I.e., len(entries) > len(topics).

This ensures they're always 32 bytes and padded, as required.
We now enforce the following rules:

1. No duplicate topics or data.
2. Topics must have 32 byte keys.
3. Topics may not be skipped. (e.g., no t1 & t3 without a t2).
4. Raw codecs.

We _don't_ require that topics/data be emitted in any specific order.

We _skip_ events with unknown keys. We _drop_ events that violate the
above rules.
We can remove these later as we add more event types, but this will aid
in debugging.
@arajasek arajasek merged commit 1996694 into release/v1.20.0 Feb 10, 2023
@arajasek arajasek deleted the steb/txhash-topic branch February 10, 2023 20:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants