From 1764f81001bac3d0b6e09961e8498ac2eafced77 Mon Sep 17 00:00:00 2001 From: Daniel Karzel Date: Wed, 27 Oct 2021 17:34:01 +1100 Subject: [PATCH] Only transition maker to `ContractSetup` if we succeed to contract taker Stumbled on this when writing actor tests. We cannot create a failing test for this code at the moment, because our current test framework does not allow us to test at this granulairty level. Nevertheless, we should fix this. Rational: If the maker is unable to contact the taker about the contract setup we fail now (previously we tried to continue). This means, that we should only transition the maker's cfd to the new state if we are able to contact the maker. --- daemon/src/maker_cfd.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/daemon/src/maker_cfd.rs b/daemon/src/maker_cfd.rs index 005f4fa..e514d39 100644 --- a/daemon/src/maker_cfd.rs +++ b/daemon/src/maker_cfd.rs @@ -574,12 +574,7 @@ where .await? .with_context(|| format!("Announcement {} not found", cfd.order.oracle_event_id))?; - // 3. Insert that we are in contract setup and refresh our own feed - cfd.state = CfdState::contract_setup(); - - append_cfd_state(&cfd, &mut conn, &self.cfd_feed_actor_inbox).await?; - - // 4. Notify the taker that we are ready for contract setup + // 3. Notify the taker that we are ready for contract setup // Use `.send` here to ensure we only continue once the message has been sent // Nothing done after this call should be able to fail, otherwise we notified the taker, but // might not transition to `Active` ourselves! @@ -590,6 +585,10 @@ where }) .await??; + // 4. Insert that we are in contract setup and refresh our own feed + cfd.state = CfdState::contract_setup(); + append_cfd_state(&cfd, &mut conn, &self.cfd_feed_actor_inbox).await?; + // 5. Spawn away the contract setup let (sender, receiver) = mpsc::unbounded(); let contract_future = setup_contract::new(