diff --git a/swap/src/network/swap_setup.rs b/swap/src/network/swap_setup.rs index 705551e4..43d5ff49 100644 --- a/swap/src/network/swap_setup.rs +++ b/swap/src/network/swap_setup.rs @@ -101,7 +101,7 @@ where T: Serialize, { let bytes = serde_cbor::to_vec(&message)?; - upgrade::write_one(substream, &bytes).await?; + upgrade::write_with_len_prefix(substream, &bytes).await?; Ok(()) } diff --git a/swap/src/protocol/alice/swap_setup.rs b/swap/src/protocol/alice/swap_setup.rs index 75ead9ec..1d228fcb 100644 --- a/swap/src/protocol/alice/swap_setup.rs +++ b/swap/src/protocol/alice/swap_setup.rs @@ -444,8 +444,13 @@ where Self::Error, >, > { + if let Some(event) = self.events.pop_front() { + return Poll::Ready(ProtocolsHandlerEvent::Custom(event)); + } + if let Some(result) = futures::ready!(self.inbound_stream.poll_unpin(cx)) { self.keep_alive = KeepAlive::No; + self.inbound_stream = OptionFuture::from(None); return Poll::Ready(ProtocolsHandlerEvent::Custom(HandlerOutEvent::Completed( result, ))); @@ -478,17 +483,17 @@ pub enum Error { }, #[error("Failed to fetch latest rate")] LatestRateFetchFailed(#[source] Box), - #[error("Failed to calculate quote: {0}")] + #[error("Failed to calculate quote")] SellQuoteCalculationFailed(#[source] anyhow::Error), #[error("Blockchain networks did not match, we are on {asb:?}, but request from {cli:?}")] BlockchainNetworkMismatch { cli: BlockchainNetwork, asb: BlockchainNetwork, }, - #[error("Io Error: {0}")] - Io(anyhow::Error), - #[error("Failed to request wallet snapshot: {0}")] - WalletSnapshotFailed(anyhow::Error), + #[error("Io Error")] + Io(#[source] anyhow::Error), + #[error("Failed to request wallet snapshot")] + WalletSnapshotFailed(#[source] anyhow::Error), #[error("Failed to complete execution setup within {seconds}s")] Timeout { seconds: u64 }, } diff --git a/swap/src/protocol/bob/swap_setup.rs b/swap/src/protocol/bob/swap_setup.rs index c189b10a..9c8b07f4 100644 --- a/swap/src/protocol/bob/swap_setup.rs +++ b/swap/src/protocol/bob/swap_setup.rs @@ -238,6 +238,7 @@ impl ProtocolsHandler for Handler { if let Some(result) = futures::ready!(self.outbound_stream.poll_unpin(cx)) { self.keep_alive = KeepAlive::No; + self.outbound_stream = OptionFuture::from(None); return Poll::Ready(ProtocolsHandlerEvent::Custom(Completed(result))); }