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: add peer to PeerTable on admin_addPeer #1177

Merged

Conversation

br0tchain
Copy link
Contributor

PR description

Handle peerAdded event on admin_addPeer to add the peer to the PeerTable
Handle peerRemoved event on admin_removePeer to remove the peer from the PeerTable

Fixed Issue(s)

fixes #560

Signed-off-by: Alexandre PARIS-VERGNE alexpv14@gmail.com

handle peerAdded on admin_addPeer to add the peer to the PeerTable
handle peerRemoved on admin_removePeer to remove the peer from the PeerTable

Signed-off-by: Alexandre PARIS-VERGNE <alexpv14@gmail.com>
@br0tchain br0tchain marked this pull request as ready for review June 30, 2020 19:14
peerPermissions,
natService,
metricsSystem,
maintainedPeers::subscribeAdd,
Copy link
Contributor

Choose a reason for hiding this comment

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

This feels too convoluted and inverted. Passing just the subscribe methods does not keep the type from needing to be known by the classes doing the subscriptions. It also impairs readability so I have no idea what object I am ultimately subscribing to. I think it would be cleaner to pass the maintainedPeers instance as part of the constructor chain instead of two curried methods and then in the PeerDiscoveryController method call

    maintainedPeers.subscribeAdd(this::onPeerAdded);
    maintainedPeers.subscribeRemove(this::onPeerRemoved);

If we want the discovery controller to be removable and re-installable we could then track the subscription IDs and then also keep a reference to the maintainedPeers object for un-installation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @shemnon, thank you for your review. Unfortunately I won't have enough time to fix this before leaving on holidays so I'll get back into it when as soon as I can.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @shemnon, I've fixed this as you suggested, it's more readable this way :)

@MadelineMurray
Copy link
Contributor

@br0tchain @shemnon - will this change anything around the peer modifications not being persisted? For context, this is what's currently included in the docs around admin_addPeer and admin_removePeer - https://besu.hyperledger.org/en/stable/HowTo/Find-and-Connect/Static-Nodes/#configure-static-nodes

@br0tchain
Copy link
Contributor Author

Hey @MadelineMurray , sorry for the late response. No it won't change anything about the peer persistence, it will just add it to the Peer Table so it will be erased when the peer reboots.

@br0tchain br0tchain force-pushed the feature/560-addpeer-to-peer-table branch 2 times, most recently from d8513aa to 9631974 Compare August 2, 2020 18:04
…subscription

Signed-off-by: Alexandre PARIS-VERGNE <alexpv14@gmail.com>
Signed-off-by: Alexandre PARIS-VERGNE <alexpv14@gmail.com>
@br0tchain br0tchain force-pushed the feature/560-addpeer-to-peer-table branch from 9631974 to 08444d8 Compare August 2, 2020 18:05
Signed-off-by: Alexandre PARIS-VERGNE <alexpv14@gmail.com>
@MadelineMurray
Copy link
Contributor

@br0tchain - no worries and thanks for the clarification.

@shemnon
Copy link
Contributor

shemnon commented Aug 5, 2020

@br0tchain is this ready for merge?

@br0tchain
Copy link
Contributor Author

I think so, I've just updated it with the latest master.

@shemnon shemnon merged commit bfcef53 into hyperledger:master Aug 5, 2020
@@ -195,6 +201,18 @@ private PeerDiscoveryController(
"type");
}

private void onPeerAdded(final Peer peer, final boolean wasAdded) {
if (wasAdded) {
addToPeerTable(DiscoveryPeer.fromEnode(peer.getEnodeURL()));
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't look right. As we discussed in the issue, we should bond to the peer rather than just adding them to our peer table and immediately advertising the node to the network.

Copy link
Contributor

Choose a reason for hiding this comment

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

Added a follow-up ticket to address since this is already merged: #1278

@@ -81,13 +82,15 @@
/* Is discovery enabled? */
private boolean isActive = false;
protected final Subscribers<PeerBondedObserver> peerBondedObservers = Subscribers.create();
private final MaintainedPeers maintainedPeers;
Copy link
Contributor

Choose a reason for hiding this comment

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

A simpler way of implementing this would be to call the publicly exposed method PeerDiscoveryAgent.bond() from P2PNetwork.addMaintainConnection.


private void onPeerRemoved(final Peer peer, final boolean wasRemoved) {
if (wasRemoved) {
peerTable.tryEvict(peer);
Copy link
Contributor

@mbaxter mbaxter Aug 5, 2020

Choose a reason for hiding this comment

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

Do we need this logic? Honestly not sure if we do or not, but it's a little unexpected at first glance.

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.

Define behaviour of admin_addPeer regarding PeerTable
5 participants