mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-08-08 14:32:24 -04:00
Merge #107
107: Ensure that Bob can cancel correctly if T1 expired and Alice did not … r=da-kami a=da-kami Bob has to check for the possibility to cancel in every state after he locked the BTC. Otherwise Bob will try to perform actions that don't have any point and it might be impossible to use the `resume` command because it will always fail in trying to go on with Alice even though that might not be possible. Co-authored-by: Daniel Karzel <daniel@comit.network>
This commit is contained in:
commit
9c83ca52ad
5 changed files with 136 additions and 51 deletions
|
@ -429,6 +429,10 @@ pub async fn run_until(
|
|||
state3,
|
||||
encrypted_signature,
|
||||
} => {
|
||||
// TODO: Evaluate if it is correct for Alice to Redeem no matter what.
|
||||
// If T1 expired she should potentially not try redeem. (The implementation
|
||||
// gives her an advantage.)
|
||||
|
||||
let signed_tx_redeem = match build_bitcoin_redeem_transaction(
|
||||
encrypted_signature,
|
||||
&state3.tx_lock,
|
||||
|
|
|
@ -223,16 +223,40 @@ where
|
|||
// Bob has locked Btc
|
||||
// Watch for Alice to Lock Xmr or for t1 to elapse
|
||||
BobState::BtcLocked(state3) => {
|
||||
// TODO(Franck): Refund if cannot connect to Alice.
|
||||
event_loop_handle.dial().await?;
|
||||
let state = if let Epoch::T0 = state3.current_epoch(bitcoin_wallet.as_ref()).await?
|
||||
{
|
||||
event_loop_handle.dial().await?;
|
||||
|
||||
// todo: watch until t1, not indefinitely
|
||||
let msg2 = event_loop_handle.recv_message2().await?;
|
||||
let state4 = state3
|
||||
.watch_for_lock_xmr(monero_wallet.as_ref(), msg2)
|
||||
.await?;
|
||||
let msg2_watcher = event_loop_handle.recv_message2();
|
||||
let t1_timeout = state3.wait_for_t1(bitcoin_wallet.as_ref());
|
||||
|
||||
let state = BobState::XmrLocked(state4);
|
||||
select! {
|
||||
msg2 = msg2_watcher => {
|
||||
|
||||
let xmr_lock_watcher = state3.clone()
|
||||
.watch_for_lock_xmr(monero_wallet.as_ref(), msg2?);
|
||||
let t1_timeout = state3.wait_for_t1(bitcoin_wallet.as_ref());
|
||||
|
||||
select! {
|
||||
state4 = xmr_lock_watcher => {
|
||||
BobState::XmrLocked(state4?)
|
||||
},
|
||||
_ = t1_timeout => {
|
||||
let state4 = state3.t1_expired();
|
||||
BobState::T1Expired(state4)
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
_ = t1_timeout => {
|
||||
let state4 = state3.t1_expired();
|
||||
BobState::T1Expired(state4)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let state4 = state3.t1_expired();
|
||||
BobState::T1Expired(state4)
|
||||
};
|
||||
let db_state = state.clone().into();
|
||||
db.insert_latest_state(swap_id, state::Swap::Bob(db_state))
|
||||
.await?;
|
||||
|
@ -249,10 +273,8 @@ where
|
|||
.await
|
||||
}
|
||||
BobState::XmrLocked(state) => {
|
||||
// TODO(Franck): Refund if cannot connect to Alice.
|
||||
event_loop_handle.dial().await?;
|
||||
|
||||
let state = if let Epoch::T0 = state.current_epoch(bitcoin_wallet.as_ref()).await? {
|
||||
event_loop_handle.dial().await?;
|
||||
// Alice has locked Xmr
|
||||
// Bob sends Alice his key
|
||||
let tx_redeem_encsig = state.tx_redeem_encsig();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue