diff --git a/daemon/src/address_map.rs b/daemon/src/address_map.rs index 8b9dd9b..d81981d 100644 --- a/daemon/src/address_map.rs +++ b/daemon/src/address_map.rs @@ -46,7 +46,7 @@ where } /// Sends a message to the actor stored with the given key. - pub async fn send(&self, key: &K, msg: M) -> bool + pub async fn send(&self, key: &K, msg: M) -> Result<(), NotConnected> where M: Message, A: Handler, @@ -56,15 +56,17 @@ where addr.send(msg) .await .expect("we checked that we are connected"); - - true + Ok(()) } - Some(_) => false, - None => false, + _ => Err(NotConnected), } } } +#[derive(thiserror::Error, Debug)] +#[error("Receiving actor is down")] +pub struct NotConnected; + /// A message to notify that an actor instance is stopping. pub struct Stopping { pub me: Address, diff --git a/daemon/src/connection.rs b/daemon/src/connection.rs index 6663b24..0130ad6 100644 --- a/daemon/src/connection.rs +++ b/daemon/src/connection.rs @@ -369,7 +369,12 @@ impl Actor { } } wire::MakerToTaker::Settlement { order_id, msg } => { - if !self.collab_settlement_actors.send(&order_id, msg).await { + if self + .collab_settlement_actors + .send(&order_id, msg) + .await + .is_err() + { tracing::warn!(%order_id, "No active collaborative settlement"); } } @@ -377,28 +382,30 @@ impl Actor { order_id, oracle_event_id, } => { - if !self + if self .rollover_actors .send( &order_id, rollover_taker::RollOverAccepted { oracle_event_id }, ) .await + .is_err() { tracing::warn!(%order_id, "No active rollover"); } } wire::MakerToTaker::RejectRollOver(order_id) => { - if !self + if self .rollover_actors .send(&order_id, rollover_taker::RollOverRejected) .await + .is_err() { tracing::warn!(%order_id, "No active rollover"); } } wire::MakerToTaker::RollOverProtocol { order_id, msg } => { - if !self.rollover_actors.send(&order_id, msg).await { + if self.rollover_actors.send(&order_id, msg).await.is_err() { tracing::warn!(%order_id, "No active rollover"); } } diff --git a/daemon/src/maker_cfd.rs b/daemon/src/maker_cfd.rs index 2807288..fa3e026 100644 --- a/daemon/src/maker_cfd.rs +++ b/daemon/src/maker_cfd.rs @@ -523,13 +523,10 @@ impl Actor { let mut conn = self.db.acquire().await?; let mut cfd = load_cfd_by_order_id(order_id, &mut conn).await?; - if !self - .setup_actors + self.setup_actors .send(&order_id, setup_maker::Accepted) .await - { - anyhow::bail!("No active contract setup for order {}", order_id); - } + .with_context(|| format!("No active contract setup for order {}", order_id))?; cfd.state = CfdState::contract_setup(); append_cfd_state(&cfd, &mut conn, &self.projection_actor).await?;