mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 02:42:27 +00:00
swarm/network: Revert WaitTillHealthy change (deferred to nxt PR)
This commit is contained in:
parent
a5953f6b75
commit
89ea2fe97f
12 changed files with 49 additions and 52 deletions
|
|
@ -751,14 +751,14 @@ func (k *Kademlia) connectedNeighbours(peers [][]byte) (got bool, n int, missing
|
||||||
// Health state of the Kademlia
|
// Health state of the Kademlia
|
||||||
// used for testing only
|
// used for testing only
|
||||||
type Health struct {
|
type Health struct {
|
||||||
KnowNN bool // whether node knows all its nearest neighbours
|
KnowNN bool // whether node knows all its nearest neighbours
|
||||||
CountKnowNN int // amount of nearest neighbors connected to
|
CountKnowNN int // amount of nearest neighbors connected to
|
||||||
CulpritsKnowNN [][]byte // which known NNs are missing
|
CulpritsKnowNN [][]byte // which known NNs are missing
|
||||||
GotNN bool // whether node is connected to all its nearest neighbours
|
ConnectNN bool // whether node is connected to all its nearest neighbours
|
||||||
CountGotNN int // amount of nearest neighbors connected to
|
CountConnectNN int // amount of nearest neighbors connected to
|
||||||
CulpritsGotNN [][]byte // which known NNs are missing
|
CulpritsConnectNN [][]byte // which known NNs are missing
|
||||||
Saturated bool // whether we have all the peers we'd like to have
|
Saturated bool // whether we have all the peers we'd like to have
|
||||||
Hive string
|
Hive string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Healthy reports the health state of the kademlia connectivity
|
// Healthy reports the health state of the kademlia connectivity
|
||||||
|
|
@ -773,13 +773,13 @@ func (k *Kademlia) Healthy(pp *PeerPot) *Health {
|
||||||
saturated := k.saturation() < depth
|
saturated := k.saturation() < depth
|
||||||
log.Trace(fmt.Sprintf("%08x: healthy: knowNNs: %v, gotNNs: %v, saturated: %v\n", k.base, knownn, gotnn, saturated))
|
log.Trace(fmt.Sprintf("%08x: healthy: knowNNs: %v, gotNNs: %v, saturated: %v\n", k.base, knownn, gotnn, saturated))
|
||||||
return &Health{
|
return &Health{
|
||||||
KnowNN: knownn,
|
KnowNN: knownn,
|
||||||
CountKnowNN: countknownn,
|
CountKnowNN: countknownn,
|
||||||
CulpritsKnowNN: culpritsknownn,
|
CulpritsKnowNN: culpritsknownn,
|
||||||
GotNN: gotnn,
|
ConnectNN: gotnn,
|
||||||
CountGotNN: countgotnn,
|
CountConnectNN: countgotnn,
|
||||||
CulpritsGotNN: culpritsgotnn,
|
CulpritsConnectNN: culpritsgotnn,
|
||||||
Saturated: saturated,
|
Saturated: saturated,
|
||||||
Hive: k.string(),
|
Hive: k.string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ func ExampleSimulation_WaitTillHealthy() {
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
ill, err := sim.WaitTillHealthy(ctx)
|
ill, err := sim.WaitTillHealthy(ctx, 2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// inspect the latest detected not healthy kademlias
|
// inspect the latest detected not healthy kademlias
|
||||||
for id, kad := range ill {
|
for id, kad := range ill {
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ var BucketKeyKademlia BucketKey = "kademlia"
|
||||||
// WaitTillHealthy is blocking until the health of all kademlias is true.
|
// 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.
|
// 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
|
// 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
|
// Prepare PeerPot map for checking Kademlia health
|
||||||
var ppmap map[string]*network.PeerPot
|
var ppmap map[string]*network.PeerPot
|
||||||
kademlias := s.kademlias()
|
kademlias := s.kademlias()
|
||||||
|
|
@ -43,7 +43,7 @@ func (s *Simulation) WaitTillHealthy(ctx context.Context) (ill map[enode.ID]*net
|
||||||
for _, k := range kademlias {
|
for _, k := range kademlias {
|
||||||
addrs = append(addrs, k.BaseAddr())
|
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
|
// Wait for healthy Kademlia on every node before checking files
|
||||||
ticker := time.NewTicker(200 * time.Millisecond)
|
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)
|
h := k.Healthy(pp)
|
||||||
//print info
|
//print info
|
||||||
log.Debug(k.String())
|
log.Debug(k.String())
|
||||||
log.Debug("kademlia", "gotNN", h.GotNN, "knowNN", h.KnowNN)
|
log.Debug("kademlia", "connectNN", h.ConnectNN, "knowNN", h.KnowNN)
|
||||||
log.Debug("kademlia", "health", h.GotNN && h.KnowNN, "addr", hex.EncodeToString(k.BaseAddr()), "node", id)
|
log.Debug("kademlia", "health", h.ConnectNN && h.KnowNN, "addr", hex.EncodeToString(k.BaseAddr()), "node", id)
|
||||||
log.Debug("kademlia", "ill condition", !h.GotNN, "addr", hex.EncodeToString(k.BaseAddr()), "node", id)
|
log.Debug("kademlia", "ill condition", !h.ConnectNN, "addr", hex.EncodeToString(k.BaseAddr()), "node", id)
|
||||||
if !h.GotNN {
|
if !h.ConnectNN {
|
||||||
ill[id] = k
|
ill[id] = k
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ func TestWaitTillHealthy(t *testing.T) {
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
ill, err := sim.WaitTillHealthy(ctx)
|
ill, err := sim.WaitTillHealthy(ctx, 2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
for id, kad := range ill {
|
for id, kad := range ill {
|
||||||
t.Log("Node", id)
|
t.Log("Node", id)
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,6 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/p2p/enode"
|
"github.com/ethereum/go-ethereum/p2p/enode"
|
||||||
"github.com/ethereum/go-ethereum/p2p/simulations"
|
"github.com/ethereum/go-ethereum/p2p/simulations"
|
||||||
"github.com/ethereum/go-ethereum/p2p/simulations/adapters"
|
"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.
|
// Common errors that are returned by functions in this package.
|
||||||
|
|
@ -43,14 +42,13 @@ type Simulation struct {
|
||||||
// of p2p/simulations.Network.
|
// of p2p/simulations.Network.
|
||||||
Net *simulations.Network
|
Net *simulations.Network
|
||||||
|
|
||||||
serviceNames []string
|
serviceNames []string
|
||||||
cleanupFuncs []func()
|
cleanupFuncs []func()
|
||||||
buckets map[enode.ID]*sync.Map
|
buckets map[enode.ID]*sync.Map
|
||||||
pivotNodeID *enode.ID
|
pivotNodeID *enode.ID
|
||||||
shutdownWG sync.WaitGroup
|
shutdownWG sync.WaitGroup
|
||||||
done chan struct{}
|
done chan struct{}
|
||||||
mu sync.RWMutex
|
mu sync.RWMutex
|
||||||
minProxBinSize int
|
|
||||||
|
|
||||||
httpSrv *http.Server //attach a HTTP server via SimulationOptions
|
httpSrv *http.Server //attach a HTTP server via SimulationOptions
|
||||||
handler *simulations.Server //HTTP handler for the server
|
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.
|
// which is used to start node.Service returned by ServiceFunc.
|
||||||
func New(services map[string]ServiceFunc) (s *Simulation) {
|
func New(services map[string]ServiceFunc) (s *Simulation) {
|
||||||
s = &Simulation{
|
s = &Simulation{
|
||||||
buckets: make(map[enode.ID]*sync.Map),
|
buckets: make(map[enode.ID]*sync.Map),
|
||||||
done: make(chan struct{}),
|
done: make(chan struct{}),
|
||||||
minProxBinSize: network.NewKadParams().MinProxBinSize,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
adapterServices := make(map[string]adapters.ServiceFunc, len(services))
|
adapterServices := make(map[string]adapters.ServiceFunc, len(services))
|
||||||
|
|
|
||||||
|
|
@ -289,8 +289,8 @@ func discoverySimulation(nodes, conns int, adapter adapters.NodeAdapter) (*simul
|
||||||
if err := client.Call(&healthy, "hive_healthy", ppmap); err != nil {
|
if err := client.Call(&healthy, "hive_healthy", ppmap); err != nil {
|
||||||
return false, fmt.Errorf("error getting node health: %s", err)
|
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))
|
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.GotNN, nil
|
return healthy.KnowNN && healthy.ConnectNN, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 64 nodes ~ 1min
|
// 64 nodes ~ 1min
|
||||||
|
|
@ -409,7 +409,7 @@ func discoveryPersistenceSimulation(nodes, conns int, adapter adapters.NodeAdapt
|
||||||
return fmt.Errorf("error getting node health: %s", err)
|
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
|
var nodeStr string
|
||||||
if err := client.Call(&nodeStr, "hive_string"); err != nil {
|
if err := client.Call(&nodeStr, "hive_string"); err != nil {
|
||||||
return fmt.Errorf("error getting node string %s", err)
|
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 {
|
for _, a := range addrs {
|
||||||
log.Info(common.Bytes2Hex(a))
|
log.Info(common.Bytes2Hex(a))
|
||||||
}
|
}
|
||||||
if !healthy.GotNN || healthy.CountKnowNN == 0 {
|
if !healthy.ConnectNN || healthy.CountKnowNN == 0 {
|
||||||
isHealthy = false
|
isHealthy = false
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
@ -497,9 +497,9 @@ func discoveryPersistenceSimulation(nodes, conns int, adapter adapters.NodeAdapt
|
||||||
if err := client.Call(&healthy, "hive_healthy", ppmap); err != nil {
|
if err := client.Call(&healthy, "hive_healthy", ppmap); err != nil {
|
||||||
return false, fmt.Errorf("error getting node health: %s", err)
|
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
|
// 64 nodes ~ 1min
|
||||||
|
|
|
||||||
|
|
@ -542,7 +542,7 @@ func testDeliveryFromNodes(t *testing.T, nodes, conns, chunkCount int, skipCheck
|
||||||
|
|
||||||
log.Debug("Waiting for kademlia")
|
log.Debug("Waiting for kademlia")
|
||||||
// TODO this does not seem to be correct usage of the function, as the simulation may have no kademlias
|
// 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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -692,7 +692,7 @@ func benchmarkDeliveryFromNodes(b *testing.B, nodes, conns, chunkCount int, skip
|
||||||
}
|
}
|
||||||
netStore := item.(*storage.NetStore)
|
netStore := item.(*storage.NetStore)
|
||||||
|
|
||||||
if _, err := sim.WaitTillHealthy(ctx); err != nil {
|
if _, err := sim.WaitTillHealthy(ctx, 2); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -113,7 +113,7 @@ func testIntervals(t *testing.T, live bool, history *Range, skipCheck bool) {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
if _, err := sim.WaitTillHealthy(ctx); err != nil {
|
if _, err := sim.WaitTillHealthy(ctx, 2); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -197,7 +197,7 @@ func runFileRetrievalTest(nodeCount int) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if _, err := sim.WaitTillHealthy(ctx); err != nil {
|
if _, err := sim.WaitTillHealthy(ctx, 2); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -287,7 +287,7 @@ func runRetrievalTest(chunkCount int, nodeCount int) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if _, err := sim.WaitTillHealthy(ctx); err != nil {
|
if _, err := sim.WaitTillHealthy(ctx, 2); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -203,7 +203,7 @@ func testSyncingViaGlobalSync(t *testing.T, chunkCount int, nodeCount int) {
|
||||||
ctx, cancelSimRun := context.WithTimeout(context.Background(), 2*time.Minute)
|
ctx, cancelSimRun := context.WithTimeout(context.Background(), 2*time.Minute)
|
||||||
defer cancelSimRun()
|
defer cancelSimRun()
|
||||||
|
|
||||||
if _, err := sim.WaitTillHealthy(ctx); err != nil {
|
if _, err := sim.WaitTillHealthy(ctx, 2); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -385,7 +385,7 @@ func testSyncingViaDirectSubscribe(t *testing.T, chunkCount int, nodeCount int)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := sim.WaitTillHealthy(ctx); err != nil {
|
if _, err := sim.WaitTillHealthy(ctx, 2); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -463,7 +463,7 @@ func testSyncingViaDirectSubscribe(t *testing.T, chunkCount int, nodeCount int)
|
||||||
conf.hashes = append(conf.hashes, hashes...)
|
conf.hashes = append(conf.hashes, hashes...)
|
||||||
mapKeysToNodes(conf)
|
mapKeysToNodes(conf)
|
||||||
|
|
||||||
if _, err := sim.WaitTillHealthy(ctx); err != nil {
|
if _, err := sim.WaitTillHealthy(ctx, 2); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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
|
// 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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -353,7 +353,7 @@ func testSwarmNetwork(t *testing.T, o *testSwarmNetworkOptions, steps ...testSwa
|
||||||
}
|
}
|
||||||
|
|
||||||
if *waitKademlia {
|
if *waitKademlia {
|
||||||
if _, err := sim.WaitTillHealthy(ctx); err != nil {
|
if _, err := sim.WaitTillHealthy(ctx, 2); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue