From fa2902ebb1d0842dfdaffcfe1c9aebba58df4391 Mon Sep 17 00:00:00 2001 From: Daniel Karzel Date: Tue, 22 Dec 2020 13:39:15 +1100 Subject: [PATCH] Allow Bob to try to refund after T2 has passed If we don't allow this, then Bob cannot refund Bitcoin if: Alice started a swap with Bob but never acts after the start (and remains offline). Bob is offline until T2 has passed. --- swap/src/bob/swap.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/swap/src/bob/swap.rs b/swap/src/bob/swap.rs index b2b55c82..f5ea9eeb 100644 --- a/swap/src/bob/swap.rs +++ b/swap/src/bob/swap.rs @@ -390,15 +390,24 @@ where .await } BobState::Cancelled(state) => { - // TODO // Bob has cancelled the swap let state = match state.current_epoch(bitcoin_wallet.as_ref()).await? { Epoch::T0 => panic!("Cancelled before t1??? Something is really wrong"), Epoch::T1 => { + // If T1 has expired but not T2 we must be able to refund state.refund_btc(bitcoin_wallet.as_ref()).await?; BobState::BtcRefunded(state) } - Epoch::T2 => BobState::Punished, + Epoch::T2 => { + // If T2 expired we still try to refund in case Alice has not acted. + // This is especially important for scenarios where Alice is offline + // indefinitely after starting the swap. + let refund_result = state.refund_btc(bitcoin_wallet.as_ref()).await; + match refund_result { + Ok(()) => BobState::BtcRefunded(state), + Err(_) => BobState::Punished, + } + } }; let db_state = state.clone().into();