Browse Source

Merge #336

336: Rejection always remove order r=da-kami a=da-kami

Fixes https://github.com/comit-network/hermes/issues/324 https://github.com/comit-network/hermes/issues/323

Since https://github.com/comit-network/hermes/issues/323 could not be reproduce I assume it is (already) fixed. Might be that https://github.com/comit-network/hermes/issues/323 was caused by a combination of problems.

Co-authored-by: Daniel Karzel <daniel@comit.network>
refactor/no-log-handler
bors[bot] 3 years ago
committed by GitHub
parent
commit
6d14aeb2c7
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 34
      daemon/src/maker_cfd.rs

34
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<Sqlite>,
) -> Result<()> {
// Update order in db
insert_new_cfd_state_by_order_id(
order_id,

Loading…
Cancel
Save