diff --git a/swarm/network/kademlia.go b/swarm/network/kademlia.go index 45fe955d83..92274bf1cf 100644 --- a/swarm/network/kademlia.go +++ b/swarm/network/kademlia.go @@ -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(), } } diff --git a/swarm/network/simulation/example_test.go b/swarm/network/simulation/example_test.go index 9cf72bab2c..a100ede516 100644 --- a/swarm/network/simulation/example_test.go +++ b/swarm/network/simulation/example_test.go @@ -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 { diff --git a/swarm/network/simulation/kademlia.go b/swarm/network/simulation/kademlia.go index d11af654c5..25bb0f6a9f 100644 --- a/swarm/network/simulation/kademlia.go +++ b/swarm/network/simulation/kademlia.go @@ -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 } } diff --git a/swarm/network/simulation/kademlia_test.go b/swarm/network/simulation/kademlia_test.go index e8b1eba8a8..f02b0e5417 100644 --- a/swarm/network/simulation/kademlia_test.go +++ b/swarm/network/simulation/kademlia_test.go @@ -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) diff --git a/swarm/network/simulation/simulation.go b/swarm/network/simulation/simulation.go index 81769df88e..106eeb71e9 100644 --- a/swarm/network/simulation/simulation.go +++ b/swarm/network/simulation/simulation.go @@ -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)) diff --git a/swarm/network/simulations/discovery/discovery_test.go b/swarm/network/simulations/discovery/discovery_test.go index 051aa0ff0c..bd86865220 100644 --- a/swarm/network/simulations/discovery/discovery_test.go +++ b/swarm/network/simulations/discovery/discovery_test.go @@ -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 diff --git a/swarm/network/stream/delivery_test.go b/swarm/network/stream/delivery_test.go index 2912c569a4..5c1f8c2512 100644 --- a/swarm/network/stream/delivery_test.go +++ b/swarm/network/stream/delivery_test.go @@ -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 } diff --git a/swarm/network/stream/intervals_test.go b/swarm/network/stream/intervals_test.go index b02a5909ea..7c7feeb112 100644 --- a/swarm/network/stream/intervals_test.go +++ b/swarm/network/stream/intervals_test.go @@ -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) } diff --git a/swarm/network/stream/snapshot_retrieval_test.go b/swarm/network/stream/snapshot_retrieval_test.go index d345ac8d02..a85d723297 100644 --- a/swarm/network/stream/snapshot_retrieval_test.go +++ b/swarm/network/stream/snapshot_retrieval_test.go @@ -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 } diff --git a/swarm/network/stream/snapshot_sync_test.go b/swarm/network/stream/snapshot_sync_test.go index 41d2ee314a..f86d9accac 100644 --- a/swarm/network/stream/snapshot_sync_test.go +++ b/swarm/network/stream/snapshot_sync_test.go @@ -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 } diff --git a/swarm/network/stream/syncer_test.go b/swarm/network/stream/syncer_test.go index e1e3d225fc..27ed49ea48 100644 --- a/swarm/network/stream/syncer_test.go +++ b/swarm/network/stream/syncer_test.go @@ -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 } diff --git a/swarm/network_test.go b/swarm/network_test.go index 71d4b8f16a..8a162a219e 100644 --- a/swarm/network_test.go +++ b/swarm/network_test.go @@ -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 } }