From 36218274c18bd0bf95023e3dd2c5f3449645c999 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Papierski?= Date: Wed, 27 Jan 2021 22:18:31 +0100 Subject: [PATCH 1/2] Update libp2p to 0.34.0 This fixes security advisory on libp2p-deflate. --- Cargo.lock | 501 +++++++++++------- node/Cargo.toml | 2 +- node/src/components/network.rs | 18 +- node/src/components/network/behavior.rs | 21 +- node/src/components/network/error.rs | 19 +- node/src/components/network/gossip.rs | 32 +- .../components/network/one_way_messaging.rs | 4 +- node/src/components/network/peer_discovery.rs | 2 +- node/src/types/node_id.rs | 16 +- 9 files changed, 374 insertions(+), 241 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 22ddf80668..ae71a4d76a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -243,7 +243,7 @@ dependencies = [ "fastrand", "futures-lite", "libc", - "log 0.4.13", + "log 0.4.14", "nb-connect", "once_cell", "parking", @@ -288,7 +288,7 @@ dependencies = [ "futures-lite", "gloo-timers", "kv-log-macro", - "log 0.4.13", + "log 0.4.14", "memchr", "num_cpus", "once_cell", @@ -315,6 +315,19 @@ 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" @@ -560,12 +573,6 @@ 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" @@ -703,7 +710,7 @@ dependencies = [ "dirs", "grpc", "lmdb", - "log 0.4.13", + "log 0.4.14", "num", "num-rational 0.3.2", "parity-wasm 0.42.1", @@ -723,7 +730,7 @@ dependencies = [ "casper-types", "grpc", "lmdb", - "log 0.4.13", + "log 0.4.14", "num-rational 0.3.2", "num-traits", "once_cell", @@ -748,7 +755,7 @@ dependencies = [ "crossbeam-channel 0.5.0", "env_logger", "grpc", - "log 0.4.13", + "log 0.4.14", "num-rational 0.3.2", "num-traits", "once_cell", @@ -780,7 +787,7 @@ dependencies = [ "libc", "linked-hash-map", "lmdb", - "log 0.4.13", + "log 0.4.14", "num", "num-derive", "num-rational 0.3.2", @@ -797,7 +804,7 @@ dependencies = [ "tempfile", "thiserror", "tracing", - "uint", + "uint 0.8.5", "uuid", "wasmi", ] @@ -845,8 +852,8 @@ dependencies = [ "libp2p", "linked-hash-map", "lmdb", - "log 0.4.13", - "multihash", + "log 0.4.14", + "multihash 0.11.4", "num", "num-derive", "num-rational 0.3.2", @@ -890,7 +897,7 @@ dependencies = [ "tracing", "tracing-futures", "tracing-subscriber", - "uint", + "uint 0.8.5", "untrusted", "uuid", "vergen", @@ -939,7 +946,7 @@ dependencies = [ "serde", "serde_json", "serde_test", - "uint", + "uint 0.8.5", "version-sync", ] @@ -971,7 +978,7 @@ dependencies = [ "clap", "heck", "indexmap", - "log 0.4.13", + "log 0.4.14", "proc-macro2", "quote", "serde", @@ -1366,7 +1373,7 @@ dependencies = [ "crossterm_winapi", "lazy_static", "libc", - "mio", + "mio 0.6.23", "parking_lot 0.10.2", "signal-hook", "winapi 0.3.9", @@ -1925,7 +1932,7 @@ checksum = "f26ecb66b4bdca6c1409b40fb255eefc2bd4f6d135dab3c3124f80ffa2a9661e" dependencies = [ "atty", "humantime", - "log 0.4.13", + "log 0.4.14", "regex", "termcolor", ] @@ -2222,18 +2229,6 @@ 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" @@ -2377,7 +2372,7 @@ dependencies = [ "futures 0.1.30", "futures-cpupool", "httpbis", - "log 0.4.13", + "log 0.4.14", "protobuf", "tls-api", "tls-api-stub", @@ -2584,7 +2579,7 @@ dependencies = [ "bytes 0.4.12", "futures 0.1.30", "futures-cpupool", - "log 0.4.13", + "log 0.4.14", "net2", "tls-api", "tls-api-stub", @@ -2678,6 +2673,22 @@ 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" @@ -2731,15 +2742,6 @@ 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" @@ -2858,7 +2860,7 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0de8b303297635ad57c9f5059fd9cee7a47f8e8daa09df0fcd07dd39fb22977f" dependencies = [ - "log 0.4.13", + "log 0.4.14", ] [[package]] @@ -2881,12 +2883,12 @@ checksum = "89203f3fba0a3795506acaad8ebce3c80c0af93f994d5a1d7a0b1eeb23271929" [[package]] name = "libp2p" -version = "0.29.1" +version = "0.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "021f703bfef6e3da78ef9828c8a244d639b8d57eedf58360922aca5ff69dfdcd" +checksum = "d5133112ce42be9482f6a87be92a605dd6bbc9e93c297aee77d172ff06908f3a" dependencies = [ "atomic", - "bytes 0.5.6", + "bytes 1.0.1", "futures 0.3.12", "lazy_static", "libp2p-core", @@ -2906,7 +2908,6 @@ dependencies = [ "libp2p-tcp", "libp2p-uds", "libp2p-yamux", - "multihash", "parity-multiaddr", "parking_lot 0.11.1", "pin-project 1.0.4", @@ -2916,12 +2917,12 @@ dependencies = [ [[package]] name = "libp2p-core" -version = "0.23.1" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3960524389409633550567e8a9e0684d25a33f4f8408887ff897dd9fdfbdb771" +checksum = "dad04d3cef6c1df366a6ab58c9cf8b06497699e335d83ac2174783946ff847d6" dependencies = [ "asn1_der", - "bs58 0.3.1", + "bs58", "ed25519-dalek", "either", "fnv", @@ -2929,8 +2930,8 @@ dependencies = [ "futures-timer", "lazy_static", "libsecp256k1", - "log 0.4.13", - "multihash", + "log 0.4.14", + "multihash 0.13.2", "multistream-select", "parity-multiaddr", "parking_lot 0.11.1", @@ -2943,16 +2944,16 @@ dependencies = [ "sha2 0.9.2", "smallvec 1.6.1", "thiserror", - "unsigned-varint", + "unsigned-varint 0.6.0", "void", "zeroize", ] [[package]] name = "libp2p-core-derive" -version = "0.20.2" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f753d9324cd3ec14bf04b8a8cd0d269c87f294153d6bf2a84497a63a5ad22213" +checksum = "f4bc40943156e42138d22ed3c57ff0e1a147237742715937622a99b10fbe0156" dependencies = [ "quote", "syn", @@ -2960,9 +2961,9 @@ dependencies = [ [[package]] name = "libp2p-deflate" -version = "0.23.0" +version = "0.27.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "567962c5c5f8a1282979441300e1739ba939024010757c3dbfab4d462189df77" +checksum = "6d42eed63305f0420736fa487f9acef720c4528bd7852a6a760f5ccde4813345" dependencies = [ "flate2", "futures 0.3.12", @@ -2971,27 +2972,27 @@ dependencies = [ [[package]] name = "libp2p-dns" -version = "0.23.0" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "436280f5fe21a58fcaff82c2606945579241f32bc0eaf2d39321aa4624a66e7f" +checksum = "5153b6db68fd4baa3b304e377db744dd8fea8ff4e4504509ee636abcde88d3e3" dependencies = [ "futures 0.3.12", "libp2p-core", - "log 0.4.13", + "log 0.4.14", ] [[package]] name = "libp2p-floodsub" -version = "0.23.0" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecc175613c5915332fd6458895407ec242ea055ae3b107a586626d5e3349350a" +checksum = "b3c63dfa06581b24b1d12bf9815b43689a784424be217d6545c800c7c75a207f" dependencies = [ "cuckoofilter", "fnv", "futures 0.3.12", "libp2p-core", "libp2p-swarm", - "log 0.4.13", + "log 0.4.14", "prost", "prost-build", "rand 0.7.3", @@ -3000,40 +3001,40 @@ dependencies = [ [[package]] name = "libp2p-gossipsub" -version = "0.23.0" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d500ad89ba14de4d18bebdff61a0ce3e769f1c5c5a95026c5da90187e5fff5c9" +checksum = "12451ba9493e87c91baf2a6dffce9ddf1fbc807a0861532d7cf477954f8ebbee" dependencies = [ + "asynchronous-codec", "base64 0.13.0", "byteorder", - "bytes 0.5.6", + "bytes 1.0.1", "fnv", "futures 0.3.12", - "futures_codec", "hex_fmt", "libp2p-core", "libp2p-swarm", - "log 0.4.13", - "lru_time_cache", + "log 0.4.14", "prost", "prost-build", "rand 0.7.3", + "regex", "sha2 0.9.2", "smallvec 1.6.1", - "unsigned-varint", + "unsigned-varint 0.6.0", "wasm-timer", ] [[package]] name = "libp2p-identify" -version = "0.23.0" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03b90b350e37f398b73d778bd94422f4e6a3afa2c1582742ce2446b8a0dba787" +checksum = "b40fb36a059b7a8cce1514bd8b546fa612e006c9937caa7f5950cb20021fe91e" dependencies = [ "futures 0.3.12", "libp2p-core", "libp2p-swarm", - "log 0.4.13", + "log 0.4.14", "prost", "prost-build", "smallvec 1.6.1", @@ -3042,83 +3043,81 @@ dependencies = [ [[package]] name = "libp2p-kad" -version = "0.24.0" +version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb78341f114bf686d5fe50b33ff1a804d88fb326c0d39ee1c22db4346b21fc27" +checksum = "456f5de8e283d7800ca848b9b9a4e2a578b790bd8ae582b885e831353cf0e5df" dependencies = [ "arrayvec", - "bytes 0.5.6", + "asynchronous-codec", + "bytes 1.0.1", "either", "fnv", "futures 0.3.12", - "futures_codec", "libp2p-core", "libp2p-swarm", - "log 0.4.13", - "multihash", + "log 0.4.14", "prost", "prost-build", "rand 0.7.3", "sha2 0.9.2", "smallvec 1.6.1", - "uint", - "unsigned-varint", + "uint 0.9.0", + "unsigned-varint 0.6.0", "void", "wasm-timer", ] [[package]] name = "libp2p-mdns" -version = "0.23.0" +version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b575514fce0a3ccbd065d6aa377bd4d5102001b05c1a22a5eee49c450254ef0f" +checksum = "b974db63233fc0e199f4ede7794294aae285c96f4b6010f853eac4099ef08590" dependencies = [ + "async-io", "data-encoding", "dns-parser", - "either", "futures 0.3.12", + "if-watch", "lazy_static", "libp2p-core", "libp2p-swarm", - "log 0.4.13", - "net2", + "log 0.4.14", "rand 0.7.3", "smallvec 1.6.1", - "tokio 0.2.24", + "socket2", "void", - "wasm-timer", ] [[package]] name = "libp2p-mplex" -version = "0.23.1" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a92b538238c80067c6417a58a07e41002b69d129355b60ec147d6337fdff0eb0" +checksum = "2705dc94b01ab9e3779b42a09bbf3712e637ed213e875c30face247291a85af0" dependencies = [ - "bytes 0.5.6", + "asynchronous-codec", + "bytes 1.0.1", "futures 0.3.12", - "futures_codec", "libp2p-core", - "log 0.4.13", + "log 0.4.14", "nohash-hasher", "parking_lot 0.11.1", "rand 0.7.3", "smallvec 1.6.1", - "unsigned-varint", + "unsigned-varint 0.6.0", ] [[package]] name = "libp2p-noise" -version = "0.25.0" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93c77142e3e5b18fefa7d267305c777c9cbe9b2232ec489979390100bebcc1e6" +checksum = "4aca322b52a0c5136142a7c3971446fb1e9964923a526c9cc6ef3b7c94e57778" dependencies = [ - "bytes 0.5.6", + "bytes 1.0.1", "curve25519-dalek", "futures 0.3.12", "lazy_static", "libp2p-core", - "log 0.4.13", + "log 0.4.14", "prost", "prost-build", "rand 0.7.3", @@ -3131,14 +3130,14 @@ dependencies = [ [[package]] name = "libp2p-ping" -version = "0.23.0" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7257135609e8877f4d286935cbe1e572b2018946881c3e7f63054577074a7ee7" +checksum = "6f3813276d0708c8db0f500d8beda1bda9ad955723b9cb272c41f4727256f73c" dependencies = [ "futures 0.3.12", "libp2p-core", "libp2p-swarm", - "log 0.4.13", + "log 0.4.14", "rand 0.7.3", "void", "wasm-timer", @@ -3146,34 +3145,34 @@ dependencies = [ [[package]] name = "libp2p-request-response" -version = "0.4.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02ba1aa5727ccc118c09ba5111480873f2fe5608cb304e258fd12c173ecf27c9" +checksum = "d37637a4b33b5390322ccc068a33897d0aa541daf4fec99f6a7efbf37295346e" dependencies = [ "async-trait", - "bytes 0.5.6", + "bytes 1.0.1", "futures 0.3.12", "libp2p-core", "libp2p-swarm", - "log 0.4.13", + "log 0.4.14", "lru", "minicbor", "rand 0.7.3", "smallvec 1.6.1", - "unsigned-varint", + "unsigned-varint 0.6.0", "wasm-timer", ] [[package]] name = "libp2p-swarm" -version = "0.23.0" +version = "0.27.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffa6fa33b16956b8a58afbfebe1406866011a1ab8960765bd36868952d7be6a1" +checksum = "d4f89ebb4d8953bda12623e9871959fe728dea3bf6eae0421dc9c42dc821e488" dependencies = [ "either", "futures 0.3.12", "libp2p-core", - "log 0.4.13", + "log 0.4.14", "rand 0.7.3", "smallvec 1.6.1", "void", @@ -3182,37 +3181,40 @@ dependencies = [ [[package]] name = "libp2p-tcp" -version = "0.23.0" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d0b6f4ef48d9493607fae069deecce0579320a1f3de6cb056770b151018a9a5" +checksum = "3dbd3d7076a478ac5a6aca55e74bdc250ac539b95de09b9d09915e0b8d01a6b2" dependencies = [ + "async-io", "futures 0.3.12", "futures-timer", "if-addrs", + "if-watch", "ipnet", + "libc", "libp2p-core", - "log 0.4.13", + "log 0.4.14", "socket2", - "tokio 0.2.24", + "tokio 1.1.0", ] [[package]] name = "libp2p-uds" -version = "0.23.0" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "945bed3c989a1b290b5a0d4e8fa6e44e01840efb9a5ab3f0d3d174f0e451ac0e" +checksum = "80ac51ce419f60be966e02103c17f67ff5dc4422ba83ba54d251d6c62a4ed487" dependencies = [ "async-std", "futures 0.3.12", "libp2p-core", - "log 0.4.13", + "log 0.4.14", ] [[package]] name = "libp2p-yamux" -version = "0.26.0" +version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07c0c9b6ef7a168c2ae854170b0b6b77550599afe06cc3ac390eb45c5d9c7110" +checksum = "490b8b27fc40fe35212df1b6a3d14bffaa4117cbff956fdc2892168a371102ad" dependencies = [ "futures 0.3.12", "libp2p-core", @@ -3297,17 +3299,18 @@ version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" dependencies = [ - "log 0.4.13", + "log 0.4.14", ] [[package]] name = "log" -version = "0.4.13" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcf3805d4480bb5b86070dcfeb9e2cb2ebc148adb753c5cca5f884d1d65a42b2" +checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" dependencies = [ - "cfg-if 0.1.10", + "cfg-if 1.0.0", "serde", + "value-bag", ] [[package]] @@ -3319,12 +3322,6 @@ 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" @@ -3439,18 +3436,18 @@ dependencies = [ [[package]] name = "minicbor" -version = "0.6.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2ef6aa869726518c5d8206fa5d1337bda8a0442807611be617891c018fa781" +checksum = "3265a9f5210bb726f81ef9c456ae0aff5321cd95748c0e71889b0e19d8f0332b" dependencies = [ "minicbor-derive", ] [[package]] name = "minicbor-derive" -version = "0.5.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b3569c0dbfff1b8d5f1434c642b67f5bf81c0f354a3f5f8f180b549dba3c07c" +checksum = "130b9455e28a3f308f6579671816a6f2621e2e0cbf55dc2f886345bef699481e" dependencies = [ "proc-macro2", "quote", @@ -3487,13 +3484,26 @@ dependencies = [ "iovec", "kernel32-sys", "libc", - "log 0.4.13", - "miow", + "log 0.4.14", + "miow 0.2.2", "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" @@ -3502,7 +3512,7 @@ checksum = "afcb699eb26d4332647cc848492bbc15eafb26f08d0304550d5aa1f612e066f0" dependencies = [ "iovec", "libc", - "mio", + "mio 0.6.23", ] [[package]] @@ -3517,6 +3527,16 @@ 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" @@ -3529,7 +3549,34 @@ dependencies = [ "sha-1 0.9.2", "sha2 0.9.2", "sha3", - "unsigned-varint", + "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", ] [[package]] @@ -3546,7 +3593,7 @@ checksum = "d050aeedc89243f5347c3e237e3e13dc76fbe4ae3742a57b94dc14f69acf76d4" dependencies = [ "buf_redux", "httparse", - "log 0.4.13", + "log 0.4.14", "mime", "mime_guess", "quick-error", @@ -3558,16 +3605,16 @@ dependencies = [ [[package]] name = "multistream-select" -version = "0.8.5" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93faf2e41f9ee62fb01680ed48f3cc26652352327aa2e59869070358f6b7dd75" +checksum = "10ddc0eb0117736f19d556355464fc87efc8ad98b29e3fd84f02531eb6e90840" dependencies = [ - "bytes 0.5.6", + "bytes 1.0.1", "futures 0.3.12", - "log 0.4.13", + "log 0.4.14", "pin-project 1.0.4", "smallvec 1.6.1", - "unsigned-varint", + "unsigned-varint 0.6.0", ] [[package]] @@ -3594,7 +3641,7 @@ checksum = "b8d96b2e1c8da3957d58100b09f102c6d9cfdfced01b7ec5a8974044bb09dbd4" dependencies = [ "lazy_static", "libc", - "log 0.4.13", + "log 0.4.14", "openssl", "openssl-probe", "openssl-sys", @@ -3643,6 +3690,15 @@ 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" @@ -3846,19 +3902,19 @@ dependencies = [ [[package]] name = "parity-multiaddr" -version = "0.9.7" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbecae7b7cfaafea47ceb5253ecdd14155ca8410e3487ed86031a6c2d5c15873" +checksum = "8bfda2e46fc5e14122649e2645645a81ee5844e0fb2e727ef560cc71a8b2d801" dependencies = [ "arrayref", - "bs58 0.4.0", + "bs58", "byteorder", "data-encoding", - "multihash", + "multihash 0.13.2", "percent-encoding", "serde", "static_assertions", - "unsigned-varint", + "unsigned-varint 0.6.0", "url", ] @@ -4198,7 +4254,7 @@ checksum = "a2a7bc6b2a29e632e45451c941832803a18cce6781db04de8a04696cdca8bde4" dependencies = [ "cfg-if 0.1.10", "libc", - "log 0.4.13", + "log 0.4.14", "wepoll-sys", "winapi 0.3.9", ] @@ -4280,6 +4336,15 @@ 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" @@ -4362,24 +4427,24 @@ dependencies = [ [[package]] name = "prost" -version = "0.6.1" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce49aefe0a6144a45de32927c77bd2859a5f7677b55f220ae5b744e87389c212" +checksum = "9e6984d2f1a23009bd270b8bb56d0926810a3d483f59c987d77969e9d8e840b2" dependencies = [ - "bytes 0.5.6", + "bytes 1.0.1", "prost-derive", ] [[package]] name = "prost-build" -version = "0.6.1" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02b10678c913ecbd69350e8535c3aef91a8676c0773fc1d7b95cdd196d7f2f26" +checksum = "32d3ebd75ac2679c2af3a92246639f9fcc8a442ee420719cc4fe195b98dd5fa3" dependencies = [ - "bytes 0.5.6", + "bytes 1.0.1", "heck", - "itertools 0.8.2", - "log 0.4.13", + "itertools 0.9.0", + "log 0.4.14", "multimap", "petgraph", "prost", @@ -4390,12 +4455,12 @@ dependencies = [ [[package]] name = "prost-derive" -version = "0.6.1" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "537aa19b95acde10a12fec4301466386f757403de4cd4e5b4fa78fb5ecb18f72" +checksum = "169a15f3008ecb5160cba7d37bcd690a7601b6d30cfb87a117d45e59d52af5d4" dependencies = [ "anyhow", - "itertools 0.8.2", + "itertools 0.9.0", "proc-macro2", "quote", "syn", @@ -4403,11 +4468,11 @@ dependencies = [ [[package]] name = "prost-types" -version = "0.6.1" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1834f67c0697c001304b75be76f67add9c89742eda3a085ad8ee0bb38c3417aa" +checksum = "b518d7cdd93dab1d1122cf07fa9a60771836c668dde9d9e2a139f957f0d9f1bb" dependencies = [ - "bytes 0.5.6", + "bytes 1.0.1", "prost", ] @@ -4435,7 +4500,7 @@ version = "2.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "50d9500ea1488a61aa96da139039b78a92eef64a0f3c82d38173729f0ad73cf8" dependencies = [ - "log 0.4.13", + "log 0.4.14", ] [[package]] @@ -4505,7 +4570,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4f7a12f176deee919f4ba55326ee17491c8b707d0987aed822682c821b660192" dependencies = [ "byteorder", - "log 0.4.13", + "log 0.4.14", "parity-wasm 0.41.0", ] @@ -4516,7 +4581,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c8ac87af529432d3a4f0e2b3bbf08af49f28f09cc73ed7e551161bdaef5f78d" dependencies = [ "byteorder", - "log 0.4.13", + "log 0.4.14", "parity-wasm 0.41.0", ] @@ -4810,7 +4875,7 @@ dependencies = [ "ipnet", "js-sys", "lazy_static", - "log 0.4.13", + "log 0.4.14", "mime", "mime_guess", "native-tls", @@ -5270,7 +5335,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7e31d442c16f047a671b5a71e2161d6e68814012b7f5379d269ebd915fac2729" dependencies = [ "libc", - "mio", + "mio 0.6.23", "signal-hook-registry", ] @@ -5660,7 +5725,7 @@ version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "049c03787a0595182357fbd487577947f4351b78ce20c3668f6d49f17feb13d1" dependencies = [ - "log 0.4.13", + "log 0.4.14", ] [[package]] @@ -5681,7 +5746,7 @@ checksum = "5a09c0b5bb588872ab2f09afa13ee6e9dac11e10a0ec9e8e3ba39a5a5d530af6" dependencies = [ "bytes 0.4.12", "futures 0.1.30", - "mio", + "mio 0.6.23", "num_cpus", "tokio-codec", "tokio-current-thread", @@ -5709,13 +5774,25 @@ dependencies = [ "iovec", "lazy_static", "memchr", - "mio", + "mio 0.6.23", "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" @@ -5736,8 +5813,8 @@ dependencies = [ "bytes 0.4.12", "futures 0.1.30", "iovec", - "log 0.4.13", - "mio", + "log 0.4.14", + "mio 0.6.23", "scoped-tls 0.1.2", "tokio 0.1.22", "tokio-executor", @@ -5785,7 +5862,7 @@ checksum = "57fc868aae093479e3131e3d165c93b1c7474109d13c90ec0dda2a1bbfff0674" dependencies = [ "bytes 0.4.12", "futures 0.1.30", - "log 0.4.13", + "log 0.4.14", ] [[package]] @@ -5818,8 +5895,8 @@ dependencies = [ "crossbeam-utils 0.7.2", "futures 0.1.30", "lazy_static", - "log 0.4.13", - "mio", + "log 0.4.14", + "mio 0.6.23", "num_cpus", "parking_lot 0.9.0", "slab 0.4.2", @@ -5861,7 +5938,7 @@ dependencies = [ "bytes 0.4.12", "futures 0.1.30", "iovec", - "mio", + "mio 0.6.23", "tokio-io", "tokio-reactor", ] @@ -5877,7 +5954,7 @@ dependencies = [ "crossbeam-utils 0.7.2", "futures 0.1.30", "lazy_static", - "log 0.4.13", + "log 0.4.14", "num_cpus", "slab 0.4.2", "tokio-executor", @@ -5933,7 +6010,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6d9e878ad426ca286e4dcae09cbd4e1973a7f8987d97570e2469703dd7f5720c" dependencies = [ "futures-util", - "log 0.4.13", + "log 0.4.14", "pin-project 0.4.27", "tokio 0.2.24", "tungstenite", @@ -5947,8 +6024,8 @@ checksum = "e2a0b10e610b39c38b031a2fcab08e4b82f16ece36504988dcbd81dbba650d82" dependencies = [ "bytes 0.4.12", "futures 0.1.30", - "log 0.4.13", - "mio", + "log 0.4.14", + "mio 0.6.23", "tokio-codec", "tokio-io", "tokio-reactor", @@ -5965,7 +6042,7 @@ dependencies = [ "iovec", "libc", "log 0.3.9", - "mio", + "mio 0.6.23", "mio-uds", "tokio-core", "tokio-io", @@ -5981,8 +6058,8 @@ dependencies = [ "futures 0.1.30", "iovec", "libc", - "log 0.4.13", - "mio", + "log 0.4.14", + "mio 0.6.23", "mio-uds", "tokio-codec", "tokio-io", @@ -5998,7 +6075,7 @@ dependencies = [ "bytes 0.5.6", "futures-core", "futures-sink", - "log 0.4.13", + "log 0.4.14", "pin-project-lite 0.1.11", "tokio 0.2.24", ] @@ -6025,7 +6102,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f47026cdc4080c07e49b37087de021820269d996f581aac150ef9e5583eefe3" dependencies = [ "cfg-if 1.0.0", - "log 0.4.13", + "log 0.4.14", "pin-project-lite 0.2.4", "tracing-attributes", "tracing-core", @@ -6068,7 +6145,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5e0f8c7178e13481ff6765bd169b33e8d554c5d2bbede5e32c356194be02b9b9" dependencies = [ "lazy_static", - "log 0.4.13", + "log 0.4.14", "tracing-core", ] @@ -6252,7 +6329,7 @@ dependencies = [ "http", "httparse", "input_buffer", - "log 0.4.13", + "log 0.4.14", "rand 0.7.3", "sha-1 0.9.2", "url", @@ -6292,6 +6369,18 @@ 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" @@ -6376,11 +6465,17 @@ 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 = [ - "bytes 0.5.6", + "asynchronous-codec", + "bytes 1.0.1", "futures-io", "futures-util", - "futures_codec", ] [[package]] @@ -6423,6 +6518,15 @@ 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" @@ -6510,7 +6614,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" dependencies = [ - "log 0.4.13", + "log 0.4.14", "try-lock", ] @@ -6525,7 +6629,7 @@ dependencies = [ "headers", "http", "hyper", - "log 0.4.13", + "log 0.4.14", "mime", "mime_guess", "multipart", @@ -6554,7 +6658,7 @@ dependencies = [ "http", "hyper", "lazycell", - "log 0.4.13", + "log 0.4.14", "serde", "serde_json", "warp", @@ -6592,7 +6696,7 @@ checksum = "7bc45447f0d4573f3d65720f636bbcc3dd6ce920ed704670118650bcd47764c7" dependencies = [ "bumpalo", "lazy_static", - "log 0.4.13", + "log 0.4.14", "proc-macro2", "quote", "syn", @@ -6717,11 +6821,12 @@ checksum = "62945bc99a6a121cb2759c7bfa7b779ddf0e69b68bb35a9b23ab72276cfdcd3c" [[package]] name = "which" -version = "3.1.1" +version = "4.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d011071ae14a2f6671d0b74080ae0cd8ebf3a6f8c9589a2cd45f23126fe29724" +checksum = "87c14ef7e1b8b8ecfc75d5eca37949410046e66f15d185c01d70824f1f8111ef" dependencies = [ "libc", + "thiserror", ] [[package]] @@ -6828,7 +6933,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9aeb8c4043cac71c3c299dff107171c220d179492350ea198e109a414981b83c" dependencies = [ "futures 0.3.12", - "log 0.4.13", + "log 0.4.14", "nohash-hasher", "parking_lot 0.11.1", "rand 0.7.3", diff --git a/node/Cargo.toml b/node/Cargo.toml index 9fd5278f7d..e993b07912 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.29.1", default-features = false, features = ["deflate", "dns", "floodsub", "gossipsub", "identify", "kad", "mdns-tokio", "mplex", "noise", "ping", "request-response", "tcp-tokio", "uds", "yamux"] } +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"] } 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/network.rs b/node/src/components/network.rs index e3bef269e0..ef99ee2301 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::Config as YamuxConfig, + yamux::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.clone()); + let our_id = NodeId::from(our_peer_id); // Convert the known addresses to multiaddr format and prepare the shutdown signal. let known_addresses = config @@ -206,7 +206,8 @@ 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); @@ -393,7 +394,7 @@ impl, P: PayloadT> Network { } fn our_id(swarm: &Swarm) -> NodeId { - NodeId::P2p(Swarm::local_peer_id(swarm).clone()) + NodeId::P2p(*Swarm::local_peer_id(swarm)) } async fn server_task, P: PayloadT>( @@ -614,6 +615,7 @@ async fn handle_one_way_messaging_event, P: PayloadT>( our_id(swarm) ) } + RequestResponseEvent::ResponseSent { .. } => {} } } @@ -623,13 +625,17 @@ async fn handle_gossip_event, P: PayloadT>( event: GossipsubEvent, ) { match event { - GossipsubEvent::Message(_sender, _message_id, message) => { + GossipsubEvent::Message { + propagation_source: sender, + 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; } }; diff --git a/node/src/components/network/behavior.rs b/node/src/components/network/behavior.rs index 7af99e1d4f..daaeb0399d 100644 --- a/node/src/components/network/behavior.rs +++ b/node/src/components/network/behavior.rs @@ -17,7 +17,8 @@ use tracing::{info, trace, warn}; use super::{ gossip::{self, TOPIC}, - one_way_messaging, peer_discovery, Config, GossipMessage, OneWayCodec, OneWayOutgoingMessage, + one_way_messaging, peer_discovery, Config, Error, GossipMessage, OneWayCodec, + OneWayOutgoingMessage, }; use crate::{components::chainspec_loader::Chainspec, types::NodeId}; @@ -48,22 +49,26 @@ pub(super) struct Behavior { } impl Behavior { - pub(super) fn new(config: &Config, chainspec: &Chainspec, our_public_key: PublicKey) -> Self { + pub(super) fn new( + config: &Config, + chainspec: &Chainspec, + our_public_key: PublicKey, + ) -> Result { let one_way_message_behavior = one_way_messaging::new_behavior(config, chainspec); - let gossip_behavior = gossip::new_behavior(config, chainspec, our_public_key.clone()); + let gossip_behavior = gossip::new_behavior(config, our_public_key.clone())?; let (kademlia_behavior, identify_behavior) = peer_discovery::new_behaviors(config, chainspec, our_public_key.clone()); - Behavior { + Ok(Behavior { one_way_message_behavior, gossip_behavior, kademlia_behavior, identify_behavior, our_id: NodeId::P2p(PeerId::from(our_public_key)), events: VecDeque::new(), - } + }) } /// Sends the given message out. @@ -112,9 +117,7 @@ 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.clone()); + let query_id = self.kademlia_behavior.get_closest_peers(random_address); info!( "{}: random kademlia lookup for peers closest to {} with {:?}", self.our_id, random_address, query_id @@ -123,7 +126,7 @@ impl Behavior { /// Initiates gossiping the given message. pub(super) fn gossip(&mut self, message: GossipMessage) { - if let Err(error) = self.gossip_behavior.publish(&*TOPIC, message) { + if let Err(error) = self.gossip_behavior.publish(TOPIC.clone(), 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 0fc8f5fa33..b1264f6d0d 100644 --- a/node/src/components/network/error.rs +++ b/node/src/components/network/error.rs @@ -1,6 +1,9 @@ use std::io; -use libp2p::{core::connection::ConnectionLimit, noise::NoiseError, Multiaddr, TransportError}; +use libp2p::{ + core::connection::ConnectionLimit, gossipsub::error::SubscriptionError, noise::NoiseError, + Multiaddr, TransportError, +}; use thiserror::Error; /// Error type returned by the `Network` component. @@ -39,4 +42,18 @@ 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, +} + +impl From for Error { + fn from(_error: SubscriptionError) -> Self { + Error::Subscription + } } diff --git a/node/src/components/network/gossip.rs b/node/src/components/network/gossip.rs index 60fe1c3d37..deece55d50 100644 --- a/node/src/components/network/gossip.rs +++ b/node/src/components/network/gossip.rs @@ -2,20 +2,21 @@ //! gossiping data to subscribed peers. use libp2p::{ - core::{ProtocolName, PublicKey}, - gossipsub::{Gossipsub, GossipsubConfigBuilder, MessageAuthenticity, Topic, ValidationMode}, + core::PublicKey, + gossipsub::{ + Gossipsub, GossipsubConfigBuilder, IdentTopic, MessageAuthenticity, ValidationMode, + }, PeerId, }; use once_cell::sync::Lazy; -use super::{Config, Error, PayloadT, ProtocolId}; -use crate::components::chainspec_loader::Chainspec; +use super::{Config, Error, PayloadT}; /// The inner portion of the `ProtocolId` for the gossip behavior. A standard prefix and suffix /// 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) static TOPIC: Lazy = Lazy::new(|| IdentTopic::new("all")); pub(super) struct GossipMessage(pub Vec); @@ -42,21 +43,18 @@ impl From for Vec { } /// Constructs a new libp2p behavior suitable for gossiping. -pub(super) fn new_behavior( - config: &Config, - chainspec: &Chainspec, - our_public_key: PublicKey, -) -> Gossipsub { - let protocol_id = ProtocolId::new(chainspec, PROTOCOL_NAME_INNER); - let gossipsub_config = GossipsubConfigBuilder::new() - .protocol_id(protocol_id.protocol_name().to_vec()) +pub(super) fn new_behavior(config: &Config, our_public_key: PublicKey) -> Result { + let gossipsub_config = GossipsubConfigBuilder::default() + .protocol_id_prefix(PROTOCOL_NAME_INNER) .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(); + .build() + .map_err(|error| Error::Behavior(error.to_owned()))?; let our_peer_id = PeerId::from(our_public_key); - let mut gossipsub = Gossipsub::new(MessageAuthenticity::Author(our_peer_id), gossipsub_config); - gossipsub.subscribe(TOPIC.clone()); - gossipsub + let mut gossipsub = Gossipsub::new(MessageAuthenticity::Author(our_peer_id), gossipsub_config) + .map_err(|error| Error::Behavior(error.to_owned()))?; + gossipsub.subscribe(&TOPIC.clone())?; + Ok(gossipsub) } diff --git a/node/src/components/network/one_way_messaging.rs b/node/src/components/network/one_way_messaging.rs index f2f6c83754..67fd9ea971 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.clone(), + destination, message: serialized_message, }), destination => { diff --git a/node/src/components/network/peer_discovery.rs b/node/src/components/network/peer_discovery.rs index acfdd50407..9119f6ff2d 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.clone(), memory_store_config); + let memory_store = MemoryStore::with_config(our_peer_id, memory_store_config); let protocol_id = ProtocolId::new(chainspec, KADEMLIA_PROTOCOL_NAME_INNER); let mut kademlia_config = KademliaConfig::default(); diff --git a/node/src/types/node_id.rs b/node/src/types/node_id.rs index a25f088e76..a5204b77dc 100644 --- a/node/src/types/node_id.rs +++ b/node/src/types/node_id.rs @@ -5,10 +5,13 @@ 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)] use rand::{Rng, RngCore}; + use serde::{de::Error as SerdeError, Deserialize, Deserializer, Serialize, Serializer}; #[cfg(test)] @@ -45,7 +48,8 @@ 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, &bytes); + let multihash = + Multihash::wrap(multihash::Code::Identity as u64, &bytes).expect("should wrap bytes"); let peer_id = PeerId::from_multihash(multihash).expect("should construct from multihash"); NodeId::P2p(peer_id) } @@ -53,9 +57,9 @@ impl NodeId { /// Used to serialize and deserialize `NodeID` where the (de)serializer isn't a human-readable type. #[derive(Serialize, Deserialize)] -enum NodeIdAsBytes<'a> { +enum NodeIdAsBytes { Tls(KeyFingerprint), - P2p(&'a [u8]), + P2p(Vec), } /// Used to serialize and deserialize `NodeID` where the (de)serializer is a human-readable type. @@ -79,7 +83,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.as_ref()), + NodeId::P2p(peer_id) => NodeIdAsBytes::P2p(peer_id.to_bytes()), }; helper.serialize(serializer) } @@ -110,8 +114,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.to_vec()) - .map_err(|_| D::Error::custom("invalid PeerId"))?; + let peer_id = + PeerId::from_bytes(&bytes).map_err(|_| D::Error::custom("invalid PeerId"))?; Ok(NodeId::P2p(peer_id)) } } From 7c94d4e38f5c08d1ff3d9fcd72b30278eb5eb3b7 Mon Sep 17 00:00:00 2001 From: Fraser Hutchison Date: Wed, 27 Jan 2021 22:58:54 +0000 Subject: [PATCH 2/2] NO-TICKET: complete upgrade of libp2p --- node/src/components/block_validator.rs | 32 +++--- node/src/components/fetcher.rs | 12 +- node/src/components/fetcher/tests.rs | 15 +-- node/src/components/gossiper.rs | 16 +-- node/src/components/gossiper/gossip_table.rs | 111 +++++++++---------- node/src/components/gossiper/tests.rs | 2 +- node/src/components/in_memory_network.rs | 10 +- node/src/components/network.rs | 8 +- node/src/components/network/behavior.rs | 16 ++- node/src/components/network/error.rs | 6 +- node/src/components/network/gossip.rs | 18 +-- node/src/components/network/protocol_id.rs | 4 + node/src/components/small_network.rs | 46 ++++---- node/src/types/node_id.rs | 3 +- node/src/types/status_feed.rs | 2 +- 15 files changed, 150 insertions(+), 151 deletions(-) diff --git a/node/src/components/block_validator.rs b/node/src/components/block_validator.rs index 4984988ebf..9780ff713c 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, From}; +use derive_more::Display; use semver::Version; use smallvec::{smallvec, SmallVec}; use tracing::error; @@ -37,11 +37,10 @@ use keyed_counter::KeyedCounter; use super::fetcher::FetchResult; /// Block validator component event. -#[derive(Debug, From, Display)] +#[derive(Debug, Display)] pub enum Event { /// A request made of the block validator component. - #[from] - Request(BlockValidationRequest), + Request(Box>), /// A deploy has been successfully found. #[display(fmt = "deploy {} found", _0)] @@ -57,6 +56,12 @@ 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. @@ -100,12 +105,14 @@ where { let mut effects = Effects::new(); match event { - Event::Request(BlockValidationRequest { - block, - sender, - responder, - block_timestamp, - }) => { + Event::Request(request) => { + let BlockValidationRequest { + block, + sender, + responder, + block_timestamp, + } = *request; + let block_deploys = block .deploys() .iter() @@ -300,10 +307,7 @@ where } self.state = BlockValidatorState::Ready(new_ready_state); } - ( - BlockValidatorState::Loading(requests), - request @ Event::Request(BlockValidationRequest { .. }), - ) => { + (BlockValidatorState::Loading(requests), request @ Event::Request(_)) => { requests.push(request); } (BlockValidatorState::Loading(_), _deploy_found_or_missing) => { diff --git a/node/src/components/fetcher.rs b/node/src/components/fetcher.rs index 53bdeab622..fce19fbc0c 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.clone()) + .entry(peer) .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.clone(), message).ignore(); + let mut effects = effect_builder.send_message(peer, message).ignore(); effects.extend( effect_builder @@ -326,11 +326,9 @@ where }, Event::GotRemotely { item, source } => { match source { - Source::Peer(peer) => self.signal( - item.id(), - Some(FetchResult::FromPeer(item, peer.clone())), - peer, - ), + Source::Peer(peer) => { + self.signal(item.id(), Some(FetchResult::FromPeer(item, peer)), 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 cde6340d99..7088a3e106 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.clone(), Arc::clone(&fetched)), + fetch_deploy(deploy_hash, *node_id, Arc::clone(&fetched)), ) .await; @@ -340,14 +340,11 @@ async fn should_fetch_from_peer() { network .process_injected_effect_on( node_without_deploy, - fetch_deploy(deploy_hash, node_with_deploy.clone(), Arc::clone(&fetched)), + fetch_deploy(deploy_hash, *node_with_deploy, Arc::clone(&fetched)), ) .await; - let expected_result = Some(FetchResult::FromPeer( - Box::new(deploy), - node_with_deploy.clone(), - )); + let expected_result = Some(FetchResult::FromPeer(Box::new(deploy), *node_with_deploy)); assert_settled( node_without_deploy, deploy_hash, @@ -378,8 +375,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].clone(); - let requesting_node = node_ids[1].clone(); + let holding_node = node_ids[0]; + let requesting_node = node_ids[1]; // Store deploy on holding node. store_deploy(&deploy, &holding_node, &mut network, None, &mut rng).await; @@ -389,7 +386,7 @@ async fn should_timeout_fetch_from_peer() { network .process_injected_effect_on( &requesting_node, - fetch_deploy(deploy_hash, holding_node.clone(), Arc::clone(&fetched)), + fetch_deploy(deploy_hash, holding_node, Arc::clone(&fetched)), ) .await; diff --git a/node/src/components/gossiper.rs b/node/src/components/gossiper.rs index 05c047cc3a..ff80385573 100644 --- a/node/src/components/gossiper.rs +++ b/node/src/components/gossiper.rs @@ -304,9 +304,7 @@ impl> Gossiper { return self.check_get_from_peer_timeout(effect_builder, item_id, holder); } }; - let mut effects = effect_builder - .send_message(holder.clone(), request) - .ignore(); + let mut effects = effect_builder.send_message(holder, request).ignore(); effects.extend( effect_builder .set_timeout(self.get_from_peer_timeout) @@ -331,10 +329,10 @@ impl> Gossiper { ) -> Effects> { let action = if T::ID_IS_COMPLETE_ITEM { self.table - .new_complete_data(&item_id, Some(sender.clone())) + .new_complete_data(&item_id, Some(sender)) .map_or_else(|| GossipAction::Noop, GossipAction::ShouldGossip) } else { - self.table.new_partial_data(&item_id, sender.clone()) + self.table.new_partial_data(&item_id, sender) }; match action { @@ -371,7 +369,7 @@ impl> Gossiper { item_id, is_already_held: false, }; - let mut effects = effect_builder.send_message(sender.clone(), reply).ignore(); + let mut effects = effect_builder.send_message(sender, reply).ignore(); effects.extend( effect_builder .set_timeout(self.get_from_peer_timeout) @@ -408,11 +406,7 @@ 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.clone(), - )); + effects.extend((self.get_from_holder)(effect_builder, item_id, sender)); } 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 a39f836055..3d1435fcd5 100644 --- a/node/src/components/gossiper/gossip_table.rs +++ b/node/src/components/gossiper/gossip_table.rs @@ -91,12 +91,11 @@ 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") - .clone(); + .expect("holders cannot be empty if we don't hold the data"); GossipAction::GetRemainder { holder } } else { GossipAction::AwaitingRemainder @@ -316,9 +315,9 @@ impl GossipTable { ); return None; } - let _ = state.holders.insert(peer.clone()); + let _ = state.holders.insert(peer); if by_us { - let _ = state.infected_by_us.insert(peer.clone()); + let _ = state.infected_by_us.insert(peer); } state.in_flight_count = state.in_flight_count.saturating_sub(1); Some(state.is_finished(infection_target, holders_limit)) @@ -519,55 +518,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].clone()); + let action = gossip_table.new_partial_data(&data_id, node_ids[0]); let expected = GossipAction::GetRemainder { - holder: node_ids[0].clone(), + holder: node_ids[0], }; 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].clone()); + let action = gossip_table.new_partial_data(&data_id, node_ids[0]); 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].clone()); + let action = gossip_table.new_partial_data(&data_id, node_ids[1]); 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].clone()); + let action = gossip_table.new_partial_data(&data_id, node_ids[2]); 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].clone()); + let action = gossip_table.new_partial_data(&data_id, node_ids[3]); 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].clone())); + let _ = gossip_table.new_complete_data(&data_id, Some(node_ids[0])); let limit = 4 + EXPECTED_DEFAULT_INFECTION_TARGET; for node_id in &node_ids[4..limit] { - let _ = gossip_table.we_infected(&data_id, node_id.clone()); + let _ = gossip_table.we_infected(&data_id, *node_id); } - let action = gossip_table.new_partial_data(&data_id, node_ids[limit].clone()); + let action = gossip_table.new_partial_data(&data_id, node_ids[limit]); 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].clone()); + let action = gossip_table.new_partial_data(&data_id, node_ids[0]); let expected = GossipAction::GetRemainder { - holder: node_ids[0].clone(), + holder: node_ids[0], }; assert_eq!(expected, action); check_holders(&node_ids[..1], &gossip_table, &data_id); @@ -581,9 +580,9 @@ mod tests { let mut gossip_table = GossipTable::new(Config::default()); - let _ = gossip_table.new_partial_data(&data_id, node_id.clone()); + let _ = gossip_table.new_partial_data(&data_id, node_id); - let action = gossip_table.we_infected(&data_id, node_id.clone()); + let action = gossip_table.we_infected(&data_id, node_id); assert_eq!(GossipAction::Noop, action); let action = gossip_table.already_infected(&data_id, node_id); @@ -610,13 +609,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].clone())); + let action = gossip_table.new_complete_data(&data_id, Some(node_ids[0])); 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].clone()); + let action = gossip_table.already_infected(&data_id, node_ids[1]); let expected = GossipAction::ShouldGossip(ShouldGossip { count: 1, exclude_peers: node_ids[..2].iter().cloned().collect(), @@ -628,7 +627,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].clone())); + let action = gossip_table.new_complete_data(&data_id, Some(node_ids[2])); assert!(action.is_none()); check_holders(&node_ids[..3], &gossip_table, &data_id); @@ -642,7 +641,7 @@ mod tests { }); assert_eq!(expected, action); - let action = gossip_table.new_complete_data(&data_id, Some(node_ids[3].clone())); + let action = gossip_table.new_complete_data(&data_id, Some(node_ids[3])); assert!(action.is_none()); check_holders(&node_ids[..4], &gossip_table, &data_id); @@ -650,7 +649,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.clone()); + let _ = gossip_table.we_infected(&data_id, *node_id); } let action = gossip_table.new_complete_data(&data_id, None); assert!(action.is_none()); @@ -659,7 +658,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].clone())); + let action = gossip_table.new_complete_data(&data_id, Some(node_ids[0])); let expected = Some(ShouldGossip { count: EXPECTED_DEFAULT_INFECTION_TARGET, exclude_peers: node_ids[..1].iter().cloned().collect(), @@ -682,14 +681,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.clone()); + let action = gossip_table.we_infected(&data_id, *node_id); 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].clone()); + let action = gossip_table.we_infected(&data_id, node_ids[limit - 1]); let expected = GossipAction::ShouldGossip(ShouldGossip { count: 1, exclude_peers: node_ids[..limit].iter().cloned().collect(), @@ -699,7 +698,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].clone()); + let action = gossip_table.we_infected(&data_id, node_ids[limit]); assert_eq!(GossipAction::Noop, action); assert!(gossip_table.finished.contains(&data_id)); } @@ -717,7 +716,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.clone()); + let action = gossip_table.already_infected(&data_id, *node_id); let expected = GossipAction::ShouldGossip(ShouldGossip { count: 1, exclude_peers: node_ids[..(index + 1)].iter().cloned().collect(), @@ -728,7 +727,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].clone()); + let action = gossip_table.already_infected(&data_id, node_ids[0]); let expected = GossipAction::ShouldGossip(ShouldGossip { count: 1, exclude_peers: node_ids[..limit].iter().cloned().collect(), @@ -737,7 +736,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].clone()); + let action = gossip_table.we_infected(&data_id, node_ids[limit]); assert_eq!(GossipAction::Noop, action); } @@ -753,16 +752,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.clone()); + let _ = gossip_table.we_infected(&data_id, *node_id); } 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.clone()); + let _ = gossip_table.already_infected(&data_id, *node_id); } // Check adding 12th non-infection doesn't cause us to stop gossiping. - let action = gossip_table.already_infected(&data_id, node_ids[holders_limit].clone()); + let action = gossip_table.already_infected(&data_id, node_ids[holders_limit]); let expected = GossipAction::ShouldGossip(ShouldGossip { count: 1, exclude_peers: node_ids[..(holders_limit + 1)].iter().cloned().collect(), @@ -781,14 +780,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].clone()); + let _ = gossip_table.we_infected(&data_id, node_ids[0]); // 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].clone()); + let action = gossip_table.check_timeout(&data_id, node_ids[0]); assert_eq!(GossipAction::Noop, action); - let action = gossip_table.check_timeout(&data_id, node_ids[1].clone()); + let action = gossip_table.check_timeout(&data_id, node_ids[1]); let expected = GossipAction::ShouldGossip(ShouldGossip { count: 1, exclude_peers: node_ids[..=1].iter().cloned().collect(), @@ -808,8 +807,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].clone()); - let _ = gossip_table.check_timeout(&data_id, node_ids[0].clone()); + let _ = gossip_table.new_partial_data(&data_id, node_ids[0]); + let _ = gossip_table.check_timeout(&data_id, node_ids[0]); } #[test] @@ -821,47 +820,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].clone()); - let _ = gossip_table.new_partial_data(&data_id, node_ids[1].clone()); + let _ = gossip_table.new_partial_data(&data_id, node_ids[0]); + let _ = gossip_table.new_partial_data(&data_id, node_ids[1]); // 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].clone()); + let action = gossip_table.remove_holder_if_unresponsive(&data_id, node_ids[0]); let expected = GossipAction::GetRemainder { - holder: node_ids[1].clone(), + holder: node_ids[1], }; 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].clone()); + let action = gossip_table.remove_holder_if_unresponsive(&data_id, node_ids[1]); 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].clone()); + let action = gossip_table.new_partial_data(&data_id, node_ids[2]); let expected = GossipAction::GetRemainder { - holder: node_ids[2].clone(), + holder: node_ids[2], }; 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].clone()); + let action = gossip_table.remove_holder_if_unresponsive(&data_id, node_ids[2]); 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].clone())); + let action = gossip_table.new_complete_data(&data_id, Some(node_ids[3])); let expected = Some(ShouldGossip { count: EXPECTED_DEFAULT_INFECTION_TARGET, - exclude_peers: iter::once(node_ids[3].clone()).collect(), + exclude_peers: iter::once(node_ids[3]).collect(), is_already_held: false, }); assert_eq!(expected, action); @@ -877,11 +876,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].clone()); - let _ = gossip_table.new_complete_data(&data_id, Some(node_ids[0].clone())); + let _ = gossip_table.new_partial_data(&data_id, node_ids[0]); + let _ = gossip_table.new_complete_data(&data_id, Some(node_ids[0])); // 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].clone()); + let action = gossip_table.remove_holder_if_unresponsive(&data_id, node_ids[0]); 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)); @@ -898,14 +897,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].clone()); + let _ = gossip_table.new_partial_data(&data_id, node_ids[0]); gossip_table.pause(&data_id); - let action = gossip_table.remove_holder_if_unresponsive(&data_id, node_ids[0].clone()); + let action = gossip_table.remove_holder_if_unresponsive(&data_id, node_ids[0]); 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].clone()); + let action = gossip_table.new_partial_data(&data_id, node_ids[1]); assert_eq!(GossipAction::Noop, action); check_holders(&node_ids[1..2], &gossip_table, &data_id); assert!(!gossip_table.current.contains_key(&data_id)); @@ -923,7 +922,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.clone()); + let _ = gossip_table.we_infected(&data_id, *node_id); } assert!(gossip_table.finished.contains(&data_id)); @@ -958,7 +957,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.clone()); + let _ = gossip_table.we_infected(deploy_id, *node_id); } assert!(gossip_table.finished.contains(&deploy_id)); } diff --git a/node/src/components/gossiper/tests.rs b/node/src/components/gossiper/tests.rs index 2ef9228e51..b6bf45169d 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].clone(); + let node_id_0 = node_ids[0]; 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 0e3c942f20..23ff3b6ba3 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.clone(), sender); + nodes_write.insert(node_id, 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.clone() + self.node_id } } @@ -513,7 +513,7 @@ where match nodes.get(&dest) { Some(sender) => { - if let Err(SendError((_, msg))) = sender.send((self.node_id.clone(), payload)) { + if let Err(SendError((_, msg))) = sender.send((self.node_id, 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.clone(), payload.clone()); + self.send(&guard, *dest, 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.clone(), payload.clone()); + self.send(&guard, *dest, payload.clone()); } responder.respond(chosen).ignore() } else { diff --git a/node/src/components/network.rs b/node/src/components/network.rs index ef99ee2301..1868a61c86 100644 --- a/node/src/components/network.rs +++ b/node/src/components/network.rs @@ -274,7 +274,7 @@ impl, P: PayloadT> Network { } } - let _ = self.peers.insert(peer_id.clone(), endpoint); + let _ = self.peers.insert(peer_id, 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 +370,7 @@ impl, P: PayloadT> Network { } for &peer_id in &peer_ids { - self.send_message(peer_id.clone(), payload.clone()); + self.send_message(*peer_id, payload.clone()); } peer_ids.into_iter().cloned().collect() @@ -389,7 +389,7 @@ impl, P: PayloadT> Network { /// Returns the node id of this network node. #[cfg(test)] pub(crate) fn node_id(&self) -> NodeId { - self.our_id.clone() + self.our_id } } @@ -881,7 +881,7 @@ impl, P: PayloadT> Component for Network { .peers .iter() .map(|(node_id, endpoint)| { - (node_id.clone(), endpoint.get_remote_address().to_string()) + (*node_id, 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 daaeb0399d..399034f280 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}, + gossipsub::{Gossipsub, GossipsubEvent, IdentTopic}, identify::{Identify, IdentifyEvent}, kad::{record::store::MemoryStore, Kademlia, KademliaEvent}, request_response::{RequestResponse, RequestResponseEvent}, @@ -16,8 +16,7 @@ use libp2p::{ use tracing::{info, trace, warn}; use super::{ - gossip::{self, TOPIC}, - one_way_messaging, peer_discovery, Config, Error, GossipMessage, OneWayCodec, + gossip, one_way_messaging, peer_discovery, Config, Error, GossipMessage, OneWayCodec, OneWayOutgoingMessage, }; use crate::{components::chainspec_loader::Chainspec, types::NodeId}; @@ -46,6 +45,8 @@ 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 { @@ -56,7 +57,8 @@ impl Behavior { ) -> Result { let one_way_message_behavior = one_way_messaging::new_behavior(config, chainspec); - let gossip_behavior = gossip::new_behavior(config, our_public_key.clone())?; + let (gossip_behavior, gossip_topic) = + gossip::new_behavior(config, chainspec, our_public_key.clone())?; let (kademlia_behavior, identify_behavior) = peer_discovery::new_behaviors(config, chainspec, our_public_key.clone()); @@ -68,6 +70,7 @@ impl Behavior { identify_behavior, our_id: NodeId::P2p(PeerId::from(our_public_key)), events: VecDeque::new(), + gossip_topic, }) } @@ -126,7 +129,10 @@ impl Behavior { /// Initiates gossiping the given message. pub(super) fn gossip(&mut self, message: GossipMessage) { - if let Err(error) = self.gossip_behavior.publish(TOPIC.clone(), message) { + if let Err(error) = self + .gossip_behavior + .publish(self.gossip_topic.clone(), 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 b1264f6d0d..ab082eb9ce 100644 --- a/node/src/components/network/error.rs +++ b/node/src/components/network/error.rs @@ -49,11 +49,11 @@ pub enum Error { /// Subscription error. #[error("subscription error")] - Subscription, + Subscription(String), } impl From for Error { - fn from(_error: SubscriptionError) -> Self { - Error::Subscription + 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 deece55d50..eb761c45e9 100644 --- a/node/src/components/network/gossip.rs +++ b/node/src/components/network/gossip.rs @@ -8,16 +8,14 @@ use libp2p::{ }, PeerId, }; -use once_cell::sync::Lazy; -use super::{Config, Error, PayloadT}; +use super::{Config, Error, PayloadT, ProtocolId}; +use crate::components::chainspec_loader::Chainspec; /// The inner portion of the `ProtocolId` for the gossip behavior. A standard prefix and suffix /// will be applied to create the full protocol name. const PROTOCOL_NAME_INNER: &str = "validator/gossip"; -pub(super) static TOPIC: Lazy = Lazy::new(|| IdentTopic::new("all")); - pub(super) struct GossipMessage(pub Vec); impl GossipMessage { @@ -43,7 +41,11 @@ impl From for Vec { } /// Constructs a new libp2p behavior suitable for gossiping. -pub(super) fn new_behavior(config: &Config, our_public_key: PublicKey) -> Result { +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) .heartbeat_interval(config.gossip_heartbeat_interval.into()) @@ -55,6 +57,8 @@ pub(super) fn new_behavior(config: &Config, our_public_key: PublicKey) -> Result 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()))?; - gossipsub.subscribe(&TOPIC.clone())?; - Ok(gossipsub) + let protocol_id = ProtocolId::new(chainspec, PROTOCOL_NAME_INNER); + let topic = IdentTopic::new(protocol_id.id()); + gossipsub.subscribe(&topic)?; + Ok((gossipsub, topic)) } diff --git a/node/src/components/network/protocol_id.rs b/node/src/components/network/protocol_id.rs index 5221c1a257..953f181de9 100644 --- a/node/src/components/network/protocol_id.rs +++ b/node/src/components/network/protocol_id.rs @@ -27,6 +27,10 @@ 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 7736a90447..fa65359fc7 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.clone(), msg.clone()); + self.send_message(*peer_id, msg.clone()); } } @@ -363,7 +363,7 @@ where } for &peer_id in &peer_ids { - self.send_message(peer_id.clone(), msg.clone()); + self.send_message(*peer_id, msg.clone()); } peer_ids.into_iter().cloned().collect() @@ -427,7 +427,7 @@ where .ignore::>(); let _ = self.incoming.insert( - peer_id.clone(), + peer_id, 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.clone())); + effects.extend(self.check_connection_complete(effect_builder, peer_id)); effects.extend( message_reader( self.event_queue, stream, self.shutdown_receiver.clone(), - self.our_id.clone(), - peer_id.clone(), + self.our_id, + peer_id, ) .event(move |result| Event::IncomingClosed { result, @@ -505,19 +505,19 @@ where sender, times_seen_asymmetric: 0, }; - if self.outgoing.insert(peer_id.clone(), connection).is_some() { + if self.outgoing.insert(peer_id, 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.clone()); + let mut effects = self.check_connection_complete(effect_builder, peer_id); let handshake = Message::Handshake { genesis_config_hash: self.genesis_config_hash, }; - let peer_id_cloned = peer_id.clone(); + let peer_id_cloned = peer_id; 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.clone(), + self.our_id, 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.clone()); + remove.push(*node_id); } 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.clone()); + remove.push(*node_id); } 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.clone(), connection.peer_address.to_string()); + ret.insert(*node_id, connection.peer_address.to_string()); } for (node_id, connection) in &self.incoming { - ret.entry(node_id.clone()) + ret.entry(*node_id) .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.clone() + self.our_id } } @@ -930,7 +930,6 @@ 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 @@ -955,7 +954,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=%cloned_our_id, %err, "dropping incoming connection during accept") + warn!(%our_id, %err, "dropping incoming connection during accept") } } } @@ -1048,26 +1047,21 @@ 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=%our_id_ref, %msg, peer_id=%peer_id_cloned, "message received"); + debug!(%our_id, %msg, %peer_id, "message received"); // We've received a message, push it to the reactor. event_queue .schedule( - Event::IncomingMessage { - peer_id: peer_id_cloned.clone(), - msg, - }, + Event::IncomingMessage { peer_id, msg }, QueueKind::NetworkIncoming, ) .await; } Err(err) => { - warn!(our_id=%our_id_ref, %err, peer_id=%peer_id_cloned, "receiving message failed, closing connection"); + warn!(%our_id, %err, %peer_id, "receiving message failed, closing connection"); return Err(err); } } @@ -1081,7 +1075,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 a5204b77dc..7f01ebecbd 100644 --- a/node/src/types/node_id.rs +++ b/node/src/types/node_id.rs @@ -11,7 +11,6 @@ use libp2p::PeerId; use once_cell::sync::Lazy; #[cfg(test)] use rand::{Rng, RngCore}; - use serde::{de::Error as SerdeError, Deserialize, Deserializer, Serialize, Serializer}; #[cfg(test)] @@ -19,7 +18,7 @@ use crate::testing::TestRng; use crate::{rpcs::docs::DocExample, tls::KeyFingerprint}; /// The network identifier for a node. -#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, DataSize)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, DataSize)] pub enum NodeId { Tls(KeyFingerprint), #[data_size(skip)] diff --git a/node/src/types/status_feed.rs b/node/src/types/status_feed.rs index 898f389cab..e3ce555010 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.clone(), socket_addr.to_string()); + peers.insert(*node_id, socket_addr.to_string()); let status_feed = StatusFeed:: { last_added_block: Some(Block::doc_example().clone()), peers,