diff --git a/daemon/src/maker_cfd.rs b/daemon/src/maker_cfd.rs index d2644cd..a6260ef 100644 --- a/daemon/src/maker_cfd.rs +++ b/daemon/src/maker_cfd.rs @@ -16,6 +16,8 @@ use bdk::bitcoin::secp256k1::schnorrsig; use cfd_protocol::secp256k1_zkp::Signature; use futures::channel::mpsc; use futures::{future, SinkExt}; +use rocket_db_pools::sqlx::Sqlite; +use sqlx::pool::PoolConnection; use std::collections::HashMap; use std::time::SystemTime; use tokio::sync::watch; @@ -500,7 +502,13 @@ impl Actor { command: TakerCommand::NotifyInvalidOrderId { id: order_id }, }) .await?; - // TODO: Return an error here? + + // An outdated order on the taker side does not require any state change on the + // maker. notifying the taker with a specific message should be sufficient. + // Since this is a scenario that we should rarely see we log + // a warning to be sure we don't trigger this code path frequently. + tracing::warn!("Taker tried to take order with outdated id {}", order_id); + return Ok(()); } }; @@ -513,12 +521,8 @@ impl Actor { current_order.min_quantity, current_order.max_quantity ); - self.takers - .do_send_async(maker_inc_connections::TakerMessage { - taker_id, - command: TakerCommand::NotifyOrderRejected { id: order_id }, - }) - .await?; + + self.reject_order(taker_id, order_id, conn).await?; return Ok(()); } @@ -654,6 +658,22 @@ impl Actor { } }; + self.reject_order(taker_id, order_id, conn).await?; + + Ok(()) + } + + /// Reject an order + /// + /// Rejection includes removing the order and saving in the db that it was rejected. + /// In the current model it is essential to remove the order because a taker + /// that received a rejection cannot communicate with the maker until a new order is published. + async fn reject_order( + &mut self, + taker_id: TakerId, + order_id: OrderId, + mut conn: PoolConnection, + ) -> Result<()> { // Update order in db insert_new_cfd_state_by_order_id( order_id,