Skip to content

Commit

Permalink
Revert "chore: upgrade libp2p to 0.52.2 (#2732)" (#2759)
Browse files Browse the repository at this point in the history
* Revert "chore: upgrade libp2p to 0.52.2 (#2732)"

This reverts commit f61e3de.

* update lockfile

* lock to 0.51.1

* fix/suppress warnings

* deprecate more
  • Loading branch information
LesnyRumcajs authored Apr 14, 2023
1 parent e79e33a commit a02c55c
Show file tree
Hide file tree
Showing 8 changed files with 249 additions and 263 deletions.
438 changes: 216 additions & 222 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ lazy_static = "1.4"
libipld = { version = "0.14", default-features = false, features = ["dag-cbor", "dag-json", "derive"] }
libipld-core = "0.14"
libipld-macro = "0.14"
libp2p = { version = "0.51.2", default-features = false }
libp2p = { version = "=0.51.1", default-features = false }
libsecp256k1 = "0.7"
log = "0.4"
lru = "0.9"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@ use cid::{
};
use forest_libp2p_bitswap::{BitswapStoreRead, BitswapStoreReadWrite};
use libipld::Block;
use libp2p::{
futures::StreamExt,
multiaddr::Protocol,
swarm::{SwarmBuilder, SwarmEvent},
Swarm,
};
use libp2p::{futures::StreamExt, multiaddr::Protocol, swarm::SwarmEvent, Swarm};
use parking_lot::RwLock;
use rand::{rngs::OsRng, Rng};
use tokio::select;
Expand All @@ -28,7 +23,9 @@ async fn main() -> anyhow::Result<()> {
let (transport, _, local_peer_id) = TransportBuilder::new().build()?;
let behaviour = DemoBehaviour::default();
let bitswap_request_manager = behaviour.bitswap.request_manager();
let mut swarm = SwarmBuilder::with_tokio_executor(transport, behaviour, local_peer_id).build();
// https://github.com/ChainSafe/forest/issues/2762
#[allow(deprecated)]
let mut swarm = Swarm::with_tokio_executor(transport, behaviour, local_peer_id);
swarm.listen_on("/ip4/127.0.0.1/tcp/0/ws".parse()?)?;
let local_peer_addr = loop {
let event = swarm.select_next_some().await;
Expand Down
11 changes: 5 additions & 6 deletions node/forest_libp2p/bitswap/tests/go_compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@ mod tests {
Cid,
};
use libp2p::{
core,
futures::StreamExt,
identity, noise, request_response,
swarm::{SwarmBuilder, SwarmEvent},
tcp, yamux, PeerId, Transport,
core, futures::StreamExt, identity, noise, request_response, swarm::SwarmEvent, tcp, yamux,
PeerId, Swarm, Transport,
};

const TIMEOUT: Duration = Duration::from_secs(60);
Expand All @@ -40,7 +37,9 @@ mod tests {
.timeout(TIMEOUT)
.boxed();
let behaviour = BitswapBehaviour::new(&[b"/test/ipfs/bitswap/1.2.0"], Default::default());
let mut swarm = SwarmBuilder::with_tokio_executor(transport, behaviour, peer_id).build();
// TODO https://github.com/ChainSafe/forest/issues/2762
#[allow(deprecated)]
let mut swarm = Swarm::with_tokio_executor(transport, behaviour, peer_id);
swarm.listen_on(LISTEN_ADDR.parse()?)?;
let expected_inbound_request_cid_str = "bitswap_request_from_go";
let expected_inbound_request_cid = Cid::new_v0(
Expand Down
12 changes: 5 additions & 7 deletions node/forest_libp2p/bitswap/tests/request_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,8 @@ mod tests {
Block, Cid,
};
use libp2p::{
core,
identity::Keypair,
multiaddr::Protocol,
noise,
swarm::{SwarmBuilder, SwarmEvent},
tcp, yamux, Multiaddr, PeerId, Swarm, Transport,
core, identity::Keypair, multiaddr::Protocol, noise, swarm::SwarmEvent, tcp, yamux,
Multiaddr, PeerId, Swarm, Transport,
};
use parking_lot::RwLock;
use rand::{rngs::OsRng, Rng};
Expand Down Expand Up @@ -113,7 +109,9 @@ mod tests {
.timeout(TIMEOUT)
.boxed();
let behaviour = BitswapBehaviour::new(&[b"/test/ipfs/bitswap/1.0.0"], Default::default());
let mut swarm = SwarmBuilder::with_tokio_executor(transport, behaviour, peer_id).build();
// https://github.com/ChainSafe/forest/issues/2762
#[allow(deprecated)]
let mut swarm = Swarm::with_tokio_executor(transport, behaviour, peer_id);
swarm.listen_on(LISTEN_ADDR.parse()?)?;
let peer_addr = loop {
let event = swarm.select_next_some().await;
Expand Down
13 changes: 1 addition & 12 deletions node/forest_libp2p/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ use ahash::{HashMap, HashSet};
use forest_libp2p_bitswap::BitswapBehaviour;
use forest_utils::encoding::blake2b_256;
use libp2p::{
allow_block_list::{self, BlockedPeers},
connection_limits::{self, ConnectionLimits},
core::identity::Keypair,
gossipsub::{
self, IdentTopic as Topic, MessageAuthenticity, MessageId, PublishError, SubscriptionError,
Expand Down Expand Up @@ -38,8 +36,6 @@ pub(crate) struct ForestBehaviour {
discovery: DiscoveryBehaviour,
ping: ping::Behaviour,
identify: identify::Behaviour,
connection_limits: connection_limits::Behaviour,
pub(super) blocked_peers: allow_block_list::Behaviour<BlockedPeers>,
pub(super) hello: HelloBehaviour,
pub(super) chain_exchange: ChainExchangeBehaviour,
pub(super) bitswap: BitswapBehaviour,
Expand All @@ -57,12 +53,7 @@ impl Recorder<ForestBehaviourEvent> for Metrics {
}

impl ForestBehaviour {
pub fn new(
local_key: &Keypair,
config: &Libp2pConfig,
network_name: &str,
connection_limits: ConnectionLimits,
) -> Self {
pub fn new(local_key: &Keypair, config: &Libp2pConfig, network_name: &str) -> Self {
let mut gs_config_builder = gossipsub::ConfigBuilder::default();
gs_config_builder.max_transmit_size(1 << 20);
gs_config_builder.validation_mode(ValidationMode::Strict);
Expand Down Expand Up @@ -113,8 +104,6 @@ impl ForestBehaviour {
"ipfs/0.1.0".into(),
local_key.public(),
)),
connection_limits: connection_limits::Behaviour::new(connection_limits),
blocked_peers: Default::default(),
bitswap,
hello: HelloBehaviour::default(),
chain_exchange: ChainExchangeBehaviour::default(),
Expand Down
4 changes: 3 additions & 1 deletion node/forest_libp2p/src/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ use libp2p::{
kad::{record::store::MemoryStore, Kademlia, KademliaConfig, KademliaEvent, QueryId},
mdns::{tokio::Behaviour as Mdns, Event as MdnsEvent},
multiaddr::Protocol,
swarm::{behaviour::toggle::Toggle, derive_prelude::*, NetworkBehaviour, PollParameters},
swarm::{
behaviour::toggle::Toggle, derive_prelude::*, NetworkBehaviour, PollParameters, ToSwarm,
},
};
use log::{debug, error, trace, warn};
use tokio::time::Interval;
Expand Down
21 changes: 14 additions & 7 deletions node/forest_libp2p/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ use futures_util::stream::StreamExt;
use fvm_ipld_blockstore::Blockstore;
use fvm_shared::clock::ChainEpoch;
pub use libp2p::gossipsub::{IdentTopic, Topic};
// https://github.com/ChainSafe/forest/issues/2762
#[allow(deprecated)]
use libp2p::swarm::ConnectionLimits;
use libp2p::{
connection_limits::ConnectionLimits,
core::{self, identity::Keypair, muxing::StreamMuxerBox, transport::Boxed, Multiaddr},
gossipsub,
metrics::{Metrics, Recorder},
Expand Down Expand Up @@ -208,7 +210,9 @@ where
let transport =
build_transport(net_keypair.clone()).expect("Failed to build libp2p transport");

let connection_limits = ConnectionLimits::default()
// https://github.com/ChainSafe/forest/issues/2762
#[allow(deprecated)]
let limits = ConnectionLimits::default()
.with_max_pending_incoming(Some(10))
.with_max_pending_outgoing(Some(30))
.with_max_established_incoming(Some(config.target_peer_count))
Expand All @@ -217,9 +221,10 @@ where

let mut swarm = SwarmBuilder::with_tokio_executor(
transport,
ForestBehaviour::new(&net_keypair, &config, network_name, connection_limits),
ForestBehaviour::new(&net_keypair, &config, network_name),
peer_id,
)
.connection_limits(limits)
.notify_handler_buffer_size(std::num::NonZeroUsize::new(20).expect("Not zero"))
.per_connection_event_buffer_size(64)
.build();
Expand Down Expand Up @@ -358,11 +363,15 @@ fn handle_peer_ops(swarm: &mut Swarm<ForestBehaviour>, peer_ops: PeerOperation)
match peer_ops {
Ban(peer_id, reason) => {
warn!("Banning {peer_id}, reason: {reason}");
swarm.behaviour_mut().blocked_peers.block_peer(peer_id);
// https://github.com/ChainSafe/forest/issues/2762
#[allow(deprecated)]
swarm.ban_peer_id(peer_id);
}
Unban(peer_id) => {
info!("Unbanning {peer_id}");
swarm.behaviour_mut().blocked_peers.unblock_peer(peer_id);
// https://github.com/ChainSafe/forest/issues/2762
#[allow(deprecated)]
swarm.unban_peer_id(peer_id);
}
}
}
Expand Down Expand Up @@ -799,8 +808,6 @@ async fn handle_forest_behaviour_event<DB>(
)
.await
}
ForestBehaviourEvent::ConnectionLimits(_) => {}
ForestBehaviourEvent::BlockedPeers(_) => {}
}
}

Expand Down

0 comments on commit a02c55c

Please sign in to comment.