From 2ba69ba340dc0f56f41fa787878f5aebb3a40c32 Mon Sep 17 00:00:00 2001 From: Mohan <86064887+binarybaron@users.noreply.github.com> Date: Fri, 6 Jun 2025 15:02:31 +0200 Subject: [PATCH] fix(asb): send zero quote on failure (#379) * fix(asb): send zero quote on failure * static function for BidQuote::ZERO --- CHANGELOG.md | 1 + swap/src/asb/event_loop.rs | 13 +++++++++++-- swap/src/network/quote.rs | 9 +++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a1b31e77..75632ef4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] - ASB: The maker will take Monero funds needed for ongoing swaps into consideration when making a quote. A warning will be displayed if the Monero funds do not cover all ongoing swaps. +- ASB: Return a zero quote when quoting fails instead of letting the request time out ## [1.1.7] - 2025-06-04 diff --git a/swap/src/asb/event_loop.rs b/swap/src/asb/event_loop.rs index f34f78a9..c1d7d276 100644 --- a/swap/src/asb/event_loop.rs +++ b/swap/src/asb/event_loop.rs @@ -259,8 +259,17 @@ where // The error is already logged in the make_quote_or_use_cached function // We don't log it here to avoid spamming on each request Err(_) => { - // TODO: Respond with the error to Bob. Currently this will timeout on Bob's side. - continue; + // We respond with a zero quote. This will stop Bob from trying to start a swap but doesn't require + // a breaking network change by changing the definition of the quote protocol + if self + .swarm + .behaviour_mut() + .quote + .send_response(channel, BidQuote::ZERO) + .is_err() + { + tracing::debug!(%peer, "Failed to respond with zero quote"); + } } } } diff --git a/swap/src/network/quote.rs b/swap/src/network/quote.rs index 277ceff2..e3e3b1f9 100644 --- a/swap/src/network/quote.rs +++ b/swap/src/network/quote.rs @@ -40,6 +40,15 @@ pub struct BidQuote { pub max_quantity: bitcoin::Amount, } +impl BidQuote { + /// A zero quote with all amounts set to zero + pub const ZERO: Self = Self { + price: bitcoin::Amount::ZERO, + min_quantity: bitcoin::Amount::ZERO, + max_quantity: bitcoin::Amount::ZERO, + }; +} + #[derive(Clone, Copy, Debug, thiserror::Error)] #[error("Received quote of 0")] pub struct ZeroQuoteReceived;