Browse Source

Handle incoming InvalidOrderId in setup_taker::Actor

chore/leaner-release-process
Lucas Soriano del Pino 3 years ago
parent
commit
f9cd6cb5d5
No known key found for this signature in database GPG Key ID: EE611E973A1530E7
  1. 12
      daemon/src/connection.rs
  2. 36
      daemon/src/setup_taker.rs
  3. 14
      daemon/src/taker_cfd.rs

12
daemon/src/connection.rs

@ -191,7 +191,7 @@ impl Actor {
},
wire::MakerToTaker::RejectOrder(order_id) => match self.setup_actors.get(&order_id) {
Some(addr) => {
let _ = addr.send(setup_taker::Rejected).await;
let _ = addr.send(setup_taker::Rejected::without_reason()).await;
}
None => {
tracing::warn!(%order_id, "No active contract setup");
@ -207,6 +207,16 @@ impl Actor {
}
}
}
wire::MakerToTaker::InvalidOrderId(order_id) => {
match self.setup_actors.get(&order_id) {
Some(addr) => {
let _ = addr.send(setup_taker::Rejected::invalid_order_id()).await;
}
None => {
tracing::warn!(%order_id, "No active contract setup");
}
}
}
other => {
// this one should go to the taker cfd actor
log_error!(self.maker_to_taker.send(other));

36
daemon/src/setup_taker.rs

@ -107,11 +107,16 @@ impl Actor {
Ok(())
}
fn handle(&mut self, _: Rejected, ctx: &mut xtra::Context<Self>) -> Result<()> {
fn handle(&mut self, msg: Rejected, ctx: &mut xtra::Context<Self>) -> Result<()> {
let order_id = self.order.id;
tracing::info!(%order_id, "Order got rejected");
if msg.is_invalid_order {
tracing::error!(%order_id, "Rejection reason: Invalid order ID");
}
self.on_completed
.send(Completed::Rejected {
order_id: self.order.id,
})
.send(Completed::Rejected { order_id })
.await?;
ctx.stop();
@ -190,7 +195,11 @@ pub struct Started(pub OrderId);
/// Message sent from the `connection::Actor` to the
/// `setup_taker::Actor` to notify that the order taken was rejected
/// by the maker.
pub struct Rejected;
pub struct Rejected {
/// Used to indicate whether the rejection stems from the order ID
/// not being recognised by the maker.
is_invalid_order: bool,
}
/// Message sent from the spawned task to `setup_taker::Actor` to
/// notify that the contract setup has finished successfully.
@ -206,6 +215,23 @@ pub struct SetupFailed {
error: anyhow::Error,
}
impl Rejected {
/// Order was rejected by the maker for not specific reason.
pub fn without_reason() -> Self {
Rejected {
is_invalid_order: false,
}
}
/// Order was rejected by the maker because it did not recognise
/// the order ID provided.
pub fn invalid_order_id() -> Self {
Rejected {
is_invalid_order: true,
}
}
}
impl xtra::Message for Started {
type Result = ();
}

14
daemon/src/taker_cfd.rs

@ -227,14 +227,6 @@ where
Ok(())
}
async fn handle_invalid_order_id(&mut self, order_id: OrderId) -> Result<()> {
tracing::debug!(%order_id, "Invalid order ID");
self.append_cfd_state_rejected(order_id).await?;
Ok(())
}
}
impl<O, M, W> Actor<O, M, W> {
@ -719,9 +711,6 @@ where
wire::MakerToTaker::RejectSettlement(order_id) => {
log_error!(self.handle_settlement_rejected(order_id))
}
wire::MakerToTaker::InvalidOrderId(order_id) => {
log_error!(self.handle_invalid_order_id(order_id))
}
wire::MakerToTaker::ConfirmRollOver {
order_id,
oracle_event_id,
@ -739,7 +728,8 @@ where
}
wire::MakerToTaker::ConfirmOrder(_)
| wire::MakerToTaker::RejectOrder(_)
| wire::MakerToTaker::Protocol { .. } => {
| wire::MakerToTaker::Protocol { .. }
| wire::MakerToTaker::InvalidOrderId(_) => {
unreachable!("These messages should be sent to the `setup_taker::Actor`")
}
}

Loading…
Cancel
Save