Skip to content

Commit

Permalink
Merge #820
Browse files Browse the repository at this point in the history
820: NO-TICKET: upgrade libp2p deflate r=Fraser999 a=Fraser999

This fixes security advisory on libp2p-deflate by upgrading the version of libp2p. See libp2p/rust-libp2p#1932.

Co-authored-by: Michał Papierski <michal@casperlabs.io>
Co-authored-by: Fraser Hutchison <fraser@casperlabs.io>
  • Loading branch information
3 people authored Jan 28, 2021
2 parents 26630fb + 7c94d4e commit 5f8d03a
Show file tree
Hide file tree
Showing 19 changed files with 506 additions and 374 deletions.
501 changes: 303 additions & 198 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jemallocator = "0.3.2"
jemalloc-ctl = "0.3.3"
k256 = { version = "0.4.2", features = ["ecdsa", "zeroize"] }
libc = "0.2.66"
libp2p = { version = "0.29.1", default-features = false, features = ["deflate", "dns", "floodsub", "gossipsub", "identify", "kad", "mdns-tokio", "mplex", "noise", "ping", "request-response", "tcp-tokio", "uds", "yamux"] }
libp2p = { version = "0.34.0", default-features = false, features = ["deflate", "dns", "floodsub", "gossipsub", "identify", "kad", "mdns", "mplex", "noise", "ping", "request-response", "tcp-tokio", "uds", "yamux"] }
linked-hash-map = "0.5.3"
lmdb = "0.8.0"
log = { version = "0.4.8", features = ["std", "serde", "kv_unstable"] }
Expand Down
32 changes: 18 additions & 14 deletions node/src/components/block_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use std::{
};

use datasize::DataSize;
use derive_more::{Display, From};
use derive_more::Display;
use semver::Version;
use smallvec::{smallvec, SmallVec};
use tracing::error;
Expand All @@ -37,11 +37,10 @@ use keyed_counter::KeyedCounter;
use super::fetcher::FetchResult;

/// Block validator component event.
#[derive(Debug, From, Display)]
#[derive(Debug, Display)]
pub enum Event<T, I> {
/// A request made of the block validator component.
#[from]
Request(BlockValidationRequest<T, I>),
Request(Box<BlockValidationRequest<T, I>>),

/// A deploy has been successfully found.
#[display(fmt = "deploy {} found", _0)]
Expand All @@ -57,6 +56,12 @@ pub enum Event<T, I> {
Loaded { chainspec: Arc<Chainspec> },
}

impl<T, I> From<BlockValidationRequest<T, I>> for Event<T, I> {
fn from(request: BlockValidationRequest<T, I>) -> Self {
Event::Request(Box::new(request))
}
}

/// State of the current process of block validation.
///
/// Tracks whether or not there are deploys still missing and who is interested in the final result.
Expand Down Expand Up @@ -100,12 +105,14 @@ where
{
let mut effects = Effects::new();
match event {
Event::Request(BlockValidationRequest {
block,
sender,
responder,
block_timestamp,
}) => {
Event::Request(request) => {
let BlockValidationRequest {
block,
sender,
responder,
block_timestamp,
} = *request;

let block_deploys = block
.deploys()
.iter()
Expand Down Expand Up @@ -300,10 +307,7 @@ where
}
self.state = BlockValidatorState::Ready(new_ready_state);
}
(
BlockValidatorState::Loading(requests),
request @ Event::Request(BlockValidationRequest { .. }),
) => {
(BlockValidatorState::Loading(requests), request @ Event::Request(_)) => {
requests.push(request);
}
(BlockValidatorState::Loading(_), _deploy_found_or_missing) => {
Expand Down
12 changes: 5 additions & 7 deletions node/src/components/fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub trait ItemFetcher<T: Item + 'static> {
responders
.entry(id)
.or_default()
.entry(peer.clone())
.entry(peer)
.or_default()
.push(responder);

Expand Down Expand Up @@ -113,7 +113,7 @@ pub trait ItemFetcher<T: Item + 'static> {
) -> Effects<Event<T>> {
match Message::new_get_request::<T>(&id) {
Ok(message) => {
let mut effects = effect_builder.send_message(peer.clone(), message).ignore();
let mut effects = effect_builder.send_message(peer, message).ignore();

effects.extend(
effect_builder
Expand Down Expand Up @@ -326,11 +326,9 @@ where
},
Event::GotRemotely { item, source } => {
match source {
Source::Peer(peer) => self.signal(
item.id(),
Some(FetchResult::FromPeer(item, peer.clone())),
peer,
),
Source::Peer(peer) => {
self.signal(item.id(), Some(FetchResult::FromPeer(item, peer)), peer)
}
Source::Client => {
// TODO - we could possibly also handle this case
Effects::new()
Expand Down
15 changes: 6 additions & 9 deletions node/src/components/fetcher/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ async fn should_fetch_from_local() {
network
.process_injected_effect_on(
node_id,
fetch_deploy(deploy_hash, node_id.clone(), Arc::clone(&fetched)),
fetch_deploy(deploy_hash, *node_id, Arc::clone(&fetched)),
)
.await;

Expand Down Expand Up @@ -340,14 +340,11 @@ async fn should_fetch_from_peer() {
network
.process_injected_effect_on(
node_without_deploy,
fetch_deploy(deploy_hash, node_with_deploy.clone(), Arc::clone(&fetched)),
fetch_deploy(deploy_hash, *node_with_deploy, Arc::clone(&fetched)),
)
.await;

let expected_result = Some(FetchResult::FromPeer(
Box::new(deploy),
node_with_deploy.clone(),
));
let expected_result = Some(FetchResult::FromPeer(Box::new(deploy), *node_with_deploy));
assert_settled(
node_without_deploy,
deploy_hash,
Expand Down Expand Up @@ -378,8 +375,8 @@ async fn should_timeout_fetch_from_peer() {
let deploy = Deploy::random(&mut rng);
let deploy_hash = *deploy.id();

let holding_node = node_ids[0].clone();
let requesting_node = node_ids[1].clone();
let holding_node = node_ids[0];
let requesting_node = node_ids[1];

// Store deploy on holding node.
store_deploy(&deploy, &holding_node, &mut network, None, &mut rng).await;
Expand All @@ -389,7 +386,7 @@ async fn should_timeout_fetch_from_peer() {
network
.process_injected_effect_on(
&requesting_node,
fetch_deploy(deploy_hash, holding_node.clone(), Arc::clone(&fetched)),
fetch_deploy(deploy_hash, holding_node, Arc::clone(&fetched)),
)
.await;

Expand Down
16 changes: 5 additions & 11 deletions node/src/components/gossiper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,7 @@ impl<T: Item + 'static, REv: ReactorEventT<T>> Gossiper<T, REv> {
return self.check_get_from_peer_timeout(effect_builder, item_id, holder);
}
};
let mut effects = effect_builder
.send_message(holder.clone(), request)
.ignore();
let mut effects = effect_builder.send_message(holder, request).ignore();
effects.extend(
effect_builder
.set_timeout(self.get_from_peer_timeout)
Expand All @@ -331,10 +329,10 @@ impl<T: Item + 'static, REv: ReactorEventT<T>> Gossiper<T, REv> {
) -> Effects<Event<T>> {
let action = if T::ID_IS_COMPLETE_ITEM {
self.table
.new_complete_data(&item_id, Some(sender.clone()))
.new_complete_data(&item_id, Some(sender))
.map_or_else(|| GossipAction::Noop, GossipAction::ShouldGossip)
} else {
self.table.new_partial_data(&item_id, sender.clone())
self.table.new_partial_data(&item_id, sender)
};

match action {
Expand Down Expand Up @@ -371,7 +369,7 @@ impl<T: Item + 'static, REv: ReactorEventT<T>> Gossiper<T, REv> {
item_id,
is_already_held: false,
};
let mut effects = effect_builder.send_message(sender.clone(), reply).ignore();
let mut effects = effect_builder.send_message(sender, reply).ignore();
effects.extend(
effect_builder
.set_timeout(self.get_from_peer_timeout)
Expand Down Expand Up @@ -408,11 +406,7 @@ impl<T: Item + 'static, REv: ReactorEventT<T>> Gossiper<T, REv> {
if !T::ID_IS_COMPLETE_ITEM {
// `sender` doesn't hold the full item; get the item from the component responsible
// for holding it, then send it to `sender`.
effects.extend((self.get_from_holder)(
effect_builder,
item_id,
sender.clone(),
));
effects.extend((self.get_from_holder)(effect_builder, item_id, sender));
}
self.table.we_infected(&item_id, sender)
};
Expand Down
Loading

0 comments on commit 5f8d03a

Please sign in to comment.