Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Implement bitswap in the network behaviour using libp2p_bitswap. #6795

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
2b67bbb
WIP, good start
expenses Jul 30, 2020
d5d3130
Add networking tests
expenses Aug 2, 2020
5bd7cb7
Merge remote-tracking branch 'origin/master' into ashley-bitswap
expenses Aug 2, 2020
6fa276d
Reindent bitswap tests using tabs
expenses Aug 3, 2020
926575f
Merge remote-tracking branch 'origin/master' into ashley-bitswap
expenses Aug 3, 2020
471b171
Use OffchainStorage instead of AuxStore
expenses Aug 3, 2020
83bc9c6
Apply suggestions
expenses Aug 3, 2020
be7baf5
Convert spaces to tabs
expenses Aug 3, 2020
6147c6a
Merge remote-tracking branch 'origin/master' into ashley-bitswap
expenses Aug 3, 2020
f90a39c
Merge remote-tracking branch 'origin/master' into ashley-bitswap
expenses Aug 4, 2020
2496778
Implement IPLD storage traits
expenses Aug 5, 2020
3244af9
Merge remote-tracking branch 'origin/master' into ashley-bitswap
expenses Aug 5, 2020
8d028d4
Documentation
expenses Aug 5, 2020
ae5fd43
Merge remote-tracking branch 'origin/master' into ashley-bitswap
expenses Aug 6, 2020
ccb5910
Fix line widths
expenses Aug 6, 2020
3da54fa
Fix browser build
expenses Aug 6, 2020
6f3d206
Merge remote-tracking branch 'origin/master' into ashley-bitswap
expenses Aug 6, 2020
e7ffe2a
Merge remote-tracking branch 'origin/master' into ashley-bitswap
expenses Aug 10, 2020
8e4c008
Insert bitswap blocks into the dht, rework to put bitswap methods on …
expenses Aug 10, 2020
435fa52
Merge remote-tracking branch 'origin/master' into ashley-bitswap
expenses Aug 10, 2020
d61bddc
Merge remote-tracking branch 'origin/master' into HEAD
expenses Aug 31, 2020
b8804df
Fix wasm build, but via patch
expenses Aug 31, 2020
f80e0ad
Merge remote-tracking branch 'origin/master' into ashley-bitswap
expenses Sep 8, 2020
4b954d2
Merge remote-tracking branch 'origin/master' into ashley-bitswap
expenses Sep 14, 2020
83de229
Remove storage impl and update
expenses Sep 18, 2020
a8a0f8b
Merge remote-tracking branch 'origin/master' into ashley-bitswap
expenses Sep 18, 2020
1f9c171
Fix wasm build
expenses Sep 18, 2020
9923b11
Remove stuff
expenses Sep 18, 2020
30fd353
Remove bitswap network tests
expenses Sep 18, 2020
38f4667
Merge remote-tracking branch 'origin/master' into ashley-bitswap
expenses Sep 21, 2020
8187024
Merge remote-tracking branch 'origin/master' into ashley-bitswap
expenses Sep 21, 2020
5de7605
Merge remote-tracking branch 'origin/master' into ashley-bitswap
expenses Sep 22, 2020
da1c738
Remove changes that slipped in accidentally
expenses Sep 22, 2020
b8f0981
Improve documentation somewhat
expenses Sep 22, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 108 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions bin/node-template/node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ pub fn new_full(config: Configuration) -> Result<TaskManager, ServiceError> {
sc_service::build_network(sc_service::BuildNetworkParams {
config: &config,
client: client.clone(),
backend: backend.clone(),
transaction_pool: transaction_pool.clone(),
spawn_handle: task_manager.spawn_handle(),
import_queue,
Expand Down Expand Up @@ -242,6 +243,7 @@ pub fn new_light(config: Configuration) -> Result<TaskManager, ServiceError> {
sc_service::build_network(sc_service::BuildNetworkParams {
config: &config,
client: client.clone(),
backend: backend.clone(),
transaction_pool: transaction_pool.clone(),
spawn_handle: task_manager.spawn_handle(),
import_queue,
Expand Down
2 changes: 2 additions & 0 deletions bin/node/cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ pub fn new_full_base(
sc_service::build_network(sc_service::BuildNetworkParams {
config: &config,
client: client.clone(),
backend: backend.clone(),
transaction_pool: transaction_pool.clone(),
spawn_handle: task_manager.spawn_handle(),
import_queue,
Expand Down Expand Up @@ -387,6 +388,7 @@ pub fn new_light_base(config: Configuration) -> Result<(
sc_service::build_network(sc_service::BuildNetworkParams {
config: &config,
client: client.clone(),
backend: backend.clone(),
transaction_pool: transaction_pool.clone(),
spawn_handle: task_manager.spawn_handle(),
import_queue,
Expand Down
3 changes: 2 additions & 1 deletion client/network-gossip/src/bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ impl<B: BlockT> Future for GossipEngine<B> {

this.forwarding_state = ForwardingState::Busy(to_forward.into());
},
Event::Dht(_) => {}
Event::Dht(_) => {},
Event::Bitswap(_) => {},
}
// The network event stream closed. Do the same for [`GossipValidator`].
Poll::Ready(None) => return Poll::Ready(()),
Expand Down
1 change: 1 addition & 0 deletions client/network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ unsigned-varint = { version = "0.4.0", features = ["futures", "futures-codec"] }
void = "1.0.2"
wasm-timer = "0.2"
zeroize = "1.0.0"
libp2p-bitswap = "0.5.1"

[dependencies.libp2p]
version = "0.22.0"
Expand Down
22 changes: 20 additions & 2 deletions client/network/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ pub struct Behaviour<B: BlockT, H: ExHashT> {
peer_info: peer_info::PeerInfoBehaviour,
/// Discovers nodes of the network.
discovery: DiscoveryBehaviour,
/// Exchanges blocks of data with other nodes.
pub bitswap: libp2p_bitswap::Bitswap,
expenses marked this conversation as resolved.
Show resolved Hide resolved
/// Block request handling.
block_requests: block_requests::BlockRequests<B>,
/// Finality proof request handling.
Expand Down Expand Up @@ -148,6 +150,9 @@ pub enum BehaviourOut<B: BlockT> {
/// Events generated by a DHT as a response to get_value or put_value requests as well as the
/// request duration.
Dht(DhtEvent, Duration),

/// Event generated by bitswap.
Bitswap(libp2p_bitswap::BitswapEvent)
expenses marked this conversation as resolved.
Show resolved Hide resolved
}

impl<B: BlockT, H: ExHashT> Behaviour<B, H> {
Expand All @@ -170,6 +175,7 @@ impl<B: BlockT, H: ExHashT> Behaviour<B, H> {
finality_proof_requests,
light_client_handler,
events: VecDeque::new(),
bitswap: libp2p_bitswap::Bitswap::new(),
role,
}
}
Expand Down Expand Up @@ -260,6 +266,11 @@ impl<B: BlockT, H: ExHashT> Behaviour<B, H> {
pub fn light_client_request(&mut self, r: light_client_handler::Request<B>) -> Result<(), light_client_handler::Error> {
self.light_client_handler.request(r)
}

fn add_discovered_node(&mut self, peer_id: PeerId) {
self.substrate.add_discovered_nodes(iter::once(peer_id.clone()));
self.bitswap.connect(peer_id);
}
expenses marked this conversation as resolved.
Show resolved Hide resolved
}

fn reported_roles_to_observed_role(local_role: &Role, remote: &PeerId, roles: Roles) -> ObservedRole {
Expand Down Expand Up @@ -438,7 +449,7 @@ impl<B: BlockT, H: ExHashT> NetworkBehaviourEventProcess<peer_info::PeerInfoEven
for addr in listen_addrs {
self.discovery.add_self_reported_address(&peer_id, protocols.iter(), addr);
}
self.substrate.add_discovered_nodes(iter::once(peer_id));
self.add_discovered_node(peer_id);
}
}

Expand All @@ -453,7 +464,7 @@ impl<B: BlockT, H: ExHashT> NetworkBehaviourEventProcess<DiscoveryOut>
// implementation for `PeerInfoEvent`.
}
DiscoveryOut::Discovered(peer_id) => {
self.substrate.add_discovered_nodes(iter::once(peer_id));
self.add_discovered_node(peer_id);
expenses marked this conversation as resolved.
Show resolved Hide resolved
}
DiscoveryOut::ValueFound(results, duration) => {
self.events.push_back(BehaviourOut::Dht(DhtEvent::ValueFound(results), duration));
Expand All @@ -476,6 +487,13 @@ impl<B: BlockT, H: ExHashT> NetworkBehaviourEventProcess<DiscoveryOut>
}
}

impl<B: BlockT, H: ExHashT> NetworkBehaviourEventProcess<libp2p_bitswap::BitswapEvent>
for Behaviour<B, H> {
fn inject_event(&mut self, event: libp2p_bitswap::BitswapEvent) {
self.events.push_back(BehaviourOut::Bitswap(event));
}
}

impl<B: BlockT, H: ExHashT> Behaviour<B, H> {
fn poll<TEv>(&mut self, _: &mut Context, _: &mut impl PollParameters) -> Poll<NetworkBehaviourAction<TEv, BehaviourOut<B>>> {
if let Some(event) = self.events.pop_front() {
Expand Down
1 change: 1 addition & 0 deletions client/network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ pub use protocol::sync::SyncState;
pub use libp2p::{Multiaddr, PeerId};
#[doc(inline)]
pub use libp2p::multiaddr;
pub use libp2p_bitswap::BitswapEvent;

pub use sc_peerset::ReputationChange;
use sp_runtime::traits::{Block as BlockT, NumberFor};
Expand Down
2 changes: 2 additions & 0 deletions client/network/src/protocol/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ pub enum DhtEvent {
pub enum Event {
/// Event generated by a DHT.
Dht(DhtEvent),
/// Event generated by Bitswap.
Bitswap(libp2p_bitswap::BitswapEvent),
expenses marked this conversation as resolved.
Show resolved Hide resolved

/// Opened a substream with the given node with the given notifications protocol.
///
Expand Down
Loading