Skip to content
This repository has been archived by the owner on Aug 2, 2021. It is now read-only.

Leaner swarm/network and p2p/simulations #1076

Closed
wants to merge 18 commits into from
Closed

Conversation

frncmx
Copy link
Contributor

@frncmx frncmx commented Dec 20, 2018

This PR is related to #1059 where we want to move node.go from swarm/network to p2p/simulations.

This PR does not achieve that yet, but already became quite huge. So let's try to merge till I continue the move.

@frncmx frncmx requested a review from lmars as a code owner December 20, 2018 14:02
Ferenc Szabo added 14 commits December 24, 2018 17:51
Only AddNode() had some valid use cases for AddNodeOption, but yet
the params were propagated everywhere.
As I surprised myself it works even with 0 or 1 nodes.
Added no useful functionality as it was just combining 2 simple
methods and the function was only used in its own test.
The method was used only its own test.
As the concept and the related functionality was not used anywhere.
As the concept and the related functionality was not used anywhere.
That also makes AddNodeOption type and the AddNode's AddNodeOptions
parameter unnecessary.
As we can just call Stop() on Network.
The utility of this function was very low. The method just combined
two simple calls into one and was used in only one place.

Note: verifyRing() now can be private.
This was the lat mixed responsibility function in node.go, i.e.,
not just adding but connecting nodes. As the responsibility of
connecting nodes belongs to p2p/simulations/connect.go I removed the
method.

Note: there was just one complex use case for AddNodesAndConnectChain
in testSwarmNetwork where we actually added nodes more than once and
we still wanted to keep them in chain topology. There I introduced
a test helper function.
swarm/network_test.go Outdated Show resolved Hide resolved
swarm/network/simulation/node.go Outdated Show resolved Hide resolved
// AddNodesAndConnectChain is a helpper method that combines
// AddNodes and ConnectNodesChain. The chain will be continued from the last
// added node, if there is one in simulation using ConnectToLastNode method.
func (s *Simulation) AddNodesAndConnectChain(count int, opts ...AddNodeOption) (ids []enode.ID, err error) {
Copy link
Member

Choose a reason for hiding this comment

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

the AddNodeOption should stay. we need to be able to control the configurations of the nodes that are being initialised

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 found no use case for that in the actual code. Do we have something in progress where we need that opts argument?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I've read that but I did not connect the two. Still, there we say "maybe in the future" and I would say YAGNI on that . If that is not too harsh from me. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The commented code was removed eventually. However, AddNodeOption was brought back for AddNode() and AddNodes().

Ferenc Szabo added 3 commits December 26, 2018 12:11
The deleted methods were all unused. So I don't want to maintain them
during refactor.
- typos
- unused global variable
- unused function parameters
- redundant import alias
- code style issue: snake case
- typos
- redundant import alias
@frncmx frncmx changed the title [wip] Leaner swarm/network and p2p/simulations Leaner swarm/network and p2p/simulations Dec 27, 2018
During my code cleanup efforts I removed the AddNodeOption type and
related functionality. As that was not used anywhere.

However, during code review I was asked to bring back the functionality.
Here I'm doing that; still, I would prefer to follow YAGNI.
Copy link
Member

@zelig zelig left a comment

Choose a reason for hiding this comment

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

i disagree with this entire pr.
in general i wonder why we spending time on one of the best qualuty code in our code base.
typos and unexports aside i would revert all changes.

@acud
Copy link
Member

acud commented Jan 3, 2019

In its current form me too. As mentioned before I disagree with removing the topology functions

@frncmx
Copy link
Contributor Author

frncmx commented Jan 4, 2019

Ok. I'll cherry-pick the inspection fixes.


@justelad and I had a little confusion around the concept of pivot, if I remember correctly. That concept is also used nowhere. But we still spent time on it and kinda duplicated the functionality when we moved connect.go.

May I keep the commits removing the concept of pivot at least? Other commits I can let go.

@frncmx
Copy link
Contributor Author

frncmx commented Jan 4, 2019

Inspection fixes =>
ethereum/go-ethereum#18393

@frncmx frncmx closed this Jan 4, 2019
@frncmx frncmx deleted the sim-move-node-methods branch January 4, 2019 15:28
@frncmx frncmx removed their assignment Jan 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants