From 7bfe2fac94a109f7879817a016559dbb12cc8a24 Mon Sep 17 00:00:00 2001 From: Yiannis Marangos Date: Tue, 13 Aug 2024 18:27:38 +0300 Subject: [PATCH] chore(node)!: Upgrade libp2p to 0.54.0 (#362) --- Cargo.lock | 194 ++++++++++++++++++++++++++------------ Cargo.toml | 8 +- node/Cargo.toml | 7 +- node/src/events.rs | 2 +- node/src/node.rs | 3 +- node/src/p2p.rs | 25 ++--- node/src/p2p/header_ex.rs | 10 +- node/src/p2p/kademlia.rs | 189 ------------------------------------- node/src/p2p/swarm.rs | 3 +- 9 files changed, 164 insertions(+), 277 deletions(-) delete mode 100644 node/src/p2p/kademlia.rs diff --git a/Cargo.lock b/Cargo.lock index 7298c889..38e4ebf2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -517,9 +517,9 @@ checksum = "d965446196e3b7decd44aa7ee49e31d630118f90ef12f97900f262eb915c951d" [[package]] name = "beetswap" -version = "0.1.1" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "defcc80a305e89c8fb185e4ce9d068ea48f03baebf1dbc8549fb36131dbc61ce" +checksum = "e41ccdd7bc2a1162380eb2657100fba24739c4b600344187d1b5a411afd326b2" dependencies = [ "asynchronous-codec", "blockstore", @@ -529,7 +529,6 @@ dependencies = [ "futures-core", "futures-timer", "futures-util", - "instant", "libp2p-core", "libp2p-identity", "libp2p-swarm", @@ -541,6 +540,7 @@ dependencies = [ "tracing", "unsigned-varint 0.8.0", "void", + "web-time", ] [[package]] @@ -631,16 +631,17 @@ dependencies = [ [[package]] name = "blockstore" -version = "0.5.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "358358b19add120a5afc3dd1c8e9161d6d06c44dfec2ef8da58b7fe5c369c90d" +checksum = "dc99329facbb960effbe7ed707c753a718877c1878eb8ca08704fa391c494020" dependencies = [ "cid", - "dashmap", + "dashmap 6.0.1", + "idb", "js-sys", "multihash", "redb", - "rexie", + "rexie 0.6.2", "thiserror", "tokio", "wasm-bindgen", @@ -1131,6 +1132,20 @@ dependencies = [ "parking_lot_core", ] +[[package]] +name = "dashmap" +version = "6.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "804c8821570c3f8b70230c2ba75ffa5c0f9a4189b9a432b6656c536712acae28" +dependencies = [ + "cfg-if", + "crossbeam-utils", + "hashbrown", + "lock_api", + "once_cell", + "parking_lot_core", +] + [[package]] name = "data-encoding" version = "2.6.0" @@ -2154,6 +2169,20 @@ dependencies = [ "syn 2.0.66", ] +[[package]] +name = "idb" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2764bba4203538c2ef2d733d5bad8fdb4622b1ebc5560831279db7b3be1332e8" +dependencies = [ + "js-sys", + "num-traits", + "thiserror", + "tokio", + "wasm-bindgen", + "web-sys", +] + [[package]] name = "idna" version = "0.4.0" @@ -2544,7 +2573,8 @@ checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" [[package]] name = "libp2p" version = "0.54.0" -source = "git+https://github.com/libp2p/rust-libp2p?rev=60e32c9d3b4bee42ac698791e917e1587eaa1388#60e32c9d3b4bee42ac698791e917e1587eaa1388" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b06a2ceb55591d19a194956ce541329007b4e4ee87c5fdd59d64dc439286a36" dependencies = [ "bytes", "either", @@ -2570,6 +2600,7 @@ dependencies = [ "libp2p-tcp", "libp2p-upnp", "libp2p-websocket", + "libp2p-websocket-websys", "libp2p-webtransport-websys", "libp2p-yamux", "multiaddr", @@ -2580,8 +2611,9 @@ dependencies = [ [[package]] name = "libp2p-allow-block-list" -version = "0.3.0" -source = "git+https://github.com/libp2p/rust-libp2p?rev=60e32c9d3b4bee42ac698791e917e1587eaa1388#60e32c9d3b4bee42ac698791e917e1587eaa1388" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1027ccf8d70320ed77e984f273bc8ce952f623762cb9bf2d126df73caef8041" dependencies = [ "libp2p-core", "libp2p-identity", @@ -2591,12 +2623,16 @@ dependencies = [ [[package]] name = "libp2p-autonat" -version = "0.12.1" -source = "git+https://github.com/libp2p/rust-libp2p?rev=60e32c9d3b4bee42ac698791e917e1587eaa1388#60e32c9d3b4bee42ac698791e917e1587eaa1388" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a083675f189803d0682a2726131628e808144911dad076858bfbe30b13065499" dependencies = [ "async-trait", "asynchronous-codec", + "bytes", + "either", "futures", + "futures-bounded", "futures-timer", "libp2p-core", "libp2p-identity", @@ -2605,14 +2641,18 @@ dependencies = [ "quick-protobuf", "quick-protobuf-codec", "rand", + "rand_core", + "thiserror", "tracing", + "void", "web-time", ] [[package]] name = "libp2p-connection-limits" -version = "0.3.1" -source = "git+https://github.com/libp2p/rust-libp2p?rev=60e32c9d3b4bee42ac698791e917e1587eaa1388#60e32c9d3b4bee42ac698791e917e1587eaa1388" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d003540ee8baef0d254f7b6bfd79bac3ddf774662ca0abf69186d517ef82ad8" dependencies = [ "libp2p-core", "libp2p-identity", @@ -2622,8 +2662,9 @@ dependencies = [ [[package]] name = "libp2p-core" -version = "0.41.3" -source = "git+https://github.com/libp2p/rust-libp2p?rev=60e32c9d3b4bee42ac698791e917e1587eaa1388#60e32c9d3b4bee42ac698791e917e1587eaa1388" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a61f26c83ed111104cd820fe9bc3aaabbac5f1652a1d213ed6e900b7918a1298" dependencies = [ "either", "fnv", @@ -2650,8 +2691,9 @@ dependencies = [ [[package]] name = "libp2p-dns" -version = "0.41.1" -source = "git+https://github.com/libp2p/rust-libp2p?rev=60e32c9d3b4bee42ac698791e917e1587eaa1388#60e32c9d3b4bee42ac698791e917e1587eaa1388" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97f37f30d5c7275db282ecd86e54f29dd2176bd3ac656f06abf43bedb21eb8bd" dependencies = [ "async-trait", "futures", @@ -2665,8 +2707,9 @@ dependencies = [ [[package]] name = "libp2p-gossipsub" -version = "0.46.2" -source = "git+https://github.com/libp2p/rust-libp2p?rev=60e32c9d3b4bee42ac698791e917e1587eaa1388#60e32c9d3b4bee42ac698791e917e1587eaa1388" +version = "0.47.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4e830fdf24ac8c444c12415903174d506e1e077fbe3875c404a78c5935a8543" dependencies = [ "asynchronous-codec", "base64", @@ -2696,8 +2739,9 @@ dependencies = [ [[package]] name = "libp2p-identify" -version = "0.44.2" -source = "git+https://github.com/libp2p/rust-libp2p?rev=60e32c9d3b4bee42ac698791e917e1587eaa1388#60e32c9d3b4bee42ac698791e917e1587eaa1388" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1711b004a273be4f30202778856368683bd9a83c4c7dcc8f848847606831a4e3" dependencies = [ "asynchronous-codec", "either", @@ -2738,7 +2782,8 @@ dependencies = [ [[package]] name = "libp2p-kad" version = "0.46.0" -source = "git+https://github.com/libp2p/rust-libp2p?rev=60e32c9d3b4bee42ac698791e917e1587eaa1388#60e32c9d3b4bee42ac698791e917e1587eaa1388" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3fd4d149f0539e608d178b7cd1cfb0c1c6a8dc367eda2bc1cc81a28a1552161" dependencies = [ "arrayvec", "asynchronous-codec", @@ -2766,8 +2811,9 @@ dependencies = [ [[package]] name = "libp2p-mdns" -version = "0.45.1" -source = "git+https://github.com/libp2p/rust-libp2p?rev=60e32c9d3b4bee42ac698791e917e1587eaa1388#60e32c9d3b4bee42ac698791e917e1587eaa1388" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14b8546b6644032565eb29046b42744aee1e9f261ed99671b2c93fb140dba417" dependencies = [ "data-encoding", "futures", @@ -2787,7 +2833,8 @@ dependencies = [ [[package]] name = "libp2p-metrics" version = "0.14.2" -source = "git+https://github.com/libp2p/rust-libp2p?rev=60e32c9d3b4bee42ac698791e917e1587eaa1388#60e32c9d3b4bee42ac698791e917e1587eaa1388" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a70afa7692c81ee03e89c40d1e8638d634f18baef6aeeea30fd245edfae4d3fd" dependencies = [ "futures", "libp2p-core", @@ -2804,8 +2851,9 @@ dependencies = [ [[package]] name = "libp2p-noise" -version = "0.44.0" -source = "git+https://github.com/libp2p/rust-libp2p?rev=60e32c9d3b4bee42ac698791e917e1587eaa1388#60e32c9d3b4bee42ac698791e917e1587eaa1388" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36b137cb1ae86ee39f8e5d6245a296518912014eaa87427d24e6ff58cfc1b28c" dependencies = [ "asynchronous-codec", "bytes", @@ -2829,8 +2877,9 @@ dependencies = [ [[package]] name = "libp2p-ping" -version = "0.44.2" -source = "git+https://github.com/libp2p/rust-libp2p?rev=60e32c9d3b4bee42ac698791e917e1587eaa1388#60e32c9d3b4bee42ac698791e917e1587eaa1388" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "005a34420359223b974ee344457095f027e51346e992d1e0dcd35173f4cdd422" dependencies = [ "either", "futures", @@ -2846,8 +2895,9 @@ dependencies = [ [[package]] name = "libp2p-quic" -version = "0.10.3" -source = "git+https://github.com/libp2p/rust-libp2p?rev=60e32c9d3b4bee42ac698791e917e1587eaa1388#60e32c9d3b4bee42ac698791e917e1587eaa1388" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46352ac5cd040c70e88e7ff8257a2ae2f891a4076abad2c439584a31c15fd24e" dependencies = [ "bytes", "futures", @@ -2869,8 +2919,9 @@ dependencies = [ [[package]] name = "libp2p-request-response" -version = "0.26.4" -source = "git+https://github.com/libp2p/rust-libp2p?rev=60e32c9d3b4bee42ac698791e917e1587eaa1388#60e32c9d3b4bee42ac698791e917e1587eaa1388" +version = "0.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1356c9e376a94a75ae830c42cdaea3d4fe1290ba409a22c809033d1b7dcab0a6" dependencies = [ "async-trait", "futures", @@ -2888,8 +2939,9 @@ dependencies = [ [[package]] name = "libp2p-swarm" -version = "0.44.3" -source = "git+https://github.com/libp2p/rust-libp2p?rev=60e32c9d3b4bee42ac698791e917e1587eaa1388#60e32c9d3b4bee42ac698791e917e1587eaa1388" +version = "0.45.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7dd6741793d2c1fb2088f67f82cf07261f25272ebe3c0b0c311e0c6b50e851a" dependencies = [ "either", "fnv", @@ -2913,8 +2965,9 @@ dependencies = [ [[package]] name = "libp2p-swarm-derive" -version = "0.34.2" -source = "git+https://github.com/libp2p/rust-libp2p?rev=60e32c9d3b4bee42ac698791e917e1587eaa1388#60e32c9d3b4bee42ac698791e917e1587eaa1388" +version = "0.35.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "206e0aa0ebe004d778d79fb0966aa0de996c19894e2c0605ba2f8524dd4443d8" dependencies = [ "heck 0.5.0", "proc-macro2", @@ -2924,8 +2977,9 @@ dependencies = [ [[package]] name = "libp2p-tcp" -version = "0.41.1" -source = "git+https://github.com/libp2p/rust-libp2p?rev=60e32c9d3b4bee42ac698791e917e1587eaa1388#60e32c9d3b4bee42ac698791e917e1587eaa1388" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad964f312c59dcfcac840acd8c555de8403e295d39edf96f5240048b5fcaa314" dependencies = [ "futures", "futures-timer", @@ -2940,8 +2994,9 @@ dependencies = [ [[package]] name = "libp2p-tls" -version = "0.4.0" -source = "git+https://github.com/libp2p/rust-libp2p?rev=60e32c9d3b4bee42ac698791e917e1587eaa1388#60e32c9d3b4bee42ac698791e917e1587eaa1388" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47b23dddc2b9c355f73c1e36eb0c3ae86f7dc964a3715f0731cfad352db4d847" dependencies = [ "futures", "futures-rustls", @@ -2958,8 +3013,9 @@ dependencies = [ [[package]] name = "libp2p-upnp" -version = "0.2.2" -source = "git+https://github.com/libp2p/rust-libp2p?rev=60e32c9d3b4bee42ac698791e917e1587eaa1388#60e32c9d3b4bee42ac698791e917e1587eaa1388" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01bf2d1b772bd3abca049214a3304615e6a36fa6ffc742bdd1ba774486200b8f" dependencies = [ "futures", "futures-timer", @@ -2973,8 +3029,9 @@ dependencies = [ [[package]] name = "libp2p-websocket" -version = "0.43.1" -source = "git+https://github.com/libp2p/rust-libp2p?rev=60e32c9d3b4bee42ac698791e917e1587eaa1388#60e32c9d3b4bee42ac698791e917e1587eaa1388" +version = "0.44.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "888b2ff2e5d8dcef97283daab35ad1043d18952b65e05279eecbe02af4c6e347" dependencies = [ "either", "futures", @@ -2985,6 +3042,7 @@ dependencies = [ "pin-project-lite", "rw-stream-sink", "soketto", + "thiserror", "tracing", "url", "webpki-roots 0.25.4", @@ -2992,9 +3050,9 @@ dependencies = [ [[package]] name = "libp2p-websocket-websys" -version = "0.3.3" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f95cd8a32fcf94ad1e5c2de37c2a05a5a4188d8358b005859a0fc9e63b6953bc" +checksum = "38cf9b429dd07be52cd82c4c484b1694df4209210a7db3b9ffb00c7606e230c8" dependencies = [ "bytes", "futures", @@ -3010,8 +3068,9 @@ dependencies = [ [[package]] name = "libp2p-webtransport-websys" -version = "0.3.0" -source = "git+https://github.com/libp2p/rust-libp2p?rev=60e32c9d3b4bee42ac698791e917e1587eaa1388#60e32c9d3b4bee42ac698791e917e1587eaa1388" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7734b77ba70a9e669f8dbfe17d866c06aef34e35e6ec8b307c4144f0f26ec369" dependencies = [ "futures", "js-sys", @@ -3030,8 +3089,9 @@ dependencies = [ [[package]] name = "libp2p-yamux" -version = "0.45.2" -source = "git+https://github.com/libp2p/rust-libp2p?rev=60e32c9d3b4bee42ac698791e917e1587eaa1388#60e32c9d3b4bee42ac698791e917e1587eaa1388" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "788b61c80789dba9760d8c669a5bedb642c8267555c803fabd8396e4ca5c5882" dependencies = [ "either", "futures", @@ -3144,22 +3204,20 @@ dependencies = [ "celestia-tendermint-proto", "celestia-types", "cid", - "dashmap", + "dashmap 5.5.3", "dotenvy", "function_name", "futures", "getrandom", "gloo-timers 0.3.0", - "instant", "js-sys", "libp2p", - "libp2p-websocket-websys", "lumina-node", "pin-project", "prost", "rand", "redb", - "rexie", + "rexie 0.5.0", "rstest", "rustls-pemfile", "rustls-pki-types", @@ -3373,14 +3431,15 @@ checksum = "defc4c55412d89136f966bbb339008b474350e5e6e78d2714439c386b3137a03" [[package]] name = "multistream-select" version = "0.13.0" -source = "git+https://github.com/libp2p/rust-libp2p?rev=60e32c9d3b4bee42ac698791e917e1587eaa1388#60e32c9d3b4bee42ac698791e917e1587eaa1388" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea0df8e5eec2298a62b326ee4f0d7fe1a6b90a09dfcf9df37b38f947a8c42f19" dependencies = [ "bytes", "futures", + "log", "pin-project", "smallvec", - "tracing", - "unsigned-varint 0.8.0", + "unsigned-varint 0.7.2", ] [[package]] @@ -3974,7 +4033,8 @@ dependencies = [ [[package]] name = "quick-protobuf-codec" version = "0.3.1" -source = "git+https://github.com/libp2p/rust-libp2p?rev=60e32c9d3b4bee42ac698791e917e1587eaa1388#60e32c9d3b4bee42ac698791e917e1587eaa1388" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15a0580ab32b169745d7a39db2ba969226ca16738931be152a3209b409de2474" dependencies = [ "asynchronous-codec", "bytes", @@ -4201,6 +4261,17 @@ dependencies = [ "web-sys", ] +[[package]] +name = "rexie" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "887466cfa8a12c08ee4b174998135cea8ff0fd84858627cd793e56535a045bc9" +dependencies = [ + "idb", + "thiserror", + "wasm-bindgen", +] + [[package]] name = "ring" version = "0.16.20" @@ -4525,7 +4596,8 @@ checksum = "955d28af4278de8121b7ebeb796b6a45735dc01436d898801014aced2773a3d6" [[package]] name = "rw-stream-sink" version = "0.4.0" -source = "git+https://github.com/libp2p/rust-libp2p?rev=60e32c9d3b4bee42ac698791e917e1587eaa1388#60e32c9d3b4bee42ac698791e917e1587eaa1388" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8c9026ff5d2f23da5e45bbc283f156383001bfb09c4e44256d02c1a685fe9a1" dependencies = [ "futures", "pin-project", diff --git a/Cargo.toml b/Cargo.toml index 4b3eae40..a4eaed8e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,13 +3,13 @@ resolver = "2" members = ["cli", "node", "node-wasm", "proto", "rpc", "types"] [workspace.dependencies] -blockstore = "0.5.0" +blockstore = "0.6.1" lumina-node = { version = "0.2.0", path = "node" } lumina-node-wasm = { version = "0.1.1", path = "node-wasm" } celestia-proto = { version = "0.2.0", path = "proto" } celestia-rpc = { version = "0.2.0", path = "rpc", default-features = false } celestia-types = { version = "0.2.0", path = "types", default-features = false } -libp2p = "0.54" +libp2p = "0.54.0" nmt-rs = "0.2.1" celestia-tendermint = { version = "0.32.1", default-features = false } celestia-tendermint-proto = "0.32.1" @@ -24,10 +24,6 @@ celestia-tendermint-proto = "0.32.1" #libp2p-core = { path = "../../rust-libp2p/core" } #libp2p-swarm = { path = "../../rust-libp2p/swarm" } -libp2p = { git = "https://github.com/libp2p/rust-libp2p", rev = "60e32c9d3b4bee42ac698791e917e1587eaa1388" } -libp2p-core = { git = "https://github.com/libp2p/rust-libp2p", rev = "60e32c9d3b4bee42ac698791e917e1587eaa1388" } -libp2p-swarm = { git = "https://github.com/libp2p/rust-libp2p", rev = "60e32c9d3b4bee42ac698791e917e1587eaa1388" } - # Uncomment this if you need debug symbols in release. # Also check node-wasm's `Cargo.toml`. #[profile.release] diff --git a/node/Cargo.toml b/node/Cargo.toml index f4ea2e52..f52f096e 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -34,11 +34,10 @@ libp2p = { workspace = true, features = [ ] } async-trait = "0.1.80" -beetswap = "0.1.1" +beetswap = "0.3.1" cid = { version = "0.11.1", features = ["serde-codec"] } dashmap = "5.5.3" futures = "0.3.30" -instant = "0.1.13" prost = "0.12.6" rand = "0.8.5" serde = { version = "1.0.203", features = ["derive"] } @@ -72,7 +71,7 @@ rustls-pki-types = "1.7.0" [target.'cfg(target_arch = "wasm32")'.dependencies] backoff = { version = "0.4.0", features = ["wasm-bindgen"] } -beetswap = { version = "0.1.1", features = ["wasm-bindgen"] } +beetswap = { version = "0.3.1", features = ["wasm-bindgen"] } blockstore = { workspace = true, features = ["indexeddb"] } celestia-types = { workspace = true, features = ["wasm-bindgen"] } getrandom = { version = "0.2.15", features = ["js"] } @@ -81,6 +80,7 @@ js-sys = "0.3.69" libp2p = { workspace = true, features = [ "noise", "wasm-bindgen", + "websocket-websys", "webtransport-websys", "yamux", ] } @@ -90,7 +90,6 @@ send_wrapper = { version = "0.6.0", features = ["futures"] } serde-wasm-bindgen = "0.6.5" wasm-bindgen = "0.2.92" wasm-bindgen-futures = "0.4.42" -libp2p-websocket-websys = "0.3.3" [target.'cfg(target_arch = "wasm32")'.dev-dependencies] function_name = "0.3.0" diff --git a/node/src/events.rs b/node/src/events.rs index 17c458e2..78b32c95 100644 --- a/node/src/events.rs +++ b/node/src/events.rs @@ -4,10 +4,10 @@ use std::fmt; use std::panic::Location; use std::time::Duration; -use instant::SystemTime; use libp2p::PeerId; use serde::Serialize; use tokio::sync::broadcast; +use web_time::SystemTime; const EVENT_CHANNEL_CAPACITY: usize = 1024; diff --git a/node/src/node.rs b/node/src/node.rs index 8c71f187..e352881b 100644 --- a/node/src/node.rs +++ b/node/src/node.rs @@ -117,6 +117,7 @@ where let event_channel = EventChannel::new(); let event_sub = event_channel.subscribe(); let store = Arc::new(config.store); + let blockstore = Arc::new(config.blockstore); let p2p = Arc::new( P2p::start(P2pArgs { @@ -124,7 +125,7 @@ where local_keypair: config.p2p_local_keypair, bootnodes: config.p2p_bootnodes, listen_on: config.p2p_listen_on, - blockstore: config.blockstore, + blockstore, store: store.clone(), event_pub: event_channel.publisher(), }) diff --git a/node/src/p2p.rs b/node/src/p2p.rs index 962bb59f..9902066f 100644 --- a/node/src/p2p.rs +++ b/node/src/p2p.rs @@ -53,7 +53,6 @@ use tracing::{debug, error, info, instrument, trace, warn}; mod header_ex; pub(crate) mod header_session; -mod kademlia; pub(crate) mod shwap; mod swarm; @@ -193,7 +192,7 @@ where /// List of the addresses on which to listen for incoming connections. pub listen_on: Vec, /// The store for headers. - pub blockstore: B, + pub blockstore: Arc, /// The store for headers. pub store: Arc, /// Event publisher. @@ -572,7 +571,7 @@ where identify: identify::Behaviour, header_ex: HeaderExBehaviour, gossipsub: gossipsub::Behaviour, - kademlia: kademlia::Behaviour, + kademlia: kad::Behaviour, } struct Worker @@ -624,7 +623,11 @@ where let gossipsub = init_gossipsub(&args, [&header_sub_topic, &bad_encoding_fraud_sub_topic])?; let kademlia = init_kademlia(&args)?; - let bitswap = init_bitswap(args.blockstore, args.store.clone(), &args.network_id)?; + let bitswap = init_bitswap( + args.blockstore.clone(), + args.store.clone(), + &args.network_id, + )?; let header_ex = HeaderExBehaviour::new(HeaderExConfig { network_id: &args.network_id, @@ -731,9 +734,6 @@ where for (peer_id, addrs) in &self.bootnodes { let dial_opts = DialOpts::peer_id(*peer_id) .addresses(addrs.clone()) - // Without this set, `kademlia::Behaviour` won't be able to canonicalize - // `/tls/ws` to `/wss`. - .extend_addresses_through_behaviour() // Tell Swarm not to dial if peer is already connected or there // is an ongoing dialing. .condition(PeerCondition::DisconnectedAndNotDialing) @@ -866,9 +866,9 @@ where #[instrument(level = "trace", skip(self))] async fn on_identify_event(&mut self, ev: identify::Event) -> Result<()> { match ev { - identify::Event::Received { peer_id, info } => { + identify::Event::Received { peer_id, info, .. } => { // Inform Kademlia about the listening addresses - // TODO: Remove this when rust-libp2p#4302 is implemented + // TODO: Remove this when rust-libp2p#5103 is implemented for addr in info.listen_addrs { self.swarm .behaviour_mut() @@ -1002,6 +1002,7 @@ where ConnectedPoint::Dialer { address, role_override: Endpoint::Dialer, + .. } => Some(address), _ => None, }; @@ -1173,7 +1174,7 @@ where Ok(gossipsub) } -fn init_kademlia(args: &P2pArgs) -> Result +fn init_kademlia(args: &P2pArgs) -> Result> where B: Blockstore, S: Store, @@ -1196,11 +1197,11 @@ where kademlia.set_mode(Some(kad::Mode::Server)); } - Ok(kademlia::Behaviour::new(kademlia)) + Ok(kademlia) } fn init_bitswap( - blockstore: B, + blockstore: Arc, store: Arc, network_id: &str, ) -> Result> diff --git a/node/src/p2p/header_ex.rs b/node/src/p2p/header_ex.rs index 205dd1c6..b7ba8c1b 100644 --- a/node/src/p2p/header_ex.rs +++ b/node/src/p2p/header_ex.rs @@ -6,6 +6,7 @@ use async_trait::async_trait; use celestia_proto::p2p::pb::{HeaderRequest, HeaderResponse}; use celestia_types::ExtendedHeader; use futures::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt}; +use libp2p::core::transport::PortUse; use libp2p::{ core::Endpoint, request_response::{self, Codec, InboundFailure, OutboundFailure, ProtocolSupport}, @@ -211,9 +212,16 @@ where peer: PeerId, addr: &Multiaddr, role_override: Endpoint, + port_use: PortUse, ) -> Result { self.req_resp - .handle_established_outbound_connection(connection_id, peer, addr, role_override) + .handle_established_outbound_connection( + connection_id, + peer, + addr, + role_override, + port_use, + ) .map(ConnHandler) } diff --git a/node/src/p2p/kademlia.rs b/node/src/p2p/kademlia.rs deleted file mode 100644 index 83f002c6..00000000 --- a/node/src/p2p/kademlia.rs +++ /dev/null @@ -1,189 +0,0 @@ -use std::ops::{Deref, DerefMut}; -use std::task::{Context, Poll}; - -use libp2p::{ - core::Endpoint, - kad, - multiaddr::{Multiaddr, Protocol}, - swarm::{ - ConnectionDenied, ConnectionId, FromSwarm, NetworkBehaviour, THandler, THandlerInEvent, - THandlerOutEvent, ToSwarm, - }, - PeerId, -}; - -type Kad = kad::Behaviour; - -pub(crate) struct Behaviour(Kad); - -impl Behaviour { - pub(crate) fn new(inner: Kad) -> Behaviour { - Behaviour(inner) - } -} - -impl NetworkBehaviour for Behaviour { - type ConnectionHandler = THandler; - type ToSwarm = kad::Event; - - fn handle_pending_outbound_connection( - &mut self, - connection_id: ConnectionId, - maybe_peer: Option, - addresses: &[Multiaddr], - effective_role: Endpoint, - ) -> Result, ConnectionDenied> { - // `libp2p::kad::Behaviour` uses the following flow to dial a peer: - // - // 1. Kad's Behaviour discovers a new peer and its addresses. - // 2. Kad's Behaviour dials with `DialOpts::peer_id()` without setting the addresses. - // 3. `Swarm` calls `Behaviour::handle_pending_outbound_connection` to resolve the addresses. - // 4. Kad's Behaviour returns the vector of discovered addresses. - // 5. The addresses returned from the above step are NOT passed to any other Behaviour's. - // - // Here we intercept the return of Kad's Behaviour and cononicalize all `/tls/ws` - // addresses to `/wss` addresses. - let mut new_addrs = self.0.handle_pending_outbound_connection( - connection_id, - maybe_peer, - addresses, - effective_role, - )?; - - for addr in new_addrs.iter_mut() { - if let Some(new_addr) = tls_ws_to_wss(addr) { - *addr = new_addr; - } - } - - for addr in addresses { - if let Some(new_addr) = tls_ws_to_wss(addr) { - new_addrs.push(new_addr); - } - } - - Ok(new_addrs) - } - - fn handle_pending_inbound_connection( - &mut self, - connection_id: ConnectionId, - local_addr: &Multiaddr, - remote_addr: &Multiaddr, - ) -> Result<(), ConnectionDenied> { - self.0 - .handle_pending_inbound_connection(connection_id, local_addr, remote_addr) - } - - fn handle_established_inbound_connection( - &mut self, - connection_id: ConnectionId, - peer: PeerId, - local_addr: &Multiaddr, - remote_addr: &Multiaddr, - ) -> Result, ConnectionDenied> { - self.0 - .handle_established_inbound_connection(connection_id, peer, local_addr, remote_addr) - } - - fn handle_established_outbound_connection( - &mut self, - connection_id: ConnectionId, - peer: PeerId, - addr: &Multiaddr, - role_override: Endpoint, - ) -> Result, ConnectionDenied> { - self.0 - .handle_established_outbound_connection(connection_id, peer, addr, role_override) - } - - fn on_connection_handler_event( - &mut self, - peer_id: PeerId, - connection_id: ConnectionId, - event: THandlerOutEvent, - ) { - self.0 - .on_connection_handler_event(peer_id, connection_id, event) - } - - fn on_swarm_event(&mut self, event: FromSwarm) { - self.0.on_swarm_event(event) - } - - fn poll( - &mut self, - cx: &mut Context<'_>, - ) -> Poll>> { - self.0.poll(cx) - } -} - -impl Deref for Behaviour { - type Target = Kad; - - fn deref(&self) -> &Self::Target { - &self.0 - } -} - -impl DerefMut for Behaviour { - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.0 - } -} - -fn tls_ws_to_wss(addr: &Multiaddr) -> Option { - let tls_idx = addr.iter().position(|proto| proto == Protocol::Tls)?; - - let Some(Protocol::Ws(s)) = addr.iter().nth(tls_idx + 1) else { - return None; - }; - - let addr = addr - .iter() - .enumerate() - .fold(Multiaddr::empty(), |mut addr, (i, proto)| { - if i == tls_idx { - // Skip Protocol::Tls - } else if i == tls_idx + 1 { - // Replace Protocol::Ws with Protocol::Wss - addr.push(Protocol::Wss(s.clone())); - } else { - addr.push(proto); - } - - addr - }); - - Some(addr) -} - -#[cfg(test)] -mod tests { - use super::*; - use crate::test_utils::async_test; - - #[async_test] - async fn tls_ws() { - let addr = "/dns4/dev.lumina.eiger.co/tcp/2121/tls/ws/p2p/12D3KooWJF4tkwBrycYhriE4nuYAo3Y8DESQzdN2tPWwndWe4KUd".parse().unwrap(); - let expected_addr = "/dns4/dev.lumina.eiger.co/tcp/2121/wss/p2p/12D3KooWJF4tkwBrycYhriE4nuYAo3Y8DESQzdN2tPWwndWe4KUd".parse().unwrap(); - - let new_addr = tls_ws_to_wss(&addr).unwrap(); - assert_eq!(new_addr, expected_addr); - } - - #[async_test] - async fn non_translatable() { - let addrs = [ - "/dns4/dev.lumina.eiger.co/tcp/2121/tls/p2p/12D3KooWJF4tkwBrycYhriE4nuYAo3Y8DESQzdN2tPWwndWe4KUd", - "/dns4/dev.lumina.eiger.co/tcp/2121/wss/p2p/12D3KooWJF4tkwBrycYhriE4nuYAo3Y8DESQzdN2tPWwndWe4KUd", - "/dns4/dev.lumina.eiger.co/tcp/2121/p2p/12D3KooWJF4tkwBrycYhriE4nuYAo3Y8DESQzdN2tPWwndWe4KUd", - ]; - - for addr in addrs { - let addr = addr.parse().unwrap(); - assert!(tls_ws_to_wss(&addr).is_none()); - } - } -} diff --git a/node/src/p2p/swarm.rs b/node/src/p2p/swarm.rs index 641216f9..1283bd86 100644 --- a/node/src/p2p/swarm.rs +++ b/node/src/p2p/swarm.rs @@ -162,8 +162,7 @@ mod imp { mod imp { use super::*; use libp2p::core::upgrade::Version; - use libp2p::{noise, webtransport_websys, yamux, SwarmBuilder, Transport}; - use libp2p_websocket_websys as websocket_websys; + use libp2p::{noise, websocket_websys, webtransport_websys, yamux, SwarmBuilder, Transport}; pub(crate) async fn new_swarm(keypair: Keypair, behaviour: B) -> Result> where