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

use try_send instead of send in protocol #3983

Merged
merged 2 commits into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion massa-node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ tracing = { version = "0.1", features = [
"max_level_debug",
"release_max_level_debug",
] }
peernet = { git = "https://github.com/massalabs/PeerNet", branch = "remove_old_method" }
peernet = { git = "https://github.com/massalabs/PeerNet", rev = "0ad0e2e" }
tracing-subscriber = "0.3"
paw = "1.0"
structopt = { version = "0.3", features = ["paw"] }
Expand Down
2 changes: 1 addition & 1 deletion massa-protocol-exports/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ thiserror = "1.0"
nom = "7.1"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
peernet = { git = "https://github.com/massalabs/PeerNet", branch = "remove_old_method" }
peernet = { git = "https://github.com/massalabs/PeerNet", rev = "0ad0e2e" }
tempfile = { version = "3.3", optional = true } # use with testing feature
mockall = "0.11.4"

Expand Down
2 changes: 1 addition & 1 deletion massa-protocol-worker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ crossbeam = "0.8"
serde_json = "1.0"
nom = "7.1"
num_enum = "0.5"
peernet = { git = "https://github.com/massalabs/PeerNet", branch = "remove_old_method" }
peernet = { git = "https://github.com/massalabs/PeerNet", rev = "0ad0e2e" }
tempfile = { version = "3.3", optional = true } # use with testing feature
rayon = "1.7.0"
lru = "0.10.0"
Expand Down
2 changes: 1 addition & 1 deletion massa-protocol-worker/src/connectivity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ pub(crate) fn start_connectivity_thread(
let peers: HashMap<PeerId, (SocketAddr, PeerConnectionType)> = network_controller.get_active_connections().get_peers_connected().into_iter().map(|(peer_id, peer)| {
(peer_id, (peer.0, peer.1))
}).collect();
responder.send((stats, peers)).unwrap_or_else(|_| warn!("Failed to send stats to responder"));
responder.try_send((stats, peers)).unwrap_or_else(|_| warn!("Failed to send stats to responder"));
}
Err(_) => {
warn!("Channel to connectivity thread is closed. Stopping the protocol");
Expand Down
16 changes: 8 additions & 8 deletions massa-protocol-worker/src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl ProtocolController for ProtocolControllerImpl {
self.sender_block_handler
.as_ref()
.unwrap()
.send(BlockHandlerPropagationCommand::IntegratedBlock { block_id, storage })
.try_send(BlockHandlerPropagationCommand::IntegratedBlock { block_id, storage })
.map_err(|_| ProtocolError::ChannelError("integrated_block command send error".into()))
}

Expand All @@ -85,7 +85,7 @@ impl ProtocolController for ProtocolControllerImpl {
self.sender_block_handler
.as_ref()
.unwrap()
.send(BlockHandlerPropagationCommand::AttackBlockDetected(
.try_send(BlockHandlerPropagationCommand::AttackBlockDetected(
block_id,
))
.map_err(|_| {
Expand Down Expand Up @@ -117,7 +117,7 @@ impl ProtocolController for ProtocolControllerImpl {
self.sender_operation_handler
.as_ref()
.unwrap()
.send(OperationHandlerPropagationCommand::AnnounceOperations(
.try_send(OperationHandlerPropagationCommand::AnnounceOperations(
operations,
))
.map_err(|_| {
Expand All @@ -130,7 +130,7 @@ impl ProtocolController for ProtocolControllerImpl {
self.sender_endorsement_handler
.as_ref()
.unwrap()
.send(EndorsementHandlerPropagationCommand::PropagateEndorsements(
.try_send(EndorsementHandlerPropagationCommand::PropagateEndorsements(
endorsements,
))
.map_err(|_| {
Expand All @@ -151,7 +151,7 @@ impl ProtocolController for ProtocolControllerImpl {
self.sender_connectivity_thread
.as_ref()
.unwrap()
.send(ConnectivityCommand::GetStats { responder: sender })
.try_send(ConnectivityCommand::GetStats { responder: sender })
.map_err(|_| ProtocolError::ChannelError("get_stats command send error".into()))?;
receiver
.recv_timeout(Duration::from_secs(10))
Expand All @@ -162,15 +162,15 @@ impl ProtocolController for ProtocolControllerImpl {
self.sender_peer_management_thread
.as_ref()
.unwrap()
.send(PeerManagementCmd::Ban(peer_ids))
.try_send(PeerManagementCmd::Ban(peer_ids))
.map_err(|_| ProtocolError::ChannelError("ban_peers command send error".into()))
}

fn unban_peers(&self, peer_ids: Vec<PeerId>) -> Result<(), ProtocolError> {
self.sender_peer_management_thread
.as_ref()
.unwrap()
.send(PeerManagementCmd::Unban(peer_ids))
.try_send(PeerManagementCmd::Unban(peer_ids))
.map_err(|_| ProtocolError::ChannelError("unban_peers command send error".into()))
}

Expand All @@ -179,7 +179,7 @@ impl ProtocolController for ProtocolControllerImpl {
self.sender_peer_management_thread
.as_ref()
.unwrap()
.send(PeerManagementCmd::GetBootstrapPeers { responder: sender })
.try_send(PeerManagementCmd::GetBootstrapPeers { responder: sender })
.map_err(|_| {
ProtocolError::ChannelError("get_bootstrap_peers command send error".into())
})?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ impl PropagationThread {
fn ban_node(&mut self, peer_id: &PeerId) -> Result<(), ProtocolError> {
massa_trace!("ban node from retrieval thread", { "peer_id": peer_id.to_string() });
self.peer_cmd_sender
.send(PeerManagementCmd::Ban(vec![peer_id.clone()]))
.try_send(PeerManagementCmd::Ban(vec![peer_id.clone()]))
.map_err(|err| ProtocolError::SendError(err.to_string()))
}
}
Expand Down
4 changes: 2 additions & 2 deletions massa-protocol-worker/src/handlers/block_handler/retrieval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ impl RetrievalThread {
fn ban_node(&mut self, peer_id: &PeerId) -> Result<(), ProtocolError> {
massa_trace!("ban node from retrieval thread", { "peer_id": peer_id.to_string() });
self.peer_cmd_sender
.send(PeerManagementCmd::Ban(vec![peer_id.clone()]))
.try_send(PeerManagementCmd::Ban(vec![peer_id.clone()]))
.map_err(|err| ProtocolError::SendError(err.to_string()))
}

Expand Down Expand Up @@ -1038,7 +1038,7 @@ impl RetrievalThread {
}
}
self.sender_propagation_ops
.send(OperationHandlerPropagationCommand::AnnounceOperations(
.try_send(OperationHandlerPropagationCommand::AnnounceOperations(
new_operations.keys().copied().collect(),
))
.map_err(|err| ProtocolError::ChannelError(err.to_string()))?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ impl RetrievalThread {
.collect()
};
endorsements_to_propagate.drop_endorsement_refs(&endorsements_to_not_propagate);
if let Err(err) = self.internal_sender.send(
if let Err(err) = self.internal_sender.try_send(
EndorsementHandlerPropagationCommand::PropagateEndorsements(
endorsements_to_propagate,
),
Expand All @@ -237,7 +237,7 @@ impl RetrievalThread {
fn ban_node(&mut self, peer_id: &PeerId) -> Result<(), ProtocolError> {
massa_trace!("ban node from retrieval thread", { "peer_id": peer_id.to_string() });
self.peer_cmd_sender
.send(PeerManagementCmd::Ban(vec![peer_id.clone()]))
.try_send(PeerManagementCmd::Ban(vec![peer_id.clone()]))
.map_err(|err| ProtocolError::SendError(err.to_string()))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ impl RetrievalThread {
.insert(Instant::now(), to_announce.clone());
self.storage.extend(ops_to_propagate);
self.internal_sender
.send(OperationHandlerPropagationCommand::AnnounceOperations(
.try_send(OperationHandlerPropagationCommand::AnnounceOperations(
to_announce,
))
.map_err(|err| ProtocolError::SendError(err.to_string()))?;
Expand Down Expand Up @@ -479,7 +479,7 @@ impl RetrievalThread {
fn ban_node(&mut self, peer_id: &PeerId) -> Result<(), ProtocolError> {
massa_trace!("ban node from retrieval thread", { "peer_id": peer_id.to_string() });
self.peer_cmd_sender
.send(PeerManagementCmd::Ban(vec![peer_id.clone()]))
.try_send(PeerManagementCmd::Ban(vec![peer_id.clone()]))
.map_err(|err| ProtocolError::SendError(err.to_string()))
}
}
Expand Down
4 changes: 2 additions & 2 deletions massa-protocol-worker/src/handlers/peer_handler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ impl PeerManagementHandler {
}).collect();
peers.push((peer_id.clone(), listeners));
}
if let Err(err) = responder.send(BootstrapPeers(peers)) {
if let Err(err) = responder.try_send(BootstrapPeers(peers)) {
warn!("error sending bootstrap peers: {:?}", err);
}
},
Expand Down Expand Up @@ -218,7 +218,7 @@ impl PeerManagementHandler {
&mut message,
)
.unwrap();
sender_msg.send((peer_id.clone(), message)).unwrap();
sender_msg.try_send((peer_id.clone(), message)).unwrap();
}

Self {
Expand Down
6 changes: 3 additions & 3 deletions massa-protocol-worker/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ impl PeerNetMessagesHandler<PeerId> for MessagesHandler {
}),
MessageTypeId::Endorsement => self
.sender_endorsements
.send((peer_id.clone(), data.to_vec()))
.try_send((peer_id.clone(), data.to_vec()))
.map_err(|err| {
PeerNetError::HandlerError.error(
"MessagesHandler",
Expand All @@ -263,7 +263,7 @@ impl PeerNetMessagesHandler<PeerId> for MessagesHandler {
}),
MessageTypeId::Operation => self
.sender_operations
.send((peer_id.clone(), data.to_vec()))
.try_send((peer_id.clone(), data.to_vec()))
.map_err(|err| {
PeerNetError::HandlerError.error(
"MessagesHandler",
Expand All @@ -272,7 +272,7 @@ impl PeerNetMessagesHandler<PeerId> for MessagesHandler {
}),
MessageTypeId::PeerManagement => self
.sender_peers
.send((peer_id.clone(), data.to_vec()))
.try_send((peer_id.clone(), data.to_vec()))
.map_err(|err| {
PeerNetError::HandlerError.error(
"MessagesHandler",
Expand Down
7 changes: 6 additions & 1 deletion massa-protocol-worker/src/tests/mock_network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,12 @@ impl ActiveConnectionsTrait for SharedMockActiveConnections {
message: Message,
_high_priority: bool,
) -> Result<(), massa_protocol_exports::ProtocolError> {
let _ = self.read().connections.get(peer_id).unwrap().send(message);
let _ = self
.read()
.connections
.get(peer_id)
.unwrap()
.try_send(message);
Ok(())
}

Expand Down
2 changes: 1 addition & 1 deletion massa-protocol-worker/src/wrap_network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl ActiveConnectionsTrait for SharedActiveConnections<PeerId> {
if let Some(connection) = self.read().connections.get(peer_id) {
connection
.send_channels
.send(message_serializer, message, high_priority)
.try_send(message_serializer, message, high_priority)
.map_err(|err| ProtocolError::SendError(err.to_string()))
} else {
Err(ProtocolError::SendError(
Expand Down