From a17f6a10cf0fb87f5cc6457c317b9db166ae761b Mon Sep 17 00:00:00 2001 From: Krzysztof Lis Date: Mon, 6 Nov 2023 11:26:00 +0100 Subject: [PATCH 1/3] chore(p2p): update to libp2p 0.53.0 --- Cargo.lock | 463 ++++++++++++-------------- crates/p2p/Cargo.toml | 11 +- crates/p2p/src/behaviour.rs | 6 +- crates/p2p/src/lib.rs | 4 +- crates/p2p/src/main_loop.rs | 246 ++++++-------- crates/p2p/src/test_utils.rs | 4 +- crates/p2p_bootstrap/Cargo.toml | 2 +- crates/p2p_bootstrap/src/behaviour.rs | 2 +- 8 files changed, 329 insertions(+), 409 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1a830827b0..2e56e33895 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -511,20 +511,33 @@ checksum = "ecc7ab41815b3c653ccd2978ec3255c81349336702dfdf62ee6f7069b12a3aae" [[package]] name = "async-trait" -version = "0.1.73" +version = "0.1.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc00ceb34980c03614e35a3a4e218276a0a824e911d07651cd0d858a51e8c0f0" +checksum = "a66537f1bb974b254c98ed142ff995236e81b9d0fe4db0575f46612cb15eb0f9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.31", + "syn 2.0.39", ] [[package]] name = "asynchronous-codec" -version = "0.6.1" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4057f2c32adbb2fc158e22fb38433c8e9bbf76b75a4732c7c0cbaf695fb65568" +dependencies = [ + "bytes", + "futures-sink", + "futures-util", + "memchr", + "pin-project-lite", +] + +[[package]] +name = "asynchronous-codec" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06a0daa378f5fd10634e44b0a29b2a87b890657658e072a30d6f26e57ddee182" +checksum = "a860072022177f903e59730004fb5dc13db9275b79bb2aef7ba8ce831956c233" dependencies = [ "bytes", "futures-sink", @@ -630,7 +643,7 @@ dependencies = [ "heck 0.4.1", "proc-macro2", "quote", - "syn 2.0.31", + "syn 2.0.39", ] [[package]] @@ -840,6 +853,9 @@ name = "bytes" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" +dependencies = [ + "serde", +] [[package]] name = "cached" @@ -1606,7 +1622,7 @@ checksum = "4756fe3fdb86d3d8fda40ee250d146300381e98110ec7e4a624407c7e0b7e63f" dependencies = [ "cairo-lang-debug 2.1.1", "quote", - "syn 2.0.31", + "syn 2.0.39", ] [[package]] @@ -2682,7 +2698,7 @@ dependencies = [ "heck 0.4.1", "proc-macro2", "quote", - "syn 2.0.31", + "syn 2.0.39", ] [[package]] @@ -2962,7 +2978,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f34ba9a9bcb8645379e9de8cb3ecfcf4d1c85ba66d90deb3259206fa5aa193b" dependencies = [ "quote", - "syn 2.0.31", + "syn 2.0.39", ] [[package]] @@ -3030,7 +3046,7 @@ checksum = "83fdaf97f4804dcebfa5862639bc9ce4121e82140bec2a987ac5140294865b5b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.31", + "syn 2.0.39", ] [[package]] @@ -3078,7 +3094,7 @@ dependencies = [ "proc-macro2", "quote", "strsim", - "syn 2.0.31", + "syn 2.0.39", ] [[package]] @@ -3100,7 +3116,7 @@ checksum = "836a9bbc7ad63342d6d6e7b815ccab164bc77a2d95d84bc3117a8c0d5c98e2d5" dependencies = [ "darling_core 0.20.3", "quote", - "syn 2.0.31", + "syn 2.0.39", ] [[package]] @@ -3238,7 +3254,7 @@ checksum = "487585f4d0c6655fe74905e2504d8ad6908e4db67f744eb140876906c2f3175d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.31", + "syn 2.0.39", ] [[package]] @@ -3262,7 +3278,7 @@ dependencies = [ "darling 0.20.3", "proc-macro2", "quote", - "syn 2.0.31", + "syn 2.0.39", ] [[package]] @@ -3319,18 +3335,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "enum-as-inner" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9720bba047d567ffc8a3cba48bf19126600e249ab7f128e9233e6376976a116" -dependencies = [ - "heck 0.4.1", - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "enum-as-inner" version = "0.6.0" @@ -3340,7 +3344,7 @@ dependencies = [ "heck 0.4.1", "proc-macro2", "quote", - "syn 2.0.31", + "syn 2.0.39", ] [[package]] @@ -3553,9 +3557,9 @@ checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" [[package]] name = "futures" -version = "0.3.28" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40" +checksum = "da0290714b38af9b4a7b094b8a37086d1b4e61f2df9122c3cad2577669145335" dependencies = [ "futures-channel", "futures-core", @@ -3568,9 +3572,9 @@ dependencies = [ [[package]] name = "futures-bounded" -version = "0.1.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b07bbbe7d7e78809544c6f718d875627addc73a7c3582447abc052cd3dc67e0" +checksum = "4a2b7bc3e71d5b3c6e1436bd600d88a7a9315b3589883018123646767ea2d522" dependencies = [ "futures-timer", "futures-util", @@ -3578,9 +3582,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.28" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" +checksum = "ff4dd66668b557604244583e3e1e1eada8c5c2e96a6d0d6653ede395b78bbacb" dependencies = [ "futures-core", "futures-sink", @@ -3588,15 +3592,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.28" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" +checksum = "eb1d22c66e66d9d72e1758f0bd7d4fd0bee04cad842ee34587d68c07e45d088c" [[package]] name = "futures-executor" -version = "0.3.28" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0" +checksum = "0f4fb8693db0cf099eadcca0efe2a5a22e4550f98ed16aba6c48700da29597bc" dependencies = [ "futures-core", "futures-task", @@ -3606,9 +3610,9 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.28" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" +checksum = "8bf34a163b5c4c52d0478a4d757da8fb65cabef42ba90515efee0f6f9fa45aaa" [[package]] name = "futures-lite" @@ -3627,13 +3631,13 @@ dependencies = [ [[package]] name = "futures-macro" -version = "0.3.28" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" +checksum = "53b153fd91e4b0147f4aced87be237c98248656bb01050b96bf3ee89220a8ddb" dependencies = [ "proc-macro2", "quote", - "syn 2.0.31", + "syn 2.0.39", ] [[package]] @@ -3648,15 +3652,15 @@ dependencies = [ [[package]] name = "futures-sink" -version = "0.3.28" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e" +checksum = "e36d3378ee38c2a36ad710c5d30c2911d752cb941c00c72dbabfb786a7970817" [[package]] name = "futures-task" -version = "0.3.28" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65" +checksum = "efd193069b0ddadc69c46389b740bbccdd97203899b48d09c5f7969591d6bae2" [[package]] name = "futures-ticker" @@ -3677,9 +3681,9 @@ checksum = "e64b03909df88034c26dc1547e8970b91f98bdb65165d6a4e9110d94263dbb2c" [[package]] name = "futures-util" -version = "0.3.28" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" +checksum = "a19526d624e703a3179b3d322efec918b6246ea0fa51d41124525f00f1cc8104" dependencies = [ "futures-channel", "futures-core", @@ -3925,6 +3929,52 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b07f60793ff0a4d9cef0f18e63b5357e06209987153a64648c972c1e5aff336f" +[[package]] +name = "hickory-proto" +version = "0.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "091a6fbccf4860009355e3efc52ff4acf37a63489aad7435372d44ceeb6fbbcf" +dependencies = [ + "async-trait", + "cfg-if", + "data-encoding", + "enum-as-inner", + "futures-channel", + "futures-io", + "futures-util", + "idna", + "ipnet", + "once_cell", + "rand", + "socket2 0.5.5", + "thiserror", + "tinyvec", + "tokio", + "tracing", + "url", +] + +[[package]] +name = "hickory-resolver" +version = "0.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35b8f021164e6a984c9030023544c57789c51760065cd510572fedcfb04164e8" +dependencies = [ + "cfg-if", + "futures-util", + "hickory-proto", + "ipconfig", + "lru-cache", + "once_cell", + "parking_lot 0.12.1", + "rand", + "resolv-conf", + "smallvec", + "thiserror", + "tokio", + "tracing", +] + [[package]] name = "hkdf" version = "0.12.3" @@ -4112,17 +4162,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" -[[package]] -name = "idna" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8" -dependencies = [ - "matches", - "unicode-bidi", - "unicode-normalization", -] - [[package]] name = "idna" version = "0.4.0" @@ -4508,9 +4547,9 @@ dependencies = [ [[package]] name = "libp2p" -version = "0.52.4" +version = "0.53.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e94495eb319a85b70a68b85e2389a95bb3555c71c49025b78c691a854a7e6464" +checksum = "67c4d7fa0c6098ed39b90780715be07b70046ee64570371147bdc771503a5d3c" dependencies = [ "bytes", "either", @@ -4547,9 +4586,9 @@ dependencies = [ [[package]] name = "libp2p-allow-block-list" -version = "0.2.0" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55b46558c5c0bf99d3e2a1a38fd54ff5476ca66dd1737b12466a1824dd219311" +checksum = "107b238b794cb83ab53b74ad5dcf7cca3200899b72fe662840cfb52f5b0a32e6" dependencies = [ "libp2p-core", "libp2p-identity", @@ -4559,11 +4598,12 @@ dependencies = [ [[package]] name = "libp2p-autonat" -version = "0.11.0" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e907be08be5e4152317a79d310a6f501a1b5c02a81dcb065dc865475bbae9498" +checksum = "d95151726170e41b591735bf95c42b888fe4aa14f65216a9fbf0edcc04510586" dependencies = [ "async-trait", + "asynchronous-codec 0.6.2", "futures", "futures-timer", "instant", @@ -4571,16 +4611,17 @@ dependencies = [ "libp2p-identity", "libp2p-request-response", "libp2p-swarm", - "log", "quick-protobuf", + "quick-protobuf-codec", "rand", + "tracing", ] [[package]] name = "libp2p-connection-limits" -version = "0.2.1" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f5107ad45cb20b2f6c3628c7b6014b996fcb13a88053f4569c872c6e30abf58" +checksum = "f2af4b1e1a1d6c5005a59b42287c0a526bcce94d8d688e2e9233b18eb843ceb4" dependencies = [ "libp2p-core", "libp2p-identity", @@ -4590,9 +4631,9 @@ dependencies = [ [[package]] name = "libp2p-core" -version = "0.40.1" +version = "0.41.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd44289ab25e4c9230d9246c475a22241e301b23e8f4061d3bdef304a1a99713" +checksum = "8b8b63f1df89173dc6c582c07abfc072acf2792ce1787363ab266e0a18882fac" dependencies = [ "either", "fnv", @@ -4600,7 +4641,6 @@ dependencies = [ "futures-timer", "instant", "libp2p-identity", - "log", "multiaddr", "multihash", "multistream-select", @@ -4610,56 +4650,60 @@ dependencies = [ "quick-protobuf", "rand", "rw-stream-sink", + "serde", "smallvec", "thiserror", + "tracing", "unsigned-varint", "void", ] [[package]] name = "libp2p-dcutr" -version = "0.10.0" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "458dce197aa5347a7ec0634a4c1343c6dfbf75859ef34d51e92b0cc333fe7cc3" +checksum = "a4f7bb7fa2b9e6cad9c30a6f67e3ff5c1e4b658c62b6375e35861a85f9c97bf3" dependencies = [ - "asynchronous-codec", + "asynchronous-codec 0.6.2", "either", "futures", + "futures-bounded", "futures-timer", "instant", "libp2p-core", "libp2p-identity", "libp2p-swarm", - "log", + "lru 0.11.1", "quick-protobuf", "quick-protobuf-codec", "thiserror", + "tracing", "void", ] [[package]] name = "libp2p-dns" -version = "0.40.1" +version = "0.41.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6a18db73084b4da2871438f6239fef35190b05023de7656e877c18a00541a3b" +checksum = "852f9ab7c3eba64b158a4d9ab00848b1d732fa9d3224aa0a75643756f98aa136" dependencies = [ "async-trait", "futures", + "hickory-resolver", "libp2p-core", "libp2p-identity", - "log", "parking_lot 0.12.1", "smallvec", - "trust-dns-resolver", + "tracing", ] [[package]] name = "libp2p-gossipsub" -version = "0.45.2" +version = "0.46.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1f9624e2a843b655f1c1b8262b8d5de6f309413fca4d66f01bb0662429f84dc" +checksum = "201f0626acd8985fae7fdd318e86c954574b9eef2e5dec433936a19a0338393d" dependencies = [ - "asynchronous-codec", + "asynchronous-codec 0.6.2", "base64 0.21.5", "byteorder", "bytes", @@ -4673,25 +4717,26 @@ dependencies = [ "libp2p-core", "libp2p-identity", "libp2p-swarm", - "log", "prometheus-client", "quick-protobuf", "quick-protobuf-codec", "rand", "regex", + "serde", "sha2", "smallvec", + "tracing", "unsigned-varint", "void", ] [[package]] name = "libp2p-identify" -version = "0.43.1" +version = "0.44.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45a96638a0a176bec0a4bcaebc1afa8cf909b114477209d7456ade52c61cd9cd" +checksum = "0544703553921214556f7567278b4f00cdd5052d29b0555ab88290cbfe54d81c" dependencies = [ - "asynchronous-codec", + "asynchronous-codec 0.6.2", "either", "futures", "futures-bounded", @@ -4699,12 +4744,12 @@ dependencies = [ "libp2p-core", "libp2p-identity", "libp2p-swarm", - "log", "lru 0.12.0", "quick-protobuf", "quick-protobuf-codec", "smallvec", "thiserror", + "tracing", "void", ] @@ -4721,6 +4766,7 @@ dependencies = [ "multihash", "quick-protobuf", "rand", + "serde", "sha2", "thiserror", "zeroize", @@ -4728,12 +4774,12 @@ dependencies = [ [[package]] name = "libp2p-kad" -version = "0.44.6" +version = "0.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16ea178dabba6dde6ffc260a8e0452ccdc8f79becf544946692fff9d412fc29d" +checksum = "91de4ab46f01286bf0a92d517b51b52b53b6f4d32a774a432ba1c49b39768043" dependencies = [ "arrayvec", - "asynchronous-codec", + "asynchronous-codec 0.6.2", "bytes", "either", "fnv", @@ -4743,13 +4789,14 @@ dependencies = [ "libp2p-core", "libp2p-identity", "libp2p-swarm", - "log", "quick-protobuf", "quick-protobuf-codec", "rand", + "serde", "sha2", "smallvec", "thiserror", + "tracing", "uint", "unsigned-varint", "void", @@ -4757,30 +4804,30 @@ dependencies = [ [[package]] name = "libp2p-mdns" -version = "0.44.0" +version = "0.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42a2567c305232f5ef54185e9604579a894fd0674819402bb0ac0246da82f52a" +checksum = "68f273a551ee9d0a79695f75afaeafb1371459dec69c29555e8a73a35608e96a" dependencies = [ "data-encoding", "futures", + "hickory-proto", "if-watch", "libp2p-core", "libp2p-identity", "libp2p-swarm", - "log", "rand", "smallvec", "socket2 0.5.5", "tokio", - "trust-dns-proto 0.22.0", + "tracing", "void", ] [[package]] name = "libp2p-metrics" -version = "0.13.1" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "239ba7d28f8d0b5d77760dc6619c05c7e88e74ec8fbbe97f856f20a56745e620" +checksum = "7ac3c92d46c061d3564b660c143356de966a9ab17eb6bfa8d6819daa2ae49b28" dependencies = [ "instant", "libp2p-core", @@ -4792,22 +4839,21 @@ dependencies = [ "libp2p-ping", "libp2p-relay", "libp2p-swarm", - "once_cell", "prometheus-client", ] [[package]] name = "libp2p-noise" -version = "0.43.2" +version = "0.44.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2eeec39ad3ad0677551907dd304b2f13f17208ccebe333bef194076cd2e8921" +checksum = "8ecd0545ce077f6ea5434bcb76e8d0fe942693b4380aaad0d34a358c2bd05793" dependencies = [ + "asynchronous-codec 0.7.0", "bytes", "curve25519-dalek", "futures", "libp2p-core", "libp2p-identity", - "log", "multiaddr", "multihash", "once_cell", @@ -4817,15 +4863,16 @@ dependencies = [ "snow", "static_assertions", "thiserror", + "tracing", "x25519-dalek", "zeroize", ] [[package]] name = "libp2p-ping" -version = "0.43.1" +version = "0.44.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e702d75cd0827dfa15f8fd92d15b9932abe38d10d21f47c50438c71dd1b5dae3" +checksum = "76b94ee41bd8c294194fe608851e45eb98de26fe79bc7913838cbffbfe8c7ce2" dependencies = [ "either", "futures", @@ -4834,16 +4881,16 @@ dependencies = [ "libp2p-core", "libp2p-identity", "libp2p-swarm", - "log", "rand", + "tracing", "void", ] [[package]] name = "libp2p-quic" -version = "0.9.3" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "130d451d83f21b81eb7b35b360bc7972aeafb15177784adc56528db082e6b927" +checksum = "3635a185249a123cbb57e97495245acbbb0a5daeb4d1a7ac9748ad7f685e631e" dependencies = [ "bytes", "futures", @@ -4852,7 +4899,6 @@ dependencies = [ "libp2p-core", "libp2p-identity", "libp2p-tls", - "log", "parking_lot 0.12.1", "quinn", "rand", @@ -4861,15 +4907,16 @@ dependencies = [ "socket2 0.5.5", "thiserror", "tokio", + "tracing", ] [[package]] name = "libp2p-relay" -version = "0.16.2" +version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65bab06b10bbfb3936955965a01bd8db105b8675faabd55c88f94703feec318b" +checksum = "9a23501adbbc740711370466a34fae080316faf4fb28253419e0e5b705d5d5c1" dependencies = [ - "asynchronous-codec", + "asynchronous-codec 0.6.2", "bytes", "either", "futures", @@ -4879,38 +4926,40 @@ dependencies = [ "libp2p-core", "libp2p-identity", "libp2p-swarm", - "log", "quick-protobuf", "quick-protobuf-codec", "rand", "static_assertions", "thiserror", + "tracing", "void", ] [[package]] name = "libp2p-request-response" -version = "0.25.3" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8e3b4d67870478db72bac87bfc260ee6641d0734e0e3e275798f089c3fecfd4" +checksum = "198a07e045ca23ad3cdb0f54ef3dfb5750056e63af06803d189b0393f865f461" dependencies = [ "async-trait", "futures", + "futures-bounded", + "futures-timer", "instant", "libp2p-core", "libp2p-identity", "libp2p-swarm", - "log", "rand", "smallvec", + "tracing", "void", ] [[package]] name = "libp2p-swarm" -version = "0.43.7" +version = "0.44.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "580189e0074af847df90e75ef54f3f30059aedda37ea5a1659e8b9fca05c0141" +checksum = "643ce11d87db56387631c9757b61b83435b434f94dc52ec267c1666e560e78b0" dependencies = [ "either", "fnv", @@ -4920,33 +4969,32 @@ dependencies = [ "libp2p-core", "libp2p-identity", "libp2p-swarm-derive", - "log", "multistream-select", "once_cell", "rand", "smallvec", "tokio", + "tracing", "void", ] [[package]] name = "libp2p-swarm-derive" -version = "0.33.0" +version = "0.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4d5ec2a3df00c7836d7696c136274c9c59705bac69133253696a6c932cd1d74" +checksum = "9b27d257436d01433a21da8da7688c83dba35826726161a328ff0989cd7af2dd" dependencies = [ "heck 0.4.1", - "proc-macro-warning", "proc-macro2", "quote", - "syn 2.0.31", + "syn 2.0.39", ] [[package]] name = "libp2p-tcp" -version = "0.40.1" +version = "0.41.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b558dd40d1bcd1aaaed9de898e9ec6a436019ecc2420dd0016e712fbb61c5508" +checksum = "8b2460fc2748919adff99ecbc1aab296e4579e41f374fb164149bd2c9e529d4c" dependencies = [ "futures", "futures-timer", @@ -4954,16 +5002,16 @@ dependencies = [ "libc", "libp2p-core", "libp2p-identity", - "log", "socket2 0.5.5", "tokio", + "tracing", ] [[package]] name = "libp2p-tls" -version = "0.2.1" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8218d1d5482b122ccae396bbf38abdcb283ecc96fa54760e1dfd251f0546ac61" +checksum = "93ce7e3c2e7569d685d08ec795157981722ff96e9e9f9eae75df3c29d02b07a5" dependencies = [ "futures", "futures-rustls", @@ -4980,30 +5028,30 @@ dependencies = [ [[package]] name = "libp2p-upnp" -version = "0.1.1" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82775a47b34f10f787ad3e2a22e2c1541e6ebef4fe9f28f3ac553921554c94c1" +checksum = "963eb8a174f828f6a51927999a9ab5e45dfa9aa2aa5fed99aa65f79de6229464" dependencies = [ "futures", "futures-timer", "igd-next", "libp2p-core", "libp2p-swarm", - "log", "tokio", + "tracing", "void", ] [[package]] name = "libp2p-yamux" -version = "0.44.1" +version = "0.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8eedcb62824c4300efb9cfd4e2a6edaf3ca097b9e68b36dabe45a44469fd6a85" +checksum = "751f4778f71bc3db1ccf2451e7f4484463fec7f00c1ac2680e39c8368c23aae8" dependencies = [ "futures", "libp2p-core", - "log", "thiserror", + "tracing", "yamux", ] @@ -5127,12 +5175,6 @@ dependencies = [ "regex-automata 0.1.10", ] -[[package]] -name = "matches" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2532096657941c2fea9c289d370a250971c689d4f143798ff67113ec042024a5" - [[package]] name = "matchit" version = "0.7.1" @@ -5364,6 +5406,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "076d548d76a0e2a0d4ab471d0b1c36c577786dfc4471242035d97a12a735c492" dependencies = [ "core2", + "serde", "unsigned-varint", ] @@ -5701,7 +5744,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.31", + "syn 2.0.39", ] [[package]] @@ -6171,11 +6214,12 @@ dependencies = [ [[package]] name = "pem" -version = "1.1.1" +version = "3.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8835c273a76a90455d7344889b0964598e3316e2a79ede8e36f16bdcf2228b8" +checksum = "3163d2912b7c3b52d651a055f2c7eec9ba5cd22d26ef75b8dd3a59980b185923" dependencies = [ - "base64 0.13.1", + "base64 0.21.5", + "serde", ] [[package]] @@ -6224,7 +6268,7 @@ dependencies = [ "phf_shared 0.11.2", "proc-macro2", "quote", - "syn 2.0.31", + "syn 2.0.39", ] [[package]] @@ -6268,7 +6312,7 @@ checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405" dependencies = [ "proc-macro2", "quote", - "syn 2.0.31", + "syn 2.0.39", ] [[package]] @@ -6446,7 +6490,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae005bd773ab59b4725093fd7df83fd7892f7d8eafb48dbd7de6e024e4215f9d" dependencies = [ "proc-macro2", - "syn 2.0.31", + "syn 2.0.39", ] [[package]] @@ -6471,31 +6515,20 @@ dependencies = [ "toml 0.5.11", ] -[[package]] -name = "proc-macro-warning" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d1eaa7fa0aa1929ffdf7eeb6eac234dde6268914a14ad44d23521ab6a9b258e" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.31", -] - [[package]] name = "proc-macro2" -version = "1.0.66" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" +checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" dependencies = [ "unicode-ident", ] [[package]] name = "prometheus-client" -version = "0.21.2" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c99afa9a01501019ac3a14d71d9f94050346f55ca471ce90c799a15c58f61e2" +checksum = "510c4f1c9d81d556458f94c98f857748130ea9737bbd6053da497503b26ea63c" dependencies = [ "dtoa", "itoa", @@ -6571,7 +6604,7 @@ dependencies = [ "prost 0.12.1", "prost-types 0.12.1", "regex", - "syn 2.0.31", + "syn 2.0.39", "tempfile", "which", ] @@ -6599,7 +6632,7 @@ dependencies = [ "itertools 0.11.0", "proc-macro2", "quote", - "syn 2.0.31", + "syn 2.0.39", ] [[package]] @@ -6657,7 +6690,7 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8ededb1cd78531627244d51dd0c7139fbe736c7d57af0092a76f0ffb2f56e98" dependencies = [ - "asynchronous-codec", + "asynchronous-codec 0.6.2", "bytes", "quick-protobuf", "thiserror", @@ -6824,9 +6857,9 @@ dependencies = [ [[package]] name = "rcgen" -version = "0.10.0" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffbe84efe2f38dea12e9bfc1f65377fdf03e53a18cb3b995faedf7934c7e785b" +checksum = "52c4f3084aa3bc7dfbba4eff4fab2a54db4324965d8872ab933565e6fbd83bc6" dependencies = [ "pem", "ring 0.16.20", @@ -7030,7 +7063,7 @@ dependencies = [ "regex", "relative-path", "rustc_version", - "syn 2.0.31", + "syn 2.0.39", "unicode-ident", ] @@ -7341,7 +7374,7 @@ checksum = "389894603bd18c46fa56231694f8d827779c0951a667087194cf9de94ed24682" dependencies = [ "proc-macro2", "quote", - "syn 2.0.31", + "syn 2.0.39", ] [[package]] @@ -7433,7 +7466,7 @@ dependencies = [ "darling 0.20.3", "proc-macro2", "quote", - "syn 2.0.31", + "syn 2.0.39", ] [[package]] @@ -7699,7 +7732,7 @@ checksum = "af6527b845423542c8a16e060ea1bc43f67229848e7cd4c4d80be994a84220ce" dependencies = [ "starknet-curve 0.4.0", "starknet-ff", - "syn 2.0.31", + "syn 2.0.39", ] [[package]] @@ -7876,9 +7909,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.31" +version = "2.0.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "718fa2415bcb8d8bd775917a1bf12a7931b6dfa890753378538118181e0cb398" +checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a" dependencies = [ "proc-macro2", "quote", @@ -8007,7 +8040,7 @@ checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.31", + "syn 2.0.39", ] [[package]] @@ -8152,7 +8185,7 @@ checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.31", + "syn 2.0.39", ] [[package]] @@ -8390,7 +8423,7 @@ checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab" dependencies = [ "proc-macro2", "quote", - "syn 2.0.31", + "syn 2.0.39", ] [[package]] @@ -8443,78 +8476,6 @@ dependencies = [ "tracing-log", ] -[[package]] -name = "trust-dns-proto" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f7f83d1e4a0e4358ac54c5c3681e5d7da5efc5a7a632c90bb6d6669ddd9bc26" -dependencies = [ - "async-trait", - "cfg-if", - "data-encoding", - "enum-as-inner 0.5.1", - "futures-channel", - "futures-io", - "futures-util", - "idna 0.2.3", - "ipnet", - "lazy_static", - "rand", - "smallvec", - "socket2 0.4.9", - "thiserror", - "tinyvec", - "tokio", - "tracing", - "url", -] - -[[package]] -name = "trust-dns-proto" -version = "0.23.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3119112651c157f4488931a01e586aa459736e9d6046d3bd9105ffb69352d374" -dependencies = [ - "async-trait", - "cfg-if", - "data-encoding", - "enum-as-inner 0.6.0", - "futures-channel", - "futures-io", - "futures-util", - "idna 0.4.0", - "ipnet", - "once_cell", - "rand", - "smallvec", - "thiserror", - "tinyvec", - "tokio", - "tracing", - "url", -] - -[[package]] -name = "trust-dns-resolver" -version = "0.23.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10a3e6c3aff1718b3c73e395d1f35202ba2ffa847c6a62eea0db8fb4cfe30be6" -dependencies = [ - "cfg-if", - "futures-util", - "ipconfig", - "lru-cache", - "once_cell", - "parking_lot 0.12.1", - "rand", - "resolv-conf", - "smallvec", - "thiserror", - "tokio", - "tracing", - "trust-dns-proto 0.23.2", -] - [[package]] name = "try-lock" version = "0.2.4" @@ -8675,7 +8636,7 @@ version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6889a77d49f1f013504cec6bf97a2c730394adedaeb1deb5ea08949a50541105" dependencies = [ - "asynchronous-codec", + "asynchronous-codec 0.6.2", "bytes", ] @@ -8698,7 +8659,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "143b538f18257fac9cad154828a57c6bf5157e1aa604d4816b5995bf6de87ae5" dependencies = [ "form_urlencoded", - "idna 0.4.0", + "idna", "percent-encoding", ] @@ -8859,7 +8820,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.31", + "syn 2.0.39", "wasm-bindgen-shared", ] @@ -8893,7 +8854,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.31", + "syn 2.0.39", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -9190,7 +9151,7 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.31", + "syn 2.0.39", ] [[package]] diff --git a/crates/p2p/Cargo.toml b/crates/p2p/Cargo.toml index f0cf75439c..8e8197ca22 100644 --- a/crates/p2p/Cargo.toml +++ b/crates/p2p/Cargo.toml @@ -8,11 +8,7 @@ rust-version = { workspace = true } # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -anyhow = { workspace = true } -async-trait = { workspace = true } -base64 = { workspace = true } -futures = { workspace = true } -libp2p = { version = "0.52.4", default-features = false, features = [ +libp2p = { version = "0.53.0", default-features = false, features = [ "autonat", "dcutr", "dns", @@ -24,10 +20,15 @@ libp2p = { version = "0.52.4", default-features = false, features = [ "ping", "relay", "request-response", + "serde", "tcp", "tokio", "yamux", ] } +anyhow = { workspace = true } +async-trait = { workspace = true } +base64 = { workspace = true } +futures = { workspace = true } p2p_proto = { path = "../p2p_proto" } pathfinder-common = { path = "../common" } prost = "0.12.1" diff --git a/crates/p2p/src/behaviour.rs b/crates/p2p/src/behaviour.rs index ef7c8f7f5f..7bd12b587b 100644 --- a/crates/p2p/src/behaviour.rs +++ b/crates/p2p/src/behaviour.rs @@ -8,7 +8,7 @@ use libp2p::dcutr; use libp2p::gossipsub::{self, IdentTopic, MessageAuthenticity, MessageId}; use libp2p::identify; use libp2p::identity; -use libp2p::kad::{self, record::store::MemoryStore}; +use libp2p::kad::{self, store::MemoryStore}; use libp2p::ping; use libp2p::relay; use libp2p::request_response::{self, ProtocolSupport}; @@ -223,10 +223,10 @@ impl From> for Event } } -fn string_to_key(input: &str) -> kad::record::Key { +fn string_to_key(input: &str) -> kad::RecordKey { use sha2::{Digest, Sha256}; let mut hasher = Sha256::new(); hasher.update(input.as_bytes()); let result = hasher.finalize(); - kad::record::Key::new(&result.as_slice()) + kad::RecordKey::new(&result.as_slice()) } diff --git a/crates/p2p/src/lib.rs b/crates/p2p/src/lib.rs index 804624e7f6..6dc8c0d31e 100644 --- a/crates/p2p/src/lib.rs +++ b/crates/p2p/src/lib.rs @@ -6,7 +6,7 @@ use std::time::Duration; use libp2p::gossipsub::IdentTopic; use libp2p::identity::Keypair; -use libp2p::kad::record::Key; +use libp2p::kad::RecordKey; use libp2p::request_response::ResponseChannel; use libp2p::swarm::Config; use libp2p::{Multiaddr, PeerId, Swarm}; @@ -224,7 +224,7 @@ pub enum Event { pub enum TestEvent { NewListenAddress(Multiaddr), PeriodicBootstrapCompleted(Result), - StartProvidingCompleted(Result), + StartProvidingCompleted(Result), ConnectionEstablished { outbound: bool, remote: PeerId }, Subscribed { remote: PeerId, topic: String }, PeerAddedToDHT { remote: PeerId }, diff --git a/crates/p2p/src/main_loop.rs b/crates/p2p/src/main_loop.rs index 6e22608fea..51c920b9ab 100644 --- a/crates/p2p/src/main_loop.rs +++ b/crates/p2p/src/main_loop.rs @@ -7,7 +7,7 @@ use libp2p::gossipsub::{self, IdentTopic}; use libp2p::identify; use libp2p::kad::{self, BootstrapError, BootstrapOk, QueryId, QueryResult}; use libp2p::multiaddr::Protocol; -use libp2p::request_response::{self, RequestId}; +use libp2p::request_response::{self, OutboundRequestId}; use libp2p::swarm::dial_opts::{DialOpts, PeerCondition}; use libp2p::swarm::SwarmEvent; use libp2p::PeerId; @@ -45,11 +45,13 @@ pub struct MainLoop { #[derive(Debug, Default)] struct PendingRequests { - pub headers: HashMap>>, - pub bodies: HashMap>>, - pub transactions: HashMap>>, - pub receipts: HashMap>>, - pub events: HashMap>>, + pub headers: HashMap>>, + pub bodies: + HashMap>>, + pub transactions: + HashMap>>, + pub receipts: HashMap>>, + pub events: HashMap>>, } #[derive(Debug, Default)] @@ -139,19 +141,12 @@ impl MainLoop { None => return, } } - Some(event) = self.swarm.next() => { - if let Err(e) = self.handle_event(event).await { - tracing::error!("event handling failed: {}", e); - } - }, + Some(event) = self.swarm.next() => self.handle_event(event).await, } } } - async fn handle_event( - &mut self, - event: SwarmEvent, - ) -> anyhow::Result<()> { + async fn handle_event(&mut self, event: SwarmEvent) { match event { // =========================== // Connection management @@ -179,8 +174,6 @@ impl MainLoop { }, ) .await; - - Ok(()) } SwarmEvent::OutgoingConnectionError { peer_id, error, .. } => { if let Some(peer_id) = peer_id { @@ -192,7 +185,6 @@ impl MainLoop { let _ = sender.send(Err(error.into())); } } - Ok(()) } SwarmEvent::ConnectionClosed { peer_id, @@ -206,7 +198,6 @@ impl MainLoop { } else { tracing::debug!(%peer_id, other_connections_for_this_peer=%num_established, "Connection closed"); } - Ok(()) } SwarmEvent::Dialing { // The only API available to the caller [`crate::client::peer_aware::Client`] only allows for dialing @@ -216,7 +207,6 @@ impl MainLoop { } => { self.peers.write().await.peer_dialing(&peer_id); tracing::debug!(%peer_id, "Dialing peer"); - Ok(()) } // =========================== // Identify @@ -268,7 +258,6 @@ impl MainLoop { } } } - Ok(()) } // =========================== // Block propagation @@ -296,7 +285,8 @@ impl MainLoop { from: peer_id, new_block, }) - .await?; + .await + .expect("Event receiver not to be dropped"); } Err(error) => { tracing::error!(from=%peer_id, %error, "Gossipsub Message") @@ -307,111 +297,104 @@ impl MainLoop { tracing::error!(from=%peer_id, %error, "Gossipsub Message"); } }; - Ok(()) } // =========================== // Discovery // =========================== - SwarmEvent::Behaviour(behaviour::Event::Kademlia(e)) => { - match e { - kad::Event::OutboundQueryProgressed { - step, result, id, .. - } => { - if step.last { - match result { - libp2p::kad::QueryResult::Bootstrap(result) => { - let network_info = self.swarm.network_info(); - let num_peers = network_info.num_peers(); - let connection_counters = network_info.connection_counters(); - let num_connections = connection_counters.num_connections(); - - let result = match result { - Ok(BootstrapOk { peer, .. }) => { - tracing::debug!(%num_peers, %num_connections, "Periodic bootstrap completed"); - Ok(peer) - } - Err(BootstrapError::Timeout { peer, .. }) => { - tracing::warn!(%num_peers, %num_connections, "Periodic bootstrap failed"); - Err(peer) - } - }; - send_test_event( - &self.event_sender, - TestEvent::PeriodicBootstrapCompleted(result), - ) - .await; - } - QueryResult::GetProviders(result) => { - use libp2p::kad::GetProvidersOk; - - let result = match result { - Ok(GetProvidersOk::FoundProviders { - providers, .. - }) => Ok(providers), - Ok(GetProvidersOk::FinishedWithNoAdditionalRecord { - .. - }) => Ok(Default::default()), - Err(e) => Err(e.into()), - }; - - let sender = self - .pending_queries - .get_providers - .remove(&id) - .expect("Query to be pending"); - - sender - .send(result) - .await - .expect("Receiver not to be dropped"); - } - _ => self.test_query_completed(id, result).await, + SwarmEvent::Behaviour(behaviour::Event::Kademlia(e)) => match e { + kad::Event::OutboundQueryProgressed { + step, result, id, .. + } => { + if step.last { + match result { + libp2p::kad::QueryResult::Bootstrap(result) => { + let network_info = self.swarm.network_info(); + let num_peers = network_info.num_peers(); + let connection_counters = network_info.connection_counters(); + let num_connections = connection_counters.num_connections(); + + let result = match result { + Ok(BootstrapOk { peer, .. }) => { + tracing::debug!(%num_peers, %num_connections, "Periodic bootstrap completed"); + Ok(peer) + } + Err(BootstrapError::Timeout { peer, .. }) => { + tracing::warn!(%num_peers, %num_connections, "Periodic bootstrap failed"); + Err(peer) + } + }; + send_test_event( + &self.event_sender, + TestEvent::PeriodicBootstrapCompleted(result), + ) + .await; } - } else if let QueryResult::GetProviders(result) = result { - use libp2p::kad::GetProvidersOk; - - let result = match result { - Ok(GetProvidersOk::FoundProviders { providers, .. }) => { - Ok(providers) - } - Ok(_) => Ok(Default::default()), - Err(_) => { - unreachable!( - "when a query times out libp2p makes it the last stage" - ) - } - }; - - let sender = self - .pending_queries - .get_providers - .get(&id) - .expect("Query to be pending"); - - sender - .send(result) - .await - .expect("Receiver not to be dropped"); - } else { - self.test_query_progressed(id, result).await; + QueryResult::GetProviders(result) => { + use libp2p::kad::GetProvidersOk; + + let result = match result { + Ok(GetProvidersOk::FoundProviders { providers, .. }) => { + Ok(providers) + } + Ok(GetProvidersOk::FinishedWithNoAdditionalRecord { + .. + }) => Ok(Default::default()), + Err(e) => Err(e.into()), + }; + + let sender = self + .pending_queries + .get_providers + .remove(&id) + .expect("Query to be pending"); + + sender + .send(result) + .await + .expect("Receiver not to be dropped"); + } + _ => self.test_query_completed(id, result).await, } - } - kad::Event::RoutingUpdated { - peer, is_new_peer, .. - } => { - if is_new_peer { - send_test_event( - &self.event_sender, - TestEvent::PeerAddedToDHT { remote: peer }, - ) + } else if let QueryResult::GetProviders(result) = result { + use libp2p::kad::GetProvidersOk; + + let result = match result { + Ok(GetProvidersOk::FoundProviders { providers, .. }) => Ok(providers), + Ok(_) => Ok(Default::default()), + Err(_) => { + unreachable!( + "when a query times out libp2p makes it the last stage" + ) + } + }; + + let sender = self + .pending_queries + .get_providers + .get(&id) + .expect("Query to be pending"); + + sender + .send(result) .await - } + .expect("Receiver not to be dropped"); + } else { + self.test_query_progressed(id, result).await; } - _ => {} } - - Ok(()) - } + kad::Event::RoutingUpdated { + peer, is_new_peer, .. + } => { + if is_new_peer { + send_test_event( + &self.event_sender, + TestEvent::PeerAddedToDHT { remote: peer }, + ) + .await + } + } + _ => {} + }, // =========================== // Block sync // =========================== @@ -431,8 +414,6 @@ impl MainLoop { }) .await .expect("Event receiver not to be dropped"); - - Ok(()) } request_response::Message::Response { request_id, @@ -444,7 +425,6 @@ impl MainLoop { .remove(&request_id) .expect("Block sync request still to be pending") .send(Ok(response)); - Ok(()) } }, SwarmEvent::Behaviour(behaviour::Event::BodiesSync( @@ -463,8 +443,6 @@ impl MainLoop { }) .await .expect("Event receiver not to be dropped"); - - Ok(()) } request_response::Message::Response { request_id, @@ -476,7 +454,6 @@ impl MainLoop { .remove(&request_id) .expect("Block sync request still to be pending") .send(Ok(response)); - Ok(()) } }, SwarmEvent::Behaviour(behaviour::Event::TransactionsSync( @@ -495,8 +472,6 @@ impl MainLoop { }) .await .expect("Event receiver not to be dropped"); - - Ok(()) } request_response::Message::Response { request_id, @@ -508,7 +483,6 @@ impl MainLoop { .remove(&request_id) .expect("Block sync request still to be pending") .send(Ok(response)); - Ok(()) } }, SwarmEvent::Behaviour(behaviour::Event::ReceiptsSync( @@ -527,8 +501,6 @@ impl MainLoop { }) .await .expect("Event receiver not to be dropped"); - - Ok(()) } request_response::Message::Response { request_id, @@ -540,7 +512,6 @@ impl MainLoop { .remove(&request_id) .expect("Block sync request still to be pending") .send(Ok(response)); - Ok(()) } }, SwarmEvent::Behaviour(behaviour::Event::EventsSync( @@ -559,8 +530,6 @@ impl MainLoop { }) .await .expect("Event receiver not to be dropped"); - - Ok(()) } request_response::Message::Response { request_id, @@ -572,7 +541,6 @@ impl MainLoop { .remove(&request_id) .expect("Block sync request still to be pending") .send(Ok(response)); - Ok(()) } }, SwarmEvent::Behaviour(behaviour::Event::HeadersSync( @@ -587,7 +555,6 @@ impl MainLoop { .remove(&request_id) .expect("Block sync request still to be pending") .send(Err(error.into())); - Ok(()) } SwarmEvent::Behaviour(behaviour::Event::BodiesSync( request_response::Event::OutboundFailure { @@ -601,7 +568,6 @@ impl MainLoop { .remove(&request_id) .expect("Block sync request still to be pending") .send(Err(error.into())); - Ok(()) } SwarmEvent::Behaviour(behaviour::Event::TransactionsSync( request_response::Event::OutboundFailure { @@ -615,7 +581,6 @@ impl MainLoop { .remove(&request_id) .expect("Block sync request still to be pending") .send(Err(error.into())); - Ok(()) } SwarmEvent::Behaviour(behaviour::Event::ReceiptsSync( request_response::Event::OutboundFailure { @@ -629,7 +594,6 @@ impl MainLoop { .remove(&request_id) .expect("Block sync request still to be pending") .send(Err(error.into())); - Ok(()) } SwarmEvent::Behaviour(behaviour::Event::EventsSync( request_response::Event::OutboundFailure { @@ -643,14 +607,12 @@ impl MainLoop { .remove(&request_id) .expect("Block sync request still to be pending") .send(Err(error.into())); - Ok(()) } // =========================== // NAT hole punching // =========================== SwarmEvent::Behaviour(behaviour::Event::Dcutr(event)) => { tracing::debug!(?event, "DCUtR event"); - Ok(()) } // =========================== // Ignored or forwarded for @@ -667,7 +629,6 @@ impl MainLoop { _ => tracing::trace!(?event, "Ignoring event"), } self.handle_event_for_test(event).await; - Ok(()) } } } @@ -889,10 +850,7 @@ impl MainLoop { } /// No-op outside tests - async fn handle_event_for_test( - &mut self, - _event: SwarmEvent, - ) { + async fn handle_event_for_test(&mut self, _event: SwarmEvent) { #[cfg(test)] test_utils::handle_event(&self.event_sender, _event).await } diff --git a/crates/p2p/src/test_utils.rs b/crates/p2p/src/test_utils.rs index 80e05c70f7..9dc4c30065 100644 --- a/crates/p2p/src/test_utils.rs +++ b/crates/p2p/src/test_utils.rs @@ -30,9 +30,9 @@ impl Client { } } -pub(super) async fn handle_event( +pub(super) async fn handle_event( event_sender: &mpsc::Sender, - event: SwarmEvent, + event: SwarmEvent, ) { match event { SwarmEvent::NewListenAddr { address, .. } => { diff --git a/crates/p2p_bootstrap/Cargo.toml b/crates/p2p_bootstrap/Cargo.toml index 55c12af8f9..1b5cb67553 100644 --- a/crates/p2p_bootstrap/Cargo.toml +++ b/crates/p2p_bootstrap/Cargo.toml @@ -12,7 +12,7 @@ anyhow = { workspace = true } base64 = { workspace = true } clap = { workspace = true, features = ["derive", "env", "wrap_help"] } futures = { workspace = true } -libp2p = { version = "0.52.4", default-features = false, features = [ +libp2p = { version = "0.53.0", default-features = false, features = [ "identify", "kad", "noise", diff --git a/crates/p2p_bootstrap/src/behaviour.rs b/crates/p2p_bootstrap/src/behaviour.rs index 0d409e7218..7a6bbd1896 100644 --- a/crates/p2p_bootstrap/src/behaviour.rs +++ b/crates/p2p_bootstrap/src/behaviour.rs @@ -4,7 +4,7 @@ use libp2p::autonat; use libp2p::dcutr; use libp2p::identify; use libp2p::identity; -use libp2p::kad::{self, record::store::MemoryStore}; +use libp2p::kad::{self, store::MemoryStore}; use libp2p::ping; use libp2p::relay; use libp2p::swarm::NetworkBehaviour; From fe92049833823e83471e26f8284ab536618bb38d Mon Sep 17 00:00:00 2001 From: Krzysztof Lis Date: Mon, 6 Nov 2023 17:19:58 +0100 Subject: [PATCH 2/3] refactor(p2p): decode and encode because [read|write]_length_prefixed were removed --- Cargo.lock | 25 ++++++++++++++++++------- crates/p2p/Cargo.toml | 9 +++++---- crates/p2p/src/sync.rs | 32 ++++++++++++++++++++++---------- 3 files changed, 45 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2e56e33895..95260b81a6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4654,7 +4654,7 @@ dependencies = [ "smallvec", "thiserror", "tracing", - "unsigned-varint", + "unsigned-varint 0.7.2", "void", ] @@ -4726,7 +4726,7 @@ dependencies = [ "sha2", "smallvec", "tracing", - "unsigned-varint", + "unsigned-varint 0.7.2", "void", ] @@ -4798,7 +4798,7 @@ dependencies = [ "thiserror", "tracing", "uint", - "unsigned-varint", + "unsigned-varint 0.7.2", "void", ] @@ -5384,7 +5384,7 @@ dependencies = [ "percent-encoding", "serde", "static_assertions", - "unsigned-varint", + "unsigned-varint 0.7.2", "url", ] @@ -5407,7 +5407,7 @@ checksum = "076d548d76a0e2a0d4ab471d0b1c36c577786dfc4471242035d97a12a735c492" dependencies = [ "core2", "serde", - "unsigned-varint", + "unsigned-varint 0.7.2", ] [[package]] @@ -5427,7 +5427,7 @@ dependencies = [ "log", "pin-project", "smallvec", - "unsigned-varint", + "unsigned-varint 0.7.2", ] [[package]] @@ -5797,6 +5797,7 @@ dependencies = [ "tokio", "tracing", "tracing-subscriber", + "unsigned-varint 0.8.0", "void", "zeroize", ] @@ -6694,7 +6695,7 @@ dependencies = [ "bytes", "quick-protobuf", "thiserror", - "unsigned-varint", + "unsigned-varint 0.7.2", ] [[package]] @@ -8640,6 +8641,16 @@ dependencies = [ "bytes", ] +[[package]] +name = "unsigned-varint" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb066959b24b5196ae73cb057f45598450d2c5f71460e98c49b738086eff9c06" +dependencies = [ + "futures-io", + "futures-util", +] + [[package]] name = "untrusted" version = "0.7.1" diff --git a/crates/p2p/Cargo.toml b/crates/p2p/Cargo.toml index 8e8197ca22..347c6e123b 100644 --- a/crates/p2p/Cargo.toml +++ b/crates/p2p/Cargo.toml @@ -8,6 +8,10 @@ rust-version = { workspace = true } # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +anyhow = { workspace = true } +async-trait = { workspace = true } +base64 = { workspace = true } +futures = { workspace = true } libp2p = { version = "0.53.0", default-features = false, features = [ "autonat", "dcutr", @@ -25,10 +29,6 @@ libp2p = { version = "0.53.0", default-features = false, features = [ "tokio", "yamux", ] } -anyhow = { workspace = true } -async-trait = { workspace = true } -base64 = { workspace = true } -futures = { workspace = true } p2p_proto = { path = "../p2p_proto" } pathfinder-common = { path = "../common" } prost = "0.12.1" @@ -39,6 +39,7 @@ sha2 = "0.10.7" stark_hash = { path = "../stark_hash" } tokio = { version = "1.32.0", features = ["macros", "rt-multi-thread", "sync"] } tracing = "0.1.37" +unsigned-varint = { version = "0.8.0", features = ["futures"] } void = "1.0.2" zeroize = "1.6.0" diff --git a/crates/p2p/src/sync.rs b/crates/p2p/src/sync.rs index 5df0430a63..0014fe380b 100644 --- a/crates/p2p/src/sync.rs +++ b/crates/p2p/src/sync.rs @@ -39,13 +39,13 @@ pub mod protocol { pub(crate) mod codec { use super::protocol; use async_trait::async_trait; - use futures::{AsyncRead, AsyncWrite, AsyncWriteExt}; - use libp2p::core::upgrade::{read_length_prefixed, write_length_prefixed}; + use futures::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt}; use libp2p::request_response::Codec; use p2p_proto::consts::MESSAGE_SIZE_LIMIT; use p2p_proto::{block, event, proto, receipt, transaction}; use p2p_proto::{ToProtobuf, TryFromProtobuf}; use std::marker::PhantomData; + use unsigned_varint::aio::read_usize; pub type Headers = SyncCodec< protocol::Headers, @@ -160,7 +160,7 @@ pub(crate) mod codec { } async fn decode( - io: &mut Reader, + mut io: &mut Reader, max_buf_size: usize, ) -> std::io::Result where @@ -168,11 +168,24 @@ pub(crate) mod codec { ProstDto: prost::Message + Default, Dto: TryFromProtobuf, { - let vec = read_length_prefixed(io, max_buf_size).await?; - if vec.is_empty() { - return Err(std::io::ErrorKind::UnexpectedEof.into()); + let encoded_len = read_usize(&mut io) + .await + .map_err(Into::::into)?; + + if encoded_len > max_buf_size { + return Err(std::io::Error::new( + std::io::ErrorKind::InvalidData, + format!( + "Encoded length {} exceeds the maximum buffer size {}", + encoded_len, max_buf_size + ), + )); } - let prost_dto = ProstDto::decode(vec.as_ref())?; + + let mut buf = vec![0u8; encoded_len]; + io.read_exact(&mut buf).await?; + + let prost_dto = ProstDto::decode(buf.as_ref())?; let dto = Dto::try_from_protobuf(prost_dto, std::any::type_name::())?; Ok(dto) } @@ -183,10 +196,9 @@ pub(crate) mod codec { ProstDto: prost::Message, Dto: ToProtobuf, { - let data = dto.to_protobuf().encode_to_vec(); - write_length_prefixed(io, &data).await?; + let data = dto.to_protobuf().encode_length_delimited_to_vec(); + io.write_all(&data).await?; io.close().await?; - Ok(()) } } From bdbf041cb26c4f3590b2d9b50c921dcd205e06da Mon Sep 17 00:00:00 2001 From: Krzysztof Lis Date: Mon, 6 Nov 2023 17:46:33 +0100 Subject: [PATCH 3/3] build: bump msrv --- Cargo.toml | 2 +- crates/load-test/Cargo.toml | 2 +- crates/stark_hash_python/Cargo.toml | 2 +- utils/pathfinder-probe/Cargo.toml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1be8b131f3..6812fd4c9e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,7 +36,7 @@ lto = true [workspace.package] edition = "2021" license = "MIT OR Apache-2.0" -rust-version = "1.72" +rust-version = "1.73" [workspace.dependencies] anyhow = "1.0.75" diff --git a/crates/load-test/Cargo.toml b/crates/load-test/Cargo.toml index 498e1c29e7..444559ccdf 100644 --- a/crates/load-test/Cargo.toml +++ b/crates/load-test/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" description = "Load test for pathfinder JSON-RPC endpoints" edition = "2021" license = "MIT OR Apache-2.0" -rust-version = "1.72" +rust-version = "1.73" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] diff --git a/crates/stark_hash_python/Cargo.toml b/crates/stark_hash_python/Cargo.toml index eb7470265c..459aa89062 100644 --- a/crates/stark_hash_python/Cargo.toml +++ b/crates/stark_hash_python/Cargo.toml @@ -3,7 +3,7 @@ name = "stark_hash_python" version = "0.1.0" edition = "2021" license = "MIT OR Apache-2.0" -rust-version = "1.72" +rust-version = "1.73" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [lib] diff --git a/utils/pathfinder-probe/Cargo.toml b/utils/pathfinder-probe/Cargo.toml index c0f1ee59c3..031da579f1 100644 --- a/utils/pathfinder-probe/Cargo.toml +++ b/utils/pathfinder-probe/Cargo.toml @@ -3,7 +3,7 @@ name = "pathfinder-probe" version = "0.1.0" edition = "2021" license = "MIT OR Apache-2.0" -rust-version = "1.72" +rust-version = "1.73" [dependencies] anyhow = "1.0.71"