From dd374474e9823843cf64fb0cf17246401eacee54 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 1 Dec 2021 11:43:02 +1100 Subject: [PATCH] Remove error case from updating projection Not finding a proposal for a specific error does not need to be bubbled up to the caller. --- daemon/src/maker_cfd.rs | 8 ++++---- daemon/src/projection.rs | 38 ++++++++++++++++++-------------------- daemon/src/taker_cfd.rs | 8 ++++---- 3 files changed, 26 insertions(+), 28 deletions(-) diff --git a/daemon/src/maker_cfd.rs b/daemon/src/maker_cfd.rs index 5fb064b..cd47680 100644 --- a/daemon/src/maker_cfd.rs +++ b/daemon/src/maker_cfd.rs @@ -187,7 +187,7 @@ impl Actor { .insert(proposal.order_id, (new_proposal.clone(), taker_id)); self.projection_actor .send(try_into_update_rollover_proposal(new_proposal)?) - .await??; + .await?; Ok(()) } @@ -211,7 +211,7 @@ impl Actor { .insert(proposal.order_id, (new_proposal.clone(), taker_id)); self.projection_actor .send(try_into_update_settlement_proposal(new_proposal)?) - .await??; + .await?; Ok(()) } @@ -269,7 +269,7 @@ impl Actor { order: *order_id, proposal: None, }) - .await?? + .await? } UpdateCfdProposal::RollOverProposal { .. } => { self.projection_actor @@ -277,7 +277,7 @@ impl Actor { order: *order_id, proposal: None, }) - .await?? + .await? } } } else { diff --git a/daemon/src/projection.rs b/daemon/src/projection.rs index f5fefd2..841d9f5 100644 --- a/daemon/src/projection.rs +++ b/daemon/src/projection.rs @@ -115,12 +115,12 @@ impl State { temp.into() } - pub fn amend_settlement_proposal(&mut self, proposal: UpdateSettlementProposal) -> Result<()> { + pub fn amend_settlement_proposal(&mut self, proposal: UpdateSettlementProposal) { let order = proposal.order; self.amend_cfd_proposal(order, proposal.into()) } - pub fn amend_rollover_proposal(&mut self, proposal: UpdateRollOverProposal) -> Result<()> { + pub fn amend_rollover_proposal(&mut self, proposal: UpdateRollOverProposal) { let order = proposal.order; self.amend_cfd_proposal(order, proposal.into()) } @@ -133,21 +133,21 @@ impl State { let _ = std::mem::replace(&mut self.cfds, cfds); } - fn amend_cfd_proposal( - &mut self, - order: OrderId, - proposal: Option, - ) -> Result<()> { + fn amend_cfd_proposal(&mut self, order: OrderId, proposal: Option) { if let Some(proposal) = proposal { self.proposals.insert(order, proposal); tracing::trace!(%order, "Cfd proposal got updated"); - } else { - if self.proposals.remove(&order).is_none() { - anyhow::bail!("Could not find proposal with order id: {}", &order) - } - tracing::trace!(%order, "Removed cfd proposal"); - }; - Ok(()) + + return; + } + + if self.proposals.remove(&order).is_none() { + tracing::trace!(%order, "Cannot remove cfd proposal: unknown"); + + return; + } + + tracing::trace!(%order, "Removed cfd proposal"); } } @@ -172,15 +172,13 @@ impl Actor { .connected_takers .send(msg.0.iter().map(|x| x.into()).collect_vec()); } - fn handle(&mut self, msg: UpdateSettlementProposal) -> Result<()> { - self.state.amend_settlement_proposal(msg)?; + fn handle(&mut self, msg: UpdateSettlementProposal) { + self.state.amend_settlement_proposal(msg); let _ = self.tx.cfds.send(self.state.to_cfds()); - Ok(()) } - fn handle(&mut self, msg: UpdateRollOverProposal) -> Result<()> { - self.state.amend_rollover_proposal(msg)?; + fn handle(&mut self, msg: UpdateRollOverProposal) { + self.state.amend_rollover_proposal(msg); let _ = self.tx.cfds.send(self.state.to_cfds()); - Ok(()) } } diff --git a/daemon/src/taker_cfd.rs b/daemon/src/taker_cfd.rs index ddc6a15..19bd120 100644 --- a/daemon/src/taker_cfd.rs +++ b/daemon/src/taker_cfd.rs @@ -122,7 +122,7 @@ impl Actor { order: *order_id, proposal: None, }) - .await?? + .await? } UpdateCfdProposal::RollOverProposal { .. } => { self.projection_actor @@ -130,7 +130,7 @@ impl Actor { order: *order_id, proposal: None, }) - .await?? + .await? } } } else { @@ -188,7 +188,7 @@ where .insert(proposal.order_id, new_proposal.clone()); self.projection_actor .send(try_into_update_rollover_proposal(new_proposal)?) - .await??; + .await?; self.conn_actor .send(wire::TakerToMaker::ProposeRollOver { @@ -240,7 +240,7 @@ impl Actor { .insert(proposal.order_id, new_proposal.clone()); self.projection_actor .send(try_into_update_settlement_proposal(new_proposal)?) - .await??; + .await?; self.conn_actor .send(wire::TakerToMaker::ProposeSettlement {