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

New Saturation for health implementation #1195

Closed
wants to merge 9 commits into from
Closed

Conversation

holisticode
Copy link
Contributor

@holisticode holisticode commented Feb 6, 2019

This PR introduces a new implementation for saturation.

Saturation is a prerequisite to consider a network healthy.
This is reflected with the new IsHealthyStrict() method.

A new function getUnsaturatedBins() has been added, which will return a list of unsaturated bins (array of int).

It is considered saturated if the length of the array is zero (equivalent to all bins below depth have the saturation criteria fulfilled).

A bin is saturated if we have connections >= MinBinSize or, if there are less connections than MinBinSize, the number of connections corresponds to the available number of peers in the PeerPot.

NOTE: The previous func (k *Kademlia) saturation() int has been left intact, as it is being used in the On function. It should be evaluated if the two are somewhat conflicting or what should be done about the existing saturation() function

Closes #1145
Closes #994

swarm/network/kademlia.go Outdated Show resolved Hide resolved
swarm/network/kademlia.go Outdated Show resolved Hide resolved
swarm/network/kademlia.go Outdated Show resolved Hide resolved
swarm/network/kademlia.go Show resolved Hide resolved
@@ -798,7 +839,10 @@ func (k *Kademlia) Healthy(pp *PeerPot) *Health {
gotnn, countgotnn, culpritsgotnn := k.connectedNeighbours(pp.NNSet)
knownn, countknownn, culpritsknownn := k.knowNeighbours(pp.NNSet)
depth := depthForPot(k.conns, k.NeighbourhoodSize, k.base)
saturated := k.saturation() < depth
// check saturation
unsaturatedBins := k.getUnsaturatedBins(pp.PeersPerBin, depth)
Copy link
Member

Choose a reason for hiding this comment

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

Note that now depth is not checked against the length of peersPerBin.
so if there are empty rows just after depth, the node will pass as healthy.

Copy link
Member

Choose a reason for hiding this comment

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

First create a testcase to show this problem

Copy link
Contributor Author

@holisticode holisticode Feb 7, 2019

Choose a reason for hiding this comment

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

I don't understand these comments.

Note that now depth is not checked against the length of peersPerBin.

peersPerBin HAS the length of depth

so if there are empty rows just after depth, the node will pass as healthy.
First create a testcase to show this problem

I can't create a Kademlia with an empty row "after" depth (do you mean shallower? or deeper?)
As far as I understand this is not even possible today anymore, as per definition depth will not allow shallower empty rows?

Copy link
Member

Choose a reason for hiding this comment

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

the real depth should be compared to the length of PeersPerBin. if they are not then
with only the nearest neighbours connected and having depth == 0, you pass the saturated test!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can we mark this as resolved?

swarm/network/kademlia.go Outdated Show resolved Hide resolved
@@ -836,7 +836,7 @@ func (k *Kademlia) GetHealthInfo(pp *PeerPot) *Health {

// check saturation
unsaturatedBins := k.getUnsaturatedBins(pp.PeersPerBin, depth)
saturated := len(unsaturatedBins) == 0 && depth == len(pp.PeersPerBin)
saturated := depth == len(pp.PeersPerBin) && len(unsaturatedBins) == 0
Copy link
Member

@zelig zelig Feb 12, 2019

Choose a reason for hiding this comment

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

can we please just put this check in the function, ie. return immediately if it is false?
maybe we should rename the function to checkSaturation and have it return an error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why return an error and not simply bool? There is nothing which can cause an error here.

It is either saturated or not. That is what is currently implemented

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.

just put the condition on the top of the function and then can submit upstream

@@ -725,7 +726,11 @@ func (k *Kademlia) getUnsaturatedBins(peersPerBin []int, depth int) []int {
})

log.Trace("list of unsaturated bins", "unsaturatedBins", unsaturatedBins)
return unsaturatedBins
// early check for depth
Copy link
Member

Choose a reason for hiding this comment

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

this should come BEFORE, if it is false you dont need to call the EachBin thing.

@holisticode
Copy link
Contributor Author

Created upstream as ethereum/go-ethereum#19071

@holisticode holisticode deleted the saturated branch February 28, 2019 17:45
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