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

[raft] fix double addPeer, should also check self. #1080

Merged
merged 2 commits into from
Oct 6, 2020

Conversation

libby
Copy link
Contributor

@libby libby commented Oct 2, 2020

When checking if an enode is already in the raft cluster, the node should
also check if it is adding its own enode.

This fixes the case where a node can be added twice by running raft.addPeer(enodeURL)
on itself, e.g. running on a node with the same enodeURL as the node being added.
The node will allow the enode to be added again, after which the cluster will be in a
weird state containing two peers with the same enodeURL, the duplicate peer will
be in a bad state and will not be conneted.

Fix by adding a check in isNodeAlreadyInClusteri(enode) to check if the enode is
the enode of running node, not just one of the peers.

When checking if an enode is already in the raft cluster, the node should
also check if it is adding its own enode.

This fixes the case where a node can be added twice by running `raft.addPeer(enodeURL)`
on itself, e.g. running on a node with the same enodeURL as the node being added.
The node will allow the enode to be added again, after which the cluster will be in a
weird state containing two peers with the same enodeURL, the duplicate peer will
be in a bad state and will not be conneted.

Fix by adding a check in `isNodeAlreadyInClusteri(enode)` to check if the enode is
the enode of running node, not just one of the peers.

In `minter_test.go` the p2p.Server is now mocked out when creating the
RaftService, this is necessary as `isNodeAlreadyInCluster` uses the
p2p.Server to check if this is the calling node (itself). Mocking out
the p2p.Server avoids a 'invalid memory address or
nil pointer dereference' exception thrown in the `minter_test.go`.
@libby libby force-pushed the fix-raft-double-add-to-self branch from 08e6ccc to d194a00 Compare October 5, 2020 17:49
@libby libby requested a review from vsmk98 October 6, 2020 13:17
@jpmsam jpmsam merged commit 2ae18c9 into Consensys:master Oct 6, 2020
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.

None yet

2 participants