From dc64ddad69329d8b0262996f315835c986c37cd7 Mon Sep 17 00:00:00 2001 From: lash Date: Fri, 14 Dec 2018 12:40:59 +0100 Subject: [PATCH] swarm/network: Make test methods submethod of peerpot and embed kad --- swarm/network/hive.go | 6 ++++ swarm/network/kademlia.go | 24 ++++++++------ swarm/network/kademlia_test.go | 30 ++++++++++------- swarm/network/simulation/example_test.go | 2 +- swarm/network/simulation/kademlia.go | 16 +++++---- swarm/network/simulation/kademlia_test.go | 2 +- .../simulations/discovery/discovery_test.go | 33 +++++++++++++------ swarm/network/stream/delivery_test.go | 5 ++- swarm/network/stream/intervals_test.go | 3 +- .../network/stream/snapshot_retrieval_test.go | 4 +-- swarm/network/stream/snapshot_sync_test.go | 15 +++++---- swarm/network/stream/syncer_test.go | 3 +- .../visualized_snapshot_sync_sim_test.go | 2 +- swarm/network_test.go | 3 +- 14 files changed, 88 insertions(+), 60 deletions(-) diff --git a/swarm/network/hive.go b/swarm/network/hive.go index ebef545929..29441a3454 100644 --- a/swarm/network/hive.go +++ b/swarm/network/hive.go @@ -242,3 +242,9 @@ func (h *Hive) savePeers() error { } return nil } + +func (h *Hive) Healthy(addr []byte, pp PeerPot) *Health { + pp.base = addr + log.Error("pp", "p", pp, "base", pp.base) + return pp.Healthy() +} diff --git a/swarm/network/kademlia.go b/swarm/network/kademlia.go index 8f1a673a0c..2acd66d40d 100644 --- a/swarm/network/kademlia.go +++ b/swarm/network/kademlia.go @@ -62,7 +62,7 @@ type KadParams struct { RetryExponent int // exponent to multiply retry intervals with MaxRetries int // maximum number of redial attempts // function to sanction or prevent suggesting a peer - Reachable func(*BzzAddr) bool + Reachable func(*BzzAddr) bool `json:"-"` } // NewKadParams returns a params struct with default values @@ -89,7 +89,7 @@ type Kademlia struct { nDepth int // stores the last neighbourhood depth nDepthC chan int // returned by DepthC function to signal neighbourhood depth change addrCountC chan int // returned by AddrCountC function to signal peer count change - Pof func(pot.Val, pot.Val, int) (int, bool) // function for calculating kademlia routing distance between two addresses + Pof func(pot.Val, pot.Val, int) (int, bool) `json:"-"` // function for calculating kademlia routing distance between two addresses } // NewKademlia creates a Kademlia table for base address addr @@ -609,16 +609,20 @@ type PeerPot struct { // used for testing only // TODO move to separate testing tools file //func NewPeerPotMap(k *Kademlia, addrs [][]byte) map[string]*PeerPot { -func NewPeerPotMap(k *Kademlia, addrs [][]byte) map[string]*PeerPot { +func NewPeerPotMap(kads []*Kademlia) map[string]*PeerPot { // create a table of all nodes for health check np := pot.NewPot(nil, 0) - for _, addr := range addrs { - np, _, _ = pot.Add(np, addr, pof) + + for _, k := range kads { + np, _, _ = pot.Add(np, k.base, pof) } ppmap := make(map[string]*PeerPot) - for i, a := range addrs { + for i, k := range kads { + + // get the address to use + a := k.base // actual kademlia depth depth := depthForPot(np, k.MinProxBinSize, a) @@ -643,7 +647,7 @@ func NewPeerPotMap(k *Kademlia, addrs [][]byte) map[string]*PeerPot { return false }) - log.Trace(fmt.Sprintf("%x NNS: %s", addrs[i][:4], LogAddrs(nns))) + log.Trace(fmt.Sprintf("%x NNS: %s", kads[i].base[:4], LogAddrs(nns))) ppmap[common.Bytes2Hex(a)] = &PeerPot{ Kademlia: k, NNSet: nns, @@ -700,7 +704,7 @@ func (o *PeerPot) knowNearestNeighbours() (got bool, n int, missing [][]byte) { if pm[pk] { gots++ } else { - log.Trace(fmt.Sprintf("%08x: known nearest neighbour %s not found", o.BaseAddr()[:4], pk[:8])) + log.Trace(fmt.Sprintf("%08x: known nearest neighbour %s not found", o.base, pk)) //(o.BaseAddr()[:4], pk[:8])) culprits = append(culprits, p) } } @@ -736,7 +740,7 @@ func (o *PeerPot) gotNearestNeighbours() (got bool, n int, missing [][]byte) { if pm[pk] { gots++ } else { - log.Trace(fmt.Sprintf("%08x: ExpNN: %s not found", o.BaseAddr()[:4], pk[:8])) + log.Trace(fmt.Sprintf("%08x: ExpNN: %s not found", o.base, pk)) //o.BaseAddr()[:4], pk[:8])) culprits = append(culprits, p) } } @@ -766,7 +770,7 @@ func (o *PeerPot) Healthy() *Health { knownn, countknownn, culpritsknownn := o.knowNearestNeighbours() depth := depthForPot(o.conns, o.MinProxBinSize, o.base) saturated := o.saturation() < depth - log.Trace(fmt.Sprintf("%08x: healthy: knowNNs: %v, gotNNs: %v, saturated: %v\n", o.BaseAddr()[:4], knownn, gotnn, saturated)) + log.Trace(fmt.Sprintf("%08x: healthy: knowNNs: %v, gotNNs: %v, saturated: %v\n", o.base, knownn, gotnn, saturated)) return &Health{ KnowNN: knownn, CountKnowNN: countknownn, diff --git a/swarm/network/kademlia_test.go b/swarm/network/kademlia_test.go index 7a71f60486..424d485b4c 100644 --- a/swarm/network/kademlia_test.go +++ b/swarm/network/kademlia_test.go @@ -462,27 +462,33 @@ func TestKademliaHiveString(t *testing.T) { // the SuggestPeer and Healthy methods for provided hex-encoded addresses. // Argument pivotAddr is the address of the kademlia. func testKademliaCase(t *testing.T, pivotAddr string, addrs ...string) { - addr := common.FromHex(pivotAddr) + addr := common.Hex2Bytes(pivotAddr) addrs = append(addrs, pivotAddr) - k := NewKademlia(addr, NewKadParams()) + //k := NewKademlia(addr, NewKadParams()) - as := make([][]byte, len(addrs)) - for i, a := range addrs { - as[i] = common.FromHex(a) + var ks []*Kademlia + //as := make([][]byte, len(addrs)) + for _, a := range addrs { + ks = append(ks, NewKademlia(common.Hex2Bytes(a), NewKadParams())) + //as[i] = common.FromHex(a) } - for _, a := range as { + // our pivot kademlia is the last one in the array + k := ks[len(ks)-1] + //for _, a := range as { + for _, curk := range ks { + a := curk.base if bytes.Equal(a, addr) { continue } p := &BzzAddr{OAddr: a, UAddr: a} if err := k.Register(p); err != nil { - t.Fatal(err) + t.Fatalf("a %x addr %x: %v", a, addr, err) } } - ppmap := NewPeerPotMap(k, as) + ppmap := NewPeerPotMap(ks) pp := ppmap[pivotAddr] @@ -495,7 +501,7 @@ func testKademliaCase(t *testing.T, pivotAddr string, addrs ...string) { } h := pp.Healthy() - if !(h.GotNN && h.KnowNN && h.Saturated) { + if !(h.GotNN && h.KnowNN) { t.Fatalf("not healthy: %#v\n%v", h, k.String()) } } @@ -646,7 +652,7 @@ population: 8 (49), MinProxBinSize: 2, MinBinSize: 2, MaxBinSize: 4 ========================================================================= */ func TestKademliaCase3(t *testing.T) { - t.Skip("depth definition has changed, causing this case to be invalid. A new batch of test cases are needed ASAP") + //t.Skip("depth definition has changed, causing this case to be invalid. A new batch of test cases are needed ASAP") testKademliaCase(t, "b4822e874a01b94ac3a35c821e6db131e785c2fcbb3556e84b36102caf09b091", "2ecf54ea38d58f9cfc3862e54e5854a7c506fbc640e0b38e46d7d45a19794999", "442374092be50fc7392e8dd3f6fab3158ff7f14f26ff98060aed9b2eecf0b97d", "b450a4a67fcfa3b976cf023d8f1f15052b727f712198ce901630efe2f95db191", "9a7291638eb1c989a6dd6661a42c735b23ac6605b5d3e428aa5ffe650e892c85", "67f62eeab9804cfcac02b25ebeab9113d1b9d03dd5200b1c5a324cc0163e722f", "2e4a0e4b53bca4a9d7e2734150e9f579f29a255ade18a268461b20d026c9ee90", "30dd79c5fcdaa1b106f6960c45c9fde7c046aa3d931088d98c52ab759d0b2ac4", "97936fb5a581e59753c54fa5feec493714f2218245f61f97a62eafd4699433e4", "3a2899b6e129e3e193f6e2aefb82589c948c246d2ec1d4272af32ef3b2660f44", "f0e2a8aa88e67269e9952431ef12e5b29b7f41a1871fbfc38567fad95655d607", "7fa12b3f3c5f8383bfc644b958f72a486969733fa097d8952b3eb4f7b4f73192", "360c167aad5fc992656d6010ec45fdce5bcd492ad9608bc515e2be70d4e430c1", "fe21bc969b3d8e5a64a6484a829c1e04208f26f3cd4de6afcbc172a5bd17f1f1", "b660a1f40141d7ccd282fe5bd9838744119bd1cb3780498b5173578cc5ad308f", "44dcb3370e76680e2fba8cd986ad45ff0b77ca45680ee8d950e47922c4af6226", "8ca126923d17fccb689647307b89f38aa14e2a7b9ebcf3c1e31ccf3d2291a3bc", "f0ae19ae9ce6329327cbf42baf090e084c196b0877d8c7b69997e0123be23ef8", "d2a2a217385158e3e1e348883a14bc423e57daa12077e8c49797d16121ea0810", "f5467ccd85bb4ebe768527db520a210459969a5f1fae6e07b43f519799f0b224", "68be5fd9f9d142a5099e3609011fe3bab7bb992c595999e31e0b3d1668dfb3cf", "4d49a8a476e4934afc6b5c36db9bece3ed1804f20b952da5a21b2b0de766aa73", "ea7155745ef3fb2d099513887a2ba279333ced65c65facbd890ce58bd3fce772", "cf19f51f4e848053d289ac95a9138cdd23fc3077ae913cd58cda8cc7a521b2e1", "590b1cd41c7e6144e76b5cd515a3a4d0a4317624620a3f1685f43ae68bdcd890", "d2ffe0626b5f94a7e00fa0b506e7455a3d9399c15800db108d5e715ef5f6e346", "69630878c50a91f6c2edd23a706bfa0b50bd5661672a37d67bab38e6bca3b698", "445e9067079899bb5faafaca915ae6c0f6b1b730a5a628835dd827636f7feb1e", "6461c77491f1c4825958949f23c153e6e1759a5be53abbcee17c9da3867f3141", "23a235f4083771ccc207771daceda700b525a59ab586788d4f6892e69e34a6e2", "bde99f79ef41a81607ddcf92b9f95dcbc6c3537e91e8bf740e193dc73b19485e", "177957c0e5f0fbd12b88022a91768095d193830986caec8d888097d3ff4310b8", "bcbbdbaa4cdf8352422072f332e05111b732354a35c4d7c617ce1fc3b8b42a5a", "774b6717fdfb0d1629fb9d4c04a9ca40079ae2955d7f82e897477055ed017abb", "16443bf625be6d39ecaa6f114e5d2c1d47a64bfd3c13808d94b55b6b6acef2ee", "8d7495d9008066505ed00ce8198af82bfa5a6b4c08768b4c9fb3aa4eb0b0cca2", "15800849a53349508cb382959527f6c3cf1a46158ff1e6e2316b7dea7967e35f", "7a792f0f4a2b731781d1b244b2a57947f1a2e32900a1c0793449f9f7ae18a7b7", "5e517c2832c9deaa7df77c7bad4d20fd6eda2b7815e155e68bc48238fac1416f", "9f51a14f0019c72bd1d472706d8c80a18c1873c6a0663e754b60eae8094483d7", "7d2fabb565122521d22ba99fed9e5be6a458fbc93156d54db27d97a00b8c3a97", "786c9e412a7db4ec278891fa534caa9a1d1a028c631c6f3aeb9c4d96ad895c36", "3bd6341d40641c2632a5a0cd7a63553a04e251efd7195897a1d27e02a7a8bfde", "31efd1f5fb57b8cff0318d77a1a9e8d67e1d1c8d18ce90f99c3a240dff48cdc8", "d9de3e1156ce1380150948acbcfecd99c96e7f4b0bc97745f4681593d017f74f", "427a2201e09f9583cd990c03b81b58148c297d474a3b50f498d83b1c7a9414cd", "bfaca11596d3dec406a9fcf5d97536516dfe7f0e3b12078428a7e1700e25218a", "351c4770a097248a650008152d0cab5825d048bef770da7f3364f59d1e721bc0", "ee00f205d1486b2be7381d962bd2867263758e880529e4e2bfedfa613bbc0e71", "6aa3b6418d89e3348e4859c823ef4d6d7cd46aa7f7e77aba586c4214d760d8f8", ) @@ -681,7 +687,7 @@ population: 8 (49), MinProxBinSize: 2, MinBinSize: 2, MaxBinSize: 4 ========================================================================= */ func TestKademliaCase4(t *testing.T) { - t.Skip("depth definition has changed, causing this case to be invalid. A new batch of test cases are needed ASAP") + //t.Skip("depth definition has changed, causing this case to be invalid. A new batch of test cases are needed ASAP") testKademliaCase(t, "9a90fe3506277244549064b8c3276abb06284a199d9063a97331947f2b7da7f4", "c19359eddef24b7be1a833b4475f212cd944263627a53f9ef4837d106c247730", "fc2b6fef99ef947f7e57c3df376891769e2a2fd83d2b8e634e0fc1e91eaa080c", "ecefc0e1a8ea7bb4b48c469e077401fce175dd75294255b96c4e54f6a2950a55", "bb7ce598efc056bba343cc2614aa3f67a575557561290b44c73a63f8f433f9f7", "55fbee6ca52dfd7f0be0db969ee8e524b654ab4f0cce7c05d83887d7d2a15460", "afa852b6b319998c6a283cc0c82d2f5b8e9410075d7700f3012761f1cfbd0f76", "36c370cfb63f2087971ba6e58d7585b04e16b8f0da335efb91554c2dd8fe191c", "6be41e029985edebc901fb77fc4fb65516b6d85086e2a98bfa3159c99391e585", "dd3cfc72ea553e7d2b28f0037a65646b30955b929d29ba4c40f4a2a811248e77", "da3a8f18e09c7b0ca235c4e33e1441a5188f1df023138bf207753ee63e768f7d", "de9e3ab4dc572d54a2d4b878329fd832bb51a149f4ce167316eeb177b61e7e01", "4e6c1ecde6ed917706257fe020a1d02d2e9d87fca4c85f0f7b132491008c5032", "72ef04b77a070e13463b3529dd312bcacfb7a12d20dc597f5ec3de0501e9b834", "3fef57186675d524ab8bb1f54ba8cb68610babca1247c0c46dbb60aed003c69d", "1d8e6b71f7a052865d6558d4ba44ad5fab7b908cc1badf5766822e1c20d0d823", "6be2f2b4ffa173014d4ec7df157d289744a2bda54bb876b264ccfa898a0da315", "b0ba3fff8643f9985c744327b0c4c869763509fd5da2de9a80a4a0a082021255", "9ccf40b9406ba2e6567101fb9b4e5334a9ec74263eff47267da266ba45e6c158", "d7347f02c180a448e60f73931845062ce00048750b584790278e9c93ef31ad81", "b68c6359a22b3bee6fecb8804311cfd816648ea31d530c9fb48e477e029d707a", "0d668a18ad7c2820214df6df95a6c855ce19fb1cb765f8ca620e45db76686d37", "3fbd2663bff65533246f1fabb9f38086854c6218aeb3dc9ac6ac73d4f0988f91", "949aa5719ca846052bfaa1b38c97b6eca3df3e24c0e0630042c6bccafbb4cdb5", "77b8a2b917bef5d54f3792183b014cca7798f713ff14fe0b2ac79b4c9f6f996d", "17e853cbd8dc00cba3cd9ffeb36f26a9f41a0eb92f80b62c2cda16771c935388", "5f682ed7a8cf2f98387c3def7c97f9f05ae39e39d393eeca3cf621268d6347f8", "ad77487eaf11fd8084ba4517a51766eb0e5b77dd3492dfa79aa3a2802fb29d20", "d247cfcacf9a8200ebaddf639f8c926ab0a001abe682f40df3785e80ed124e91", "195589442e11907eede1ee6524157f1125f68399f3170c835ff81c603b069f6c", "5b5ca0a67f3c54e7d3a6a862ef56168ec9ed1f4945e6c24de6d336b2be2e6f8c", "56430e4caa253015f1f998dce4a48a88af1953f68e94eca14f53074ae9c3e467", "0b1eed6a5bf612d1d8e08f5c546f3d12e838568fd3aa43ed4c537f10c65545d6", "7058db19a56dfff01988ac4a62e1310597f9c8d7ebde6890dadabf047d722d39", "b847380d6888ff7cd11402d086b19eccc40950b52c9d67e73cb4f8462f5df078", "df6c048419a2290ab546d527e9eeba349e7f7e1759bafe4adac507ce60ef9670", "91fc5b4b24fc3fbfea7f9a3d0f0437cb5733c0c2345d8bdffd7048d6e3b8a37b", "957d8ea51b37523952b6f5ae95462fcd4aed1483ef32cc80b69580aaeee03606", "efa82e4e91ad9ab781977400e9ac0bb9de7389aaedebdae979b73d1d3b8d72b0", "7400c9f3f3fc0cc6fe8cc37ab24b9771f44e9f78be913f73cd35fc4be030d6bd", "9bb28f4122d61f7bb56fe27ef706159fb802fef0f5de9dfa32c9c5b3183235f1", "40a8de6e98953498b806614532ea4abf8b99ad7f9719fb68203a6eae2efa5b2a", "412de0b218b8f7dcacc9205cd16ffb4eca5b838f46a2f4f9f534026061a47308", "17f56ecad51075080680ad9faa0fd8946b824d3296ddb20be07f9809fe8d1c5a", "fffd4e7ae885a41948a342b6647955a7ec8a8039039f510cff467ef597675457", "35e78e11b5ac46a29dd04ab0043136c3291f4ca56cb949ace33111ed56395463", "94824fc80230af82077c83bfc01dc9675b1f9d3d538b1e5f41c21ac753598691", "fa470ae314ca3fce493f21b423eef2a49522e09126f6f2326fa3c9cac0b344f7", "7078860b5b621b21ac7b95f9fc4739c8235ce5066a8b9bd7d938146a34fa88ec", "eea53560f0428bfd2eca4f86a5ce9dec5ff1309129a975d73465c1c9e9da71d1", @@ -717,7 +723,7 @@ population: 13 (49), MinProxBinSize: 2, MinBinSize: 2, MaxBinSize: 4 ========================================================================= */ func TestKademliaCase5(t *testing.T) { - t.Skip("depth definition has changed, causing this case to be invalid. A new batch of test cases are needed ASAP") + //t.Skip("depth definition has changed, causing this case to be invalid. A new batch of test cases are needed ASAP") testKademliaCase(t, "5dd5c77dd9006a800478fcebb02d48d4036389e7d3c8f6a83b97dbad13f4c0a9", "78fafa0809929a1279ece089a51d12457c2d8416dff859aeb2ccc24bb50df5ec", "1dd39b1257e745f147cbbc3cadd609ccd6207c41056dbc4254bba5d2527d3ee5", "5f61dd66d4d94aec8fcc3ce0e7885c7edf30c43143fa730e2841c5d28e3cd081", "8aa8b0472cb351d967e575ad05c4b9f393e76c4b01ef4b3a54aac5283b78abc9", "4502f385152a915b438a6726ce3ea9342e7a6db91a23c2f6bee83a885ed7eb82", "718677a504249db47525e959ef1784bed167e1c46f1e0275b9c7b588e28a3758", "7c54c6ed1f8376323896ed3a4e048866410de189e9599dd89bf312ca4adb96b5", "18e03bd3378126c09e799a497150da5c24c895aedc84b6f0dbae41fc4bac081a", "23db76ac9e6e58d9f5395ca78252513a7b4118b4155f8462d3d5eec62486cadc", "40ae0e8f065e96c7adb7fa39505136401f01780481e678d718b7f6dbb2c906ec", "c1539998b8bae19d339d6bbb691f4e9daeb0e86847545229e80fe0dffe716e92", "ed139d73a2699e205574c08722ca9f030ad2d866c662f1112a276b91421c3cb9", "5bdb19584b7a36d09ca689422ef7e6bb681b8f2558a6b2177a8f7c812f631022", "636c9de7fe234ffc15d67a504c69702c719f626c17461d3f2918e924cd9d69e2", "de4455413ff9335c440d52458c6544191bd58a16d85f700c1de53b62773064ea", "de1963310849527acabc7885b6e345a56406a8f23e35e436b6d9725e69a79a83", "a80a50a467f561210a114cba6c7fb1489ed43a14d61a9edd70e2eb15c31f074d", "7804f12b8d8e6e4b375b242058242068a3809385e05df0e64973cde805cf729c", "60f9aa320c02c6f2e6370aa740cf7cea38083fa95fca8c99552cda52935c1520", "d8da963602390f6c002c00ce62a84b514edfce9ebde035b277a957264bb54d21", "8463d93256e026fe436abad44697152b9a56ac8e06a0583d318e9571b83d073c", "9a3f78fcefb9a05e40a23de55f6153d7a8b9d973ede43a380bf46bb3b3847de1", "e3bb576f4b3760b9ca6bff59326f4ebfc4a669d263fb7d67ab9797adea54ed13", "4d5cdbd6dcca5bdf819a0fe8d175dc55cc96f088d37462acd5ea14bc6296bdbe", "5a0ed28de7b5258c727cb85447071c74c00a5fbba9e6bc0393bc51944d04ab2a", "61e4ddb479c283c638f4edec24353b6cc7a3a13b930824aad016b0996ca93c47", "7e3610868acf714836cafaaa7b8c009a9ac6e3a6d443e5586cf661530a204ee2", "d74b244d4345d2c86e30a097105e4fb133d53c578320285132a952cdaa64416e", "cfeed57d0f935bfab89e3f630a7c97e0b1605f0724d85a008bbfb92cb47863a8", "580837af95055670e20d494978f60c7f1458dc4b9e389fc7aa4982b2aca3bce3", "df55c0c49e6c8a83d82dfa1c307d3bf6a20e18721c80d8ec4f1f68dc0a137ced", "5f149c51ce581ba32a285439a806c063ced01ccd4211cd024e6a615b8f216f95", "1eb76b00aeb127b10dd1b7cd4c3edeb4d812b5a658f0feb13e85c4d2b7c6fe06", "7a56ba7c3fb7cbfb5561a46a75d95d7722096b45771ec16e6fa7bbfab0b35dfe", "4bae85ad88c28470f0015246d530adc0cd1778bdd5145c3c6b538ee50c4e04bd", "afd1892e2a7145c99ec0ebe9ded0d3fec21089b277a68d47f45961ec5e39e7e0", "953138885d7b36b0ef79e46030f8e61fd7037fbe5ce9e0a94d728e8c8d7eab86", "de761613ef305e4f628cb6bf97d7b7dc69a9d513dc233630792de97bcda777a6", "3f3087280063d09504c084bbf7fdf984347a72b50d097fd5b086ffabb5b3fb4c", "7d18a94bb1ebfdef4d3e454d2db8cb772f30ca57920dd1e402184a9e598581a0", "a7d6fbdc9126d9f10d10617f49fb9f5474ffe1b229f76b7dd27cebba30eccb5d", "fad0246303618353d1387ec10c09ee991eb6180697ed3470ed9a6b377695203d", "1cf66e09ea51ee5c23df26615a9e7420be2ac8063f28f60a3bc86020e94fe6f3", "8269cdaa153da7c358b0b940791af74d7c651cd4d3f5ed13acfe6d0f2c539e7f", "90d52eaaa60e74bf1c79106113f2599471a902d7b1c39ac1f55b20604f453c09", "9788fd0c09190a3f3d0541f68073a2f44c2fcc45bb97558a7c319f36c25a75b3", "10b68fc44157ecfdae238ee6c1ce0333f906ad04d1a4cb1505c8e35c3c87fbb0", "e5284117fdf3757920475c786e0004cb00ba0932163659a89b36651a01e57394", "403ad51d911e113dcd5f9ff58c94f6d278886a2a4da64c3ceca2083282c92de3", diff --git a/swarm/network/simulation/example_test.go b/swarm/network/simulation/example_test.go index a100ede516..9cf72bab2c 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, 2) + ill, err := sim.WaitTillHealthy(ctx) 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 7982810ca3..8297fe52a5 100644 --- a/swarm/network/simulation/kademlia.go +++ b/swarm/network/simulation/kademlia.go @@ -34,15 +34,17 @@ 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, kadMinProxSize int) (ill map[enode.ID]*network.Kademlia, err error) { +func (s *Simulation) WaitTillHealthy(ctx context.Context) (ill map[enode.ID]*network.Kademlia, err error) { // Prepare PeerPot map for checking Kademlia health var ppmap map[string]*network.PeerPot kademlias := s.kademlias() + var kademliasArray []*network.Kademlia addrs := make([][]byte, 0, len(kademlias)) for _, k := range kademlias { addrs = append(addrs, k.BaseAddr()) + kademliasArray = append(kademliasArray, k) } - ppmap = network.NewPeerPotMap(kadMinProxSize, addrs) + ppmap = network.NewPeerPotMap(kademliasArray) //kadMinProxSize, addrs) // Wait for healthy Kademlia on every node before checking files ticker := time.NewTicker(200 * time.Millisecond) @@ -63,13 +65,13 @@ func (s *Simulation) WaitTillHealthy(ctx context.Context, kadMinProxSize int) (i addr := common.Bytes2Hex(k.BaseAddr()) pp := ppmap[addr] //call Healthy RPC - h := k.Healthy(pp) + h := pp.Healthy() //print info log.Debug(k.String()) - log.Debug("kademlia", "empty bins", pp.EmptyBins, "gotNN", h.GotNN, "knowNN", h.KnowNN, "full", h.Full) - log.Debug("kademlia", "health", h.GotNN && h.KnowNN && h.Full, "addr", hex.EncodeToString(k.BaseAddr()), "node", id) - log.Debug("kademlia", "ill condition", !h.GotNN || !h.Full, "addr", hex.EncodeToString(k.BaseAddr()), "node", id) - if !h.GotNN || !h.Full { + 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 { ill[id] = k } } diff --git a/swarm/network/simulation/kademlia_test.go b/swarm/network/simulation/kademlia_test.go index f02b0e5417..e8b1eba8a8 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, 2) + ill, err := sim.WaitTillHealthy(ctx) if err != nil { for id, kad := range ill { t.Log("Node", id) diff --git a/swarm/network/simulations/discovery/discovery_test.go b/swarm/network/simulations/discovery/discovery_test.go index cd5456b73e..5c744e84e3 100644 --- a/swarm/network/simulations/discovery/discovery_test.go +++ b/swarm/network/simulations/discovery/discovery_test.go @@ -265,7 +265,11 @@ func discoverySimulation(nodes, conns int, adapter adapters.NodeAdapter) (*simul wg.Wait() log.Debug(fmt.Sprintf("nodes: %v", len(addrs))) // construct the peer pot, so that kademlia health can be checked - ppmap := network.NewPeerPotMap(testMinProxBinSize, addrs) + var kads []*network.Kademlia + for _, a := range addrs { + kads = append(kads, network.NewKademlia(a, network.NewKadParams())) + } + ppmap := network.NewPeerPotMap(kads) check := func(ctx context.Context, id enode.ID) (bool, error) { select { case <-ctx.Done(): @@ -281,12 +285,15 @@ func discoverySimulation(nodes, conns int, adapter adapters.NodeAdapter) (*simul if err != nil { return false, fmt.Errorf("error getting node client: %s", err) } + healthy := &network.Health{} - if err := client.Call(&healthy, "hive_healthy", ppmap[id.String()]); err != nil { + pp := ppmap[id.String()] + log.Error("pp in", "p", pp, "base", pp.BaseAddr()) + if err := client.Call(&healthy, "hive_healthy", pp.BaseAddr(), pp); err != nil { return false, fmt.Errorf("error getting node health: %s", err) } - log.Debug(fmt.Sprintf("node %4s healthy: got nearest neighbours: %v, know nearest neighbours: %v, saturated: %v\n%v", id, healthy.GotNN, healthy.KnowNN, healthy.Full, healthy.Hive)) - return healthy.KnowNN && healthy.GotNN && healthy.Full, nil + log.Debug(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 } // 64 nodes ~ 1min @@ -379,7 +386,11 @@ func discoveryPersistenceSimulation(nodes, conns int, adapter adapters.NodeAdapt // run a simulation which connects the 10 nodes in a ring and waits // for full peer discovery - ppmap := network.NewPeerPotMap(testMinProxBinSize, addrs) + var kads []*network.Kademlia + for _, a := range addrs { + kads = append(kads, network.NewKademlia(a, network.NewKadParams())) + } + ppmap := network.NewPeerPotMap(kads) var restartTime time.Time @@ -400,12 +411,14 @@ func discoveryPersistenceSimulation(nodes, conns int, adapter adapters.NodeAdapt } healthy := &network.Health{} addr := id.String() - if err := client.Call(&healthy, "hive_healthy", ppmap[addr]); err != nil { + log.Error("before hive healthy call") + pp := ppmap[addr] + if err := client.Call(&healthy, "hive_healthy", pp.BaseAddr(), pp); err != nil { return fmt.Errorf("error getting node health: %s", err) } - log.Info(fmt.Sprintf("NODE: %s, IS HEALTHY: %t", addr, healthy.GotNN && healthy.KnowNN && healthy.Full)) - if !healthy.GotNN || !healthy.Full { + log.Info(fmt.Sprintf("NODE: %s, IS HEALTHY: %t", addr, healthy.GotNN && healthy.KnowNN)) + if !healthy.GotNN { isHealthy = false break } @@ -482,9 +495,9 @@ func discoveryPersistenceSimulation(nodes, conns int, adapter adapters.NodeAdapt if err := client.Call(&healthy, "hive_healthy", ppmap[id.String()]); 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, saturated: %v", id, healthy.GotNN, healthy.KnowNN, healthy.Full)) + log.Info(fmt.Sprintf("node %4s healthy: got nearest neighbours: %v, know nearest neighbours: %v", id, healthy.GotNN, healthy.KnowNN)) - return healthy.KnowNN && healthy.GotNN && healthy.Full, nil + return healthy.KnowNN && healthy.GotNN, nil } // 64 nodes ~ 1min diff --git a/swarm/network/stream/delivery_test.go b/swarm/network/stream/delivery_test.go index f537c13234..e8d52570c0 100644 --- a/swarm/network/stream/delivery_test.go +++ b/swarm/network/stream/delivery_test.go @@ -454,7 +454,6 @@ func TestDeliveryFromNodes(t *testing.T) { func testDeliveryFromNodes(t *testing.T, nodes, conns, chunkCount int, skipCheck bool) { - t.Skip("temporarily disabled as simulations.WaitTillHealthy cannot be trusted") sim := simulation.New(map[string]simulation.ServiceFunc{ "streamer": func(ctx *adapters.ServiceContext, bucket *sync.Map) (s node.Service, cleanup func(), err error) { node := ctx.Config.Node() @@ -543,7 +542,7 @@ func testDeliveryFromNodes(t *testing.T, nodes, conns, chunkCount int, skipCheck } log.Debug("Waiting for kademlia") - if _, err := sim.WaitTillHealthy(ctx, 2); err != nil { + if _, err := sim.WaitTillHealthy(ctx); err != nil { return err } @@ -693,7 +692,7 @@ func benchmarkDeliveryFromNodes(b *testing.B, nodes, conns, chunkCount int, skip } netStore := item.(*storage.NetStore) - if _, err := sim.WaitTillHealthy(ctx, 2); err != nil { + if _, err := sim.WaitTillHealthy(ctx); err != nil { return err } diff --git a/swarm/network/stream/intervals_test.go b/swarm/network/stream/intervals_test.go index 668cf586c0..b02a5909ea 100644 --- a/swarm/network/stream/intervals_test.go +++ b/swarm/network/stream/intervals_test.go @@ -53,7 +53,6 @@ func TestIntervalsLiveAndHistory(t *testing.T) { func testIntervals(t *testing.T, live bool, history *Range, skipCheck bool) { - t.Skip("temporarily disabled as simulations.WaitTillHealthy cannot be trusted") nodes := 2 chunkCount := dataChunkCount externalStreamName := "externalStream" @@ -114,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, 2); err != nil { + if _, err := sim.WaitTillHealthy(ctx); err != nil { t.Fatal(err) } diff --git a/swarm/network/stream/snapshot_retrieval_test.go b/swarm/network/stream/snapshot_retrieval_test.go index 62b53fad3b..942e431e13 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, 2); err != nil { + if _, err := sim.WaitTillHealthy(ctx); err != nil { return err } @@ -288,7 +288,7 @@ func runRetrievalTest(chunkCount int, nodeCount int) error { if err != nil { return err } - if _, err := sim.WaitTillHealthy(ctx, 2); err != nil { + if _, err := sim.WaitTillHealthy(ctx); err != nil { return err } diff --git a/swarm/network/stream/snapshot_sync_test.go b/swarm/network/stream/snapshot_sync_test.go index 40b4327fd1..933efe490d 100644 --- a/swarm/network/stream/snapshot_sync_test.go +++ b/swarm/network/stream/snapshot_sync_test.go @@ -183,7 +183,6 @@ func streamerFunc(ctx *adapters.ServiceContext, bucket *sync.Map) (s node.Servic func testSyncingViaGlobalSync(t *testing.T, chunkCount int, nodeCount int) { - t.Skip("temporarily disabled as simulations.WaitTillHealthy cannot be trusted") sim := simulation.New(simServiceMap) defer sim.Close() @@ -205,7 +204,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, 2); err != nil { + if _, err := sim.WaitTillHealthy(ctx); err != nil { t.Fatal(err) } @@ -332,7 +331,6 @@ kademlia network. The snapshot should have 'streamer' in its service list. */ func testSyncingViaDirectSubscribe(t *testing.T, chunkCount int, nodeCount int) error { - t.Skip("temporarily disabled as simulations.WaitTillHealthy cannot be trusted") sim := simulation.New(map[string]simulation.ServiceFunc{ "streamer": func(ctx *adapters.ServiceContext, bucket *sync.Map) (s node.Service, cleanup func(), err error) { n := ctx.Config.Node() @@ -388,7 +386,7 @@ func testSyncingViaDirectSubscribe(t *testing.T, chunkCount int, nodeCount int) return err } - if _, err := sim.WaitTillHealthy(ctx, 2); err != nil { + if _, err := sim.WaitTillHealthy(ctx); err != nil { return err } @@ -466,7 +464,7 @@ func testSyncingViaDirectSubscribe(t *testing.T, chunkCount int, nodeCount int) conf.hashes = append(conf.hashes, hashes...) mapKeysToNodes(conf) - if _, err := sim.WaitTillHealthy(ctx, 2); err != nil { + if _, err := sim.WaitTillHealthy(ctx); err != nil { return err } @@ -555,9 +553,12 @@ func mapKeysToNodes(conf *synctestConfig) { np, _, _ = pot.Add(np, a, pof) } - var kadMinProxSize = 2 + var kads []*network.Kademlia + for _, a := range conf.addrs { + kads = append(kads, network.NewKademlia(a, network.NewKadParams())) + } - ppmap := network.NewPeerPotMap(kadMinProxSize, conf.addrs) + ppmap := network.NewPeerPotMap(kads) //for each address, run EachNeighbour on the chunk hashes pot to identify closest nodes log.Trace(fmt.Sprintf("Generated hash chunk(s): %v", conf.hashes)) diff --git a/swarm/network/stream/syncer_test.go b/swarm/network/stream/syncer_test.go index 3e3cee18d6..e1e3d225fc 100644 --- a/swarm/network/stream/syncer_test.go +++ b/swarm/network/stream/syncer_test.go @@ -69,7 +69,6 @@ func createMockStore(globalStore mock.GlobalStorer, id enode.ID, addr *network.B func testSyncBetweenNodes(t *testing.T, nodes, conns, chunkCount int, skipCheck bool, po uint8) { - t.Skip("temporarily disabled as simulations.WaitTillHealthy cannot be trusted") sim := simulation.New(map[string]simulation.ServiceFunc{ "streamer": func(ctx *adapters.ServiceContext, bucket *sync.Map) (s node.Service, cleanup func(), err error) { var store storage.ChunkStore @@ -180,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, 2); err != nil { + if _, err := sim.WaitTillHealthy(ctx); err != nil { return err } diff --git a/swarm/network/stream/visualized_snapshot_sync_sim_test.go b/swarm/network/stream/visualized_snapshot_sync_sim_test.go index 96b707797c..638eae6e3d 100644 --- a/swarm/network/stream/visualized_snapshot_sync_sim_test.go +++ b/swarm/network/stream/visualized_snapshot_sync_sim_test.go @@ -96,7 +96,6 @@ func watchSim(sim *simulation.Simulation) (context.Context, context.CancelFunc) //This test requests bogus hashes into the network func TestNonExistingHashesWithServer(t *testing.T) { - t.Skip("temporarily disabled as simulations.WaitTillHealthy cannot be trusted") nodeCount, _, sim := setupSim(retrievalSimServiceMap) defer sim.Close() @@ -211,6 +210,7 @@ func TestSnapshotSyncWithServer(t *testing.T) { }, }).WithServer(":8888") //start with the HTTP server + nodeCount, chunkCount, sim := setupSim(simServiceMap) defer sim.Close() log.Info("Initializing test config") diff --git a/swarm/network_test.go b/swarm/network_test.go index 41993dfc6b..71d4b8f16a 100644 --- a/swarm/network_test.go +++ b/swarm/network_test.go @@ -260,7 +260,6 @@ type testSwarmNetworkOptions struct { // - Checking if a file is retrievable from all nodes. func testSwarmNetwork(t *testing.T, o *testSwarmNetworkOptions, steps ...testSwarmNetworkStep) { - t.Skip("temporarily disabled as simulations.WaitTillHealthy cannot be trusted") if o == nil { o = new(testSwarmNetworkOptions) } @@ -354,7 +353,7 @@ func testSwarmNetwork(t *testing.T, o *testSwarmNetworkOptions, steps ...testSwa } if *waitKademlia { - if _, err := sim.WaitTillHealthy(ctx, 2); err != nil { + if _, err := sim.WaitTillHealthy(ctx); err != nil { return err } }