Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update libp2p from 0.50.0 to 0.53.1 #1379

Merged
merged 68 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from 57 commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
91fb125
WIP
MitchTurner Sep 22, 2023
f7004e5
WIP
MitchTurner Sep 25, 2023
707eee5
Merge remote-tracking branch 'origin/master' into update-libp2p
MitchTurner Oct 2, 2023
98d92e6
Merge branch 'master' into update-libp2p
bvrooman Oct 6, 2023
ae3f78f
Update Cargo.lock
bvrooman Oct 6, 2023
16c9e42
Merge branch 'master' into update-libp2p
Dentosal Oct 9, 2023
e77f2ff
WIP
MitchTurner Oct 9, 2023
5e30e1f
Some fixes, but now we need to add several more behaviours to replace…
xgreenx Oct 10, 2023
0e1e297
Remove addresses from PeerInfo
MitchTurner Oct 17, 2023
2eb3060
Merge remote-tracking branch 'origin/master' into update-libp2p
MitchTurner Oct 17, 2023
9d5ac7e
Fix lock file
MitchTurner Oct 17, 2023
ac7808b
Merge remote-tracking branch 'origin/master' into update-libp2p
MitchTurner Nov 22, 2023
9ba837e
Fix removed read/write methods
MitchTurner Nov 24, 2023
7e8fd6a
Remove FastMessageId, among other cleanup
MitchTurner Nov 24, 2023
9c74512
Remove `TokioDnsConfig`, other cleanup
MitchTurner Nov 24, 2023
99e8d51
Remove a bunch of unused stuff, replace private function, etc
MitchTurner Nov 24, 2023
74f7159
WIP
MitchTurner Nov 24, 2023
c333c37
Add trait impls, bump version, other update stuff
MitchTurner Nov 24, 2023
4fdd8cd
Fix typing around poll code
MitchTurner Nov 25, 2023
7e26141
Get compiling with a bunch of TODOs
MitchTurner Nov 25, 2023
2c4ca7c
Use BytesCodec for reading raw bytes from socket
MitchTurner Nov 27, 2023
f61d5a1
Migrate from `Upgrade` traits to `ConnectionUpgrade` traits
MitchTurner Nov 27, 2023
741d353
Migrate more missed trait impls
MitchTurner Nov 27, 2023
8efb0c6
Replace missing handle call in discovery
MitchTurner Nov 27, 2023
82d86d7
Add missing trait methods
MitchTurner Nov 27, 2023
abb1850
Add trait methods to peer_report
MitchTurner Nov 27, 2023
c31f581
WIP: fix test errors
MitchTurner Nov 27, 2023
93357b9
Get tests compiling
MitchTurner Nov 28, 2023
ba4b3a3
Add extra instumentation
MitchTurner Nov 29, 2023
1ba608e
Fixed something
xgreenx Nov 29, 2023
ef58a70
Move behavior to avoid bug
MitchTurner Nov 30, 2023
9852266
WIP: Update `SwarmBuilder`
MitchTurner Dec 1, 2023
4fc93cc
Fix the peer_id in the service to use same as Swarm
MitchTurner Dec 1, 2023
8cdda2c
WIP: Fix discovery test
MitchTurner Dec 2, 2023
06d6be0
Push something
xgreenx Dec 4, 2023
d713ed6
Track connection closures
MitchTurner Dec 5, 2023
560a4ee
WIP: use our transport
MitchTurner Dec 7, 2023
1dcee3d
Use our transport with `SwarmBuilder`
MitchTurner Dec 7, 2023
04ebd3b
WIP modify peer_report handlers
MitchTurner Dec 8, 2023
2686ff9
Replace stupid either with select
MitchTurner Dec 8, 2023
0ac9225
Fix gossipsub tests by reordering sub-behaviors
MitchTurner Dec 11, 2023
8740bde
Ignore failing mdns test
MitchTurner Dec 12, 2023
ff3ebd6
Remove extra async stuff
MitchTurner Dec 12, 2023
cc137d9
WIP cleanup warnings
MitchTurner Dec 13, 2023
bfaf2bd
Fix other compilation warnings
MitchTurner Dec 13, 2023
c093509
Merge remote-tracking branch 'origin/master' into update-libp2p
MitchTurner Dec 13, 2023
06527c3
WIP: Move Heartbeat and Identify to FuelBehavior
MitchTurner Dec 14, 2023
e7683ed
Finish removing heartbeat and identify from peer report
MitchTurner Dec 14, 2023
d039644
Replace address truncation logic, fix warnings
MitchTurner Dec 14, 2023
5f66b04
Fixed checksum verification. Instead of having a manual upgrade for t…
xgreenx Dec 15, 2023
bb0aa0b
Fixed the codec deserialization
xgreenx Dec 15, 2023
87d1e6b
Sort deps
MitchTurner Dec 15, 2023
3b2e92e
Extend timeout because it would not run locally
MitchTurner Dec 15, 2023
a883d81
Refactor behavior event handler
MitchTurner Dec 15, 2023
e23317b
Fixed mdns behaviour
xgreenx Dec 15, 2023
6fb2a47
reorder helpers
MitchTurner Dec 15, 2023
128ec77
Merge branch 'master' into update-libp2p
MitchTurner Dec 15, 2023
48687d9
Use connection timeout from config
MitchTurner Dec 16, 2023
f5a0913
Cleanup
MitchTurner Dec 16, 2023
7b8b5fb
Remove unused dep
MitchTurner Dec 18, 2023
e54c02e
Remove unused dep, remove unused fields
MitchTurner Dec 18, 2023
a4fe8ac
Cleanup, add details to todo
MitchTurner Dec 18, 2023
1897d92
Cleanup
MitchTurner Dec 18, 2023
2eaa139
Update crates/fuel-core/src/p2p_test_helpers.rs
MitchTurner Dec 19, 2023
1dbf6c8
Fix typo, add issue to TODO
MitchTurner Dec 19, 2023
d68c2a0
Merge remote-tracking branch 'origin/master' into update-libp2p
MitchTurner Dec 20, 2023
44de252
Merge branch 'master' into update-libp2p
MitchTurner Dec 20, 2023
e946440
Remove `()`
MitchTurner Dec 20, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2,643 changes: 961 additions & 1,682 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,8 @@ proptest = "1.1"
pin-project-lite = "0.2"
axum = "0.5"
lazy_static = "1.4"
libp2p-prom-client = { package = "prometheus-client", version = "0.18" }
once_cell = "1.16"
prometheus-client = "0.20"
prometheus-client = "0.22.0"
itertools = "0.10"
insta = "1.8"
tempfile = "3.4"
Expand Down
4 changes: 2 additions & 2 deletions crates/fuel-core/src/p2p_test_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,11 +378,11 @@ pub fn make_config(name: String, mut node_config: Config) -> Config {
pub async fn make_node(node_config: Config, test_txs: Vec<Transaction>) -> Node {
let db = Database::in_memory();
let node = tokio::time::timeout(
Duration::from_secs(1),
Duration::from_secs(2),
FuelService::from_database(db.clone(), node_config),
)
.await
.expect("All services should start in less than 1 second")
.expect("All services should start in less than 2 second")
MitchTurner marked this conversation as resolved.
Show resolved Hide resolved
.expect("The `FuelService should start without error");

let config = node.shared.config.clone();
Expand Down
4 changes: 1 addition & 3 deletions crates/fuel-core/src/service/adapters/producer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ use fuel_core_storage::{
use fuel_core_types::{
blockchain::{
block::CompressedBlock,
primitives::{
self,
},
primitives,
},
fuel_tx,
fuel_tx::Receipt,
Expand Down
1 change: 0 additions & 1 deletion crates/metrics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ description = "Fuel metrics"

[dependencies]
axum = { workspace = true }
libp2p-prom-client = { workspace = true }
once_cell = { workspace = true }
pin-project-lite = { workspace = true }
prometheus-client = { workspace = true }
Expand Down
6 changes: 3 additions & 3 deletions crates/metrics/src/p2p_metrics.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use libp2p_prom_client::{
use once_cell::race::OnceBox;
use prometheus_client::{
metrics::counter::Counter,
registry::Registry,
};
use once_cell::race::OnceBox;
use std::sync::OnceLock;

pub struct P2PMetrics {
Expand All @@ -27,7 +27,7 @@ impl P2PMetrics {
metrics.peer_metrics.register(
"Peer_Counter",
"A Counter which keeps track of each unique peer the p2p service has connected to",
Box::new(metrics.unique_peers.clone()),
metrics.unique_peers.clone(),
);

metrics
Expand Down
9 changes: 3 additions & 6 deletions crates/metrics/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,20 @@ use axum::{
},
};
use core::ops::Deref;
use libp2p_prom_client::encoding::text::encode as libp2p_encode;
use prometheus_client::encoding::text::encode;

pub fn encode_metrics_response() -> impl IntoResponse {
// encode libp2p metrics using older prometheus
let mut libp2p_bytes = Vec::<u8>::new();
let mut encoded = String::new();
if let Some(value) = p2p_metrics().gossip_sub_registry.get() {
if libp2p_encode(&mut libp2p_bytes, value).is_err() {
if encode(&mut encoded, value).is_err() {
return error_body()
}
}
if libp2p_encode(&mut libp2p_bytes, &p2p_metrics().peer_metrics).is_err() {
if encode(&mut encoded, &p2p_metrics().peer_metrics).is_err() {
return error_body()
}

let mut encoded = String::from_utf8_lossy(&libp2p_bytes).into_owned();

// encode the rest of the fuel-core metrics using latest prometheus
{
let lock = services_metrics()
Expand Down
42 changes: 25 additions & 17 deletions crates/services/p2p/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ description = "Fuel client networking"
[dependencies]
anyhow = { workspace = true }
async-trait = { workspace = true }
asynchronous-codec = "0.7.0"
MitchTurner marked this conversation as resolved.
Show resolved Hide resolved
fuel-core-chain-config = { workspace = true }
fuel-core-metrics = { workspace = true } # TODO make this a feature
fuel-core-services = { workspace = true }
Expand All @@ -21,46 +22,50 @@ fuel-core-types = { workspace = true, features = [
"serde",
] }
futures = { workspace = true }
hex = "0.4"
ip_network = "0.4"
libp2p = { version = "=0.50.0", default-features = false, features = [
libp2p = { version = "=0.53.1", default-features = false, features = [
"dns",
"gossipsub",
"identify",
"kad",
"macros",
"mdns",
"mplex",
"noise",
"noise",
"request-response",
"secp256k1",
"tcp",
"tokio",
"yamux",
"websocket",
] }
libp2p-core = "=0.38.0"
libp2p-dns = "=0.38.0"
libp2p-gossipsub = "=0.43.0"
libp2p-identify = "=0.41.0"
libp2p-kad = "=0.42.0"
libp2p-mdns = "=0.42.0"
libp2p-mplex = "=0.38.0"
libp2p-noise = "=0.41.0"
libp2p-prom-client = { workspace = true }
libp2p-request-response = "=0.23.0"
libp2p-swarm = "=0.41.1"
libp2p-tcp = "=0.38.0"
libp2p-websocket = "=0.40.0"
libp2p-yamux = "=0.42.0"
libp2p-allow-block-list = "=0.3.0"
libp2p-core = "=0.41.1"
libp2p-dns = "=0.41.0"
libp2p-gossipsub = "=0.46.0"
libp2p-identify = "=0.44.0"
libp2p-kad = "=0.45.1"
libp2p-mdns = "=0.45.1"
libp2p-mplex = "=0.41.0"
libp2p-noise = "=0.44.0"
libp2p-request-response = "=0.26.0"
libp2p-swarm = "=0.44.0"
libp2p-tcp = "=0.41.0"
libp2p-tls = "0.3.0"
libp2p-websocket = "=0.43.0"
libp2p-yamux = "=0.45.0"
postcard = { workspace = true, features = ["use-std"] }
prometheus-client = { workspace = true }
quick-protobuf = "0.8.1"
quick-protobuf-codec = "0.3.0"
rand = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_with = "1.11"
sha2 = "0.10"
thiserror = "1.0.47"
tokio = { workspace = true, features = ["sync"] }
tracing = { workspace = true }
void = "1"

[dev-dependencies]
ctor = "0.1"
Expand All @@ -75,5 +80,8 @@ tokio = { workspace = true, features = ["full", "test-util"] }
tracing-attributes = { workspace = true }
tracing-subscriber = { workspace = true, features = ["env-filter"] }

[dev-dependencies.libp2p-swarm-test]
version = "0.3.0"

[features]
test-helpers = ["fuel-core-types/test-helpers"]
105 changes: 84 additions & 21 deletions crates/services/p2p/src/behavior.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::{
config::build_gossipsub_behaviour,
topics::GossipTopic,
},
heartbeat,
peer_report::{
PeerReportBehaviour,
PeerReportEvent,
Expand All @@ -21,47 +22,63 @@ use crate::{
use fuel_core_types::fuel_types::BlockHeight;
use libp2p::{
gossipsub::{
error::PublishError,
Gossipsub,
GossipsubEvent,
Behaviour as Gossipsub,
Event as GossipsubEvent,
MessageAcceptance,
MessageId,
PublishError,
},
identify,
request_response::{
Behaviour as RequestResponse,
Config as RequestResponseConfig,
Event as RequestResponseEvent,
ProtocolSupport,
RequestId,
RequestResponse,
RequestResponseConfig,
RequestResponseEvent,
ResponseChannel,
},
swarm::NetworkBehaviour,
Multiaddr,
PeerId,
};
use libp2p_kad::KademliaEvent;
use libp2p_allow_block_list as allow_block_list;
use libp2p_kad::Event as KademliaEvent;
use libp2p_request_response::OutboundRequestId;

#[derive(Debug)]
pub enum FuelBehaviourEvent {
Discovery(KademliaEvent),
PeerReport(PeerReportEvent),
Gossipsub(GossipsubEvent),
RequestResponse(RequestResponseEvent<RequestMessage, NetworkResponse>),
BlockedPeers(void::Void),
Identify(identify::Event),
Heartbeat(heartbeat::HeartbeatEvent),
}

/// Handles all p2p protocols needed for Fuel.
#[derive(NetworkBehaviour)]
#[behaviour(out_event = "FuelBehaviourEvent")]
#[behaviour(to_swarm = "FuelBehaviourEvent")]
MitchTurner marked this conversation as resolved.
Show resolved Hide resolved
pub struct FuelBehaviour<Codec: NetworkCodec> {
/// Node discovery
discovery: DiscoveryBehaviour,
/// **WARNING**: The order of the behaviours is important and fragile, at least for the tests.

/// Identifies and periodically requests `BlockHeight` from connected nodes
peer_report: PeerReportBehaviour,
/// The Behaviour to manage connections to blocked peers.
blocked_peer: allow_block_list::Behaviour<allow_block_list::BlockedPeers>,

/// Message propagation for p2p
gossipsub: Gossipsub,

/// Handles regular heartbeats from peers
heartbeat: heartbeat::Heartbeat,

/// The Behaviour to identify peers.
identify: identify::Behaviour,

/// Identifies and periodically requests `BlockHeight` from connected nodes
peer_report: PeerReportBehaviour,

/// Node discovery
discovery: DiscoveryBehaviour,

/// RequestResponse protocol
request_response: RequestResponse<Codec>,
}
Expand All @@ -77,7 +94,7 @@ impl<Codec: NetworkCodec> FuelBehaviour<Codec> {

discovery_config
.enable_mdns(p2p_config.enable_mdns)
.discovery_limit(p2p_config.max_peers_connected as usize)
.max_peers_connected(p2p_config.max_peers_connected as usize)
.allow_private_addresses(p2p_config.allow_private_addresses)
.with_bootstrap_nodes(p2p_config.bootstrap_nodes.clone())
.with_reserved_nodes(p2p_config.reserved_nodes.clone())
Expand All @@ -98,21 +115,45 @@ impl<Codec: NetworkCodec> FuelBehaviour<Codec> {

let peer_report = PeerReportBehaviour::new(p2p_config);

let identify = {
let identify_config = identify::Config::new(
"/fuel/1.0".to_string(),
Voxelot marked this conversation as resolved.
Show resolved Hide resolved
p2p_config.keypair.public(),
);
if let Some(interval) = p2p_config.identify_interval {
identify::Behaviour::new(identify_config.with_interval(interval))
} else {
identify::Behaviour::new(identify_config)
}
};

let heartbeat = heartbeat::Heartbeat::new(
p2p_config.heartbeat_config.clone(),
BlockHeight::default(),
);

let req_res_protocol =
std::iter::once((codec.get_req_res_protocol(), ProtocolSupport::Full));
core::iter::once((codec.get_req_res_protocol(), ProtocolSupport::Full));

let mut req_res_config = RequestResponseConfig::default();
req_res_config.set_request_timeout(p2p_config.set_request_timeout);
req_res_config.set_connection_keep_alive(p2p_config.set_connection_keep_alive);
let req_res_config = RequestResponseConfig::default();
req_res_config
.clone()
.with_request_timeout(p2p_config.set_request_timeout);

// TODO: Do we need to set this via the `SwarmBuilder` somewhere? https://github.com/libp2p/rust-libp2p/pull/4679
// req_res_config.set_connection_keep_alive(p2p_config.set_connection_keep_alive);
MitchTurner marked this conversation as resolved.
Show resolved Hide resolved

let request_response =
RequestResponse::new(codec, req_res_protocol, req_res_config);
RequestResponse::with_codec(codec, req_res_protocol, req_res_config);

Self {
discovery: discovery_config.finish(),
gossipsub,
peer_report,
request_response,
blocked_peer: Default::default(),
identify,
heartbeat,
}
}

Expand All @@ -138,7 +179,7 @@ impl<Codec: NetworkCodec> FuelBehaviour<Codec> {
&mut self,
message_request: RequestMessage,
peer_id: &PeerId,
) -> RequestId {
) -> OutboundRequestId {
self.request_response.send_request(peer_id, message_request)
}

Expand Down Expand Up @@ -181,13 +222,17 @@ impl<Codec: NetworkCodec> FuelBehaviour<Codec> {
}

pub fn update_block_height(&mut self, block_height: BlockHeight) {
self.peer_report.update_block_height(block_height);
self.heartbeat.update_block_height(block_height);
}

#[cfg(test)]
pub fn get_peer_score(&self, peer_id: &PeerId) -> Option<f64> {
self.gossipsub.peer_score(peer_id)
}

pub fn block_peer(&mut self, peer_id: PeerId) {
self.blocked_peer.block_peer(peer_id)
}
}

impl From<KademliaEvent> for FuelBehaviourEvent {
Expand All @@ -213,3 +258,21 @@ impl From<RequestResponseEvent<RequestMessage, NetworkResponse>> for FuelBehavio
FuelBehaviourEvent::RequestResponse(event)
}
}

impl From<identify::Event> for FuelBehaviourEvent {
fn from(event: identify::Event) -> Self {
FuelBehaviourEvent::Identify(event)
}
}

impl From<heartbeat::HeartbeatEvent> for FuelBehaviourEvent {
fn from(event: heartbeat::HeartbeatEvent) -> Self {
FuelBehaviourEvent::Heartbeat(event)
}
}

impl From<void::Void> for FuelBehaviourEvent {
fn from(event: void::Void) -> Self {
FuelBehaviourEvent::BlockedPeers(event)
}
}
2 changes: 1 addition & 1 deletion crates/services/p2p/src/codecs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
ResponseMessage,
},
};
use libp2p::request_response::RequestResponseCodec;
use libp2p::request_response::Codec as RequestResponseCodec;
use std::io;

/// Implement this in order to handle serialization & deserialization of Gossipsub messages
Expand Down