Skip to content

Commit

Permalink
bump libp2p
Browse files Browse the repository at this point in the history
  • Loading branch information
LesnyRumcajs committed Aug 2, 2022
1 parent 961ac23 commit ad6ea5b
Show file tree
Hide file tree
Showing 18 changed files with 548 additions and 499 deletions.
908 changes: 482 additions & 426 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
FROM rust:1-buster AS build-env

# Install dependencies
RUN apt-get update && apt-get install --no-install-recommends -y build-essential clang ocl-icd-opencl-dev
RUN apt-get update && apt-get install --no-install-recommends -y build-essential clang ocl-icd-opencl-dev cmake

WORKDIR /usr/src/forest
COPY . .
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ sudo apt install build-essential clang ocl-icd-opencl-dev libssl-dev
sudo pacman -S base-devel clang ocl-icd openssl

# Fedora (36)
sudo dnf install -y clang-devel ocl-icd-devel
sudo dnf install -y clang-devel ocl-icd-devel cmake
```

## Installation
Expand Down
1 change: 0 additions & 1 deletion blockchain/chain_sync/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ forest_blocks = { path = "../blocks" }
beacon = { path = "../beacon" }
forest_db = "0.1"
forest_encoding = "0.2.1"
libp2p = { version = "0.40.0-rc.1", default-features = false }
ipld_blockstore = "0.1"
chain = { path = "../chain" }
forest_message = { version = "0.7", features = ["proofs", "blst"] }
Expand Down
4 changes: 2 additions & 2 deletions blockchain/chain_sync/src/chain_muxer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ use forest_blocks::{
Block, Error as ForestBlockError, FullTipset, GossipBlock, Tipset, TipsetKeys,
};
use forest_libp2p::{
hello::HelloRequest, rpc::RequestResponseError, NetworkEvent, NetworkMessage, PubsubMessage,
hello::HelloRequest, rpc::RequestResponseError, NetworkEvent, NetworkMessage, PeerId,
PubsubMessage,
};
use forest_message::SignedMessage;
use fvm_shared::message::Message;
use ipld_blockstore::BlockStore;
use libp2p::core::PeerId;
use message_pool::{MessagePool, Provider};
use state_manager::StateManager;

Expand Down
3 changes: 1 addition & 2 deletions blockchain/chain_sync/src/network_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ use forest_libp2p::{
},
hello::{HelloRequest, HelloResponse},
rpc::RequestResponseError,
NetworkMessage,
NetworkMessage, PeerId,
};
use futures::channel::oneshot::channel as oneshot_channel;
use ipld_blockstore::{BlockStore, BlockStoreExt};
use libp2p::core::PeerId;
use log::{debug, trace, warn};
use std::convert::TryFrom;
use std::sync::Arc;
Expand Down
2 changes: 1 addition & 1 deletion blockchain/chain_sync/src/peer_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{cmp::Ordering, collections::HashSet};

use async_std::sync::RwLock;
use forest_blocks::Tipset;
use libp2p::core::PeerId;
use forest_libp2p::PeerId;
use log::{debug, trace};
use rand::seq::SliceRandom;
use smallvec::SmallVec;
Expand Down
2 changes: 1 addition & 1 deletion forest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ base64 = "0.13"
forest_libp2p = { path = "../node/forest_libp2p" }
utils = { path = "../node/utils" }
forest_db = "0.1"
libp2p = { version = "0.41", default-features = false, features = ["identify"] }
libp2p = { version = "0.46", default-features = false, features = ["identify"] }
futures = "0.3"
log = "0.4"
async-log = "2.0"
Expand Down
3 changes: 1 addition & 2 deletions forest/src/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use chain::ChainStore;
use chain_sync::consensus::SyncGossipSubmitter;
use chain_sync::ChainMuxer;
use fil_types::verifier::FullVerifier;
use forest_libp2p::{get_keypair, Libp2pConfig, Libp2pService};
use forest_libp2p::{ed25519, get_keypair, Keypair, Libp2pConfig, Libp2pService};
use fvm_shared::version::NetworkVersion;
use genesis::{get_network_name_from_genesis, import_chain, read_genesis_header};
use key_management::ENCRYPTED_KEYSTORE_NAME;
Expand All @@ -22,7 +22,6 @@ use state_manager::StateManager;
use utils::write_to_file;

use async_std::{channel::bounded, sync::RwLock, task};
use libp2p::identity::{ed25519, Keypair};
use log::{debug, error, info, trace, warn};
use rpassword::read_password;

Expand Down
4 changes: 4 additions & 0 deletions ipld/blockstore/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ pub trait BlockStoreExt: BlockStore {
}
}

fn contains(&self, cid: &Cid) -> anyhow::Result<bool> {
Ok(self.get(cid)?.is_some())
}

/// Put an object in the block store and return the Cid identifier.
fn put_obj<S>(&self, obj: &S, code: Code) -> anyhow::Result<Cid>
where
Expand Down
4 changes: 2 additions & 2 deletions node/forest_libp2p/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2021"
anyhow = "1.0"
utils = { path = "../utils" }
networks = { path = "../../types/networks" }
libp2p = { version = "0.40.0-rc.1", default-features = false, features = [
libp2p = { version = "0.46", default-features = false, features = [
"gossipsub",
"kad",
"identify",
Expand Down Expand Up @@ -43,7 +43,7 @@ smallvec = "1.1"
chain = { path = "../../blockchain/chain" }
forest_db = "0.1"
fvm_ipld_car = "0.4.1"
libp2p-bitswap = { git = "https://github.com/ChainSafe/libp2p-bitswap", rev = "8d3913ea7fc1e693776c83eecc7a9675c3426446" }
libp2p-bitswap = { git = "https://github.com/ChainSafe/libp2p-bitswap", rev = "e624f3048880ee7baf9978658c5542389d286fdf" }
tiny-cid = "0.2"
ipld_blockstore = "0.1"
async-trait = "0.1"
Expand Down
2 changes: 1 addition & 1 deletion node/forest_libp2p/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ impl ForestBehaviour {
) -> Poll<
NetworkBehaviourAction<
<Self as NetworkBehaviour>::OutEvent,
<Self as NetworkBehaviour>::ProtocolsHandler,
<Self as NetworkBehaviour>::ConnectionHandler,
>,
> {
// Poll to see if any response is ready to be sent back.
Expand Down
93 changes: 42 additions & 51 deletions node/forest_libp2p/src/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,15 @@
use async_std::stream::{self, Interval};
use async_std::task;
use futures::prelude::*;
use libp2p::swarm::DialError;
use libp2p::core::transport::ListenerId;
use libp2p::swarm::behaviour::toggle::ToggleIntoConnectionHandler;
use libp2p::swarm::{ConnectionHandler, DialError, IntoConnectionHandler};
use libp2p::{
core::{
connection::{ConnectionId, ListenerId},
ConnectedPoint, Multiaddr, PeerId, PublicKey,
},
core::{connection::ConnectionId, ConnectedPoint, Multiaddr, PeerId, PublicKey},
kad::{handler::KademliaHandlerProto, Kademlia, KademliaConfig, KademliaEvent, QueryId},
mdns::MdnsEvent,
multiaddr::Protocol,
swarm::{
toggle::{Toggle, ToggleIntoProtoHandler},
IntoProtocolsHandler, NetworkBehaviour, NetworkBehaviourAction, PollParameters,
ProtocolsHandler,
},
swarm::{behaviour::toggle::Toggle, NetworkBehaviour, NetworkBehaviourAction, PollParameters},
};
use libp2p::{kad::record::store::MemoryStore, mdns::Mdns};
use log::{debug, error, trace, warn};
Expand Down Expand Up @@ -214,10 +209,10 @@ impl DiscoveryBehaviour {
}

impl NetworkBehaviour for DiscoveryBehaviour {
type ProtocolsHandler = ToggleIntoProtoHandler<KademliaHandlerProto<QueryId>>;
type ConnectionHandler = ToggleIntoConnectionHandler<KademliaHandlerProto<QueryId>>;
type OutEvent = DiscoveryOut;

fn new_handler(&mut self) -> Self::ProtocolsHandler {
fn new_handler(&mut self) -> Self::ConnectionHandler {
self.kademlia.new_handler()
}

Expand Down Expand Up @@ -250,49 +245,57 @@ impl NetworkBehaviour for DiscoveryBehaviour {
conn: &ConnectionId,
endpoint: &ConnectedPoint,
failed_addresses: Option<&Vec<Multiaddr>>,
other_established: usize,
) {
self.num_connections += 1;

self.kademlia
.inject_connection_established(peer_id, conn, endpoint, failed_addresses)
}

fn inject_connected(&mut self, peer_id: &PeerId) {
let multiaddr = self.addresses_of_peer(peer_id);
self.peer_addresses.insert(*peer_id, multiaddr);
self.peers.insert(*peer_id);
self.pending_events
.push_back(DiscoveryOut::Connected(*peer_id));
if other_established == 0 {
let multiaddr = self.addresses_of_peer(peer_id);
self.peer_addresses.insert(*peer_id, multiaddr);
self.peers.insert(*peer_id);
self.pending_events
.push_back(DiscoveryOut::Connected(*peer_id));
}

self.kademlia.inject_connected(peer_id)
self.kademlia.inject_connection_established(
peer_id,
conn,
endpoint,
failed_addresses,
other_established,
)
}

fn inject_connection_closed(
&mut self,
peer_id: &PeerId,
conn: &ConnectionId,
endpoint: &ConnectedPoint,
handler: <Self::ProtocolsHandler as IntoProtocolsHandler>::Handler,
handler: <Self::ConnectionHandler as IntoConnectionHandler>::Handler,
remaining_established: usize,
) {
self.num_connections -= 1;

self.kademlia
.inject_connection_closed(peer_id, conn, endpoint, handler)
}

fn inject_disconnected(&mut self, peer_id: &PeerId) {
self.peers.remove(peer_id);
self.pending_events
.push_back(DiscoveryOut::Disconnected(*peer_id));
if remaining_established == 0 {
self.peers.remove(peer_id);
self.pending_events
.push_back(DiscoveryOut::Disconnected(*peer_id));
}

self.kademlia.inject_disconnected(peer_id)
self.kademlia.inject_connection_closed(
peer_id,
conn,
endpoint,
handler,
remaining_established,
)
}

fn inject_event(
&mut self,
peer_id: PeerId,
connection: ConnectionId,
event: <<Self::ProtocolsHandler as IntoProtocolsHandler>::Handler as ProtocolsHandler>::OutEvent,
event: <<Self::ConnectionHandler as IntoConnectionHandler>::Handler as ConnectionHandler>::OutEvent,
) {
if let Some(kad) = self.kademlia.as_mut() {
return kad.inject_event(peer_id, connection, event);
Expand All @@ -311,7 +314,7 @@ impl NetworkBehaviour for DiscoveryBehaviour {
fn inject_dial_failure(
&mut self,
peer_id: Option<PeerId>,
handler: Self::ProtocolsHandler,
handler: Self::ConnectionHandler,
err: &DialError,
) {
self.kademlia.inject_dial_failure(peer_id, handler, err)
Expand All @@ -334,7 +337,7 @@ impl NetworkBehaviour for DiscoveryBehaviour {
&mut self,
cx: &mut Context,
params: &mut impl PollParameters,
) -> Poll<NetworkBehaviourAction<Self::OutEvent, Self::ProtocolsHandler>> {
) -> Poll<NetworkBehaviourAction<Self::OutEvent, Self::ConnectionHandler>> {
// Immediately process the content of `discovered`.
if let Some(ev) = self.pending_events.pop_front() {
return Poll::Ready(NetworkBehaviourAction::GenerateEvent(ev));
Expand Down Expand Up @@ -376,19 +379,8 @@ impl NetworkBehaviour for DiscoveryBehaviour {
debug!("Libp2p => Unhandled Kademlia event: {:?}", other)
}
},
NetworkBehaviourAction::DialAddress { address, handler } => {
return Poll::Ready(NetworkBehaviourAction::DialAddress { address, handler })
}
NetworkBehaviourAction::DialPeer {
peer_id,
condition,
handler,
} => {
return Poll::Ready(NetworkBehaviourAction::DialPeer {
peer_id,
condition,
handler,
})
NetworkBehaviourAction::Dial { opts, handler } => {
return Poll::Ready(NetworkBehaviourAction::Dial { opts, handler });
}
NetworkBehaviourAction::NotifyHandler {
peer_id,
Expand Down Expand Up @@ -440,8 +432,7 @@ impl NetworkBehaviour for DiscoveryBehaviour {
}
MdnsEvent::Expired(_) => {}
},
NetworkBehaviourAction::DialAddress { .. } => {}
NetworkBehaviourAction::DialPeer { .. } => {}
NetworkBehaviourAction::Dial { .. } => {}
// Nothing to notify handler
NetworkBehaviourAction::NotifyHandler { event, .. } => match event {},
NetworkBehaviourAction::ReportObservedAddr { address, score } => {
Expand Down
1 change: 1 addition & 0 deletions node/forest_libp2p/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ pub use self::service::*;

// Re-export some libp2p types
pub use libp2p::core::PeerId;
pub use libp2p::identity::{ed25519, Keypair};
pub use libp2p::multiaddr::{Multiaddr, Protocol};
pub use multihash::Multihash;
12 changes: 7 additions & 5 deletions node/forest_libp2p/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ use libp2p::request_response::ResponseChannel;
use libp2p::swarm::SwarmEvent;
use libp2p::{
core,
core::connection::ConnectionLimits,
core::muxing::StreamMuxerBox,
core::transport::Boxed,
identity::{ed25519, Keypair},
mplex, noise, yamux, PeerId, Swarm, Transport,
mplex, noise,
swarm::ConnectionLimits,
yamux, PeerId, Swarm, Transport,
};
use libp2p::{core::Multiaddr, swarm::SwarmBuilder};
use log::{debug, error, info, trace, warn};
Expand Down Expand Up @@ -354,7 +355,7 @@ where
for multiaddr in addresses.iter_mut() {
multiaddr.push(Protocol::P2p(Multihash::from_bytes(&peer_id.to_bytes()).unwrap()));

if Swarm::dial_addr(swarm_stream.get_mut(), multiaddr.clone()).is_ok() {
if Swarm::dial(swarm_stream.get_mut(), multiaddr.clone()).is_ok() {
success = true;
break;
};
Expand Down Expand Up @@ -403,8 +404,9 @@ async fn emit_event(sender: &Sender<NetworkEvent>, event: NetworkEvent) {

/// Builds the transport stack that LibP2P will communicate over.
pub fn build_transport(local_key: Keypair) -> Boxed<(PeerId, StreamMuxerBox)> {
let transport = libp2p::tcp::TcpConfig::new().nodelay(true);
let transport = libp2p::websocket::WsConfig::new(transport.clone()).or_transport(transport);
let tcp_transport =
|| libp2p::tcp::TcpTransport::new(libp2p::tcp::GenTcpConfig::new().nodelay(true));
let transport = libp2p::websocket::WsConfig::new(tcp_transport()).or_transport(tcp_transport());
let transport = async_std::task::block_on(libp2p::dns::DnsConfig::system(transport)).unwrap();
let auth_config = {
let dh_keys = noise::Keypair::<noise::X25519Spec>::new()
Expand Down
1 change: 0 additions & 1 deletion node/rpc-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ async-std = { version = "1.9", features = ["attributes"] }
once_cell = "1.7"
serde = { version = "1.0", default-features = false, features = ["derive"] }
serde_json = "1.0"
libp2p = { version = "0.40.0-rc.1", default-features = false }
fvm_shared = { version = "0.8.0", default-features = false }
fvm_ipld_bitfield = { version = "0.5.2", features = ["json"] }
cid = { version = "0.8", default-features = false, features = ["std"] }
Expand Down
2 changes: 1 addition & 1 deletion vm/actor_interface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ forest_vm = "0.3.1"
ipld_blockstore = "0.1"
serde = { version = "1.0", features = ["derive"] }
forest_encoding = "0.2"
libp2p = { version = "0.40.0-rc.1", default-features = false }
libp2p = { version = "0.46", default-features = false }
forest_hash_utils = "0.1"
forest_json_utils = "0.1"
forest_json = { version = "0.1.0", path = "../../utils/json/" }
Expand Down
1 change: 0 additions & 1 deletion vm/state_migration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ forest_vm = "0.3.1"
ipld_blockstore = "0.1"
serde = { version = "1.0", features = ["derive"] }
forest_encoding = "0.2"
libp2p = { version = "0.40.0-rc.1", default-features = false }
fvm_ipld_bitfield = "0.5.2"
forest_hash_utils = "0.1"
forest_json_utils = "0.1"
Expand Down

0 comments on commit ad6ea5b

Please sign in to comment.