From 53fcd9224c77b7f3292d5ca27f7c0183fca939f2 Mon Sep 17 00:00:00 2001 From: Daniel Karzel Date: Tue, 9 Feb 2021 12:13:43 +1100 Subject: [PATCH] Give finding the refund tx priority over waiting for the punish transaction to be finalized. This was introduced due to a CI run, where Bob included tx_refund, but Alice had waited until T2 had expired, and then went for punishing Bob instead of refunding. Weirdly, Alice's punich transaction did not fail in that scenario. --- swap/src/protocol/alice/swap.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/swap/src/protocol/alice/swap.rs b/swap/src/protocol/alice/swap.rs index 1d7d5a79..97a542de 100644 --- a/swap/src/protocol/alice/swap.rs +++ b/swap/src/protocol/alice/swap.rs @@ -417,9 +417,16 @@ async fn run_until_internal( pin_mut!(punish_tx_finalised); pin_mut!(refund_tx_seen); - match select(punish_tx_finalised, refund_tx_seen).await { - Either::Left(_) => { - let state = AliceState::BtcPunished; + match select(refund_tx_seen, punish_tx_finalised).await { + Either::Left((published_refund_tx, _)) => { + let spend_key = extract_monero_private_key( + published_refund_tx, + tx_refund, + state3.s_a, + state3.a.clone(), + state3.S_b_bitcoin, + )?; + let state = AliceState::BtcRefunded { spend_key, state3 }; let db_state = (&state).into(); db.insert_latest_state(swap_id, database::Swap::Alice(db_state)) .await?; @@ -435,15 +442,8 @@ async fn run_until_internal( ) .await } - Either::Right((published_refund_tx, _)) => { - let spend_key = extract_monero_private_key( - published_refund_tx, - tx_refund, - state3.s_a, - state3.a.clone(), - state3.S_b_bitcoin, - )?; - let state = AliceState::BtcRefunded { spend_key, state3 }; + Either::Right(_) => { + let state = AliceState::BtcPunished; let db_state = (&state).into(); db.insert_latest_state(swap_id, database::Swap::Alice(db_state)) .await?;