Skip to content

Commit

Permalink
Remove Arc
Browse files Browse the repository at this point in the history
  • Loading branch information
xgreenx committed Jan 6, 2024
1 parent 4711528 commit 8ca11b1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 26 deletions.
23 changes: 9 additions & 14 deletions crates/services/p2p/src/p2p_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ use crate::{
FuelBehaviour,
FuelBehaviourEvent,
},
codecs::{
postcard::PostcardCodec,
GossipsubCodec,
},
config::{
build_transport_function,
Config,
Expand All @@ -14,6 +18,7 @@ use crate::{
},
topics::GossipsubTopics,
},
heartbeat::HeartbeatEvent,
peer_manager::{
PeerManager,
Punisher,
Expand Down Expand Up @@ -57,19 +62,9 @@ use libp2p::{
SwarmBuilder,
};
use libp2p_gossipsub::PublishError;

use crate::{
codecs::{
postcard::PostcardCodec,
GossipsubCodec,
RequestResponseConverter,
},
heartbeat::HeartbeatEvent,
};
use rand::seq::IteratorRandom;
use std::{
collections::HashMap,
sync::Arc,
time::Duration,
};
use tracing::{
Expand Down Expand Up @@ -573,11 +568,11 @@ impl FuelP2PService {
(
ResponseChannelItem::Block(channel),
ResponseMessage::Block(block),
) => channel.send(block.map(|b| Arc::into_inner(b).expect("There are not other references, we just received this from the network"))).is_ok(),
) => channel.send(block).is_ok(),
(
ResponseChannelItem::Transactions(channel),
ResponseMessage::Transactions(transactions),
) => channel.send(transactions.map(|b| Arc::into_inner(b).expect("There are not other references, we just received this from the network"))).is_ok(),
) => channel.send(transactions).is_ok(),
(
ResponseChannelItem::SealedHeaders(channel),
ResponseMessage::SealedHeaders(headers),
Expand Down Expand Up @@ -1579,7 +1574,7 @@ mod tests {
consensus: Consensus::PoA(PoAConsensus::new(Default::default())),
};

let _ = node_b.send_response_msg(*request_id, ResponseMessage::Block(Some(Arc::new(sealed_block))));
let _ = node_b.send_response_msg(*request_id, ResponseMessage::Block(Some(sealed_block)));
}
RequestMessage::SealedHeaders(range) => {
let sealed_headers: Vec<_> = arbitrary_headers_for_range(range.clone());
Expand All @@ -1589,7 +1584,7 @@ mod tests {
RequestMessage::Transactions(_) => {
let txs = (0..5).map(|_| Transaction::default_test_tx()).collect();
let transactions = vec![Transactions(txs)];
let _ = node_b.send_response_msg(*request_id, ResponseMessage::Transactions(Some(Arc::new(transactions))));
let _ = node_b.send_response_msg(*request_id, ResponseMessage::Transactions(Some(transactions)));
}
}
}
Expand Down
12 changes: 4 additions & 8 deletions crates/services/p2p/src/request_response/messages.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
use std::{
ops::Range,
sync::Arc,
};

use fuel_core_types::{
blockchain::{
SealedBlock,
Expand All @@ -16,6 +11,7 @@ use serde::{
Deserialize,
Serialize,
};
use std::ops::Range;
use thiserror::Error;
use tokio::sync::oneshot;

Expand All @@ -40,11 +36,11 @@ pub enum ResponseChannelItem {
Transactions(oneshot::Sender<Option<Vec<Transactions>>>),
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Serialize, Deserialize)]
pub enum ResponseMessage {
Block(Option<Arc<SealedBlock>>),
Block(Option<SealedBlock>),
SealedHeaders(Option<Vec<SealedBlockHeader>>),
Transactions(Option<Arc<Vec<Transactions>>>),
Transactions(Option<Vec<Transactions>>),
}

#[derive(Debug, Error)]
Expand Down
6 changes: 2 additions & 4 deletions crates/services/p2p/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,8 +566,7 @@ where
match request_message {
RequestMessage::Block(block_height) => {
match self.db.get_sealed_block(&block_height) {
Ok(maybe_block) => {
let response = maybe_block.map(Arc::new);
Ok(response) => {
let _ = self.p2p_service.send_response_msg(request_id, ResponseMessage::Block(response));
},
Err(e) => {
Expand All @@ -580,8 +579,7 @@ where
}
RequestMessage::Transactions(range) => {
match self.db.get_transactions(range.clone()) {
Ok(maybe_transactions) => {
let response = maybe_transactions.map(Arc::new);
Ok(response) => {
let _ = self.p2p_service.send_response_msg(request_id, ResponseMessage::Transactions(response));
},
Err(e) => {
Expand Down

0 comments on commit 8ca11b1

Please sign in to comment.