From af50c655ae0e73bf1a90282a22f26468089a0f36 Mon Sep 17 00:00:00 2001 From: rishflab Date: Tue, 31 Aug 2021 15:21:44 +1000 Subject: [PATCH] Remove timeout on send encrypted signature Bob was timing out if the encrypted signature could not be sent in 60 seconds. This behaviour is unnecessary because we are racing against the cancel timelock anyway. By timing out before this, we remove the opportunity for bob and alice to re-establish a connection. --- swap/src/cli/event_loop.rs | 4 ++-- swap/src/protocol/bob/swap.rs | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/swap/src/cli/event_loop.rs b/swap/src/cli/event_loop.rs index 2ed37b26..d8c0d453 100644 --- a/swap/src/cli/event_loop.rs +++ b/swap/src/cli/event_loop.rs @@ -54,7 +54,7 @@ impl EventLoop { ) -> Result<(Self, EventLoopHandle)> { let execution_setup = bmrng::channel_with_timeout(1, Duration::from_secs(60)); let transfer_proof = bmrng::channel_with_timeout(1, Duration::from_secs(60)); - let encrypted_signature = bmrng::channel_with_timeout(1, Duration::from_secs(60)); + let encrypted_signature = bmrng::channel(1); let quote = bmrng::channel_with_timeout(1, Duration::from_secs(60)); let event_loop = EventLoop { @@ -248,7 +248,7 @@ impl EventLoopHandle { pub async fn send_encrypted_signature( &mut self, tx_redeem_encsig: EncryptedSignature, - ) -> Result<()> { + ) -> Result<(), bmrng::error::RequestError> { Ok(self .encrypted_signature .send_receive(tx_redeem_encsig) diff --git a/swap/src/protocol/bob/swap.rs b/swap/src/protocol/bob/swap.rs index c1987e20..45c5a3b1 100644 --- a/swap/src/protocol/bob/swap.rs +++ b/swap/src/protocol/bob/swap.rs @@ -176,8 +176,12 @@ async fn next_state( // Bob sends Alice his key select! { - _ = event_loop_handle.send_encrypted_signature(state.tx_redeem_encsig()) => { - BobState::EncSigSent(state) + result = event_loop_handle.send_encrypted_signature(state.tx_redeem_encsig()) => { + match result { + Ok(_) => BobState::EncSigSent(state), + Err(bmrng::error::RequestError::RecvError | bmrng::error::RequestError::SendError(_)) => bail!("Failed to communicate encrypted signature through event loop channel"), + Err(bmrng::error::RequestError::RecvTimeoutError) => unreachable!("We construct the channel with no timeout"), + } }, result = tx_lock_status.wait_until_confirmed_with(state.cancel_timelock) => { let _ = result?;