Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2857,6 +2857,15 @@ mod tests {
let description =
Bolt11InvoiceDescription::Direct(Description::new("not running".to_string()).unwrap())
.into();
assert_eq!(
node.bolt11_payment().quote_circular_route(
1_000,
UserChannelId(1),
UserChannelId(2),
None
),
Err(Error::NotRunning),
);
let invoice = node.bolt11_payment().receive(1_000, &description, 3_600).unwrap();
assert_eq!(node.bolt11_payment().send(&invoice, None), Err(Error::NotRunning));
assert_eq!(
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ use lightning::ln::funding::{
use lightning::ln::msgs::{BaseMessageHandler, SocketAddress};
use lightning::ln::peer_handler::CustomMessageHandler;
use lightning::routing::gossip::NodeAlias;

use lightning::sign::EntropySource;
use lightning::util::persist::KVStore;
use lightning::util::wallet_utils::{ConfirmedUtxo, Wallet as LdkWallet};
Expand Down Expand Up @@ -1083,6 +1082,7 @@ impl Node {
Arc::clone(&self.config),
Arc::clone(&self.is_running),
Arc::clone(&self.logger),
Arc::clone(&self._router),
)
}

Expand All @@ -1101,6 +1101,7 @@ impl Node {
Arc::clone(&self.config),
Arc::clone(&self.is_running),
Arc::clone(&self.logger),
Arc::clone(&self._router),
))
}

Expand Down
39 changes: 37 additions & 2 deletions src/payment/bolt11.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use lightning_invoice::{
};
use lightning_types::payment::{PaymentHash, PaymentPreimage};

use super::circular::{quote_circular_route, CircularRouteQuote};
use crate::config::{Config, LDK_PAYMENT_RETRY_TIMEOUT};
use crate::connection::ConnectionManager;
use crate::data_store::DataStoreUpdateResult;
Expand All @@ -37,7 +38,8 @@ use crate::payment::store::{
};
use crate::peer_store::{PeerInfo, PeerStore};
use crate::runtime::Runtime;
use crate::types::{ChannelManager, PaymentStore};
use crate::types::{ChannelManager, PaymentStore, Router};
use crate::UserChannelId;

#[cfg(not(feature = "uniffi"))]
type Bolt11Invoice = LdkBolt11Invoice;
Expand Down Expand Up @@ -69,6 +71,7 @@ impl_writeable_tlv_based!(PaymentMetadata, {
pub struct Bolt11Payment {
runtime: Arc<Runtime>,
channel_manager: Arc<ChannelManager>,
router: Arc<Router>,
connection_manager: Arc<ConnectionManager<Arc<Logger>>>,
liquidity_source: Arc<LiquiditySource<Arc<Logger>>>,
payment_store: Arc<PaymentStore>,
Expand All @@ -84,11 +87,12 @@ impl Bolt11Payment {
connection_manager: Arc<ConnectionManager<Arc<Logger>>>,
liquidity_source: Arc<LiquiditySource<Arc<Logger>>>, payment_store: Arc<PaymentStore>,
peer_store: Arc<PeerStore<Arc<Logger>>>, config: Arc<Config>,
is_running: Arc<RwLock<bool>>, logger: Arc<Logger>,
is_running: Arc<RwLock<bool>>, logger: Arc<Logger>, router: Arc<Router>,
) -> Self {
Self {
runtime,
channel_manager,
router,
connection_manager,
liquidity_source,
payment_store,
Expand Down Expand Up @@ -303,6 +307,37 @@ impl Bolt11Payment {

#[cfg_attr(feature = "uniffi", uniffi::export)]
impl Bolt11Payment {
/// Estimate a circular route through two exact, distinct local channels without sending.
///
/// Every returned path leaves through `first_hop_user_channel_id` and returns through
/// `last_hop_user_channel_id`, including when there are several channels to the same peer.
/// This does not create an invoice, send a probe or HTLC, or modify payment records.
/// A quote does not reserve liquidity or guarantee that a subsequent payment will succeed.
///
/// `route_parameters` overrides the node-wide configuration when provided; otherwise the
/// node-wide configuration or LDK defaults are used. An unset fee cap retains LDK's default.
/// This method does not submit the quoted route. Circular payment execution is not supported.
pub fn quote_circular_route(
&self, amount_msat: u64, first_hop_user_channel_id: UserChannelId,
last_hop_user_channel_id: UserChannelId, route_parameters: Option<RouteParametersConfig>,
) -> Result<CircularRouteQuote, Error> {
if !*self.is_running.read().expect("lock") {
return Err(Error::NotRunning);
}
// Match LDK's ordinary BOLT11 feature conversion without creating an invoice.
quote_circular_route(
&*self.router,
self.channel_manager.get_our_node_id(),
self.channel_manager.init_features().to_context(),
&self.channel_manager.list_channels(),
self.channel_manager.compute_inflight_htlcs(),
amount_msat,
first_hop_user_channel_id,
last_hop_user_channel_id,
route_parameters.or(self.config.route_parameters).unwrap_or_default(),
)
}

/// Send a payment given an invoice.
///
/// If `route_parameters` are provided they will override the default as well as the
Expand Down
Loading
Loading