diff --git a/.drone.yml b/.drone.yml index 049d43c76e..bbc45ad580 100644 --- a/.drone.yml +++ b/.drone.yml @@ -34,7 +34,7 @@ steps: commands: - cargo install cargo-audit - cargo generate-lockfile - - cargo audit + - cargo audit --ignore RUSTSEC-2020-0123 trigger: branch: diff --git a/Cargo.lock b/Cargo.lock index ae71a4d76a..22ddf80668 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -243,7 +243,7 @@ dependencies = [ "fastrand", "futures-lite", "libc", - "log 0.4.14", + "log 0.4.13", "nb-connect", "once_cell", "parking", @@ -288,7 +288,7 @@ dependencies = [ "futures-lite", "gloo-timers", "kv-log-macro", - "log 0.4.14", + "log 0.4.13", "memchr", "num_cpus", "once_cell", @@ -315,19 +315,6 @@ dependencies = [ "syn", ] -[[package]] -name = "asynchronous-codec" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb4401f0a3622dad2e0763fa79e0eb328bc70fb7dccfdd645341f00d671247d6" -dependencies = [ - "bytes 1.0.1", - "futures-sink", - "futures-util", - "memchr", - "pin-project-lite 0.2.4", -] - [[package]] name = "atomic" version = "0.5.0" @@ -573,6 +560,12 @@ dependencies = [ "once_cell", ] +[[package]] +name = "bs58" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "476e9cd489f9e121e02ffa6014a8ef220ecb15c05ed23fc34cca13925dc283fb" + [[package]] name = "bs58" version = "0.4.0" @@ -710,7 +703,7 @@ dependencies = [ "dirs", "grpc", "lmdb", - "log 0.4.14", + "log 0.4.13", "num", "num-rational 0.3.2", "parity-wasm 0.42.1", @@ -730,7 +723,7 @@ dependencies = [ "casper-types", "grpc", "lmdb", - "log 0.4.14", + "log 0.4.13", "num-rational 0.3.2", "num-traits", "once_cell", @@ -755,7 +748,7 @@ dependencies = [ "crossbeam-channel 0.5.0", "env_logger", "grpc", - "log 0.4.14", + "log 0.4.13", "num-rational 0.3.2", "num-traits", "once_cell", @@ -787,7 +780,7 @@ dependencies = [ "libc", "linked-hash-map", "lmdb", - "log 0.4.14", + "log 0.4.13", "num", "num-derive", "num-rational 0.3.2", @@ -804,7 +797,7 @@ dependencies = [ "tempfile", "thiserror", "tracing", - "uint 0.8.5", + "uint", "uuid", "wasmi", ] @@ -852,8 +845,8 @@ dependencies = [ "libp2p", "linked-hash-map", "lmdb", - "log 0.4.14", - "multihash 0.11.4", + "log 0.4.13", + "multihash", "num", "num-derive", "num-rational 0.3.2", @@ -897,7 +890,7 @@ dependencies = [ "tracing", "tracing-futures", "tracing-subscriber", - "uint 0.8.5", + "uint", "untrusted", "uuid", "vergen", @@ -946,7 +939,7 @@ dependencies = [ "serde", "serde_json", "serde_test", - "uint 0.8.5", + "uint", "version-sync", ] @@ -978,7 +971,7 @@ dependencies = [ "clap", "heck", "indexmap", - "log 0.4.14", + "log 0.4.13", "proc-macro2", "quote", "serde", @@ -1373,7 +1366,7 @@ dependencies = [ "crossterm_winapi", "lazy_static", "libc", - "mio 0.6.23", + "mio", "parking_lot 0.10.2", "signal-hook", "winapi 0.3.9", @@ -1932,7 +1925,7 @@ checksum = "f26ecb66b4bdca6c1409b40fb255eefc2bd4f6d135dab3c3124f80ffa2a9661e" dependencies = [ "atty", "humantime", - "log 0.4.14", + "log 0.4.13", "regex", "termcolor", ] @@ -2229,6 +2222,18 @@ dependencies = [ "slab 0.4.2", ] +[[package]] +name = "futures_codec" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce54d63f8b0c75023ed920d46fd71d0cbbb830b0ee012726b5b4f506fb6dea5b" +dependencies = [ + "bytes 0.5.6", + "futures 0.3.12", + "memchr", + "pin-project 0.4.27", +] + [[package]] name = "generic-array" version = "0.12.3" @@ -2372,7 +2377,7 @@ dependencies = [ "futures 0.1.30", "futures-cpupool", "httpbis", - "log 0.4.14", + "log 0.4.13", "protobuf", "tls-api", "tls-api-stub", @@ -2579,7 +2584,7 @@ dependencies = [ "bytes 0.4.12", "futures 0.1.30", "futures-cpupool", - "log 0.4.14", + "log 0.4.13", "net2", "tls-api", "tls-api-stub", @@ -2673,22 +2678,6 @@ dependencies = [ "libc", ] -[[package]] -name = "if-watch" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b8538953a3f0d0d3868f0a706eb4273535e10d72acb5c82c1c23ae48835c85" -dependencies = [ - "async-io", - "futures 0.3.12", - "futures-lite", - "if-addrs", - "ipnet", - "libc", - "log 0.4.14", - "winapi 0.3.9", -] - [[package]] name = "indexmap" version = "1.6.1" @@ -2742,6 +2731,15 @@ dependencies = [ "serde", ] +[[package]] +name = "itertools" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f56a2d0bc861f9165be4eb3442afd3c236d8a98afd426f65d92324ae1091a484" +dependencies = [ + "either", +] + [[package]] name = "itertools" version = "0.9.0" @@ -2860,7 +2858,7 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0de8b303297635ad57c9f5059fd9cee7a47f8e8daa09df0fcd07dd39fb22977f" dependencies = [ - "log 0.4.14", + "log 0.4.13", ] [[package]] @@ -2883,12 +2881,12 @@ checksum = "89203f3fba0a3795506acaad8ebce3c80c0af93f994d5a1d7a0b1eeb23271929" [[package]] name = "libp2p" -version = "0.34.0" +version = "0.29.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5133112ce42be9482f6a87be92a605dd6bbc9e93c297aee77d172ff06908f3a" +checksum = "021f703bfef6e3da78ef9828c8a244d639b8d57eedf58360922aca5ff69dfdcd" dependencies = [ "atomic", - "bytes 1.0.1", + "bytes 0.5.6", "futures 0.3.12", "lazy_static", "libp2p-core", @@ -2908,6 +2906,7 @@ dependencies = [ "libp2p-tcp", "libp2p-uds", "libp2p-yamux", + "multihash", "parity-multiaddr", "parking_lot 0.11.1", "pin-project 1.0.4", @@ -2917,12 +2916,12 @@ dependencies = [ [[package]] name = "libp2p-core" -version = "0.27.0" +version = "0.23.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dad04d3cef6c1df366a6ab58c9cf8b06497699e335d83ac2174783946ff847d6" +checksum = "3960524389409633550567e8a9e0684d25a33f4f8408887ff897dd9fdfbdb771" dependencies = [ "asn1_der", - "bs58", + "bs58 0.3.1", "ed25519-dalek", "either", "fnv", @@ -2930,8 +2929,8 @@ dependencies = [ "futures-timer", "lazy_static", "libsecp256k1", - "log 0.4.14", - "multihash 0.13.2", + "log 0.4.13", + "multihash", "multistream-select", "parity-multiaddr", "parking_lot 0.11.1", @@ -2944,16 +2943,16 @@ dependencies = [ "sha2 0.9.2", "smallvec 1.6.1", "thiserror", - "unsigned-varint 0.6.0", + "unsigned-varint", "void", "zeroize", ] [[package]] name = "libp2p-core-derive" -version = "0.21.0" +version = "0.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4bc40943156e42138d22ed3c57ff0e1a147237742715937622a99b10fbe0156" +checksum = "f753d9324cd3ec14bf04b8a8cd0d269c87f294153d6bf2a84497a63a5ad22213" dependencies = [ "quote", "syn", @@ -2961,9 +2960,9 @@ dependencies = [ [[package]] name = "libp2p-deflate" -version = "0.27.1" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d42eed63305f0420736fa487f9acef720c4528bd7852a6a760f5ccde4813345" +checksum = "567962c5c5f8a1282979441300e1739ba939024010757c3dbfab4d462189df77" dependencies = [ "flate2", "futures 0.3.12", @@ -2972,27 +2971,27 @@ dependencies = [ [[package]] name = "libp2p-dns" -version = "0.27.0" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5153b6db68fd4baa3b304e377db744dd8fea8ff4e4504509ee636abcde88d3e3" +checksum = "436280f5fe21a58fcaff82c2606945579241f32bc0eaf2d39321aa4624a66e7f" dependencies = [ "futures 0.3.12", "libp2p-core", - "log 0.4.14", + "log 0.4.13", ] [[package]] name = "libp2p-floodsub" -version = "0.27.0" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3c63dfa06581b24b1d12bf9815b43689a784424be217d6545c800c7c75a207f" +checksum = "ecc175613c5915332fd6458895407ec242ea055ae3b107a586626d5e3349350a" dependencies = [ "cuckoofilter", "fnv", "futures 0.3.12", "libp2p-core", "libp2p-swarm", - "log 0.4.14", + "log 0.4.13", "prost", "prost-build", "rand 0.7.3", @@ -3001,40 +3000,40 @@ dependencies = [ [[package]] name = "libp2p-gossipsub" -version = "0.27.0" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12451ba9493e87c91baf2a6dffce9ddf1fbc807a0861532d7cf477954f8ebbee" +checksum = "d500ad89ba14de4d18bebdff61a0ce3e769f1c5c5a95026c5da90187e5fff5c9" dependencies = [ - "asynchronous-codec", "base64 0.13.0", "byteorder", - "bytes 1.0.1", + "bytes 0.5.6", "fnv", "futures 0.3.12", + "futures_codec", "hex_fmt", "libp2p-core", "libp2p-swarm", - "log 0.4.14", + "log 0.4.13", + "lru_time_cache", "prost", "prost-build", "rand 0.7.3", - "regex", "sha2 0.9.2", "smallvec 1.6.1", - "unsigned-varint 0.6.0", + "unsigned-varint", "wasm-timer", ] [[package]] name = "libp2p-identify" -version = "0.27.0" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b40fb36a059b7a8cce1514bd8b546fa612e006c9937caa7f5950cb20021fe91e" +checksum = "03b90b350e37f398b73d778bd94422f4e6a3afa2c1582742ce2446b8a0dba787" dependencies = [ "futures 0.3.12", "libp2p-core", "libp2p-swarm", - "log 0.4.14", + "log 0.4.13", "prost", "prost-build", "smallvec 1.6.1", @@ -3043,81 +3042,83 @@ dependencies = [ [[package]] name = "libp2p-kad" -version = "0.28.0" +version = "0.24.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "456f5de8e283d7800ca848b9b9a4e2a578b790bd8ae582b885e831353cf0e5df" +checksum = "fb78341f114bf686d5fe50b33ff1a804d88fb326c0d39ee1c22db4346b21fc27" dependencies = [ "arrayvec", - "asynchronous-codec", - "bytes 1.0.1", + "bytes 0.5.6", "either", "fnv", "futures 0.3.12", + "futures_codec", "libp2p-core", "libp2p-swarm", - "log 0.4.14", + "log 0.4.13", + "multihash", "prost", "prost-build", "rand 0.7.3", "sha2 0.9.2", "smallvec 1.6.1", - "uint 0.9.0", - "unsigned-varint 0.6.0", + "uint", + "unsigned-varint", "void", "wasm-timer", ] [[package]] name = "libp2p-mdns" -version = "0.28.0" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b974db63233fc0e199f4ede7794294aae285c96f4b6010f853eac4099ef08590" +checksum = "b575514fce0a3ccbd065d6aa377bd4d5102001b05c1a22a5eee49c450254ef0f" dependencies = [ - "async-io", "data-encoding", "dns-parser", + "either", "futures 0.3.12", - "if-watch", "lazy_static", "libp2p-core", "libp2p-swarm", - "log 0.4.14", + "log 0.4.13", + "net2", "rand 0.7.3", "smallvec 1.6.1", - "socket2", + "tokio 0.2.24", "void", + "wasm-timer", ] [[package]] name = "libp2p-mplex" -version = "0.27.0" +version = "0.23.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2705dc94b01ab9e3779b42a09bbf3712e637ed213e875c30face247291a85af0" +checksum = "a92b538238c80067c6417a58a07e41002b69d129355b60ec147d6337fdff0eb0" dependencies = [ - "asynchronous-codec", - "bytes 1.0.1", + "bytes 0.5.6", "futures 0.3.12", + "futures_codec", "libp2p-core", - "log 0.4.14", + "log 0.4.13", "nohash-hasher", "parking_lot 0.11.1", "rand 0.7.3", "smallvec 1.6.1", - "unsigned-varint 0.6.0", + "unsigned-varint", ] [[package]] name = "libp2p-noise" -version = "0.29.0" +version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4aca322b52a0c5136142a7c3971446fb1e9964923a526c9cc6ef3b7c94e57778" +checksum = "93c77142e3e5b18fefa7d267305c777c9cbe9b2232ec489979390100bebcc1e6" dependencies = [ - "bytes 1.0.1", + "bytes 0.5.6", "curve25519-dalek", "futures 0.3.12", "lazy_static", "libp2p-core", - "log 0.4.14", + "log 0.4.13", "prost", "prost-build", "rand 0.7.3", @@ -3130,14 +3131,14 @@ dependencies = [ [[package]] name = "libp2p-ping" -version = "0.27.0" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f3813276d0708c8db0f500d8beda1bda9ad955723b9cb272c41f4727256f73c" +checksum = "7257135609e8877f4d286935cbe1e572b2018946881c3e7f63054577074a7ee7" dependencies = [ "futures 0.3.12", "libp2p-core", "libp2p-swarm", - "log 0.4.14", + "log 0.4.13", "rand 0.7.3", "void", "wasm-timer", @@ -3145,34 +3146,34 @@ dependencies = [ [[package]] name = "libp2p-request-response" -version = "0.9.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d37637a4b33b5390322ccc068a33897d0aa541daf4fec99f6a7efbf37295346e" +checksum = "02ba1aa5727ccc118c09ba5111480873f2fe5608cb304e258fd12c173ecf27c9" dependencies = [ "async-trait", - "bytes 1.0.1", + "bytes 0.5.6", "futures 0.3.12", "libp2p-core", "libp2p-swarm", - "log 0.4.14", + "log 0.4.13", "lru", "minicbor", "rand 0.7.3", "smallvec 1.6.1", - "unsigned-varint 0.6.0", + "unsigned-varint", "wasm-timer", ] [[package]] name = "libp2p-swarm" -version = "0.27.1" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4f89ebb4d8953bda12623e9871959fe728dea3bf6eae0421dc9c42dc821e488" +checksum = "ffa6fa33b16956b8a58afbfebe1406866011a1ab8960765bd36868952d7be6a1" dependencies = [ "either", "futures 0.3.12", "libp2p-core", - "log 0.4.14", + "log 0.4.13", "rand 0.7.3", "smallvec 1.6.1", "void", @@ -3181,40 +3182,37 @@ dependencies = [ [[package]] name = "libp2p-tcp" -version = "0.27.0" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dbd3d7076a478ac5a6aca55e74bdc250ac539b95de09b9d09915e0b8d01a6b2" +checksum = "9d0b6f4ef48d9493607fae069deecce0579320a1f3de6cb056770b151018a9a5" dependencies = [ - "async-io", "futures 0.3.12", "futures-timer", "if-addrs", - "if-watch", "ipnet", - "libc", "libp2p-core", - "log 0.4.14", + "log 0.4.13", "socket2", - "tokio 1.1.0", + "tokio 0.2.24", ] [[package]] name = "libp2p-uds" -version = "0.27.0" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80ac51ce419f60be966e02103c17f67ff5dc4422ba83ba54d251d6c62a4ed487" +checksum = "945bed3c989a1b290b5a0d4e8fa6e44e01840efb9a5ab3f0d3d174f0e451ac0e" dependencies = [ "async-std", "futures 0.3.12", "libp2p-core", - "log 0.4.14", + "log 0.4.13", ] [[package]] name = "libp2p-yamux" -version = "0.30.0" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "490b8b27fc40fe35212df1b6a3d14bffaa4117cbff956fdc2892168a371102ad" +checksum = "07c0c9b6ef7a168c2ae854170b0b6b77550599afe06cc3ac390eb45c5d9c7110" dependencies = [ "futures 0.3.12", "libp2p-core", @@ -3299,18 +3297,17 @@ version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" dependencies = [ - "log 0.4.14", + "log 0.4.13", ] [[package]] name = "log" -version = "0.4.14" +version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" +checksum = "fcf3805d4480bb5b86070dcfeb9e2cb2ebc148adb753c5cca5f884d1d65a42b2" dependencies = [ - "cfg-if 1.0.0", + "cfg-if 0.1.10", "serde", - "value-bag", ] [[package]] @@ -3322,6 +3319,12 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "lru_time_cache" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78f957950068c53af3b32a1b3a6e69f6dd3c19fa6f0dcc1168b846662d5e10b1" + [[package]] name = "mach" version = "0.3.2" @@ -3436,18 +3439,18 @@ dependencies = [ [[package]] name = "minicbor" -version = "0.7.1" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3265a9f5210bb726f81ef9c456ae0aff5321cd95748c0e71889b0e19d8f0332b" +checksum = "9a2ef6aa869726518c5d8206fa5d1337bda8a0442807611be617891c018fa781" dependencies = [ "minicbor-derive", ] [[package]] name = "minicbor-derive" -version = "0.6.1" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "130b9455e28a3f308f6579671816a6f2621e2e0cbf55dc2f886345bef699481e" +checksum = "2b3569c0dbfff1b8d5f1434c642b67f5bf81c0f354a3f5f8f180b549dba3c07c" dependencies = [ "proc-macro2", "quote", @@ -3484,26 +3487,13 @@ dependencies = [ "iovec", "kernel32-sys", "libc", - "log 0.4.14", - "miow 0.2.2", + "log 0.4.13", + "miow", "net2", "slab 0.4.2", "winapi 0.2.8", ] -[[package]] -name = "mio" -version = "0.7.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e50ae3f04d169fcc9bde0b547d1c205219b7157e07ded9c5aff03e0637cb3ed7" -dependencies = [ - "libc", - "log 0.4.14", - "miow 0.3.6", - "ntapi", - "winapi 0.3.9", -] - [[package]] name = "mio-uds" version = "0.6.8" @@ -3512,7 +3502,7 @@ checksum = "afcb699eb26d4332647cc848492bbc15eafb26f08d0304550d5aa1f612e066f0" dependencies = [ "iovec", "libc", - "mio 0.6.23", + "mio", ] [[package]] @@ -3527,16 +3517,6 @@ dependencies = [ "ws2_32-sys", ] -[[package]] -name = "miow" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a33c1b55807fbed163481b5ba66db4b2fa6cde694a5027be10fb724206c5897" -dependencies = [ - "socket2", - "winapi 0.3.9", -] - [[package]] name = "multihash" version = "0.11.4" @@ -3549,34 +3529,7 @@ dependencies = [ "sha-1 0.9.2", "sha2 0.9.2", "sha3", - "unsigned-varint 0.5.1", -] - -[[package]] -name = "multihash" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dac63698b887d2d929306ea48b63760431ff8a24fac40ddb22f9c7f49fb7cab" -dependencies = [ - "digest 0.9.0", - "generic-array 0.14.4", - "multihash-derive", - "sha2 0.9.2", - "unsigned-varint 0.5.1", -] - -[[package]] -name = "multihash-derive" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85ee3c48cb9d9b275ad967a0e96715badc13c6029adb92f34fa17b9ff28fd81f" -dependencies = [ - "proc-macro-crate", - "proc-macro-error", - "proc-macro2", - "quote", - "syn", - "synstructure", + "unsigned-varint", ] [[package]] @@ -3593,7 +3546,7 @@ checksum = "d050aeedc89243f5347c3e237e3e13dc76fbe4ae3742a57b94dc14f69acf76d4" dependencies = [ "buf_redux", "httparse", - "log 0.4.14", + "log 0.4.13", "mime", "mime_guess", "quick-error", @@ -3605,16 +3558,16 @@ dependencies = [ [[package]] name = "multistream-select" -version = "0.10.0" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10ddc0eb0117736f19d556355464fc87efc8ad98b29e3fd84f02531eb6e90840" +checksum = "93faf2e41f9ee62fb01680ed48f3cc26652352327aa2e59869070358f6b7dd75" dependencies = [ - "bytes 1.0.1", + "bytes 0.5.6", "futures 0.3.12", - "log 0.4.14", + "log 0.4.13", "pin-project 1.0.4", "smallvec 1.6.1", - "unsigned-varint 0.6.0", + "unsigned-varint", ] [[package]] @@ -3641,7 +3594,7 @@ checksum = "b8d96b2e1c8da3957d58100b09f102c6d9cfdfced01b7ec5a8974044bb09dbd4" dependencies = [ "lazy_static", "libc", - "log 0.4.14", + "log 0.4.13", "openssl", "openssl-probe", "openssl-sys", @@ -3690,15 +3643,6 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451" -[[package]] -name = "ntapi" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44" -dependencies = [ - "winapi 0.3.9", -] - [[package]] name = "num" version = "0.3.1" @@ -3902,19 +3846,19 @@ dependencies = [ [[package]] name = "parity-multiaddr" -version = "0.11.0" +version = "0.9.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bfda2e46fc5e14122649e2645645a81ee5844e0fb2e727ef560cc71a8b2d801" +checksum = "fbecae7b7cfaafea47ceb5253ecdd14155ca8410e3487ed86031a6c2d5c15873" dependencies = [ "arrayref", - "bs58", + "bs58 0.4.0", "byteorder", "data-encoding", - "multihash 0.13.2", + "multihash", "percent-encoding", "serde", "static_assertions", - "unsigned-varint 0.6.0", + "unsigned-varint", "url", ] @@ -4254,7 +4198,7 @@ checksum = "a2a7bc6b2a29e632e45451c941832803a18cce6781db04de8a04696cdca8bde4" dependencies = [ "cfg-if 0.1.10", "libc", - "log 0.4.14", + "log 0.4.13", "wepoll-sys", "winapi 0.3.9", ] @@ -4336,15 +4280,6 @@ dependencies = [ "treeline", ] -[[package]] -name = "proc-macro-crate" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d6ea3c4595b96363c13943497db34af4460fb474a95c43f4446ad341b8c9785" -dependencies = [ - "toml", -] - [[package]] name = "proc-macro-error" version = "1.0.4" @@ -4427,24 +4362,24 @@ dependencies = [ [[package]] name = "prost" -version = "0.7.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e6984d2f1a23009bd270b8bb56d0926810a3d483f59c987d77969e9d8e840b2" +checksum = "ce49aefe0a6144a45de32927c77bd2859a5f7677b55f220ae5b744e87389c212" dependencies = [ - "bytes 1.0.1", + "bytes 0.5.6", "prost-derive", ] [[package]] name = "prost-build" -version = "0.7.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32d3ebd75ac2679c2af3a92246639f9fcc8a442ee420719cc4fe195b98dd5fa3" +checksum = "02b10678c913ecbd69350e8535c3aef91a8676c0773fc1d7b95cdd196d7f2f26" dependencies = [ - "bytes 1.0.1", + "bytes 0.5.6", "heck", - "itertools 0.9.0", - "log 0.4.14", + "itertools 0.8.2", + "log 0.4.13", "multimap", "petgraph", "prost", @@ -4455,12 +4390,12 @@ dependencies = [ [[package]] name = "prost-derive" -version = "0.7.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "169a15f3008ecb5160cba7d37bcd690a7601b6d30cfb87a117d45e59d52af5d4" +checksum = "537aa19b95acde10a12fec4301466386f757403de4cd4e5b4fa78fb5ecb18f72" dependencies = [ "anyhow", - "itertools 0.9.0", + "itertools 0.8.2", "proc-macro2", "quote", "syn", @@ -4468,11 +4403,11 @@ dependencies = [ [[package]] name = "prost-types" -version = "0.7.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b518d7cdd93dab1d1122cf07fa9a60771836c668dde9d9e2a139f957f0d9f1bb" +checksum = "1834f67c0697c001304b75be76f67add9c89742eda3a085ad8ee0bb38c3417aa" dependencies = [ - "bytes 1.0.1", + "bytes 0.5.6", "prost", ] @@ -4500,7 +4435,7 @@ version = "2.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "50d9500ea1488a61aa96da139039b78a92eef64a0f3c82d38173729f0ad73cf8" dependencies = [ - "log 0.4.14", + "log 0.4.13", ] [[package]] @@ -4570,7 +4505,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4f7a12f176deee919f4ba55326ee17491c8b707d0987aed822682c821b660192" dependencies = [ "byteorder", - "log 0.4.14", + "log 0.4.13", "parity-wasm 0.41.0", ] @@ -4581,7 +4516,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c8ac87af529432d3a4f0e2b3bbf08af49f28f09cc73ed7e551161bdaef5f78d" dependencies = [ "byteorder", - "log 0.4.14", + "log 0.4.13", "parity-wasm 0.41.0", ] @@ -4875,7 +4810,7 @@ dependencies = [ "ipnet", "js-sys", "lazy_static", - "log 0.4.14", + "log 0.4.13", "mime", "mime_guess", "native-tls", @@ -5335,7 +5270,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7e31d442c16f047a671b5a71e2161d6e68814012b7f5379d269ebd915fac2729" dependencies = [ "libc", - "mio 0.6.23", + "mio", "signal-hook-registry", ] @@ -5725,7 +5660,7 @@ version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "049c03787a0595182357fbd487577947f4351b78ce20c3668f6d49f17feb13d1" dependencies = [ - "log 0.4.14", + "log 0.4.13", ] [[package]] @@ -5746,7 +5681,7 @@ checksum = "5a09c0b5bb588872ab2f09afa13ee6e9dac11e10a0ec9e8e3ba39a5a5d530af6" dependencies = [ "bytes 0.4.12", "futures 0.1.30", - "mio 0.6.23", + "mio", "num_cpus", "tokio-codec", "tokio-current-thread", @@ -5774,25 +5709,13 @@ dependencies = [ "iovec", "lazy_static", "memchr", - "mio 0.6.23", + "mio", "num_cpus", "pin-project-lite 0.1.11", "slab 0.4.2", "tokio-macros", ] -[[package]] -name = "tokio" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8efab2086f17abcddb8f756117665c958feee6b2e39974c2f1600592ab3a4195" -dependencies = [ - "autocfg", - "libc", - "mio 0.7.7", - "pin-project-lite 0.2.4", -] - [[package]] name = "tokio-codec" version = "0.1.2" @@ -5813,8 +5736,8 @@ dependencies = [ "bytes 0.4.12", "futures 0.1.30", "iovec", - "log 0.4.14", - "mio 0.6.23", + "log 0.4.13", + "mio", "scoped-tls 0.1.2", "tokio 0.1.22", "tokio-executor", @@ -5862,7 +5785,7 @@ checksum = "57fc868aae093479e3131e3d165c93b1c7474109d13c90ec0dda2a1bbfff0674" dependencies = [ "bytes 0.4.12", "futures 0.1.30", - "log 0.4.14", + "log 0.4.13", ] [[package]] @@ -5895,8 +5818,8 @@ dependencies = [ "crossbeam-utils 0.7.2", "futures 0.1.30", "lazy_static", - "log 0.4.14", - "mio 0.6.23", + "log 0.4.13", + "mio", "num_cpus", "parking_lot 0.9.0", "slab 0.4.2", @@ -5938,7 +5861,7 @@ dependencies = [ "bytes 0.4.12", "futures 0.1.30", "iovec", - "mio 0.6.23", + "mio", "tokio-io", "tokio-reactor", ] @@ -5954,7 +5877,7 @@ dependencies = [ "crossbeam-utils 0.7.2", "futures 0.1.30", "lazy_static", - "log 0.4.14", + "log 0.4.13", "num_cpus", "slab 0.4.2", "tokio-executor", @@ -6010,7 +5933,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6d9e878ad426ca286e4dcae09cbd4e1973a7f8987d97570e2469703dd7f5720c" dependencies = [ "futures-util", - "log 0.4.14", + "log 0.4.13", "pin-project 0.4.27", "tokio 0.2.24", "tungstenite", @@ -6024,8 +5947,8 @@ checksum = "e2a0b10e610b39c38b031a2fcab08e4b82f16ece36504988dcbd81dbba650d82" dependencies = [ "bytes 0.4.12", "futures 0.1.30", - "log 0.4.14", - "mio 0.6.23", + "log 0.4.13", + "mio", "tokio-codec", "tokio-io", "tokio-reactor", @@ -6042,7 +5965,7 @@ dependencies = [ "iovec", "libc", "log 0.3.9", - "mio 0.6.23", + "mio", "mio-uds", "tokio-core", "tokio-io", @@ -6058,8 +5981,8 @@ dependencies = [ "futures 0.1.30", "iovec", "libc", - "log 0.4.14", - "mio 0.6.23", + "log 0.4.13", + "mio", "mio-uds", "tokio-codec", "tokio-io", @@ -6075,7 +5998,7 @@ dependencies = [ "bytes 0.5.6", "futures-core", "futures-sink", - "log 0.4.14", + "log 0.4.13", "pin-project-lite 0.1.11", "tokio 0.2.24", ] @@ -6102,7 +6025,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f47026cdc4080c07e49b37087de021820269d996f581aac150ef9e5583eefe3" dependencies = [ "cfg-if 1.0.0", - "log 0.4.14", + "log 0.4.13", "pin-project-lite 0.2.4", "tracing-attributes", "tracing-core", @@ -6145,7 +6068,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5e0f8c7178e13481ff6765bd169b33e8d554c5d2bbede5e32c356194be02b9b9" dependencies = [ "lazy_static", - "log 0.4.14", + "log 0.4.13", "tracing-core", ] @@ -6329,7 +6252,7 @@ dependencies = [ "http", "httparse", "input_buffer", - "log 0.4.14", + "log 0.4.13", "rand 0.7.3", "sha-1 0.9.2", "url", @@ -6369,18 +6292,6 @@ dependencies = [ "static_assertions", ] -[[package]] -name = "uint" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e11fe9a9348741cf134085ad57c249508345fe16411b3d7fb4ff2da2f1d6382e" -dependencies = [ - "byteorder", - "crunchy", - "hex", - "static_assertions", -] - [[package]] name = "undelegate" version = "0.1.0" @@ -6465,17 +6376,11 @@ name = "unsigned-varint" version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7fdeedbf205afadfe39ae559b75c3240f24e257d0ca27e85f85cb82aa19ac35" - -[[package]] -name = "unsigned-varint" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35581ff83d4101e58b582e607120c7f5ffb17e632a980b1f38334d76b36908b2" dependencies = [ - "asynchronous-codec", - "bytes 1.0.1", + "bytes 0.5.6", "futures-io", "futures-util", + "futures_codec", ] [[package]] @@ -6518,15 +6423,6 @@ dependencies = [ "serde", ] -[[package]] -name = "value-bag" -version = "1.0.0-alpha.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b676010e055c99033117c2343b33a40a30b91fecd6c49055ac9cd2d6c305ab1" -dependencies = [ - "ctor", -] - [[package]] name = "vcpkg" version = "0.2.11" @@ -6614,7 +6510,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" dependencies = [ - "log 0.4.14", + "log 0.4.13", "try-lock", ] @@ -6629,7 +6525,7 @@ dependencies = [ "headers", "http", "hyper", - "log 0.4.14", + "log 0.4.13", "mime", "mime_guess", "multipart", @@ -6658,7 +6554,7 @@ dependencies = [ "http", "hyper", "lazycell", - "log 0.4.14", + "log 0.4.13", "serde", "serde_json", "warp", @@ -6696,7 +6592,7 @@ checksum = "7bc45447f0d4573f3d65720f636bbcc3dd6ce920ed704670118650bcd47764c7" dependencies = [ "bumpalo", "lazy_static", - "log 0.4.14", + "log 0.4.13", "proc-macro2", "quote", "syn", @@ -6821,12 +6717,11 @@ checksum = "62945bc99a6a121cb2759c7bfa7b779ddf0e69b68bb35a9b23ab72276cfdcd3c" [[package]] name = "which" -version = "4.0.2" +version = "3.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87c14ef7e1b8b8ecfc75d5eca37949410046e66f15d185c01d70824f1f8111ef" +checksum = "d011071ae14a2f6671d0b74080ae0cd8ebf3a6f8c9589a2cd45f23126fe29724" dependencies = [ "libc", - "thiserror", ] [[package]] @@ -6933,7 +6828,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9aeb8c4043cac71c3c299dff107171c220d179492350ea198e109a414981b83c" dependencies = [ "futures 0.3.12", - "log 0.4.14", + "log 0.4.13", "nohash-hasher", "parking_lot 0.11.1", "rand 0.7.3", diff --git a/node/Cargo.toml b/node/Cargo.toml index e993b07912..9fd5278f7d 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -46,7 +46,7 @@ jemallocator = "0.3.2" jemalloc-ctl = "0.3.3" k256 = { version = "0.4.2", features = ["ecdsa", "zeroize"] } libc = "0.2.66" -libp2p = { version = "0.34.0", default-features = false, features = ["deflate", "dns", "floodsub", "gossipsub", "identify", "kad", "mdns", "mplex", "noise", "ping", "request-response", "tcp-tokio", "uds", "yamux"] } +libp2p = { version = "0.29.1", default-features = false, features = ["deflate", "dns", "floodsub", "gossipsub", "identify", "kad", "mdns-tokio", "mplex", "noise", "ping", "request-response", "tcp-tokio", "uds", "yamux"] } linked-hash-map = "0.5.3" lmdb = "0.8.0" log = { version = "0.4.8", features = ["std", "serde", "kv_unstable"] } diff --git a/node/src/components/block_validator.rs b/node/src/components/block_validator.rs index 9780ff713c..4984988ebf 100644 --- a/node/src/components/block_validator.rs +++ b/node/src/components/block_validator.rs @@ -18,7 +18,7 @@ use std::{ }; use datasize::DataSize; -use derive_more::Display; +use derive_more::{Display, From}; use semver::Version; use smallvec::{smallvec, SmallVec}; use tracing::error; @@ -37,10 +37,11 @@ use keyed_counter::KeyedCounter; use super::fetcher::FetchResult; /// Block validator component event. -#[derive(Debug, Display)] +#[derive(Debug, From, Display)] pub enum Event { /// A request made of the block validator component. - Request(Box>), + #[from] + Request(BlockValidationRequest), /// A deploy has been successfully found. #[display(fmt = "deploy {} found", _0)] @@ -56,12 +57,6 @@ pub enum Event { Loaded { chainspec: Arc }, } -impl From> for Event { - fn from(request: BlockValidationRequest) -> Self { - Event::Request(Box::new(request)) - } -} - /// State of the current process of block validation. /// /// Tracks whether or not there are deploys still missing and who is interested in the final result. @@ -105,14 +100,12 @@ where { let mut effects = Effects::new(); match event { - Event::Request(request) => { - let BlockValidationRequest { - block, - sender, - responder, - block_timestamp, - } = *request; - + Event::Request(BlockValidationRequest { + block, + sender, + responder, + block_timestamp, + }) => { let block_deploys = block .deploys() .iter() @@ -307,7 +300,10 @@ where } self.state = BlockValidatorState::Ready(new_ready_state); } - (BlockValidatorState::Loading(requests), request @ Event::Request(_)) => { + ( + BlockValidatorState::Loading(requests), + request @ Event::Request(BlockValidationRequest { .. }), + ) => { requests.push(request); } (BlockValidatorState::Loading(_), _deploy_found_or_missing) => { diff --git a/node/src/components/fetcher.rs b/node/src/components/fetcher.rs index fce19fbc0c..53bdeab622 100644 --- a/node/src/components/fetcher.rs +++ b/node/src/components/fetcher.rs @@ -77,7 +77,7 @@ pub trait ItemFetcher { responders .entry(id) .or_default() - .entry(peer) + .entry(peer.clone()) .or_default() .push(responder); @@ -113,7 +113,7 @@ pub trait ItemFetcher { ) -> Effects> { match Message::new_get_request::(&id) { Ok(message) => { - let mut effects = effect_builder.send_message(peer, message).ignore(); + let mut effects = effect_builder.send_message(peer.clone(), message).ignore(); effects.extend( effect_builder @@ -326,9 +326,11 @@ where }, Event::GotRemotely { item, source } => { match source { - Source::Peer(peer) => { - self.signal(item.id(), Some(FetchResult::FromPeer(item, peer)), peer) - } + Source::Peer(peer) => self.signal( + item.id(), + Some(FetchResult::FromPeer(item, peer.clone())), + peer, + ), Source::Client => { // TODO - we could possibly also handle this case Effects::new() diff --git a/node/src/components/fetcher/tests.rs b/node/src/components/fetcher/tests.rs index 7088a3e106..cde6340d99 100644 --- a/node/src/components/fetcher/tests.rs +++ b/node/src/components/fetcher/tests.rs @@ -294,7 +294,7 @@ async fn should_fetch_from_local() { network .process_injected_effect_on( node_id, - fetch_deploy(deploy_hash, *node_id, Arc::clone(&fetched)), + fetch_deploy(deploy_hash, node_id.clone(), Arc::clone(&fetched)), ) .await; @@ -340,11 +340,14 @@ async fn should_fetch_from_peer() { network .process_injected_effect_on( node_without_deploy, - fetch_deploy(deploy_hash, *node_with_deploy, Arc::clone(&fetched)), + fetch_deploy(deploy_hash, node_with_deploy.clone(), Arc::clone(&fetched)), ) .await; - let expected_result = Some(FetchResult::FromPeer(Box::new(deploy), *node_with_deploy)); + let expected_result = Some(FetchResult::FromPeer( + Box::new(deploy), + node_with_deploy.clone(), + )); assert_settled( node_without_deploy, deploy_hash, @@ -375,8 +378,8 @@ async fn should_timeout_fetch_from_peer() { let deploy = Deploy::random(&mut rng); let deploy_hash = *deploy.id(); - let holding_node = node_ids[0]; - let requesting_node = node_ids[1]; + let holding_node = node_ids[0].clone(); + let requesting_node = node_ids[1].clone(); // Store deploy on holding node. store_deploy(&deploy, &holding_node, &mut network, None, &mut rng).await; @@ -386,7 +389,7 @@ async fn should_timeout_fetch_from_peer() { network .process_injected_effect_on( &requesting_node, - fetch_deploy(deploy_hash, holding_node, Arc::clone(&fetched)), + fetch_deploy(deploy_hash, holding_node.clone(), Arc::clone(&fetched)), ) .await; diff --git a/node/src/components/gossiper.rs b/node/src/components/gossiper.rs index ff80385573..05c047cc3a 100644 --- a/node/src/components/gossiper.rs +++ b/node/src/components/gossiper.rs @@ -304,7 +304,9 @@ impl> Gossiper { return self.check_get_from_peer_timeout(effect_builder, item_id, holder); } }; - let mut effects = effect_builder.send_message(holder, request).ignore(); + let mut effects = effect_builder + .send_message(holder.clone(), request) + .ignore(); effects.extend( effect_builder .set_timeout(self.get_from_peer_timeout) @@ -329,10 +331,10 @@ impl> Gossiper { ) -> Effects> { let action = if T::ID_IS_COMPLETE_ITEM { self.table - .new_complete_data(&item_id, Some(sender)) + .new_complete_data(&item_id, Some(sender.clone())) .map_or_else(|| GossipAction::Noop, GossipAction::ShouldGossip) } else { - self.table.new_partial_data(&item_id, sender) + self.table.new_partial_data(&item_id, sender.clone()) }; match action { @@ -369,7 +371,7 @@ impl> Gossiper { item_id, is_already_held: false, }; - let mut effects = effect_builder.send_message(sender, reply).ignore(); + let mut effects = effect_builder.send_message(sender.clone(), reply).ignore(); effects.extend( effect_builder .set_timeout(self.get_from_peer_timeout) @@ -406,7 +408,11 @@ impl> Gossiper { if !T::ID_IS_COMPLETE_ITEM { // `sender` doesn't hold the full item; get the item from the component responsible // for holding it, then send it to `sender`. - effects.extend((self.get_from_holder)(effect_builder, item_id, sender)); + effects.extend((self.get_from_holder)( + effect_builder, + item_id, + sender.clone(), + )); } self.table.we_infected(&item_id, sender) }; diff --git a/node/src/components/gossiper/gossip_table.rs b/node/src/components/gossiper/gossip_table.rs index 3d1435fcd5..a39f836055 100644 --- a/node/src/components/gossiper/gossip_table.rs +++ b/node/src/components/gossiper/gossip_table.rs @@ -91,11 +91,12 @@ impl State { } if is_new { - let holder = *self + let holder = self .holders .iter() .next() - .expect("holders cannot be empty if we don't hold the data"); + .expect("holders cannot be empty if we don't hold the data") + .clone(); GossipAction::GetRemainder { holder } } else { GossipAction::AwaitingRemainder @@ -315,9 +316,9 @@ impl GossipTable { ); return None; } - let _ = state.holders.insert(peer); + let _ = state.holders.insert(peer.clone()); if by_us { - let _ = state.infected_by_us.insert(peer); + let _ = state.infected_by_us.insert(peer.clone()); } state.in_flight_count = state.in_flight_count.saturating_sub(1); Some(state.is_finished(infection_target, holders_limit)) @@ -518,55 +519,55 @@ mod tests { assert_eq!(EXPECTED_DEFAULT_HOLDERS_LIMIT, gossip_table.holders_limit); // Check new partial data causes `GetRemainder` to be returned. - let action = gossip_table.new_partial_data(&data_id, node_ids[0]); + let action = gossip_table.new_partial_data(&data_id, node_ids[0].clone()); let expected = GossipAction::GetRemainder { - holder: node_ids[0], + holder: node_ids[0].clone(), }; assert_eq!(expected, action); check_holders(&node_ids[..1], &gossip_table, &data_id); // Check same partial data from same source causes `AwaitingRemainder` to be returned. - let action = gossip_table.new_partial_data(&data_id, node_ids[0]); + let action = gossip_table.new_partial_data(&data_id, node_ids[0].clone()); assert_eq!(GossipAction::AwaitingRemainder, action); check_holders(&node_ids[..1], &gossip_table, &data_id); // Check same partial data from different source causes `AwaitingRemainder` to be returned // and holders updated. - let action = gossip_table.new_partial_data(&data_id, node_ids[1]); + let action = gossip_table.new_partial_data(&data_id, node_ids[1].clone()); assert_eq!(GossipAction::AwaitingRemainder, action); check_holders(&node_ids[..2], &gossip_table, &data_id); // Pause gossiping and check same partial data from third source causes `Noop` to be // returned and holders updated. gossip_table.pause(&data_id); - let action = gossip_table.new_partial_data(&data_id, node_ids[2]); + let action = gossip_table.new_partial_data(&data_id, node_ids[2].clone()); assert_eq!(GossipAction::Noop, action); check_holders(&node_ids[..3], &gossip_table, &data_id); // Reset the data and check same partial data from fourth source causes `AwaitingRemainder` // to be returned and holders updated. gossip_table.resume(&data_id).unwrap(); - let action = gossip_table.new_partial_data(&data_id, node_ids[3]); + let action = gossip_table.new_partial_data(&data_id, node_ids[3].clone()); assert_eq!(GossipAction::AwaitingRemainder, action); check_holders(&node_ids[..4], &gossip_table, &data_id); // Finish the gossip by reporting three infections, then check same partial data causes // `Noop` to be returned and holders cleared. - let _ = gossip_table.new_complete_data(&data_id, Some(node_ids[0])); + let _ = gossip_table.new_complete_data(&data_id, Some(node_ids[0].clone())); let limit = 4 + EXPECTED_DEFAULT_INFECTION_TARGET; for node_id in &node_ids[4..limit] { - let _ = gossip_table.we_infected(&data_id, *node_id); + let _ = gossip_table.we_infected(&data_id, node_id.clone()); } - let action = gossip_table.new_partial_data(&data_id, node_ids[limit]); + let action = gossip_table.new_partial_data(&data_id, node_ids[limit].clone()); assert_eq!(GossipAction::Noop, action); check_holders(&node_ids[..0], &gossip_table, &data_id); // Time the finished data out, then check same partial data causes `GetRemainder` to be // returned as per a completely new entry. Instant::advance_time(DEFAULT_FINISHED_ENTRY_DURATION_SECS * 1_000 + 1); - let action = gossip_table.new_partial_data(&data_id, node_ids[0]); + let action = gossip_table.new_partial_data(&data_id, node_ids[0].clone()); let expected = GossipAction::GetRemainder { - holder: node_ids[0], + holder: node_ids[0].clone(), }; assert_eq!(expected, action); check_holders(&node_ids[..1], &gossip_table, &data_id); @@ -580,9 +581,9 @@ mod tests { let mut gossip_table = GossipTable::new(Config::default()); - let _ = gossip_table.new_partial_data(&data_id, node_id); + let _ = gossip_table.new_partial_data(&data_id, node_id.clone()); - let action = gossip_table.we_infected(&data_id, node_id); + let action = gossip_table.we_infected(&data_id, node_id.clone()); assert_eq!(GossipAction::Noop, action); let action = gossip_table.already_infected(&data_id, node_id); @@ -609,13 +610,13 @@ mod tests { // Check same complete data from other source causes `Noop` to be returned since we still // have all gossip requests in flight. Check it updates holders. - let action = gossip_table.new_complete_data(&data_id, Some(node_ids[0])); + let action = gossip_table.new_complete_data(&data_id, Some(node_ids[0].clone())); assert!(action.is_none()); check_holders(&node_ids[..1], &gossip_table, &data_id); // Check receiving a gossip response, causes `ShouldGossip` to be returned and holders // updated. - let action = gossip_table.already_infected(&data_id, node_ids[1]); + let action = gossip_table.already_infected(&data_id, node_ids[1].clone()); let expected = GossipAction::ShouldGossip(ShouldGossip { count: 1, exclude_peers: node_ids[..2].iter().cloned().collect(), @@ -627,7 +628,7 @@ mod tests { // Pause gossiping and check same complete data from third source causes `Noop` to be // returned and holders updated. gossip_table.pause(&data_id); - let action = gossip_table.new_complete_data(&data_id, Some(node_ids[2])); + let action = gossip_table.new_complete_data(&data_id, Some(node_ids[2].clone())); assert!(action.is_none()); check_holders(&node_ids[..3], &gossip_table, &data_id); @@ -641,7 +642,7 @@ mod tests { }); assert_eq!(expected, action); - let action = gossip_table.new_complete_data(&data_id, Some(node_ids[3])); + let action = gossip_table.new_complete_data(&data_id, Some(node_ids[3].clone())); assert!(action.is_none()); check_holders(&node_ids[..4], &gossip_table, &data_id); @@ -649,7 +650,7 @@ mod tests { // causes `Noop` to be returned and holders cleared. let limit = 4 + EXPECTED_DEFAULT_INFECTION_TARGET; for node_id in &node_ids[4..limit] { - let _ = gossip_table.we_infected(&data_id, *node_id); + let _ = gossip_table.we_infected(&data_id, node_id.clone()); } let action = gossip_table.new_complete_data(&data_id, None); assert!(action.is_none()); @@ -658,7 +659,7 @@ mod tests { // Time the finished data out, then check same complete data causes `ShouldGossip` to be // returned as per a completely new entry. Instant::advance_time(DEFAULT_FINISHED_ENTRY_DURATION_SECS * 1_000 + 1); - let action = gossip_table.new_complete_data(&data_id, Some(node_ids[0])); + let action = gossip_table.new_complete_data(&data_id, Some(node_ids[0].clone())); let expected = Some(ShouldGossip { count: EXPECTED_DEFAULT_INFECTION_TARGET, exclude_peers: node_ids[..1].iter().cloned().collect(), @@ -681,14 +682,14 @@ mod tests { let _ = gossip_table.new_complete_data(&data_id, None); let limit = EXPECTED_DEFAULT_INFECTION_TARGET - 1; for node_id in node_ids.iter().take(limit) { - let action = gossip_table.we_infected(&data_id, *node_id); + let action = gossip_table.we_infected(&data_id, node_id.clone()); assert_eq!(GossipAction::Noop, action); assert!(!gossip_table.finished.contains(&data_id)); } // Check recording an infection from an already-recorded infectee doesn't cause us to stop // gossiping. - let action = gossip_table.we_infected(&data_id, node_ids[limit - 1]); + let action = gossip_table.we_infected(&data_id, node_ids[limit - 1].clone()); let expected = GossipAction::ShouldGossip(ShouldGossip { count: 1, exclude_peers: node_ids[..limit].iter().cloned().collect(), @@ -698,7 +699,7 @@ mod tests { assert!(!gossip_table.finished.contains(&data_id)); // Check third new infection does cause us to stop gossiping. - let action = gossip_table.we_infected(&data_id, node_ids[limit]); + let action = gossip_table.we_infected(&data_id, node_ids[limit].clone()); assert_eq!(GossipAction::Noop, action); assert!(gossip_table.finished.contains(&data_id)); } @@ -716,7 +717,7 @@ mod tests { let _ = gossip_table.new_complete_data(&data_id, None); let limit = EXPECTED_DEFAULT_HOLDERS_LIMIT - 1; for (index, node_id) in node_ids.iter().enumerate().take(limit) { - let action = gossip_table.already_infected(&data_id, *node_id); + let action = gossip_table.already_infected(&data_id, node_id.clone()); let expected = GossipAction::ShouldGossip(ShouldGossip { count: 1, exclude_peers: node_ids[..(index + 1)].iter().cloned().collect(), @@ -727,7 +728,7 @@ mod tests { // Check recording a non-infection from an already-recorded holder doesn't cause us to stop // gossiping. - let action = gossip_table.already_infected(&data_id, node_ids[0]); + let action = gossip_table.already_infected(&data_id, node_ids[0].clone()); let expected = GossipAction::ShouldGossip(ShouldGossip { count: 1, exclude_peers: node_ids[..limit].iter().cloned().collect(), @@ -736,7 +737,7 @@ mod tests { assert_eq!(expected, action); // Check 15th non-infection does cause us to stop gossiping. - let action = gossip_table.we_infected(&data_id, node_ids[limit]); + let action = gossip_table.we_infected(&data_id, node_ids[limit].clone()); assert_eq!(GossipAction::Noop, action); } @@ -752,16 +753,16 @@ mod tests { let _ = gossip_table.new_complete_data(&data_id, None); let infection_limit = EXPECTED_DEFAULT_INFECTION_TARGET - 1; for node_id in &node_ids[0..infection_limit] { - let _ = gossip_table.we_infected(&data_id, *node_id); + let _ = gossip_table.we_infected(&data_id, node_id.clone()); } let holders_limit = EXPECTED_DEFAULT_HOLDERS_LIMIT - 2; for node_id in &node_ids[infection_limit..holders_limit] { - let _ = gossip_table.already_infected(&data_id, *node_id); + let _ = gossip_table.already_infected(&data_id, node_id.clone()); } // Check adding 12th non-infection doesn't cause us to stop gossiping. - let action = gossip_table.already_infected(&data_id, node_ids[holders_limit]); + let action = gossip_table.already_infected(&data_id, node_ids[holders_limit].clone()); let expected = GossipAction::ShouldGossip(ShouldGossip { count: 1, exclude_peers: node_ids[..(holders_limit + 1)].iter().cloned().collect(), @@ -780,14 +781,14 @@ mod tests { // Add new complete data and get a response from node 0 only. let _ = gossip_table.new_complete_data(&data_id, None); - let _ = gossip_table.we_infected(&data_id, node_ids[0]); + let _ = gossip_table.we_infected(&data_id, node_ids[0].clone()); // check_timeout for node 0 should return Noop, and for node 1 it should represent a timed // out response and return ShouldGossip. - let action = gossip_table.check_timeout(&data_id, node_ids[0]); + let action = gossip_table.check_timeout(&data_id, node_ids[0].clone()); assert_eq!(GossipAction::Noop, action); - let action = gossip_table.check_timeout(&data_id, node_ids[1]); + let action = gossip_table.check_timeout(&data_id, node_ids[1].clone()); let expected = GossipAction::ShouldGossip(ShouldGossip { count: 1, exclude_peers: node_ids[..=1].iter().cloned().collect(), @@ -807,8 +808,8 @@ mod tests { let data_id: u64 = rng.gen(); let mut gossip_table = GossipTable::new(Config::default()); - let _ = gossip_table.new_partial_data(&data_id, node_ids[0]); - let _ = gossip_table.check_timeout(&data_id, node_ids[0]); + let _ = gossip_table.new_partial_data(&data_id, node_ids[0].clone()); + let _ = gossip_table.check_timeout(&data_id, node_ids[0].clone()); } #[test] @@ -820,47 +821,47 @@ mod tests { let mut gossip_table = GossipTable::new(Config::default()); // Add new partial data from nodes 0 and 1. - let _ = gossip_table.new_partial_data(&data_id, node_ids[0]); - let _ = gossip_table.new_partial_data(&data_id, node_ids[1]); + let _ = gossip_table.new_partial_data(&data_id, node_ids[0].clone()); + let _ = gossip_table.new_partial_data(&data_id, node_ids[1].clone()); // Node 0 should be removed from the holders since it hasn't provided us with the full data, // and we should be told to get the remainder from node 1. - let action = gossip_table.remove_holder_if_unresponsive(&data_id, node_ids[0]); + let action = gossip_table.remove_holder_if_unresponsive(&data_id, node_ids[0].clone()); let expected = GossipAction::GetRemainder { - holder: node_ids[1], + holder: node_ids[1].clone(), }; assert_eq!(expected, action); check_holders(&node_ids[1..2], &gossip_table, &data_id); // Node 1 should be removed from the holders since it hasn't provided us with the full data, // and the entry should be removed since there are no more holders. - let action = gossip_table.remove_holder_if_unresponsive(&data_id, node_ids[1]); + let action = gossip_table.remove_holder_if_unresponsive(&data_id, node_ids[1].clone()); assert_eq!(GossipAction::Noop, action); check_holders(&node_ids[..0], &gossip_table, &data_id); assert!(!gossip_table.current.contains_key(&data_id)); assert!(!gossip_table.paused.contains_key(&data_id)); // Add new partial data from node 2 and check gossiping has been resumed. - let action = gossip_table.new_partial_data(&data_id, node_ids[2]); + let action = gossip_table.new_partial_data(&data_id, node_ids[2].clone()); let expected = GossipAction::GetRemainder { - holder: node_ids[2], + holder: node_ids[2].clone(), }; assert_eq!(expected, action); check_holders(&node_ids[2..3], &gossip_table, &data_id); // Node 2 should be removed from the holders since it hasn't provided us with the full data, // and the entry should be paused since there are no more holders. - let action = gossip_table.remove_holder_if_unresponsive(&data_id, node_ids[2]); + let action = gossip_table.remove_holder_if_unresponsive(&data_id, node_ids[2].clone()); assert_eq!(GossipAction::Noop, action); check_holders(&node_ids[..0], &gossip_table, &data_id); assert!(!gossip_table.current.contains_key(&data_id)); assert!(!gossip_table.paused.contains_key(&data_id)); // Add new complete data from node 3 and check gossiping has been resumed. - let action = gossip_table.new_complete_data(&data_id, Some(node_ids[3])); + let action = gossip_table.new_complete_data(&data_id, Some(node_ids[3].clone())); let expected = Some(ShouldGossip { count: EXPECTED_DEFAULT_INFECTION_TARGET, - exclude_peers: iter::once(node_ids[3]).collect(), + exclude_peers: iter::once(node_ids[3].clone()).collect(), is_already_held: false, }); assert_eq!(expected, action); @@ -876,11 +877,11 @@ mod tests { let mut gossip_table = GossipTable::new(Config::default()); // Add new partial data from node 0 and record that we have received the full data from it. - let _ = gossip_table.new_partial_data(&data_id, node_ids[0]); - let _ = gossip_table.new_complete_data(&data_id, Some(node_ids[0])); + let _ = gossip_table.new_partial_data(&data_id, node_ids[0].clone()); + let _ = gossip_table.new_complete_data(&data_id, Some(node_ids[0].clone())); // Node 0 should remain as a holder since we now hold the complete data. - let action = gossip_table.remove_holder_if_unresponsive(&data_id, node_ids[0]); + let action = gossip_table.remove_holder_if_unresponsive(&data_id, node_ids[0].clone()); assert_eq!(GossipAction::Noop, action); // Noop as all RPCs are still in-flight check_holders(&node_ids[..1], &gossip_table, &data_id); assert!(gossip_table.current.contains_key(&data_id)); @@ -897,14 +898,14 @@ mod tests { // Add new partial data from node 0, manually pause gossiping, then record that node 0 // failed to provide the full data. - let _ = gossip_table.new_partial_data(&data_id, node_ids[0]); + let _ = gossip_table.new_partial_data(&data_id, node_ids[0].clone()); gossip_table.pause(&data_id); - let action = gossip_table.remove_holder_if_unresponsive(&data_id, node_ids[0]); + let action = gossip_table.remove_holder_if_unresponsive(&data_id, node_ids[0].clone()); assert_eq!(GossipAction::Noop, action); check_holders(&node_ids[..0], &gossip_table, &data_id); // Add new partial data from node 1 and check gossiping has not been resumed. - let action = gossip_table.new_partial_data(&data_id, node_ids[1]); + let action = gossip_table.new_partial_data(&data_id, node_ids[1].clone()); assert_eq!(GossipAction::Noop, action); check_holders(&node_ids[1..2], &gossip_table, &data_id); assert!(!gossip_table.current.contains_key(&data_id)); @@ -922,7 +923,7 @@ mod tests { // Add new complete data and finish via infection limit. let _ = gossip_table.new_complete_data(&data_id, None); for node_id in &node_ids[0..EXPECTED_DEFAULT_INFECTION_TARGET] { - let _ = gossip_table.we_infected(&data_id, *node_id); + let _ = gossip_table.we_infected(&data_id, node_id.clone()); } assert!(gossip_table.finished.contains(&data_id)); @@ -957,7 +958,7 @@ mod tests { for deploy_id in &deploy_ids { let _ = gossip_table.new_complete_data(deploy_id, None); for node_id in &node_ids[0..EXPECTED_DEFAULT_INFECTION_TARGET] { - let _ = gossip_table.we_infected(deploy_id, *node_id); + let _ = gossip_table.we_infected(deploy_id, node_id.clone()); } assert!(gossip_table.finished.contains(&deploy_id)); } diff --git a/node/src/components/gossiper/tests.rs b/node/src/components/gossiper/tests.rs index b6bf45169d..2ef9228e51 100644 --- a/node/src/components/gossiper/tests.rs +++ b/node/src/components/gossiper/tests.rs @@ -440,7 +440,7 @@ async fn should_get_from_alternate_source() { debug!("removed node {}", &node_ids[0]); // Run node 2 until it receives and responds to the gossip request from node 0. - let node_id_0 = node_ids[0]; + let node_id_0 = node_ids[0].clone(); let sent_gossip_response = move |event: &Event| -> bool { match event { Event::NetworkRequest(NetworkRequest::SendMessage { diff --git a/node/src/components/in_memory_network.rs b/node/src/components/in_memory_network.rs index 23ff3b6ba3..0e3c942f20 100644 --- a/node/src/components/in_memory_network.rs +++ b/node/src/components/in_memory_network.rs @@ -481,7 +481,7 @@ where { let mut nodes_write = nodes.write().expect("network lock poisoned"); assert!(!nodes_write.contains_key(&node_id)); - nodes_write.insert(node_id, sender); + nodes_write.insert(node_id.clone(), sender); } tokio::spawn(receiver_task(event_queue, receiver)); @@ -492,7 +492,7 @@ where /// Returns this node's ID. #[inline] pub fn node_id(&self) -> NodeId { - self.node_id + self.node_id.clone() } } @@ -513,7 +513,7 @@ where match nodes.get(&dest) { Some(sender) => { - if let Err(SendError((_, msg))) = sender.send((self.node_id, payload)) { + if let Err(SendError((_, msg))) = sender.send((self.node_id.clone(), payload)) { warn!(%dest, %msg, "could not send message (send error)"); // We do nothing else, the message is just dropped. @@ -558,7 +558,7 @@ where NetworkRequest::Broadcast { payload, responder } => { if let Ok(guard) = self.nodes.read() { for dest in guard.keys().filter(|&node_id| node_id != &self.node_id) { - self.send(&guard, *dest, payload.clone()); + self.send(&guard, dest.clone(), payload.clone()); } } else { error!("network lock has been poisoned") @@ -582,7 +582,7 @@ where .collect(); // Not terribly efficient, but will always get us the maximum amount of nodes. for dest in chosen.iter() { - self.send(&guard, *dest, payload.clone()); + self.send(&guard, dest.clone(), payload.clone()); } responder.respond(chosen).ignore() } else { diff --git a/node/src/components/network.rs b/node/src/components/network.rs index 1868a61c86..e3bef269e0 100644 --- a/node/src/components/network.rs +++ b/node/src/components/network.rs @@ -33,7 +33,7 @@ use libp2p::{ request_response::{RequestResponseEvent, RequestResponseMessage}, swarm::{SwarmBuilder, SwarmEvent}, tcp::TokioTcpConfig, - yamux::YamuxConfig, + yamux::Config as YamuxConfig, Multiaddr, PeerId, Swarm, Transport, }; use rand::seq::IteratorRandom; @@ -145,7 +145,7 @@ impl, P: PayloadT> Network { // Create a new Ed25519 keypair for this session. let our_id_keys = Keypair::generate_ed25519(); let our_peer_id = PeerId::from(our_id_keys.public()); - let our_id = NodeId::from(our_peer_id); + let our_id = NodeId::from(our_peer_id.clone()); // Convert the known addresses to multiaddr format and prepare the shutdown signal. let known_addresses = config @@ -206,8 +206,7 @@ impl, P: PayloadT> Network { .boxed(); // Create a Swarm to manage peers and events. - let behavior = Behavior::new(&config, chainspec, our_id_keys.public())?; - + let behavior = Behavior::new(&config, chainspec, our_id_keys.public()); let mut swarm = SwarmBuilder::new(transport, behavior, our_peer_id) .executor(Box::new(|future| { tokio::spawn(future); @@ -274,7 +273,7 @@ impl, P: PayloadT> Network { } } - let _ = self.peers.insert(peer_id, endpoint); + let _ = self.peers.insert(peer_id.clone(), endpoint); // TODO - see if this can be removed. The announcement is only used by the joiner reactor. effect_builder.announce_new_peer(peer_id).ignore() } @@ -370,7 +369,7 @@ impl, P: PayloadT> Network { } for &peer_id in &peer_ids { - self.send_message(*peer_id, payload.clone()); + self.send_message(peer_id.clone(), payload.clone()); } peer_ids.into_iter().cloned().collect() @@ -389,12 +388,12 @@ impl, P: PayloadT> Network { /// Returns the node id of this network node. #[cfg(test)] pub(crate) fn node_id(&self) -> NodeId { - self.our_id + self.our_id.clone() } } fn our_id(swarm: &Swarm) -> NodeId { - NodeId::P2p(*Swarm::local_peer_id(swarm)) + NodeId::P2p(Swarm::local_peer_id(swarm).clone()) } async fn server_task, P: PayloadT>( @@ -615,7 +614,6 @@ async fn handle_one_way_messaging_event, P: PayloadT>( our_id(swarm) ) } - RequestResponseEvent::ResponseSent { .. } => {} } } @@ -625,17 +623,13 @@ async fn handle_gossip_event, P: PayloadT>( event: GossipsubEvent, ) { match event { - GossipsubEvent::Message { - propagation_source: sender, - message, - .. - } => { + GossipsubEvent::Message(_sender, _message_id, message) => { // We've received a gossiped message: announce it via the reactor on the // `NetworkIncoming` queue. let sender = match message.source { Some(source) => NodeId::from(source), None => { - warn!(%sender, ?message, "{}: libp2p gossiped message without source", our_id(swarm)); + warn!(%_sender, ?message, "{}: libp2p gossiped message without source", our_id(swarm)); return; } }; @@ -881,7 +875,7 @@ impl, P: PayloadT> Component for Network { .peers .iter() .map(|(node_id, endpoint)| { - (*node_id, endpoint.get_remote_address().to_string()) + (node_id.clone(), endpoint.get_remote_address().to_string()) }) .collect(); responder.respond(peers).ignore() diff --git a/node/src/components/network/behavior.rs b/node/src/components/network/behavior.rs index 399034f280..7af99e1d4f 100644 --- a/node/src/components/network/behavior.rs +++ b/node/src/components/network/behavior.rs @@ -6,7 +6,7 @@ use std::{ use derive_more::From; use libp2p::{ core::PublicKey, - gossipsub::{Gossipsub, GossipsubEvent, IdentTopic}, + gossipsub::{Gossipsub, GossipsubEvent}, identify::{Identify, IdentifyEvent}, kad::{record::store::MemoryStore, Kademlia, KademliaEvent}, request_response::{RequestResponse, RequestResponseEvent}, @@ -16,8 +16,8 @@ use libp2p::{ use tracing::{info, trace, warn}; use super::{ - gossip, one_way_messaging, peer_discovery, Config, Error, GossipMessage, OneWayCodec, - OneWayOutgoingMessage, + gossip::{self, TOPIC}, + one_way_messaging, peer_discovery, Config, GossipMessage, OneWayCodec, OneWayOutgoingMessage, }; use crate::{components::chainspec_loader::Chainspec, types::NodeId}; @@ -45,33 +45,25 @@ pub(super) struct Behavior { /// Events generated by the behavior that are pending a poll. #[behaviour(ignore)] events: VecDeque, - #[behaviour(ignore)] - gossip_topic: IdentTopic, } impl Behavior { - pub(super) fn new( - config: &Config, - chainspec: &Chainspec, - our_public_key: PublicKey, - ) -> Result { + pub(super) fn new(config: &Config, chainspec: &Chainspec, our_public_key: PublicKey) -> Self { let one_way_message_behavior = one_way_messaging::new_behavior(config, chainspec); - let (gossip_behavior, gossip_topic) = - gossip::new_behavior(config, chainspec, our_public_key.clone())?; + let gossip_behavior = gossip::new_behavior(config, chainspec, our_public_key.clone()); let (kademlia_behavior, identify_behavior) = peer_discovery::new_behaviors(config, chainspec, our_public_key.clone()); - Ok(Behavior { + Behavior { one_way_message_behavior, gossip_behavior, kademlia_behavior, identify_behavior, our_id: NodeId::P2p(PeerId::from(our_public_key)), events: VecDeque::new(), - gossip_topic, - }) + } } /// Sends the given message out. @@ -120,7 +112,9 @@ impl Behavior { /// Performs a random kademlia lookup in order to refresh the routing table. pub(super) fn discover_peers(&mut self) { let random_address = PeerId::random(); - let query_id = self.kademlia_behavior.get_closest_peers(random_address); + let query_id = self + .kademlia_behavior + .get_closest_peers(random_address.clone()); info!( "{}: random kademlia lookup for peers closest to {} with {:?}", self.our_id, random_address, query_id @@ -129,10 +123,7 @@ impl Behavior { /// Initiates gossiping the given message. pub(super) fn gossip(&mut self, message: GossipMessage) { - if let Err(error) = self - .gossip_behavior - .publish(self.gossip_topic.clone(), message) - { + if let Err(error) = self.gossip_behavior.publish(&*TOPIC, message) { warn!(?error, "{}: failed to gossip new message", self.our_id); } } diff --git a/node/src/components/network/error.rs b/node/src/components/network/error.rs index ab082eb9ce..0fc8f5fa33 100644 --- a/node/src/components/network/error.rs +++ b/node/src/components/network/error.rs @@ -1,9 +1,6 @@ use std::io; -use libp2p::{ - core::connection::ConnectionLimit, gossipsub::error::SubscriptionError, noise::NoiseError, - Multiaddr, TransportError, -}; +use libp2p::{core::connection::ConnectionLimit, noise::NoiseError, Multiaddr, TransportError}; use thiserror::Error; /// Error type returned by the `Network` component. @@ -42,18 +39,4 @@ pub enum Error { /// Message too large. #[error("message of {actual_size} bytes exceeds limit of {max_size} bytes")] MessageTooLarge { max_size: u32, actual_size: u64 }, - - /// Behavior error. - #[error("unable to create new behavior {0}")] - Behavior(String), - - /// Subscription error. - #[error("subscription error")] - Subscription(String), -} - -impl From for Error { - fn from(error: SubscriptionError) -> Self { - Error::Subscription(format!("{:?}", error)) - } } diff --git a/node/src/components/network/gossip.rs b/node/src/components/network/gossip.rs index eb761c45e9..60fe1c3d37 100644 --- a/node/src/components/network/gossip.rs +++ b/node/src/components/network/gossip.rs @@ -2,12 +2,11 @@ //! gossiping data to subscribed peers. use libp2p::{ - core::PublicKey, - gossipsub::{ - Gossipsub, GossipsubConfigBuilder, IdentTopic, MessageAuthenticity, ValidationMode, - }, + core::{ProtocolName, PublicKey}, + gossipsub::{Gossipsub, GossipsubConfigBuilder, MessageAuthenticity, Topic, ValidationMode}, PeerId, }; +use once_cell::sync::Lazy; use super::{Config, Error, PayloadT, ProtocolId}; use crate::components::chainspec_loader::Chainspec; @@ -16,6 +15,8 @@ use crate::components::chainspec_loader::Chainspec; /// will be applied to create the full protocol name. const PROTOCOL_NAME_INNER: &str = "validator/gossip"; +pub(super) static TOPIC: Lazy = Lazy::new(|| Topic::new("all".into())); + pub(super) struct GossipMessage(pub Vec); impl GossipMessage { @@ -45,20 +46,17 @@ pub(super) fn new_behavior( config: &Config, chainspec: &Chainspec, our_public_key: PublicKey, -) -> Result<(Gossipsub, IdentTopic), Error> { - let gossipsub_config = GossipsubConfigBuilder::default() - .protocol_id_prefix(PROTOCOL_NAME_INNER) +) -> Gossipsub { + let protocol_id = ProtocolId::new(chainspec, PROTOCOL_NAME_INNER); + let gossipsub_config = GossipsubConfigBuilder::new() + .protocol_id(protocol_id.protocol_name().to_vec()) .heartbeat_interval(config.gossip_heartbeat_interval.into()) .max_transmit_size(config.max_gossip_message_size as usize) .duplicate_cache_time(config.gossip_duplicate_cache_timeout.into()) .validation_mode(ValidationMode::Permissive) - .build() - .map_err(|error| Error::Behavior(error.to_owned()))?; + .build(); let our_peer_id = PeerId::from(our_public_key); - let mut gossipsub = Gossipsub::new(MessageAuthenticity::Author(our_peer_id), gossipsub_config) - .map_err(|error| Error::Behavior(error.to_owned()))?; - let protocol_id = ProtocolId::new(chainspec, PROTOCOL_NAME_INNER); - let topic = IdentTopic::new(protocol_id.id()); - gossipsub.subscribe(&topic)?; - Ok((gossipsub, topic)) + let mut gossipsub = Gossipsub::new(MessageAuthenticity::Author(our_peer_id), gossipsub_config); + gossipsub.subscribe(TOPIC.clone()); + gossipsub } diff --git a/node/src/components/network/one_way_messaging.rs b/node/src/components/network/one_way_messaging.rs index 67fd9ea971..f2f6c83754 100644 --- a/node/src/components/network/one_way_messaging.rs +++ b/node/src/components/network/one_way_messaging.rs @@ -56,9 +56,9 @@ impl Outgoing { }); } - match destination { + match &destination { NodeId::P2p(destination) => Ok(Outgoing { - destination, + destination: destination.clone(), message: serialized_message, }), destination => { diff --git a/node/src/components/network/peer_discovery.rs b/node/src/components/network/peer_discovery.rs index 9119f6ff2d..acfdd50407 100644 --- a/node/src/components/network/peer_discovery.rs +++ b/node/src/components/network/peer_discovery.rs @@ -32,7 +32,7 @@ pub(super) fn new_behaviors( max_value_bytes: 0, ..Default::default() }; - let memory_store = MemoryStore::with_config(our_peer_id, memory_store_config); + let memory_store = MemoryStore::with_config(our_peer_id.clone(), memory_store_config); let protocol_id = ProtocolId::new(chainspec, KADEMLIA_PROTOCOL_NAME_INNER); let mut kademlia_config = KademliaConfig::default(); diff --git a/node/src/components/network/protocol_id.rs b/node/src/components/network/protocol_id.rs index 953f181de9..5221c1a257 100644 --- a/node/src/components/network/protocol_id.rs +++ b/node/src/components/network/protocol_id.rs @@ -27,10 +27,6 @@ impl ProtocolId { ProtocolId { id } } - - pub(super) fn id(&self) -> String { - self.id.clone() - } } impl ProtocolName for ProtocolId { diff --git a/node/src/components/small_network.rs b/node/src/components/small_network.rs index fa65359fc7..7736a90447 100644 --- a/node/src/components/small_network.rs +++ b/node/src/components/small_network.rs @@ -332,7 +332,7 @@ where /// Queues a message to be sent to all nodes. fn broadcast_message(&self, msg: Message

) { for peer_id in self.outgoing.keys() { - self.send_message(*peer_id, msg.clone()); + self.send_message(peer_id.clone(), msg.clone()); } } @@ -363,7 +363,7 @@ where } for &peer_id in &peer_ids { - self.send_message(*peer_id, msg.clone()); + self.send_message(peer_id.clone(), msg.clone()); } peer_ids.into_iter().cloned().collect() @@ -427,7 +427,7 @@ where .ignore::>(); let _ = self.incoming.insert( - peer_id, + peer_id.clone(), IncomingConnection { peer_address, times_seen_asymmetric: 0, @@ -435,15 +435,15 @@ where ); // If the connection is now complete, announce the new peer before starting reader. - effects.extend(self.check_connection_complete(effect_builder, peer_id)); + effects.extend(self.check_connection_complete(effect_builder, peer_id.clone())); effects.extend( message_reader( self.event_queue, stream, self.shutdown_receiver.clone(), - self.our_id, - peer_id, + self.our_id.clone(), + peer_id.clone(), ) .event(move |result| Event::IncomingClosed { result, @@ -505,19 +505,19 @@ where sender, times_seen_asymmetric: 0, }; - if self.outgoing.insert(peer_id, connection).is_some() { + if self.outgoing.insert(peer_id.clone(), connection).is_some() { // We assume that for a reconnect to have happened, the outgoing entry must have // been either non-existent yet or cleaned up by the handler of the connection // closing event. If this is not the case, an assumed invariant has been violated. error!(our_id=%self.our_id, %peer_id, "did not expect leftover channel in outgoing map"); } - let mut effects = self.check_connection_complete(effect_builder, peer_id); + let mut effects = self.check_connection_complete(effect_builder, peer_id.clone()); let handshake = Message::Handshake { genesis_config_hash: self.genesis_config_hash, }; - let peer_id_cloned = peer_id; + let peer_id_cloned = peer_id.clone(); effects.extend( message_sender(receiver, sink, handshake).event(move |result| Event::OutgoingFailed { peer_id: Some(peer_id), @@ -529,7 +529,7 @@ where handshake_reader( self.event_queue, stream, - self.our_id, + self.our_id.clone(), peer_id_cloned, peer_address, ) @@ -612,7 +612,7 @@ where for (node_id, conn) in self.incoming.iter_mut() { if !self.outgoing.contains_key(node_id) { if conn.times_seen_asymmetric >= MAX_ASYMMETRIC_CONNECTION_SEEN { - remove.push(*node_id); + remove.push(node_id.clone()); } else { conn.times_seen_asymmetric += 1; } @@ -623,7 +623,7 @@ where for (node_id, conn) in self.outgoing.iter_mut() { if !self.incoming.contains_key(node_id) { if conn.times_seen_asymmetric >= MAX_ASYMMETRIC_CONNECTION_SEEN { - remove.push(*node_id); + remove.push(node_id.clone()); } else { conn.times_seen_asymmetric += 1; } @@ -743,10 +743,10 @@ where pub(crate) fn peers(&self) -> BTreeMap { let mut ret = BTreeMap::new(); for (node_id, connection) in &self.outgoing { - ret.insert(*node_id, connection.peer_address.to_string()); + ret.insert(node_id.clone(), connection.peer_address.to_string()); } for (node_id, connection) in &self.incoming { - ret.entry(*node_id) + ret.entry(node_id.clone()) .or_insert_with(|| connection.peer_address.to_string()); } ret @@ -764,7 +764,7 @@ where /// - Used in validator test. #[cfg(test)] pub(crate) fn node_id(&self) -> NodeId { - self.our_id + self.our_id.clone() } } @@ -930,6 +930,7 @@ async fn server_task( // stay open, preventing reuse. // We first create a future that never terminates, handling incoming connections: + let cloned_our_id = our_id.clone(); let accept_connections = async move { loop { // We handle accept errors here, since they can be caused by a temporary resource @@ -954,7 +955,7 @@ async fn server_task( // The code in its current state will consume 100% CPU if local resource // exhaustion happens, as no distinction is made and no delay introduced. Err(err) => { - warn!(%our_id, %err, "dropping incoming connection during accept") + warn!(our_id=%cloned_our_id, %err, "dropping incoming connection during accept") } } } @@ -1047,21 +1048,26 @@ where P: DeserializeOwned + Send + Display, REv: From>, { + let our_id_ref = &our_id; + let peer_id_cloned = peer_id.clone(); let read_messages = async move { while let Some(msg_result) = stream.next().await { match msg_result { Ok(msg) => { - debug!(%our_id, %msg, %peer_id, "message received"); + debug!(our_id=%our_id_ref, %msg, peer_id=%peer_id_cloned, "message received"); // We've received a message, push it to the reactor. event_queue .schedule( - Event::IncomingMessage { peer_id, msg }, + Event::IncomingMessage { + peer_id: peer_id_cloned.clone(), + msg, + }, QueueKind::NetworkIncoming, ) .await; } Err(err) => { - warn!(%our_id, %err, %peer_id, "receiving message failed, closing connection"); + warn!(our_id=%our_id_ref, %err, peer_id=%peer_id_cloned, "receiving message failed, closing connection"); return Err(err); } } @@ -1075,7 +1081,7 @@ where // while loop to terminate. match select(Box::pin(shutdown_messages), Box::pin(read_messages)).await { Either::Left(_) => info!( - %our_id, + our_id=%our_id, %peer_id, "shutting down incoming connection message reader" ), diff --git a/node/src/types/node_id.rs b/node/src/types/node_id.rs index 7f01ebecbd..a25f088e76 100644 --- a/node/src/types/node_id.rs +++ b/node/src/types/node_id.rs @@ -5,8 +5,6 @@ use std::{ use datasize::DataSize; use hex_fmt::HexFmt; -#[cfg(test)] -use libp2p::multihash::Multihash; use libp2p::PeerId; use once_cell::sync::Lazy; #[cfg(test)] @@ -18,7 +16,7 @@ use crate::testing::TestRng; use crate::{rpcs::docs::DocExample, tls::KeyFingerprint}; /// The network identifier for a node. -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, DataSize)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, DataSize)] pub enum NodeId { Tls(KeyFingerprint), #[data_size(skip)] @@ -47,8 +45,7 @@ impl NodeId { pub(crate) fn random_p2p(rng: &mut TestRng) -> Self { let mut bytes = [0u8; 32]; rng.fill_bytes(&mut bytes[..]); - let multihash = - Multihash::wrap(multihash::Code::Identity as u64, &bytes).expect("should wrap bytes"); + let multihash = multihash::wrap(multihash::Code::Identity, &bytes); let peer_id = PeerId::from_multihash(multihash).expect("should construct from multihash"); NodeId::P2p(peer_id) } @@ -56,9 +53,9 @@ impl NodeId { /// Used to serialize and deserialize `NodeID` where the (de)serializer isn't a human-readable type. #[derive(Serialize, Deserialize)] -enum NodeIdAsBytes { +enum NodeIdAsBytes<'a> { Tls(KeyFingerprint), - P2p(Vec), + P2p(&'a [u8]), } /// Used to serialize and deserialize `NodeID` where the (de)serializer is a human-readable type. @@ -82,7 +79,7 @@ impl Serialize for NodeId { let helper = match self { NodeId::Tls(key_fingerprint) => NodeIdAsBytes::Tls(*key_fingerprint), - NodeId::P2p(peer_id) => NodeIdAsBytes::P2p(peer_id.to_bytes()), + NodeId::P2p(peer_id) => NodeIdAsBytes::P2p(peer_id.as_ref()), }; helper.serialize(serializer) } @@ -113,8 +110,8 @@ impl<'de> Deserialize<'de> for NodeId { match helper { NodeIdAsBytes::Tls(key_fingerprint) => Ok(NodeId::Tls(key_fingerprint)), NodeIdAsBytes::P2p(bytes) => { - let peer_id = - PeerId::from_bytes(&bytes).map_err(|_| D::Error::custom("invalid PeerId"))?; + let peer_id = PeerId::from_bytes(bytes.to_vec()) + .map_err(|_| D::Error::custom("invalid PeerId"))?; Ok(NodeId::P2p(peer_id)) } } diff --git a/node/src/types/status_feed.rs b/node/src/types/status_feed.rs index e3ce555010..898f389cab 100644 --- a/node/src/types/status_feed.rs +++ b/node/src/types/status_feed.rs @@ -26,7 +26,7 @@ static GET_STATUS_RESULT: Lazy = Lazy::new(|| { let node_id = NodeId::doc_example(); let socket_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 54321); let mut peers = BTreeMap::new(); - peers.insert(*node_id, socket_addr.to_string()); + peers.insert(node_id.clone(), socket_addr.to_string()); let status_feed = StatusFeed:: { last_added_block: Some(Block::doc_example().clone()), peers,