From aa7735a1354b4021133aef07c44a0092f97ba5a4 Mon Sep 17 00:00:00 2001 From: chad Date: Fri, 30 Aug 2024 15:16:01 -0500 Subject: [PATCH 1/9] chore: upgrade libp2p from 0.53.2 to 0.54.1 --- Cargo.lock | 194 ++++++++++-------- crates/keygen/Cargo.toml | 2 +- crates/services/p2p/Cargo.toml | 4 +- crates/services/p2p/src/discovery.rs | 13 +- .../p2p/src/discovery/discovery_config.rs | 7 +- .../p2p/src/discovery/mdns_wrapper.rs | 7 +- crates/services/p2p/src/heartbeat.rs | 8 +- crates/services/p2p/src/p2p_service.rs | 16 +- crates/services/p2p/src/peer_report.rs | 12 +- .../forkless-upgrade/Cargo.toml | 2 +- 10 files changed, 150 insertions(+), 115 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 56845a7ce5a..e0d8fe815c0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3491,7 +3491,7 @@ dependencies = [ "postcard", "prometheus-client", "quick-protobuf", - "quick-protobuf-codec 0.3.1", + "quick-protobuf-codec", "rand", "rayon", "serde", @@ -5054,19 +5054,18 @@ checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" [[package]] name = "libp2p" -version = "0.53.2" +version = "0.54.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "681fb3f183edfbedd7a57d32ebe5dcdc0b9f94061185acf3c30249349cc6fc99" +checksum = "bbbe80f9c7e00526cd6b838075b9c171919404a4732cb2fa8ece0a093223bfc4" dependencies = [ "bytes", "either", "futures", "futures-timer", "getrandom", - "instant", "libp2p-allow-block-list", "libp2p-connection-limits", - "libp2p-core", + "libp2p-core 0.42.0", "libp2p-dns", "libp2p-gossipsub", "libp2p-identify", @@ -5090,11 +5089,11 @@ dependencies = [ [[package]] name = "libp2p-allow-block-list" -version = "0.3.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "107b238b794cb83ab53b74ad5dcf7cca3200899b72fe662840cfb52f5b0a32e6" +checksum = "d1027ccf8d70320ed77e984f273bc8ce952f623762cb9bf2d126df73caef8041" dependencies = [ - "libp2p-core", + "libp2p-core 0.42.0", "libp2p-identity", "libp2p-swarm", "void", @@ -5102,11 +5101,11 @@ dependencies = [ [[package]] name = "libp2p-connection-limits" -version = "0.3.1" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7cd50a78ccfada14de94cbacd3ce4b0138157f376870f13d3a8422cd075b4fd" +checksum = "8d003540ee8baef0d254f7b6bfd79bac3ddf774662ca0abf69186d517ef82ad8" dependencies = [ - "libp2p-core", + "libp2p-core 0.42.0", "libp2p-identity", "libp2p-swarm", "void", @@ -5140,16 +5139,44 @@ dependencies = [ "web-time", ] +[[package]] +name = "libp2p-core" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a61f26c83ed111104cd820fe9bc3aaabbac5f1652a1d213ed6e900b7918a1298" +dependencies = [ + "either", + "fnv", + "futures", + "futures-timer", + "libp2p-identity", + "multiaddr", + "multihash", + "multistream-select", + "once_cell", + "parking_lot", + "pin-project", + "quick-protobuf", + "rand", + "rw-stream-sink", + "smallvec", + "thiserror", + "tracing", + "unsigned-varint 0.8.0", + "void", + "web-time", +] + [[package]] name = "libp2p-dns" -version = "0.41.1" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d17cbcf7160ff35c3e8e560de4a068fe9d6cb777ea72840e48eb76ff9576c4b6" +checksum = "97f37f30d5c7275db282ecd86e54f29dd2176bd3ac656f06abf43bedb21eb8bd" dependencies = [ "async-trait", "futures", "hickory-resolver", - "libp2p-core", + "libp2p-core 0.42.0", "libp2p-identity", "parking_lot", "smallvec", @@ -5158,12 +5185,12 @@ dependencies = [ [[package]] name = "libp2p-gossipsub" -version = "0.46.1" +version = "0.47.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d665144a616dadebdc5fff186b1233488cdcd8bfb1223218ff084b6d052c94f7" +checksum = "b4e830fdf24ac8c444c12415903174d506e1e077fbe3875c404a78c5935a8543" dependencies = [ "asynchronous-codec 0.7.0", - "base64 0.21.7", + "base64 0.22.1", "byteorder", "bytes", "either", @@ -5172,38 +5199,38 @@ dependencies = [ "futures-ticker", "getrandom", "hex_fmt", - "instant", - "libp2p-core", + "libp2p-core 0.42.0", "libp2p-identity", "libp2p-swarm", "prometheus-client", "quick-protobuf", - "quick-protobuf-codec 0.3.1", + "quick-protobuf-codec", "rand", "regex", "sha2 0.10.8", "smallvec", "tracing", "void", + "web-time", ] [[package]] name = "libp2p-identify" -version = "0.44.2" +version = "0.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5d635ebea5ca0c3c3e77d414ae9b67eccf2a822be06091b9c1a0d13029a1e2f" +checksum = "1711b004a273be4f30202778856368683bd9a83c4c7dcc8f848847606831a4e3" dependencies = [ "asynchronous-codec 0.7.0", "either", "futures", "futures-bounded", "futures-timer", - "libp2p-core", + "libp2p-core 0.42.0", "libp2p-identity", "libp2p-swarm", "lru", "quick-protobuf", - "quick-protobuf-codec 0.3.1", + "quick-protobuf-codec", "smallvec", "thiserror", "tracing", @@ -5232,9 +5259,9 @@ dependencies = [ [[package]] name = "libp2p-kad" -version = "0.45.3" +version = "0.46.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cc5767727d062c4eac74dd812c998f0e488008e82cce9c33b463d38423f9ad2" +checksum = "ced237d0bd84bbebb7c2cad4c073160dacb4fe40534963c32ed6d4c6bb7702a3" dependencies = [ "arrayvec", "asynchronous-codec 0.7.0", @@ -5244,12 +5271,11 @@ dependencies = [ "futures", "futures-bounded", "futures-timer", - "instant", - "libp2p-core", + "libp2p-core 0.42.0", "libp2p-identity", "libp2p-swarm", "quick-protobuf", - "quick-protobuf-codec 0.3.1", + "quick-protobuf-codec", "rand", "sha2 0.10.8", "smallvec", @@ -5257,19 +5283,20 @@ dependencies = [ "tracing", "uint", "void", + "web-time", ] [[package]] name = "libp2p-mdns" -version = "0.45.1" +version = "0.46.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49007d9a339b3e1d7eeebc4d67c05dbf23d300b7d091193ec2d3f26802d7faf2" +checksum = "14b8546b6644032565eb29046b42744aee1e9f261ed99671b2c93fb140dba417" dependencies = [ "data-encoding", "futures", "hickory-proto", "if-watch", - "libp2p-core", + "libp2p-core 0.42.0", "libp2p-identity", "libp2p-swarm", "rand", @@ -5282,13 +5309,12 @@ dependencies = [ [[package]] name = "libp2p-metrics" -version = "0.14.1" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fdac91ae4f291046a3b2660c039a2830c931f84df2ee227989af92f7692d3357" +checksum = "77ebafa94a717c8442d8db8d3ae5d1c6a15e30f2d347e0cd31d057ca72e42566" dependencies = [ "futures", - "instant", - "libp2p-core", + "libp2p-core 0.42.0", "libp2p-gossipsub", "libp2p-identify", "libp2p-identity", @@ -5296,6 +5322,7 @@ dependencies = [ "libp2p-swarm", "pin-project", "prometheus-client", + "web-time", ] [[package]] @@ -5307,7 +5334,7 @@ dependencies = [ "asynchronous-codec 0.6.2", "bytes", "futures", - "libp2p-core", + "libp2p-core 0.41.3", "libp2p-identity", "nohash-hasher", "parking_lot", @@ -5319,15 +5346,15 @@ dependencies = [ [[package]] name = "libp2p-noise" -version = "0.44.0" +version = "0.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ecd0545ce077f6ea5434bcb76e8d0fe942693b4380aaad0d34a358c2bd05793" +checksum = "36b137cb1ae86ee39f8e5d6245a296518912014eaa87427d24e6ff58cfc1b28c" dependencies = [ "asynchronous-codec 0.7.0", "bytes", "curve25519-dalek", "futures", - "libp2p-core", + "libp2p-core 0.42.0", "libp2p-identity", "multiaddr", "multihash", @@ -5345,31 +5372,31 @@ dependencies = [ [[package]] name = "libp2p-plaintext" -version = "0.41.0" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67330af40b67217e746d42551913cfb7ad04c74fa300fb329660a56318590b3f" +checksum = "5b63d926c6be56a2489e0e7316b17fe95a70bc5c4f3e85740bb3e67c0f3c6a44" dependencies = [ - "asynchronous-codec 0.6.2", + "asynchronous-codec 0.7.0", "bytes", "futures", - "libp2p-core", + "libp2p-core 0.42.0", "libp2p-identity", "quick-protobuf", - "quick-protobuf-codec 0.2.0", + "quick-protobuf-codec", "tracing", ] [[package]] name = "libp2p-quic" -version = "0.10.3" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c67296ad4e092e23f92aea3d2bdb6f24eab79c0929ed816dfb460ea2f4567d2b" +checksum = "46352ac5cd040c70e88e7ff8257a2ae2f891a4076abad2c439584a31c15fd24e" dependencies = [ "bytes", "futures", "futures-timer", "if-watch", - "libp2p-core", + "libp2p-core 0.42.0", "libp2p-identity", "libp2p-tls", "parking_lot", @@ -5385,37 +5412,36 @@ dependencies = [ [[package]] name = "libp2p-request-response" -version = "0.26.3" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c314fe28368da5e3a262553fb0ad575c1c8934c461e10de10265551478163836" +checksum = "1356c9e376a94a75ae830c42cdaea3d4fe1290ba409a22c809033d1b7dcab0a6" dependencies = [ "async-trait", "futures", "futures-bounded", "futures-timer", - "instant", - "libp2p-core", + "libp2p-core 0.42.0", "libp2p-identity", "libp2p-swarm", "rand", "smallvec", "tracing", "void", + "web-time", ] [[package]] name = "libp2p-swarm" -version = "0.44.2" +version = "0.45.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80cae6cb75f89dbca53862f9ebe0b9f463aa7b302762fcfaafb9e51dcc9b0f7e" +checksum = "d7dd6741793d2c1fb2088f67f82cf07261f25272ebe3c0b0c311e0c6b50e851a" dependencies = [ "async-std", "either", "fnv", "futures", "futures-timer", - "instant", - "libp2p-core", + "libp2p-core 0.42.0", "libp2p-identity", "libp2p-swarm-derive", "lru", @@ -5426,13 +5452,14 @@ dependencies = [ "tokio", "tracing", "void", + "web-time", ] [[package]] name = "libp2p-swarm-derive" -version = "0.34.2" +version = "0.35.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5daceb9dd908417b6dfcfe8e94098bc4aac54500c282e78120b885dadc09b999" +checksum = "206e0aa0ebe004d778d79fb0966aa0de996c19894e2c0605ba2f8524dd4443d8" dependencies = [ "heck 0.5.0", "proc-macro2", @@ -5442,14 +5469,14 @@ dependencies = [ [[package]] name = "libp2p-swarm-test" -version = "0.3.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a73027f1bdabd15d08b2c7954911cd56a6265c476763b2ceb10d9dc5ea4366b2" +checksum = "ea4e1d1d92421dc4c90cad42e3cd24f50fd210191c9f126d41bd483a09567f67" dependencies = [ "async-trait", "futures", "futures-timer", - "libp2p-core", + "libp2p-core 0.42.0", "libp2p-identity", "libp2p-plaintext", "libp2p-swarm", @@ -5461,16 +5488,16 @@ dependencies = [ [[package]] name = "libp2p-tcp" -version = "0.41.0" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b2460fc2748919adff99ecbc1aab296e4579e41f374fb164149bd2c9e529d4c" +checksum = "ad964f312c59dcfcac840acd8c555de8403e295d39edf96f5240048b5fcaa314" dependencies = [ - "async-io 1.13.0", + "async-io 2.3.4", "futures", "futures-timer", "if-watch", "libc", - "libp2p-core", + "libp2p-core 0.42.0", "libp2p-identity", "socket2 0.5.7", "tokio", @@ -5479,13 +5506,13 @@ dependencies = [ [[package]] name = "libp2p-tls" -version = "0.4.1" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b7b831e55ce2aa6c354e6861a85fdd4dd0a2b97d5e276fabac0e4810a71776" +checksum = "47b23dddc2b9c355f73c1e36eb0c3ae86f7dc964a3715f0731cfad352db4d847" dependencies = [ "futures", "futures-rustls", - "libp2p-core", + "libp2p-core 0.42.0", "libp2p-identity", "rcgen", "ring 0.17.8", @@ -5498,14 +5525,14 @@ dependencies = [ [[package]] name = "libp2p-upnp" -version = "0.2.2" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cccf04b0e3ff3de52d07d5fd6c3b061d0e7f908ffc683c32d9638caedce86fc8" +checksum = "01bf2d1b772bd3abca049214a3304615e6a36fa6ffc742bdd1ba774486200b8f" dependencies = [ "futures", "futures-timer", "igd-next", - "libp2p-core", + "libp2p-core 0.42.0", "libp2p-swarm", "tokio", "tracing", @@ -5514,14 +5541,14 @@ dependencies = [ [[package]] name = "libp2p-websocket" -version = "0.43.2" +version = "0.44.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85b953b6803a1f3161a989538974d72511c4e48a4af355337b6fb90723c56c05" +checksum = "888b2ff2e5d8dcef97283daab35ad1043d18952b65e05279eecbe02af4c6e347" dependencies = [ "either", "futures", "futures-rustls", - "libp2p-core", + "libp2p-core 0.42.0", "libp2p-identity", "parking_lot", "pin-project-lite", @@ -5535,13 +5562,13 @@ dependencies = [ [[package]] name = "libp2p-yamux" -version = "0.45.2" +version = "0.46.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddd5265f6b80f94d48a3963541aad183cc598a645755d2f1805a373e41e0716b" +checksum = "788b61c80789dba9760d8c669a5bedb642c8267555c803fabd8396e4ca5c5882" dependencies = [ "either", "futures", - "libp2p-core", + "libp2p-core 0.42.0", "thiserror", "tracing", "yamux 0.12.1", @@ -7065,19 +7092,6 @@ dependencies = [ "byteorder", ] -[[package]] -name = "quick-protobuf-codec" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8ededb1cd78531627244d51dd0c7139fbe736c7d57af0092a76f0ffb2f56e98" -dependencies = [ - "asynchronous-codec 0.6.2", - "bytes", - "quick-protobuf", - "thiserror", - "unsigned-varint 0.7.2", -] - [[package]] name = "quick-protobuf-codec" version = "0.3.1" diff --git a/crates/keygen/Cargo.toml b/crates/keygen/Cargo.toml index a18a98e4fe0..2ab255389b9 100644 --- a/crates/keygen/Cargo.toml +++ b/crates/keygen/Cargo.toml @@ -14,5 +14,5 @@ description = "Create to create command line utilities for fuel-core key managem anyhow = { workspace = true } clap = { workspace = true, features = ["derive", "env"] } fuel-core-types = { workspace = true, features = ["alloc", "serde", "random"] } -libp2p-identity = { version = "0.2.4", features = ["secp256k1", "peerid"] } +libp2p-identity = { version = "0.2.9", features = ["secp256k1", "peerid"] } serde = { workspace = true, features = ["derive"] } diff --git a/crates/services/p2p/Cargo.toml b/crates/services/p2p/Cargo.toml index 7557b294b44..4941688e5fc 100644 --- a/crates/services/p2p/Cargo.toml +++ b/crates/services/p2p/Cargo.toml @@ -21,7 +21,7 @@ fuel-core-types = { workspace = true, features = ["std", "serde"] } futures = { workspace = true } hex = { workspace = true } ip_network = "0.4" -libp2p = { version = "0.53.2", default-features = false, features = [ +libp2p = { version = "0.54.1", default-features = false, features = [ "dns", "gossipsub", "identify", @@ -63,7 +63,7 @@ tracing-attributes = { workspace = true } tracing-subscriber = { workspace = true, features = ["env-filter"] } [dev-dependencies.libp2p-swarm-test] -version = "0.3.0" +version = "0.4.0" [features] test-helpers = ["fuel-core-types/test-helpers"] diff --git a/crates/services/p2p/src/discovery.rs b/crates/services/p2p/src/discovery.rs index c92d2238119..216ad690330 100644 --- a/crates/services/p2p/src/discovery.rs +++ b/crates/services/p2p/src/discovery.rs @@ -1,7 +1,10 @@ use self::mdns_wrapper::MdnsWrapper; use futures::FutureExt; use libp2p::{ - core::Endpoint, + core::{ + transport::PortUse, + Endpoint, + }, kad::{ self, store::MemoryStore, @@ -124,12 +127,14 @@ impl NetworkBehaviour for Behaviour { peer: PeerId, addr: &Multiaddr, role_override: Endpoint, + port_use: PortUse, ) -> Result, ConnectionDenied> { self.kademlia.handle_established_outbound_connection( connection_id, peer, addr, role_override, + port_use, ) } @@ -199,7 +204,7 @@ impl NetworkBehaviour for Behaviour { // poll sub-behaviors if let Poll::Ready(kad_action) = self.kademlia.poll(cx) { - return Poll::Ready(kad_action) + return Poll::Ready(kad_action); }; while let Poll::Ready(mdns_event) = self.mdns.poll(cx) { @@ -372,10 +377,10 @@ mod tests { } _ => {} } - continue 'polling + continue 'polling; } } - break + break; } // if there are no swarms left to discover we are done with the discovery diff --git a/crates/services/p2p/src/discovery/discovery_config.rs b/crates/services/p2p/src/discovery/discovery_config.rs index 9800ca7e8ea..575bfc44dab 100644 --- a/crates/services/p2p/src/discovery/discovery_config.rs +++ b/crates/services/p2p/src/discovery/discovery_config.rs @@ -110,11 +110,10 @@ impl Config { // kademlia setup let memory_store = MemoryStore::new(local_peer_id.to_owned()); - let mut kademlia_config = kad::Config::default(); let network = format!("/fuel/kad/{network_name}/kad/1.0.0"); - kademlia_config.set_protocol_names(vec![ - StreamProtocol::try_from_owned(network).expect("Invalid kad protocol") - ]); + let kademlia_config = kad::Config::new( + StreamProtocol::try_from_owned(network).expect("Invalid kad protocol"), + ); let mut kademlia = kad::Behaviour::with_config(local_peer_id, memory_store, kademlia_config); diff --git a/crates/services/p2p/src/discovery/mdns_wrapper.rs b/crates/services/p2p/src/discovery/mdns_wrapper.rs index 2b38b703759..af2a440ba40 100644 --- a/crates/services/p2p/src/discovery/mdns_wrapper.rs +++ b/crates/services/p2p/src/discovery/mdns_wrapper.rs @@ -1,6 +1,9 @@ use crate::Multiaddr; use libp2p::{ - core::Endpoint, + core::{ + transport::PortUse, + Endpoint, + }, mdns::{ self, tokio::Behaviour as TokioMdns, @@ -107,6 +110,7 @@ impl NetworkBehaviour for MdnsWrapper { peer: PeerId, addr: &Multiaddr, role_override: Endpoint, + port_use: PortUse, ) -> Result, ConnectionDenied> { match self { MdnsWrapper::Ready(mdns) => mdns.handle_established_outbound_connection( @@ -114,6 +118,7 @@ impl NetworkBehaviour for MdnsWrapper { peer, addr, role_override, + port_use, ), MdnsWrapper::Disabled => Ok(dummy::ConnectionHandler), } diff --git a/crates/services/p2p/src/heartbeat.rs b/crates/services/p2p/src/heartbeat.rs index 5e0f4d4544a..6a9af79929d 100644 --- a/crates/services/p2p/src/heartbeat.rs +++ b/crates/services/p2p/src/heartbeat.rs @@ -7,7 +7,10 @@ use handler::{ HeartbeatOutEvent, }; use libp2p::{ - core::Endpoint, + core::{ + transport::PortUse, + Endpoint, + }, swarm::{ derive_prelude::ConnectionId, ConnectionDenied, @@ -104,6 +107,7 @@ impl NetworkBehaviour for Behaviour { _peer: PeerId, _addr: &Multiaddr, _role_override: Endpoint, + _port_use: PortUse, ) -> Result, ConnectionDenied> { Ok(HeartbeatHandler::new(self.config.clone())) } @@ -141,7 +145,7 @@ impl NetworkBehaviour for Behaviour { _: &mut std::task::Context<'_>, ) -> Poll>> { if let Some(action) = self.pending_events.pop_front() { - return Poll::Ready(action.build()) + return Poll::Ready(action.build()); } Poll::Pending diff --git a/crates/services/p2p/src/p2p_service.rs b/crates/services/p2p/src/p2p_service.rs index e1afcad3a60..817471983a6 100644 --- a/crates/services/p2p/src/p2p_service.rs +++ b/crates/services/p2p/src/p2p_service.rs @@ -113,10 +113,10 @@ pub struct FuelP2PService { /// to the peer that requested it. inbound_requests_table: HashMap>, - /// NetworkCodec used as `` for encoding and decoding of Gossipsub messages + /// NetworkCodec used as `` for encoding and decoding of Gossipsub messages network_codec: PostcardCodec, - /// Stores additional p2p network info + /// Stores additional p2p network info network_metadata: NetworkMetadata, /// Whether or not metrics collection is enabled @@ -180,7 +180,7 @@ impl FuelP2PService { // configure and build P2P Service let (transport_function, connection_state) = build_transport_function(&config); - let tcp_config = tcp::Config::new().port_reuse(true); + let tcp_config = tcp::Config::new(); let behaviour = FuelBehaviour::new(&config, codec.clone()); let mut swarm = SwarmBuilder::with_existing_identity(config.keypair.clone()) @@ -652,7 +652,7 @@ impl FuelP2PService { fn handle_identify_event(&mut self, event: identify::Event) -> Option { match event { - identify::Event::Received { peer_id, info } => { + identify::Event::Received { peer_id, info, .. } => { self.update_metrics(increment_unique_peers); let mut addresses = info.listen_addrs; @@ -680,8 +680,12 @@ impl FuelP2PService { } identify::Event::Sent { .. } => {} identify::Event::Pushed { .. } => {} - identify::Event::Error { peer_id, error } => { - debug!(target: "fuel-p2p", "Identification with peer {:?} failed => {}", peer_id, error); + identify::Event::Error { + connection_id, + peer_id, + error, + } => { + debug!(target: "fuel-p2p", "Identification with peer {:?} with connection id {:?} failed => {}", peer_id, connection_id, error); } } None diff --git a/crates/services/p2p/src/peer_report.rs b/crates/services/p2p/src/peer_report.rs index 2c4579d7e2b..0546ed91411 100644 --- a/crates/services/p2p/src/peer_report.rs +++ b/crates/services/p2p/src/peer_report.rs @@ -4,7 +4,10 @@ use crate::{ }; use libp2p::{ self, - core::Endpoint, + core::{ + transport::PortUse, + Endpoint, + }, swarm::{ derive_prelude::{ ConnectionClosed, @@ -121,6 +124,7 @@ impl NetworkBehaviour for Behaviour { _peer: PeerId, _addr: &Multiaddr, _role_override: Endpoint, + _port_use: PortUse, ) -> Result, ConnectionDenied> { Ok(dummy::ConnectionHandler) } @@ -193,7 +197,7 @@ impl NetworkBehaviour for Behaviour { cx: &mut Context<'_>, ) -> Poll>> { if let Some(event) = self.pending_events.pop_front() { - return Poll::Ready(event) + return Poll::Ready(event); } if let Some((instant, peer_id)) = self.reserved_nodes_to_connect.front() { @@ -214,12 +218,12 @@ impl NetworkBehaviour for Behaviour { .build(); self.pending_connections.insert(opts.connection_id()); - return Poll::Ready(ToSwarm::Dial { opts }) + return Poll::Ready(ToSwarm::Dial { opts }); } } if self.decay_interval.poll_tick(cx).is_ready() { - return Poll::Ready(ToSwarm::GenerateEvent(PeerReportEvent::PerformDecay)) + return Poll::Ready(ToSwarm::GenerateEvent(PeerReportEvent::PerformDecay)); } Poll::Pending diff --git a/version-compatibility/forkless-upgrade/Cargo.toml b/version-compatibility/forkless-upgrade/Cargo.toml index 07366c030a8..0ec7dcac0dd 100644 --- a/version-compatibility/forkless-upgrade/Cargo.toml +++ b/version-compatibility/forkless-upgrade/Cargo.toml @@ -9,7 +9,7 @@ build = "build.rs" [dev-dependencies] anyhow = "1.0" clap = "4.4" -libp2p = "0.53.2" +libp2p = "0.54.1" hex = "0.4.3" rand = "0.8" tempfile = "3.4" From fc20f560690a851458c183c4b4e53c66b263223c Mon Sep 17 00:00:00 2001 From: chad Date: Sun, 1 Sep 2024 16:10:55 -0500 Subject: [PATCH 2/9] feat: add config options for max pending connection for both incoming and outgoing --- bin/fuel-core/src/cli/run/p2p.rs | 17 +++++++++++++---- crates/services/p2p/src/behavior.rs | 18 ++++++++++++++++++ crates/services/p2p/src/config.rs | 8 ++++++++ 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/bin/fuel-core/src/cli/run/p2p.rs b/bin/fuel-core/src/cli/run/p2p.rs index 47b107f8312..8d68aea6580 100644 --- a/bin/fuel-core/src/cli/run/p2p.rs +++ b/bin/fuel-core/src/cli/run/p2p.rs @@ -95,6 +95,15 @@ pub struct P2PArgs { #[clap(long = "max-connections-per-peer", default_value = "3", env)] pub max_connections_per_peer: u32, + /// Max number of concurrent pending incoming connections + /// Useful in mitigating against DDoS attacks + #[clap(long = "max-pending-incoming-connections", default_value = "100", env)] + pub max_pending_incoming_connections: u32, + + /// Max number of concurrent pending outgoing connections + #[clap(long = "max-pending-outgoing-connections", default_value = "100", env)] + pub max_pending_outgoing_connections: u32, + /// Set the delay between random walks for p2p node discovery in seconds. /// If it's not set the random walk will be disabled. /// Also if `reserved_nodes_only_mode` is set to `true`, @@ -210,16 +219,16 @@ impl KeypairArg { let secret = SecretKey::from_str(s); if let Ok(secret) = secret { - return Ok(KeypairArg::InlineSecret(secret)) + return Ok(KeypairArg::InlineSecret(secret)); } let path = PathBuf::from_str(s); if let Ok(pathbuf) = path { if pathbuf.exists() { - return Ok(KeypairArg::Path(pathbuf)) + return Ok(KeypairArg::Path(pathbuf)); } else { return Err(anyhow!( "path `{pathbuf:?}` does not exist for keypair argument" - )) + )); } } Err(anyhow!( @@ -245,7 +254,7 @@ impl P2PArgs { ) -> anyhow::Result>> { if !self.enable_p2p { tracing::info!("P2P service disabled"); - return Ok(None) + return Ok(None); } let local_keypair = { diff --git a/crates/services/p2p/src/behavior.rs b/crates/services/p2p/src/behavior.rs index 1feac658f59..bb2587357c1 100644 --- a/crates/services/p2p/src/behavior.rs +++ b/crates/services/p2p/src/behavior.rs @@ -19,6 +19,10 @@ use crate::{ use fuel_core_types::fuel_types::BlockHeight; use libp2p::{ allow_block_list, + connection_limits::{ + self, + ConnectionLimits, + }, gossipsub::{ self, MessageAcceptance, @@ -62,6 +66,9 @@ pub struct FuelBehaviour { /// RequestResponse protocol request_response: request_response::Behaviour, + + /// The Behaviour to manage connection limits. + connection_limits: connection_limits::Behaviour, } impl FuelBehaviour { @@ -112,6 +119,16 @@ impl FuelBehaviour { BlockHeight::default(), ); + let connection_limits = connection_limits::Behaviour::new( + ConnectionLimits::default() + .with_max_pending_incoming(Some( + p2p_config.max_pending_incoming_connections, + )) + .with_max_pending_outgoing(Some( + p2p_config.max_pending_outgoing_connections, + )), + ); + let req_res_protocol = core::iter::once((codec.get_req_res_protocol(), ProtocolSupport::Full)); @@ -133,6 +150,7 @@ impl FuelBehaviour { blocked_peer: Default::default(), identify, heartbeat, + connection_limits, } } diff --git a/crates/services/p2p/src/config.rs b/crates/services/p2p/src/config.rs index a807f79be33..79b6fe4f104 100644 --- a/crates/services/p2p/src/config.rs +++ b/crates/services/p2p/src/config.rs @@ -94,6 +94,10 @@ pub struct Config { /// Max number of connections per single peer /// The total number of connections will be `(max_peers_connected + reserved_nodes.len()) * max_connections_per_peer` pub max_connections_per_peer: u32, + /// Max number of concurrent pending incoming connections + pub max_pending_incoming_connections: u32, + /// Max number of concurrent pending outgoing connections + pub max_pending_outgoing_connections: u32, /// The interval at which identification requests are sent to /// the remote on established connections after the first request pub identify_interval: Option, @@ -155,6 +159,8 @@ impl Config { enable_mdns: self.enable_mdns, max_peers_connected: self.max_peers_connected, max_connections_per_peer: self.max_connections_per_peer, + max_pending_incoming_connections: self.max_pending_incoming_connections, + max_pending_outgoing_connections: self.max_pending_outgoing_connections, allow_private_addresses: self.allow_private_addresses, random_walk: self.random_walk, connection_idle_timeout: self.connection_idle_timeout, @@ -204,6 +210,8 @@ impl Config { enable_mdns: false, max_peers_connected: 50, max_connections_per_peer: 3, + max_pending_incoming_connections: 100, + max_pending_outgoing_connections: 100, allow_private_addresses: true, random_walk: Some(Duration::from_millis(500)), connection_idle_timeout: Some(Duration::from_secs(120)), From df12b4b51f9ec86fc77c06edf1038c7fd7e7d6c0 Mon Sep 17 00:00:00 2001 From: chad Date: Sun, 1 Sep 2024 16:36:35 -0500 Subject: [PATCH 3/9] docs: update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 00b02fa32d1..44f040d8dad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Added - [2135](https://github.com/FuelLabs/fuel-core/pull/2135): Added metrics logging for number of blocks served over the p2p req/res protocol. - +- [2150](https://github.com/FuelLabs/fuel-core/pull/2150): Upgraded `libp2p` to `0.54.1` and introduced `max_pending_incoming_connections` and `max_pending_outgoing_connections` to limit the number of pending connections. ## [Version 0.35.0] From 66f509396cbc99105f5e12970112576556fc29d9 Mon Sep 17 00:00:00 2001 From: chad Date: Sun, 1 Sep 2024 16:45:36 -0500 Subject: [PATCH 4/9] fix: add missing params for config --- bin/fuel-core/src/cli/run/p2p.rs | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/bin/fuel-core/src/cli/run/p2p.rs b/bin/fuel-core/src/cli/run/p2p.rs index 8d68aea6580..4bce3c98cb2 100644 --- a/bin/fuel-core/src/cli/run/p2p.rs +++ b/bin/fuel-core/src/cli/run/p2p.rs @@ -1,30 +1,15 @@ use anyhow::anyhow; -use clap::{ - builder::ArgPredicate::IsPresent, - Args, -}; +use clap::{builder::ArgPredicate::IsPresent, Args}; use fuel_core::{ p2p::{ - config::{ - convert_to_libp2p_keypair, - Config, - NotInitialized, - MAX_RESPONSE_SIZE, - }, + config::{convert_to_libp2p_keypair, Config, NotInitialized, MAX_RESPONSE_SIZE}, gossipsub_config::default_gossipsub_builder, - heartbeat, - Multiaddr, - }, - types::{ - fuel_crypto, - fuel_crypto::SecretKey, + heartbeat, Multiaddr, }, + types::{fuel_crypto, fuel_crypto::SecretKey}, }; use std::{ - net::{ - IpAddr, - Ipv4Addr, - }, + net::{IpAddr, Ipv4Addr}, num::NonZeroU32, path::PathBuf, str::FromStr, @@ -319,6 +304,8 @@ impl P2PArgs { enable_mdns: self.enable_mdns, max_peers_connected: self.max_peers_connected, max_connections_per_peer: self.max_connections_per_peer, + max_pending_incoming_connections: self.max_pending_incoming_connections, + max_pending_outgoing_connections: self.max_pending_outgoing_connections, allow_private_addresses: self.allow_private_addresses, random_walk, connection_idle_timeout: Some(Duration::from_secs( From 88ebc9e8300d7196b7b02196ba3d19b3fa14e0ef Mon Sep 17 00:00:00 2001 From: chad Date: Sun, 1 Sep 2024 16:52:53 -0500 Subject: [PATCH 5/9] formatting --- bin/fuel-core/src/cli/run/p2p.rs | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/bin/fuel-core/src/cli/run/p2p.rs b/bin/fuel-core/src/cli/run/p2p.rs index 4bce3c98cb2..3960697a69c 100644 --- a/bin/fuel-core/src/cli/run/p2p.rs +++ b/bin/fuel-core/src/cli/run/p2p.rs @@ -1,15 +1,30 @@ use anyhow::anyhow; -use clap::{builder::ArgPredicate::IsPresent, Args}; +use clap::{ + builder::ArgPredicate::IsPresent, + Args, +}; use fuel_core::{ p2p::{ - config::{convert_to_libp2p_keypair, Config, NotInitialized, MAX_RESPONSE_SIZE}, + config::{ + convert_to_libp2p_keypair, + Config, + NotInitialized, + MAX_RESPONSE_SIZE, + }, gossipsub_config::default_gossipsub_builder, - heartbeat, Multiaddr, + heartbeat, + Multiaddr, + }, + types::{ + fuel_crypto, + fuel_crypto::SecretKey, }, - types::{fuel_crypto, fuel_crypto::SecretKey}, }; use std::{ - net::{IpAddr, Ipv4Addr}, + net::{ + IpAddr, + Ipv4Addr, + }, num::NonZeroU32, path::PathBuf, str::FromStr, From 1f8d1af48645395470f61e6493bb2064c60e5397 Mon Sep 17 00:00:00 2001 From: chad Date: Wed, 4 Sep 2024 09:51:26 -0500 Subject: [PATCH 6/9] feat: add max established connection limits --- bin/fuel-core/src/cli/run/p2p.rs | 5 +++++ crates/services/p2p/src/behavior.rs | 3 ++- crates/services/p2p/src/config.rs | 4 ++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/bin/fuel-core/src/cli/run/p2p.rs b/bin/fuel-core/src/cli/run/p2p.rs index 3960697a69c..b697e59351a 100644 --- a/bin/fuel-core/src/cli/run/p2p.rs +++ b/bin/fuel-core/src/cli/run/p2p.rs @@ -104,6 +104,10 @@ pub struct P2PArgs { #[clap(long = "max-pending-outgoing-connections", default_value = "100", env)] pub max_pending_outgoing_connections: u32, + /// Max number of established connections + #[clap(long = "max-established-connections", default_value = "100", env)] + pub max_established_connections: u32, + /// Set the delay between random walks for p2p node discovery in seconds. /// If it's not set the random walk will be disabled. /// Also if `reserved_nodes_only_mode` is set to `true`, @@ -321,6 +325,7 @@ impl P2PArgs { max_connections_per_peer: self.max_connections_per_peer, max_pending_incoming_connections: self.max_pending_incoming_connections, max_pending_outgoing_connections: self.max_pending_outgoing_connections, + max_established_connections: self.max_established_connections, allow_private_addresses: self.allow_private_addresses, random_walk, connection_idle_timeout: Some(Duration::from_secs( diff --git a/crates/services/p2p/src/behavior.rs b/crates/services/p2p/src/behavior.rs index bb2587357c1..55612eaafa9 100644 --- a/crates/services/p2p/src/behavior.rs +++ b/crates/services/p2p/src/behavior.rs @@ -126,7 +126,8 @@ impl FuelBehaviour { )) .with_max_pending_outgoing(Some( p2p_config.max_pending_outgoing_connections, - )), + )) + .with_max_established(Some(p2p_config.max_established_connections)), ); let req_res_protocol = diff --git a/crates/services/p2p/src/config.rs b/crates/services/p2p/src/config.rs index 79b6fe4f104..6e6314a4d92 100644 --- a/crates/services/p2p/src/config.rs +++ b/crates/services/p2p/src/config.rs @@ -98,6 +98,8 @@ pub struct Config { pub max_pending_incoming_connections: u32, /// Max number of concurrent pending outgoing connections pub max_pending_outgoing_connections: u32, + /// Max number of established connections + pub max_established_connections: u32, /// The interval at which identification requests are sent to /// the remote on established connections after the first request pub identify_interval: Option, @@ -161,6 +163,7 @@ impl Config { max_connections_per_peer: self.max_connections_per_peer, max_pending_incoming_connections: self.max_pending_incoming_connections, max_pending_outgoing_connections: self.max_pending_outgoing_connections, + max_established_connections: self.max_established_connections, allow_private_addresses: self.allow_private_addresses, random_walk: self.random_walk, connection_idle_timeout: self.connection_idle_timeout, @@ -212,6 +215,7 @@ impl Config { max_connections_per_peer: 3, max_pending_incoming_connections: 100, max_pending_outgoing_connections: 100, + max_established_connections: 150, allow_private_addresses: true, random_walk: Some(Duration::from_millis(500)), connection_idle_timeout: Some(Duration::from_secs(120)), From 9bb8a893ca7ddd3c48a9f3df1cdbf7f48094b293 Mon Sep 17 00:00:00 2001 From: chad Date: Sat, 7 Sep 2024 13:54:54 -0500 Subject: [PATCH 7/9] docs: re-add changed heading for CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a94f6aa42c8..6830062c3a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Added - [2135](https://github.com/FuelLabs/fuel-core/pull/2135): Added metrics logging for number of blocks served over the p2p req/res protocol. - [2150](https://github.com/FuelLabs/fuel-core/pull/2150): Upgraded `libp2p` to `0.54.1` and introduced `max_pending_incoming_connections` , `max_established_connections` and `max_pending_outgoing_connections` to limit the number of pending connections. + +### Changed #### Breaking - [2145](https://github.com/FuelLabs/fuel-core/pull/2145): feat: Introduce time port in PoA service. From 09f5d116d488b9d5115ac5c4d95ffcf9c6172598 Mon Sep 17 00:00:00 2001 From: chad Date: Thu, 19 Sep 2024 18:21:37 -0500 Subject: [PATCH 8/9] docs: update CHANGELOG.md --- CHANGELOG.md | 120 +++++++++++++++++++++++++-------------------------- 1 file changed, 59 insertions(+), 61 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 718aee73708..93de9acd01a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,11 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] ### Added -- [2135](https://github.com/FuelLabs/fuel-core/pull/2135): Added metrics logging for number of blocks served over the p2p req/res protocol. -- [2150](https://github.com/FuelLabs/fuel-core/pull/2150): Upgraded `libp2p` to `0.54.1` and introduced `max_pending_incoming_connections` , `max_established_connections` and `max_pending_outgoing_connections` to limit the number of pending connections. - - [2131](https://github.com/FuelLabs/fuel-core/pull/2131): Add flow in TxPool in order to ask to newly connected peers to share their transaction pool - [2182](https://github.com/FuelLabs/fuel-core/pull/2151): Limit number of transactions that can be fetched via TxSource::next +- [2150](https://github.com/FuelLabs/fuel-core/pull/2150): Upgraded `libp2p` to `0.54.1` and introduced `max_pending_incoming_connections` , `max_established_connections` and `max_pending_outgoing_connections` to limit the number of pending connections. ### Changed @@ -140,7 +138,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). And the following CLI flags are serving a new purpose - "min-gas-price" - the minimum gas price that the gas price algorithm will return - [2045](https://github.com/FuelLabs/fuel-core/pull/2045): Include withdrawal message only if transaction is executed successfully. -- [2041](https://github.com/FuelLabs/fuel-core/pull/2041): Add code for startup of the gas price algorithm updater so +- [2041](https://github.com/FuelLabs/fuel-core/pull/2041): Add code for startup of the gas price algorithm updater so the gas price db on startup is always in sync with the on chain db ## [Version 0.31.0] @@ -254,7 +252,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Changed -- [#1906](https://github.com/FuelLabs/fuel-core/pull/1906): Makes `cli::snapshot::Command` members public such that clients can create and execute snapshot commands programmatically. This enables snapshot execution in external programs, such as the regenesis test suite. +- [#1906](https://github.com/FuelLabs/fuel-core/pull/1906): Makes `cli::snapshot::Command` members public such that clients can create and execute snapshot commands programmatically. This enables snapshot execution in external programs, such as the regenesis test suite. - [#1891](https://github.com/FuelLabs/fuel-core/pull/1891): Regenesis now preserves `FuelBlockMerkleData` and `FuelBlockMerkleMetadata` in the off-chain table. These tables are checked when querying message proofs. - [#1886](https://github.com/FuelLabs/fuel-core/pull/1886): Use ref to `Block` in validation code - [#1876](https://github.com/FuelLabs/fuel-core/pull/1876): Updated benchmark to include the worst scenario for `CROO` opcode. Also include consensus parameters in bench output. @@ -278,12 +276,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - [#1868](https://github.com/FuelLabs/fuel-core/pull/1868): Include the `event_inbox_root` in the header hash. Changed types of the `transactions_count` to `u16` and `message_receipt_count` to `u32` instead of `u64`. Updated the application hash root calculation to not pad numbers. - [#1866](https://github.com/FuelLabs/fuel-core/pull/1866): Fixed a runtime panic that occurred when restarting a node. The panic happens when the relayer database is already populated, and the relayer attempts an empty commit during start up. This invalid commit is removed in this PR. - [#1871](https://github.com/FuelLabs/fuel-core/pull/1871): Fixed `block` endpoint to return fetch the blocks from both databases after regenesis. -- [#1856](https://github.com/FuelLabs/fuel-core/pull/1856): Replaced instances of `Union` with `Enum` for GraphQL definitions of `ConsensusParametersVersion` and related types. This is needed because `Union` does not support multiple `Version`s inside discriminants or empty variants. -- [#1870](https://github.com/FuelLabs/fuel-core/pull/1870): Fixed benchmarks for the `0.25.3`. +- [#1856](https://github.com/FuelLabs/fuel-core/pull/1856): Replaced instances of `Union` with `Enum` for GraphQL definitions of `ConsensusParametersVersion` and related types. This is needed because `Union` does not support multiple `Version`s inside discriminants or empty variants. +- [#1870](https://github.com/FuelLabs/fuel-core/pull/1870): Fixed benchmarks for the `0.25.3`. - [#1870](https://github.com/FuelLabs/fuel-core/pull/1870): Improves the performance of getting the size of the contract from the `InMemoryTransaction`. - [#1851](https://github.com/FuelLabs/fuel-core/pull/1851/): Provided migration capabilities (enabled addition of new column families) to RocksDB instance. -### Added +### Added - [#1853](https://github.com/FuelLabs/fuel-core/pull/1853): Added a test case to verify the database's behavior when new columns are added to the RocksDB database. - [#1860](https://github.com/FuelLabs/fuel-core/pull/1860): Regenesis now preserves `FuelBlockIdsToHeights` off-chain table. @@ -341,14 +339,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Along with the new block height, the regenesis process also increases the state transition bytecode and consensus parameters versions. It guarantees that a new network doesn't use values from the previous network and allows us not to migrate `StateTransitionBytecodeVersions` and `ConsensusParametersVersions` tables. - Added a new CLI argument, `native-executor-version,` that allows overriding of the default version of the native executor. It can be useful for side rollups that have their own history of executor upgrades. - Replaced: - + ```rust let file = std::fs::File::open(path)?; let mut snapshot: Self = serde_json::from_reader(&file)?; ``` - + with a: - + ```rust let mut json = String::new(); std::fs::File::open(&path) @@ -360,7 +358,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Updated all tests to use `Config::local_node_*` instead of working with the `SnapshotReader` directly. It is the preparation of the tests for the futures bumps of the `Executor::VERSION`. When we increase the version, all tests continue to use `GenesisBlock.state_transition_bytecode = 0` while the version is different, which forces the usage of the WASM executor, while for tests, we still prefer to test native execution. The `Config::local_node_*` handles it and forces the executor to use the native version. - Reworked the `build.rs` file of the upgradable executor. The script now caches WASM bytecode to avoid recompilation. Also, fixed the issue with outdated WASM bytecode. The script reacts on any modifications of the `fuel-core-wasm-executor` and forces recompilation (it is why we need the cache), so WASM bytecode always is actual now. - [#1822](https://github.com/FuelLabs/fuel-core/pull/1822): Removed support of `Create` transaction from debugger since it doesn't have any script to execute. -- [#1822](https://github.com/FuelLabs/fuel-core/pull/1822): Use `fuel-vm 0.49.0` with new transactions types - `Upgrade` and `Upload`. Also added `max_bytecode_subsections` field to the `ConsensusParameters` to limit the number of bytecode subsections in the state transition bytecode. +- [#1822](https://github.com/FuelLabs/fuel-core/pull/1822): Use `fuel-vm 0.49.0` with new transactions types - `Upgrade` and `Upload`. Also added `max_bytecode_subsections` field to the `ConsensusParameters` to limit the number of bytecode subsections in the state transition bytecode. - [#1816](https://github.com/FuelLabs/fuel-core/pull/1816): Updated the upgradable executor to fetch the state transition bytecode from the database when the version doesn't match a native one. This change enables the WASM executor in the "production" build and requires a `wasm32-unknown-unknown` target. ## [Version 0.24.2] @@ -399,9 +397,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - [1785](https://github.com/FuelLabs/fuel-core/pull/1785): Producer will only include DA height if it has enough gas to include the associate forced transactions. - [#1771](https://github.com/FuelLabs/fuel-core/pull/1771): Contract 'states' and 'balances' brought back into `ContractConfig`. Parquet now writes a file per table. - [1779](https://github.com/FuelLabs/fuel-core/pull/1779): Modify Relayer service to order Events from L1 by block index -- [#1783](https://github.com/FuelLabs/fuel-core/pull/1783): The PR upgrade `fuel-vm` to `0.48.0` release. Because of some breaking changes, we also adapted our codebase to follow them: +- [#1783](https://github.com/FuelLabs/fuel-core/pull/1783): The PR upgrade `fuel-vm` to `0.48.0` release. Because of some breaking changes, we also adapted our codebase to follow them: - Implementation of `Default` for configs was moved under the `test-helpers` feature. The `fuel-core` binary uses testnet configuration instead of `Default::default`(for cases when `ChainConfig` was not provided by the user). - - All parameter types are enums now and require corresponding modifications across the codebase(we need to use getters and setters). The GraphQL API remains the same for simplicity, but each parameter now has one more field - `version`, that can be used to decide how to deserialize. + - All parameter types are enums now and require corresponding modifications across the codebase(we need to use getters and setters). The GraphQL API remains the same for simplicity, but each parameter now has one more field - `version`, that can be used to decide how to deserialize. - The `UtxoId` type now is 34 bytes instead of 33. It affects hex representation and requires adding `00`. - The `block_gas_limit` was moved to `ConsensusParameters` from `ChainConfig`. It means the block producer doesn't specify the block gas limit anymore, and we don't need to propagate this information. - The `bytecodeLength` field is removed from the `Create` transaction. @@ -424,13 +422,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - The change splits the `KeyValueStore` into `KeyValueInspect` and `KeyValueMutate`, as well the `Blueprint` into `BlueprintInspect` and `BlueprintMutate`. It allows requiring less restricted constraints for any read-related operations. - One of the main ideas of the change is to allow for the actual storage only to implement `KeyValueInspect` and `Modifiable` without the `KeyValueMutate`. It simplifies work with the databases and provides a safe way of interacting with them (Modification into the database can only go through the `Modifiable::commit_changes`). This feature is used to [track the height](https://github.com/FuelLabs/fuel-core/pull/1694/files#diff-c95a3d57a39feac7c8c2f3b193a24eec39e794413adc741df36450f9a4539898) of each database during commits and even limit how commits are done, providing additional safety. This part of the change was done as a [separate commit](https://github.com/FuelLabs/fuel-core/pull/1694/commits/7b1141ac838568e3590f09dd420cb24a6946bd32). - + - The `StorageTransaction` is a `StructuredStorage` that uses `InMemoryTransaction` inside to accumulate modifications. Only `InMemoryTransaction` has a real implementation of the `KeyValueMutate`(Other types only implement it in tests). - + - The implementation of the `Modifiable` for the `Database` contains a business logic that provides additional safety but limits the usage of the database. The `Database` now tracks its height and is responsible for its updates. In the `commit_changes` function, it analyzes the changes that were done and tries to find a new height(For example, in the case of the `OnChain` database, we are looking for a new `Block` in the `FuelBlocks` table). - + - As was planned in the issue, now the executor has full control over how commits to the storage are done. - + - All mutation methods now require `&mut self` - exclusive ownership over the object to be able to write into it. It almost negates the chance of concurrent modification of the storage, but it is still possible since the `Database` implements the `Clone` trait. To be sure that we don't corrupt the state of the database, the `commit_changes` function implements additional safety checks to be sure that we commit updates per each height only once time. - Side changes: @@ -522,7 +520,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - [#1657](https://github.com/FuelLabs/fuel-core/pull/1657): Changed `CROO` gas price type from `Word` to `DependentGasPrice`. The dependent gas price values are dummy values while awaiting updated benchmarks. - [#1671](https://github.com/FuelLabs/fuel-core/pull/1671): The GraphQL API uses block height instead of the block id where it is possible. The transaction status contains `block_height` instead of the `block_id`. - [#1675](https://github.com/FuelLabs/fuel-core/pull/1675): Simplify GQL schema by disabling contract resolvers in most cases, and just return a ContractId scalar instead. -- [#1658](https://github.com/FuelLabs/fuel-core/pull/1658): Receipts are part of the transaction status. +- [#1658](https://github.com/FuelLabs/fuel-core/pull/1658): Receipts are part of the transaction status. Removed `reason` from the `TransactionExecutionResult::Failed`. It can be calculated based on the program state and receipts. Also, it is not possible to fetch `receipts` from the `Transaction` directly anymore. Instead, you need to fetch `status` and its receipts. - [#1646](https://github.com/FuelLabs/fuel-core/pull/1646): Remove redundant receipts from queries. @@ -536,57 +534,57 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - [#1596](https://github.com/FuelLabs/fuel-core/pull/1596): Make `Consensus` type a version-able enum - [#1593](https://github.com/FuelLabs/fuel-core/pull/1593): Make `Block` type a version-able enum - [#1576](https://github.com/FuelLabs/fuel-core/pull/1576): The change moves the implementation of the storage traits for required tables from `fuel-core` to `fuel-core-storage` crate. The change also adds a more flexible configuration of the encoding/decoding per the table and allows the implementation of specific behaviors for the table in a much easier way. It unifies the encoding between database, SMTs, and iteration, preventing mismatching bytes representation on the Rust type system level. Plus, it increases the re-usage of the code by applying the same blueprint to other tables. - + It is a breaking PR because it changes database encoding/decoding for some tables. - + ### StructuredStorage - + The change adds a new type `StructuredStorage`. It is a wrapper around the key-value storage that implements the storage traits(`StorageInspect`, `StorageMutate`, `StorageRead`, etc) for the tables with blueprint. This blueprint works in tandem with the `TableWithBlueprint` trait. The table may implement `TableWithBlueprint` specifying the blueprint, as an example: - + ```rust impl TableWithBlueprint for ContractsRawCode { type Blueprint = Plain; - + fn column() -> Column { Column::ContractsRawCode } } ``` - + It is a definition of the blueprint for the `ContractsRawCode` table. It has a plain blueprint meaning it simply encodes/decodes bytes and stores/loads them into/from the storage. As a key codec and value codec, it uses a `Raw` encoding/decoding that simplifies writing bytes and loads them back into the memory without applying any serialization or deserialization algorithm. - + If the table implements `TableWithBlueprint` and the selected codec satisfies all blueprint requirements, the corresponding storage traits for that table are implemented on the `StructuredStorage` type. - + ### Codecs - + Each blueprint allows customizing the key and value codecs. It allows the use of different codecs for different tables, taking into account the complexity and weight of the data and providing a way of more optimal implementation. - + That property may be very useful to perform migration in a more easier way. Plus, it also can be a `no_std` migration potentially allowing its fraud proving. - + An example of migration: - + ```rust /// Define the table for V1 value encoding/decoding. impl TableWithBlueprint for ContractsRawCodeV1 { type Blueprint = Plain; - + fn column() -> Column { Column::ContractsRawCode } } - + /// Define the table for V2 value encoding/decoding. /// It uses `Postcard` codec for the value instead of `Raw` codec. /// /// # Dev-note: The columns is the same. impl TableWithBlueprint for ContractsRawCodeV2 { type Blueprint = Plain; - + fn column() -> Column { Column::ContractsRawCode } } - + fn migration(storage: &mut Database) { let mut iter = storage.iter_all::(None); while let Ok((key, value)) = iter.next() { @@ -595,19 +593,19 @@ and this project adheres to [Semantic Versioning](http://semver.org/). } } ``` - + ### Structures - + The blueprint of the table defines its behavior. As an example, a `Plain` blueprint simply encodes/decodes bytes and stores/loads them into/from the storage. The `SMT` blueprint builds a sparse merkle tree on top of the key-value pairs. - + Implementing a blueprint one time, we can apply it to any table satisfying the requirements of this blueprint. It increases the re-usage of the code and minimizes duplication. - + It can be useful if we decide to create global roots for all required tables that are used in fraud proving. - + ```rust impl TableWithBlueprint for SpentMessages { type Blueprint = Plain; - + fn column() -> Column { Column::SpentMessages } @@ -615,28 +613,28 @@ and this project adheres to [Semantic Versioning](http://semver.org/). | | \|/ - + impl TableWithBlueprint for SpentMessages { type Blueprint = Sparse; - + fn column() -> Column { Column::SpentMessages } } ``` - + ### Side changes - + #### `iter_all` The `iter_all` functionality now accepts the table instead of `K` and `V` generics. It is done to use the correct codec during deserialization. Also, the table definition provides the column. - + #### Duplicated unit tests - + The `fuel-core-storage` crate provides macros that generate unit tests. Almost all tables had the same test like `get`, `insert`, `remove`, `exist`. All duplicated tests were moved to macros. The unique one still stays at the same place where it was before. - + #### `StorageBatchMutate` - + Added a new `StorageBatchMutate` trait that we can move to `fuel-storage` crate later. It allows batch operations on the storage. It may be more performant in some cases. - [#1573](https://github.com/FuelLabs/fuel-core/pull/1573): Remove nested p2p request/response encoding. Only breaks p2p networking compatibility with older fuel-core versions, but is otherwise fully internal. @@ -650,22 +648,22 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ```shell --tx-blacklist-addresses The list of banned addresses ignored by the `TxPool` - + [env: TX_BLACKLIST_ADDRESSES=] - + --tx-blacklist-coins The list of banned coins ignored by the `TxPool` - + [env: TX_BLACKLIST_COINS=] - + --tx-blacklist-messages The list of banned messages ignored by the `TxPool` - + [env: TX_BLACKLIST_MESSAGES=] - + --tx-blacklist-contracts The list of banned contracts ignored by the `TxPool` - + [env: TX_BLACKLIST_CONTRACTS=] ``` @@ -700,13 +698,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Changed -- [#1517](https://github.com/FuelLabs/fuel-core/pull/1517): Changed default gossip heartbeat interval to 500ms. +- [#1517](https://github.com/FuelLabs/fuel-core/pull/1517): Changed default gossip heartbeat interval to 500ms. - [#1520](https://github.com/FuelLabs/fuel-core/pull/1520): Extract `executor` into `fuel-core-executor` crate. ### Fixed #### Breaking -- [#1536](https://github.com/FuelLabs/fuel-core/pull/1536): The change fixes the contracts tables to not touch SMT nodes of foreign contracts. Before, it was possible to invalidate the SMT from another contract. It is a breaking change and requires re-calculating the whole state from the beginning with new SMT roots. +- [#1536](https://github.com/FuelLabs/fuel-core/pull/1536): The change fixes the contracts tables to not touch SMT nodes of foreign contracts. Before, it was possible to invalidate the SMT from another contract. It is a breaking change and requires re-calculating the whole state from the beginning with new SMT roots. - [#1542](https://github.com/FuelLabs/fuel-core/pull/1542): Migrates information about peers to NodeInfo instead of ChainInfo. It also elides information about peers in the default node_info query. ## [Version 0.21.0] @@ -732,7 +730,7 @@ FuelVM received a lot of safety and stability improvements: - Removed the `ChainId` from the `PredicateId` calculation, allowing the use of predicates cross-chain. - Improvements in the performance of some storage-related opcodes. - Support the `ECAL` instruction that allows adding custom functionality to the VM. It can be used to create unique rollups or advanced indexers in the future. -- Support of [transaction policies](https://github.com/FuelLabs/fuel-vm/blob/master/CHANGELOG.md#version-0420) provides additional safety for the user. +- Support of [transaction policies](https://github.com/FuelLabs/fuel-vm/blob/master/CHANGELOG.md#version-0420) provides additional safety for the user. It also allows the implementation of a multi-dimensional price model in the future, making the transaction execution cheaper and allowing more transactions that don't affect storage. - Refactored errors, returning more detailed errors to the user, simplifying debugging. @@ -773,8 +771,8 @@ FuelVM received a lot of safety and stability improvements: - [#1339](https://github.com/FuelLabs/fuel-core/pull/1339): Adds `baseAssetId` to `FeeParameters` in the GraphQL API. - [#1331](https://github.com/FuelLabs/fuel-core/pull/1331): Add peer reputation reporting to block import code. - [#1324](https://github.com/FuelLabs/fuel-core/pull/1324): Added pyroscope profiling to fuel-core, intended to be used by a secondary docker image that has debug symbols enabled. -- [#1309](https://github.com/FuelLabs/fuel-core/pull/1309): Add documentation for running debug builds with CLion and Visual Studio Code. -- [#1308](https://github.com/FuelLabs/fuel-core/pull/1308): Add support for loading .env files when compiling with the `env` feature. This allows users to conveniently supply CLI arguments in a secure and IDE-agnostic way. +- [#1309](https://github.com/FuelLabs/fuel-core/pull/1309): Add documentation for running debug builds with CLion and Visual Studio Code. +- [#1308](https://github.com/FuelLabs/fuel-core/pull/1308): Add support for loading .env files when compiling with the `env` feature. This allows users to conveniently supply CLI arguments in a secure and IDE-agnostic way. - [#1304](https://github.com/FuelLabs/fuel-core/pull/1304): Implemented `submit_and_await_commit_with_receipts` method for `FuelClient`. - [#1286](https://github.com/FuelLabs/fuel-core/pull/1286): Include readable names for test cases where missing. - [#1274](https://github.com/FuelLabs/fuel-core/pull/1274): Added tests to benchmark block synchronization. From 21f4cbe82ce92c3341a42aa822f02215afe847f6 Mon Sep 17 00:00:00 2001 From: chad Date: Mon, 21 Oct 2024 12:46:44 -0500 Subject: [PATCH 9/9] linting fixes --- crates/services/p2p/src/p2p_service.rs | 136 ++++++++++++++++++++----- 1 file changed, 110 insertions(+), 26 deletions(-) diff --git a/crates/services/p2p/src/p2p_service.rs b/crates/services/p2p/src/p2p_service.rs index 03fef53e211..518f019746c 100644 --- a/crates/services/p2p/src/p2p_service.rs +++ b/crates/services/p2p/src/p2p_service.rs @@ -1,42 +1,87 @@ use crate::{ - behavior::{FuelBehaviour, FuelBehaviourEvent}, - codecs::{postcard::PostcardCodec, GossipsubCodec}, - config::{build_transport_function, Config}, + behavior::{ + FuelBehaviour, + FuelBehaviourEvent, + }, + codecs::{ + postcard::PostcardCodec, + GossipsubCodec, + }, + config::{ + build_transport_function, + Config, + }, dnsaddr_resolution::DnsResolver, gossipsub::{ messages::{ - GossipTopicTag, GossipsubBroadcastRequest, + GossipTopicTag, + GossipsubBroadcastRequest, GossipsubMessage as FuelGossipsubMessage, }, topics::GossipsubTopics, }, heartbeat, - peer_manager::{PeerManager, Punisher}, + peer_manager::{ + PeerManager, + Punisher, + }, peer_report::PeerReportEvent, request_response::messages::{ - RequestError, RequestMessage, ResponseError, ResponseMessage, ResponseSendError, + RequestError, + RequestMessage, + ResponseError, + ResponseMessage, + ResponseSendError, ResponseSender, }, TryPeerId, }; -use fuel_core_metrics::{global_registry, p2p_metrics::increment_unique_peers}; +use fuel_core_metrics::{ + global_registry, + p2p_metrics::increment_unique_peers, +}; use fuel_core_types::{ - fuel_types::BlockHeight, services::p2p::peer_reputation::AppScore, + fuel_types::BlockHeight, + services::p2p::peer_reputation::AppScore, }; use futures::prelude::*; use libp2p::{ - gossipsub::{self, MessageAcceptance, MessageId, PublishError, TopicHash}, + gossipsub::{ + self, + MessageAcceptance, + MessageId, + PublishError, + TopicHash, + }, identify, - metrics::{Metrics, Recorder}, + metrics::{ + Metrics, + Recorder, + }, multiaddr::Protocol, - request_response::{self, InboundRequestId, OutboundRequestId, ResponseChannel}, + request_response::{ + self, + InboundRequestId, + OutboundRequestId, + ResponseChannel, + }, swarm::SwarmEvent, - tcp, Multiaddr, PeerId, Swarm, SwarmBuilder, + tcp, + Multiaddr, + PeerId, + Swarm, + SwarmBuilder, }; use rand::seq::IteratorRandom; -use std::{collections::HashMap, time::Duration}; +use std::{ + collections::HashMap, + time::Duration, +}; use tokio::sync::broadcast; -use tracing::{debug, warn}; +use tracing::{ + debug, + warn, +}; /// Maximum amount of peer's addresses that we are ready to store per peer const MAX_IDENTIFY_ADDRESSES: usize = 10; @@ -784,43 +829,82 @@ impl FuelP2PService { #[allow(clippy::cast_possible_truncation)] #[cfg(test)] mod tests { - use super::{FuelP2PService, PublishError}; + use super::{ + FuelP2PService, + PublishError, + }; use crate::{ codecs::postcard::PostcardCodec, config::Config, gossipsub::{ - messages::{GossipsubBroadcastRequest, GossipsubMessage}, - topics::{GossipTopic, NEW_TX_GOSSIP_TOPIC}, + messages::{ + GossipsubBroadcastRequest, + GossipsubMessage, + }, + topics::{ + GossipTopic, + NEW_TX_GOSSIP_TOPIC, + }, }, p2p_service::FuelP2PEvent, peer_manager::PeerInfo, request_response::messages::{ - RequestMessage, ResponseError, ResponseMessage, ResponseSender, + RequestMessage, + ResponseError, + ResponseMessage, + ResponseSender, }, service::to_message_acceptance, }; use fuel_core_types::{ blockchain::{ - consensus::{poa::PoAConsensus, Consensus}, + consensus::{ + poa::PoAConsensus, + Consensus, + }, header::BlockHeader, SealedBlockHeader, }, - fuel_tx::{Transaction, TransactionBuilder, TxId, UniqueIdentifier}, + fuel_tx::{ + Transaction, + TransactionBuilder, + TxId, + UniqueIdentifier, + }, fuel_types::ChainId, services::p2p::{ - GossipsubMessageAcceptance, NetworkableTransactionPool, Transactions, + GossipsubMessageAcceptance, + NetworkableTransactionPool, + Transactions, }, }; - use futures::{future::join_all, StreamExt}; + use futures::{ + future::join_all, + StreamExt, + }; use libp2p::{ gossipsub::Topic, identity::Keypair, - swarm::{ListenError, SwarmEvent}, - Multiaddr, PeerId, + swarm::{ + ListenError, + SwarmEvent, + }, + Multiaddr, + PeerId, }; use rand::Rng; - use std::{collections::HashSet, ops::Range, sync::Arc, time::Duration}; - use tokio::sync::{broadcast, mpsc, oneshot, watch}; + use std::{ + collections::HashSet, + ops::Range, + sync::Arc, + time::Duration, + }; + use tokio::sync::{ + broadcast, + mpsc, + oneshot, + watch, + }; use tracing_attributes::instrument; type P2PService = FuelP2PService;