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

Support parsing altair sync committee gossip topics #2589

Merged
merged 3 commits into from
May 31, 2021

Conversation

dapplion
Copy link
Contributor

@dapplion dapplion commented May 30, 2021

Motivation

Gossip topic parser does not support altair sync committee topics.

Description

I've refactored the parsing functions to not use a Regex. Also now Typescript won't compile if we forget to add tests for new GossipType.

Closes #2588

@github-actions github-actions bot added the scope-networking All issues related to networking, gossip, and libp2p. label May 30, 2021
@codeclimate
Copy link

codeclimate bot commented May 30, 2021

Code Climate has analyzed commit 8b7f1d8 and detected 1 issue on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 1

View more on Code Climate.

return `/eth2/${forkDigestHex}/${topicType}/${topic.encoding ?? DEFAULT_ENCODING}`;
const forkDigestHexNoPrefix = toHexStringNoPrefix(forkDigest);
const topicType = stringifyGossipTopicType(topic);
return [topicPrefix, forkDigestHexNoPrefix, topicType, topic.encoding ?? DEFAULT_ENCODING].join("/");
Copy link
Contributor

Choose a reason for hiding this comment

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

is this "/" or "_"?

Copy link
Contributor

Choose a reason for hiding this comment

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

nvm, should be "/"

// eslint-disable-next-line @typescript-eslint/naming-convention
export const AttestationSubnetRegExp = new RegExp("^/eth2/[a-f0-9]{8}/beacon_attestation_([0-9]+)/\\w+$");
const topicStrNoPrefix = topicStr.slice(topicPrefix.length + 1); // +1 for the second '/' in '/eth2/...'
const [forkDigestHexNoPrefix, gossipTypeStr, encodingStr] = topicStrNoPrefix.split("/");
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const [forkDigestHexNoPrefix, gossipTypeStr, encodingStr] = topicStrNoPrefix.split("/");
const [,,forkDigestHexNoPrefix, gossipTypeStr, encodingStr] = topicStrNoPrefix.split("/");

I think that now you can remove slice line above. Maybe it will be a little bit easier to read code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But it's not the same logic, you are doing extra work since you have to run .split() on extra characters that you already now are not useful.

Copy link
Member

Choose a reason for hiding this comment

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

do you think that split vs slice would have notable performance impact?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

do you think that split vs slice would have notable performance impact?

Maybe, I've not quantified it. Tho this is a hot path since we want to process a lot of gossip objects per second. To understand your proposal do you suggest

const [,,forkDigestHexNoPrefix, gossipTypeStr, encodingStr] = topicStrNoPrefix.split("/");

or

const [,,forkDigestHexNoPrefix, gossipTypeStr, encodingStr] = topicStr.split("/");

?

Assuming the latter I don't see the advantage of the [,, syntax towards readability, such that it justifies doing extra unnecessary work. I can add more comments to make the intention and rationale more clear.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've benchmark it and

  • splice is very fast, 250000 opts / ms
  • split is costlier at 2000 opts / ms

Using a regex is slightly faster to extract topic parts (~10%) so I've updated that.

twoeths
twoeths previously approved these changes May 31, 2021
@wemeetagain wemeetagain merged commit 1b85078 into master May 31, 2021
@wemeetagain wemeetagain deleted the dapplion/sync-gossip branch May 31, 2021 22:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope-networking All issues related to networking, gossip, and libp2p.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bad gossip topic type: sync_committee_0
4 participants