swarm/network: Revert WaitTillHealthy change (deferred to nxt PR)

This commit is contained in:
lash 2018-12-20 11:02:46 +01:00
parent a5953f6b75
commit 89ea2fe97f
12 changed files with 49 additions and 52 deletions

View file

@ -751,14 +751,14 @@ func (k *Kademlia) connectedNeighbours(peers [][]byte) (got bool, n int, missing
// Health state of the Kademlia
// used for testing only
type Health struct {
KnowNN bool // whether node knows all its nearest neighbours
CountKnowNN int // amount of nearest neighbors connected to
CulpritsKnowNN [][]byte // which known NNs are missing
GotNN bool // whether node is connected to all its nearest neighbours
CountGotNN int // amount of nearest neighbors connected to
CulpritsGotNN [][]byte // which known NNs are missing
Saturated bool // whether we have all the peers we'd like to have
Hive string
KnowNN bool // whether node knows all its nearest neighbours
CountKnowNN int // amount of nearest neighbors connected to
CulpritsKnowNN [][]byte // which known NNs are missing
ConnectNN bool // whether node is connected to all its nearest neighbours
CountConnectNN int // amount of nearest neighbors connected to
CulpritsConnectNN [][]byte // which known NNs are missing
Saturated bool // whether we have all the peers we'd like to have
Hive string
}
// Healthy reports the health state of the kademlia connectivity
@ -773,13 +773,13 @@ func (k *Kademlia) Healthy(pp *PeerPot) *Health {
saturated := k.saturation() < depth
log.Trace(fmt.Sprintf("%08x: healthy: knowNNs: %v, gotNNs: %v, saturated: %v\n", k.base, knownn, gotnn, saturated))
return &Health{
KnowNN: knownn,
CountKnowNN: countknownn,
CulpritsKnowNN: culpritsknownn,
GotNN: gotnn,
CountGotNN: countgotnn,
CulpritsGotNN: culpritsgotnn,
Saturated: saturated,
Hive: k.string(),
KnowNN: knownn,
CountKnowNN: countknownn,
CulpritsKnowNN: culpritsknownn,
ConnectNN: gotnn,
CountConnectNN: countgotnn,
CulpritsConnectNN: culpritsgotnn,
Saturated: saturated,
Hive: k.string(),
}
}

View file

@ -59,7 +59,7 @@ func ExampleSimulation_WaitTillHealthy() {
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
defer cancel()
ill, err := sim.WaitTillHealthy(ctx)
ill, err := sim.WaitTillHealthy(ctx, 2)
if err != nil {
// inspect the latest detected not healthy kademlias
for id, kad := range ill {

View file

@ -34,7 +34,7 @@ var BucketKeyKademlia BucketKey = "kademlia"
// WaitTillHealthy is blocking until the health of all kademlias is true.
// If error is not nil, a map of kademlia that was found not healthy is returned.
// TODO: Check correctness since change in kademlia depth calculation logic
func (s *Simulation) WaitTillHealthy(ctx context.Context) (ill map[enode.ID]*network.Kademlia, err error) {
func (s *Simulation) WaitTillHealthy(ctx context.Context, kadMinProxSize int) (ill map[enode.ID]*network.Kademlia, err error) {
// Prepare PeerPot map for checking Kademlia health
var ppmap map[string]*network.PeerPot
kademlias := s.kademlias()
@ -43,7 +43,7 @@ func (s *Simulation) WaitTillHealthy(ctx context.Context) (ill map[enode.ID]*net
for _, k := range kademlias {
addrs = append(addrs, k.BaseAddr())
}
ppmap = network.NewPeerPotMap(s.minProxBinSize, addrs)
ppmap = network.NewPeerPotMap(kadMinProxSize, addrs)
// Wait for healthy Kademlia on every node before checking files
ticker := time.NewTicker(200 * time.Millisecond)
@ -67,10 +67,10 @@ func (s *Simulation) WaitTillHealthy(ctx context.Context) (ill map[enode.ID]*net
h := k.Healthy(pp)
//print info
log.Debug(k.String())
log.Debug("kademlia", "gotNN", h.GotNN, "knowNN", h.KnowNN)
log.Debug("kademlia", "health", h.GotNN && h.KnowNN, "addr", hex.EncodeToString(k.BaseAddr()), "node", id)
log.Debug("kademlia", "ill condition", !h.GotNN, "addr", hex.EncodeToString(k.BaseAddr()), "node", id)
if !h.GotNN {
log.Debug("kademlia", "connectNN", h.ConnectNN, "knowNN", h.KnowNN)
log.Debug("kademlia", "health", h.ConnectNN && h.KnowNN, "addr", hex.EncodeToString(k.BaseAddr()), "node", id)
log.Debug("kademlia", "ill condition", !h.ConnectNN, "addr", hex.EncodeToString(k.BaseAddr()), "node", id)
if !h.ConnectNN {
ill[id] = k
}
}

View file

@ -54,7 +54,7 @@ func TestWaitTillHealthy(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
defer cancel()
ill, err := sim.WaitTillHealthy(ctx)
ill, err := sim.WaitTillHealthy(ctx, 2)
if err != nil {
for id, kad := range ill {
t.Log("Node", id)

View file

@ -28,7 +28,6 @@ import (
"github.com/ethereum/go-ethereum/p2p/enode"
"github.com/ethereum/go-ethereum/p2p/simulations"
"github.com/ethereum/go-ethereum/p2p/simulations/adapters"
"github.com/ethereum/go-ethereum/swarm/network"
)
// Common errors that are returned by functions in this package.
@ -43,14 +42,13 @@ type Simulation struct {
// of p2p/simulations.Network.
Net *simulations.Network
serviceNames []string
cleanupFuncs []func()
buckets map[enode.ID]*sync.Map
pivotNodeID *enode.ID
shutdownWG sync.WaitGroup
done chan struct{}
mu sync.RWMutex
minProxBinSize int
serviceNames []string
cleanupFuncs []func()
buckets map[enode.ID]*sync.Map
pivotNodeID *enode.ID
shutdownWG sync.WaitGroup
done chan struct{}
mu sync.RWMutex
httpSrv *http.Server //attach a HTTP server via SimulationOptions
handler *simulations.Server //HTTP handler for the server
@ -74,9 +72,8 @@ type ServiceFunc func(ctx *adapters.ServiceContext, bucket *sync.Map) (s node.Se
// which is used to start node.Service returned by ServiceFunc.
func New(services map[string]ServiceFunc) (s *Simulation) {
s = &Simulation{
buckets: make(map[enode.ID]*sync.Map),
done: make(chan struct{}),
minProxBinSize: network.NewKadParams().MinProxBinSize,
buckets: make(map[enode.ID]*sync.Map),
done: make(chan struct{}),
}
adapterServices := make(map[string]adapters.ServiceFunc, len(services))

View file

@ -289,8 +289,8 @@ func discoverySimulation(nodes, conns int, adapter adapters.NodeAdapter) (*simul
if err := client.Call(&healthy, "hive_healthy", ppmap); err != nil {
return false, fmt.Errorf("error getting node health: %s", err)
}
log.Info(fmt.Sprintf("node %4s healthy: got nearest neighbours: %v, know nearest neighbours: %v,\n\n%v", id, healthy.GotNN, healthy.KnowNN, healthy.Hive))
return healthy.KnowNN && healthy.GotNN, nil
log.Info(fmt.Sprintf("node %4s healthy: connected nearest neighbours: %v, know nearest neighbours: %v,\n\n%v", id, healthy.ConnectNN, healthy.KnowNN, healthy.Hive))
return healthy.KnowNN && healthy.ConnectNN, nil
}
// 64 nodes ~ 1min
@ -409,7 +409,7 @@ func discoveryPersistenceSimulation(nodes, conns int, adapter adapters.NodeAdapt
return fmt.Errorf("error getting node health: %s", err)
}
log.Info(fmt.Sprintf("NODE: %s, IS HEALTHY: %t", addr, healthy.GotNN && healthy.KnowNN && healthy.CountKnowNN > 0))
log.Info(fmt.Sprintf("NODE: %s, IS HEALTHY: %t", addr, healthy.ConnectNN && healthy.KnowNN && healthy.CountKnowNN > 0))
var nodeStr string
if err := client.Call(&nodeStr, "hive_string"); err != nil {
return fmt.Errorf("error getting node string %s", err)
@ -418,7 +418,7 @@ func discoveryPersistenceSimulation(nodes, conns int, adapter adapters.NodeAdapt
for _, a := range addrs {
log.Info(common.Bytes2Hex(a))
}
if !healthy.GotNN || healthy.CountKnowNN == 0 {
if !healthy.ConnectNN || healthy.CountKnowNN == 0 {
isHealthy = false
break
}
@ -497,9 +497,9 @@ func discoveryPersistenceSimulation(nodes, conns int, adapter adapters.NodeAdapt
if err := client.Call(&healthy, "hive_healthy", ppmap); err != nil {
return false, fmt.Errorf("error getting node health: %s", err)
}
log.Info(fmt.Sprintf("node %4s healthy: got nearest neighbours: %v, know nearest neighbours: %v", id, healthy.GotNN, healthy.KnowNN))
log.Info(fmt.Sprintf("node %4s healthy: got nearest neighbours: %v, know nearest neighbours: %v", id, healthy.ConnectNN, healthy.KnowNN))
return healthy.KnowNN && healthy.GotNN, nil
return healthy.KnowNN && healthy.ConnectNN, nil
}
// 64 nodes ~ 1min

View file

@ -542,7 +542,7 @@ func testDeliveryFromNodes(t *testing.T, nodes, conns, chunkCount int, skipCheck
log.Debug("Waiting for kademlia")
// TODO this does not seem to be correct usage of the function, as the simulation may have no kademlias
if _, err := sim.WaitTillHealthy(ctx); err != nil {
if _, err := sim.WaitTillHealthy(ctx, 2); err != nil {
return err
}
@ -692,7 +692,7 @@ func benchmarkDeliveryFromNodes(b *testing.B, nodes, conns, chunkCount int, skip
}
netStore := item.(*storage.NetStore)
if _, err := sim.WaitTillHealthy(ctx); err != nil {
if _, err := sim.WaitTillHealthy(ctx, 2); err != nil {
return err
}

View file

@ -113,7 +113,7 @@ func testIntervals(t *testing.T, live bool, history *Range, skipCheck bool) {
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
defer cancel()
if _, err := sim.WaitTillHealthy(ctx); err != nil {
if _, err := sim.WaitTillHealthy(ctx, 2); err != nil {
t.Fatal(err)
}

View file

@ -197,7 +197,7 @@ func runFileRetrievalTest(nodeCount int) error {
if err != nil {
return err
}
if _, err := sim.WaitTillHealthy(ctx); err != nil {
if _, err := sim.WaitTillHealthy(ctx, 2); err != nil {
return err
}
@ -287,7 +287,7 @@ func runRetrievalTest(chunkCount int, nodeCount int) error {
if err != nil {
return err
}
if _, err := sim.WaitTillHealthy(ctx); err != nil {
if _, err := sim.WaitTillHealthy(ctx, 2); err != nil {
return err
}

View file

@ -203,7 +203,7 @@ func testSyncingViaGlobalSync(t *testing.T, chunkCount int, nodeCount int) {
ctx, cancelSimRun := context.WithTimeout(context.Background(), 2*time.Minute)
defer cancelSimRun()
if _, err := sim.WaitTillHealthy(ctx); err != nil {
if _, err := sim.WaitTillHealthy(ctx, 2); err != nil {
t.Fatal(err)
}
@ -385,7 +385,7 @@ func testSyncingViaDirectSubscribe(t *testing.T, chunkCount int, nodeCount int)
return err
}
if _, err := sim.WaitTillHealthy(ctx); err != nil {
if _, err := sim.WaitTillHealthy(ctx, 2); err != nil {
return err
}
@ -463,7 +463,7 @@ func testSyncingViaDirectSubscribe(t *testing.T, chunkCount int, nodeCount int)
conf.hashes = append(conf.hashes, hashes...)
mapKeysToNodes(conf)
if _, err := sim.WaitTillHealthy(ctx); err != nil {
if _, err := sim.WaitTillHealthy(ctx, 2); err != nil {
return err
}

View file

@ -179,7 +179,7 @@ func testSyncBetweenNodes(t *testing.T, nodes, conns, chunkCount int, skipCheck
}
}
// here we distribute chunks of a random file into stores 1...nodes
if _, err := sim.WaitTillHealthy(ctx); err != nil {
if _, err := sim.WaitTillHealthy(ctx, 2); err != nil {
return err
}

View file

@ -353,7 +353,7 @@ func testSwarmNetwork(t *testing.T, o *testSwarmNetworkOptions, steps ...testSwa
}
if *waitKademlia {
if _, err := sim.WaitTillHealthy(ctx); err != nil {
if _, err := sim.WaitTillHealthy(ctx, 2); err != nil {
return err
}
}