Skip to content

Commit

Permalink
chore(eth-websocket): remove some unnecessary wrappers (#2291)
Browse files Browse the repository at this point in the history
* remove unnecessary Arc<

The inners are already `Arc<`ed

* eth websocket: avoid locking control message sender and clone it instead

* review(sami): move tx declaration close to where it's being used

* review(sami): free rx end out of the Arc

and arc the entire controller channel instead
  • Loading branch information
mariocynicys authored Dec 26, 2024
1 parent 7c4bc27 commit ae5c6c1
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions mm2src/coins/eth/web3_transport/websocket_transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ pub struct WebsocketTransport {

#[derive(Debug)]
struct ControllerChannel {
tx: Arc<AsyncMutex<UnboundedSender<ControllerMessage>>>,
rx: Arc<AsyncMutex<UnboundedReceiver<ControllerMessage>>>,
tx: UnboundedSender<ControllerMessage>,
rx: AsyncMutex<UnboundedReceiver<ControllerMessage>>,
}

enum ControllerMessage {
Expand Down Expand Up @@ -86,11 +86,10 @@ impl WebsocketTransport {
node,
event_handlers,
request_id: Arc::new(AtomicUsize::new(1)),
controller_channel: ControllerChannel {
tx: Arc::new(AsyncMutex::new(req_tx)),
rx: Arc::new(AsyncMutex::new(req_rx)),
}
.into(),
controller_channel: Arc::new(ControllerChannel {
tx: req_tx,
rx: AsyncMutex::new(req_rx),
}),
connection_guard: Arc::new(AsyncMutex::new(())),
proxy_sign_keypair: None,
last_request_failed: Arc::new(AtomicBool::new(false)),
Expand Down Expand Up @@ -298,7 +297,7 @@ impl WebsocketTransport {
}

pub(crate) async fn stop_connection_loop(&self) {
let mut tx = self.controller_channel.tx.lock().await;
let mut tx = self.controller_channel.tx.clone();
tx.send(ControllerMessage::Close)
.await
.expect("receiver channel must be alive");
Expand Down Expand Up @@ -357,12 +356,11 @@ async fn send_request(
serialized_request = serde_json::to_string(&wrapper)?;
}

let mut tx = transport.controller_channel.tx.lock().await;

let (notification_sender, notification_receiver) = oneshot::channel::<Vec<u8>>();

event_handlers.on_outgoing_request(&request_bytes);

let mut tx = transport.controller_channel.tx.clone();
tx.send(ControllerMessage::Request(WsRequest {
request_id,
serialized_request,
Expand Down

0 comments on commit ae5c6c1

Please sign in to comment.