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

Domain Type Discovery #1039

Merged
merged 16 commits into from
Oct 30, 2023
Merged

Domain Type Discovery #1039

merged 16 commits into from
Oct 30, 2023

Conversation

moshe-blox
Copy link
Contributor

@moshe-blox moshe-blox commented Jun 29, 2023

This PR introduces domain type-based peer discovery to our discovery service.

The code now checks for domain type compatibility when discovering peers. A mismatched domain type results in the node being skipped, ensuring nodes connect only with peers in the same domain. The domain type of each node is stored in the Ethereum Node Record (ENR).

We also adjust how we decorate node records, moving away from a map[string]interface{}-based approach to using type-safe decorators for the different parameters.

Incidentally, the field operatorID has been removed from the node record because it exposes the operator's IP address (plus, it was unused).

This upgrade ensures better network segmentation and can help to prevent potential cross-talk between nodes operating in different network domains, which we've recently witnessed on JatoV1 & JatoV2.

@moshe-blox
Copy link
Contributor Author

moshe-blox commented Jun 29, 2023

image

Something is wrong with the GitHub actions, says "unused" but it's used just below 😅

network/discovery/dv5_service.go Outdated Show resolved Hide resolved
network/discovery/dv5_service.go Outdated Show resolved Hide resolved
@moshe-blox
Copy link
Contributor Author

TODO: check the domain type in handshake as well as discovery (in case the discovery record was out of date)

@y0sher
Copy link
Contributor

y0sher commented Aug 23, 2023

TODO: check the domain type in handshake as well as discovery (in case the discovery record was out of date)

are you planning to do it as part of this PR or should we create a ticket for it?

Comment on lines 361 to 362
genesis.DecorateWithDomainType(dvs.domainType),
genesis.DecorateWithSubnets(opts.Subnets),
Copy link
Contributor

Choose a reason for hiding this comment

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

should genesis be hardcoded? shouldn't it be derived from the domain type? probably relates to what @olegshmuelov is working on right now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

now that forks are removed, these became package methods

@moshe-blox moshe-blox marked this pull request as ready for review August 28, 2023 15:58
y0sher
y0sher previously approved these changes Aug 30, 2023
Copy link
Contributor

@y0sher y0sher left a comment

Choose a reason for hiding this comment

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

Good! this should solve the connections with different network IDs?

@moshe-blox
Copy link
Contributor Author

Good! this should solve the connections with different network IDs?

yes

however, you'd still get messages from peers with different domain type until the handshake fails and the connection is closed, but i guess that's a different PR, no?

Comment on lines 137 to 146
nodeDomainType, err := records.GetDomainTypeEntry(e.Node.Record())
if err != nil {
logger.Debug("could not read domain type", zap.Error(err))
return
}
if nodeDomainType != dvs.domainType {
logger.Debug("skipping node with different domain type")
return
}

Choose a reason for hiding this comment

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

@moshe-blox
Due to it being not backward compatible and requiring a fork, let's not enforce the check.
and add it once we ready with fork support

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@moshe-blox
Copy link
Contributor Author

moshe-blox commented Sep 5, 2023

I just noticed that discovery rejects peers without shared subnets only when we're at the connection limit, however the handshake rejects them in either case (iirc).

So we should either match this condition in the handshake as well or remove it altogether.

y0sher
y0sher previously approved these changes Sep 6, 2023
nkryuchkov
nkryuchkov previously approved these changes Oct 6, 2023
}

dvs.subnetsIdx.UpdatePeerSubnets(e.AddrInfo.ID, nodeSubnets)
if !dvs.limitNodeFilter(e.Node) {
Copy link
Contributor

Choose a reason for hiding this comment

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

can these two ifs be combined?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

func DecorateNode(node *enode.LocalNode, decorations ...NodeRecordDecoration) error {
for _, decoration := range decorations {
if err := decoration(node); err != nil {
return errors.Wrap(err, "failed to decorate node record")
Copy link
Contributor

Choose a reason for hiding this comment

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

let's use fmt.Errorf for new code because github.com/pkg/errors is discontinued

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@moshe-blox moshe-blox dismissed stale reviews from nkryuchkov and y0sher via 8a04a9c October 9, 2023 07:34
@moshe-blox moshe-blox requested a review from y0sher October 9, 2023 07:35
nkryuchkov
nkryuchkov previously approved these changes Oct 9, 2023
@moshe-blox
Copy link
Contributor Author

No changes, just forgot to revert .gitlab-ci.yml

@liorrutenberg liorrutenberg merged commit db963c9 into stage Oct 30, 2023
5 checks passed
@liorrutenberg liorrutenberg deleted the domain-type-discovery branch October 30, 2023 11:35
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.

4 participants