From ad4c2720bd255624f9e97f0900c491e485bfb724 Mon Sep 17 00:00:00 2001 From: Mariusz Klochowicz Date: Fri, 22 Oct 2021 13:46:18 +1030 Subject: [PATCH] Use spawn_fallible inside maker_inc_connections to log errors Preparation for removing log_error! macro from this actor. --- daemon/src/maker_cfd.rs | 44 +++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/daemon/src/maker_cfd.rs b/daemon/src/maker_cfd.rs index 39fddea..04b4fb0 100644 --- a/daemon/src/maker_cfd.rs +++ b/daemon/src/maker_cfd.rs @@ -8,6 +8,7 @@ use crate::model::cfd::{ }; use crate::model::{TakerId, Usd}; use crate::monitor::MonitorParams; +use crate::tokio_ext::spawn_fallible; use crate::wallet::Wallet; use crate::{log_error, maker_inc_connections, monitor, oracle, setup_contract, wire}; use anyhow::{Context as _, Result}; @@ -574,12 +575,18 @@ where // Use `.send` here to ensure we only continue once the message has been sent // Nothing done after this call should be able to fail, otherwise we notified the taker, but // might not transition to `Active` ourselves! - self.takers - .send(maker_inc_connections::TakerMessage { - taker_id, - command: TakerCommand::NotifyOrderAccepted { id: order_id }, - }) - .await?; + spawn_fallible::<_, anyhow::Error>({ + let takers = self.takers.clone(); + async move { + takers + .send(maker_inc_connections::TakerMessage { + taker_id, + command: TakerCommand::NotifyOrderAccepted { id: order_id }, + }) + .await?; + Ok(()) + } + }); // 5. Spawn away the contract setup let (sender, receiver) = mpsc::unbounded(); @@ -751,15 +758,22 @@ where .await? .with_context(|| format!("Announcement {} not found", oracle_event_id))?; - self.takers - .send(maker_inc_connections::TakerMessage { - taker_id, - command: TakerCommand::NotifyRollOverAccepted { - id: proposal.order_id, - oracle_event_id, - }, - }) - .await?; + spawn_fallible::<_, anyhow::Error>({ + let takers = self.takers.clone(); + let order_id = proposal.order_id; + async move { + takers + .send(maker_inc_connections::TakerMessage { + taker_id, + command: TakerCommand::NotifyRollOverAccepted { + id: order_id, + oracle_event_id, + }, + }) + .await?; + Ok(()) + } + }); self.oracle_actor .do_send_async(oracle::MonitorAttestation {