From a253a625827eeb08fe4dbb04edc2cac86a1ddfdc Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Mon, 15 Nov 2021 18:30:43 +1100 Subject: [PATCH] Migrate `do_send_async` to `send` First clean up state, then attempt to send the message. If it fails, we bubble up but leave things in a consistent state. --- daemon/src/maker_cfd.rs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/daemon/src/maker_cfd.rs b/daemon/src/maker_cfd.rs index 18f0a8a..d5a3b96 100644 --- a/daemon/src/maker_cfd.rs +++ b/daemon/src/maker_cfd.rs @@ -375,15 +375,18 @@ where let taker_id = self.get_taker_id_of_proposal(&order_id)?; + // clean-up state ahead of sending to ensure consistency in case we fail to deliver the + // message + self.remove_pending_proposal(&order_id) + .context("rejected settlement")?; + self.takers - .do_send_async(maker_inc_connections::TakerMessage { + .send(maker_inc_connections::TakerMessage { taker_id, command: TakerCommand::NotifySettlementRejected { id: order_id }, }) - .await?; + .await??; - self.remove_pending_proposal(&order_id) - .context("rejected settlement")?; Ok(()) } @@ -404,15 +407,18 @@ where } }; + // clean-up state ahead of sending to ensure consistency in case we fail to deliver the + // message + self.remove_pending_proposal(&order_id) + .context("rejected roll_over")?; + self.takers - .do_send_async(maker_inc_connections::TakerMessage { + .send(maker_inc_connections::TakerMessage { taker_id, command: TakerCommand::NotifyRollOverRejected { id: order_id }, }) - .await?; + .await??; - self.remove_pending_proposal(&order_id) - .context("rejected roll_over")?; Ok(()) } }