diff --git a/coordinator/src/routes.rs b/coordinator/src/routes.rs index 781a0a665..60fee75b1 100644 --- a/coordinator/src/routes.rs +++ b/coordinator/src/routes.rs @@ -120,10 +120,6 @@ pub fn router( "/api/prepare_onboarding_payment", post(prepare_onboarding_payment), ) - .route( - "/api/prepare_regular_payment/:peer_id", - post(prepare_regular_payment), - ) .route("/api/newaddress", get(get_unused_address)) .route("/api/node", get(get_node_info)) .route("/api/invoice", get(get_invoice)) @@ -261,33 +257,6 @@ pub async fn prepare_onboarding_payment( Ok(Json(route_hint_hop.into())) } -pub async fn prepare_regular_payment( - peer_id: Path, - State(app_state): State>, -) -> Result, AppError> { - let peer_id = peer_id.0; - let peer_id: PublicKey = peer_id.parse().map_err(|e| { - AppError::BadRequest(format!( - "Provided public key {peer_id} was not valid: {e:#}" - )) - })?; - - let route_hint_hop = spawn_blocking({ - let app_state = app_state.clone(); - move || { - app_state - .node - .inner - .prepare_payment_with_route_hint(peer_id) - } - }) - .await - .expect("task to complete") - .map_err(|e| AppError::InternalServerError(format!("Could not prepare payment: {e:#}")))?; - - Ok(Json(route_hint_hop.into())) -} - pub async fn get_unused_address(State(app_state): State>) -> impl IntoResponse { app_state.node.inner.get_unused_address().to_string() } diff --git a/crates/ln-dlc-node/src/ln/channel_details.rs b/crates/ln-dlc-node/src/ln/channel_details.rs index 669f869fa..645a9a45a 100644 --- a/crates/ln-dlc-node/src/ln/channel_details.rs +++ b/crates/ln-dlc-node/src/ln/channel_details.rs @@ -47,7 +47,6 @@ pub struct ChannelConfig { impl From for ChannelDetails { fn from(cd: lightning::ln::channelmanager::ChannelDetails) -> Self { - let scid = cd.get_outbound_payment_scid(); ChannelDetails { channel_id: cd.channel_id, counterparty: cd.counterparty.node_id, @@ -76,7 +75,7 @@ impl From for ChannelDetails { max_dust_htlc_exposure_msat: c.max_dust_htlc_exposure_msat, force_close_avoidance_max_fee_satoshis: c.force_close_avoidance_max_fee_satoshis, }), - scid, + scid: cd.short_channel_id, } } } diff --git a/crates/ln-dlc-node/src/node/invoice.rs b/crates/ln-dlc-node/src/node/invoice.rs index 06646f3f9..bca385261 100644 --- a/crates/ln-dlc-node/src/node/invoice.rs +++ b/crates/ln-dlc-node/src/node/invoice.rs @@ -181,38 +181,40 @@ where Ok(route_hint_hop) } - pub fn prepare_payment_with_route_hint(&self, target_node: PublicKey) -> Result { + pub fn prepare_payment_with_route_hint(&self, hop_node_id: PublicKey) -> Result { let channels = self.channel_manager.list_channels(); let channel = channels .iter() - .find(|channel| channel.counterparty.node_id == target_node) - .with_context(|| format!("Couldn't find channel for {target_node}"))?; + .find(|channel| channel.counterparty.node_id == hop_node_id) + .with_context(|| format!("Couldn't find channel for {hop_node_id}"))?; - let short_channel_id = channel.get_outbound_payment_scid().with_context(|| { + let short_channel_id = channel.get_inbound_payment_scid().with_context(|| { format!( - "Couldn't find short channel id for channel: {}, trader_id={target_node}", + "Couldn't find short channel id for channel: {}, hop_node_id={hop_node_id}", channel.channel_id.to_hex() ) })?; - let ldk_config = self.ldk_config.read(); + let counterparty_forwarding_info = channel + .clone() + .counterparty + .forwarding_info + .context("Couldn't find forwarding info")?; let route_hint_hop = RouteHintHop { - src_node_id: self.info.pubkey, + src_node_id: hop_node_id, short_channel_id, fees: RoutingFees { - base_msat: ldk_config.channel_config.forwarding_fee_base_msat, - proportional_millionths: ldk_config - .channel_config - .forwarding_fee_proportional_millionths, + base_msat: counterparty_forwarding_info.fee_base_msat, + proportional_millionths: counterparty_forwarding_info.fee_proportional_millionths, }, - cltv_expiry_delta: MIN_CLTV_EXPIRY_DELTA, + cltv_expiry_delta: counterparty_forwarding_info.cltv_expiry_delta, htlc_minimum_msat: None, htlc_maximum_msat: None, }; tracing::info!( - peer_id = %target_node, + peer_id = %hop_node_id, route_hint_hop = ?route_hint_hop, "Created route hint for payment to private channel" ); diff --git a/crates/ln-dlc-node/src/tests/just_in_time_channel/create.rs b/crates/ln-dlc-node/src/tests/just_in_time_channel/create.rs index a4c817381..82c20b620 100644 --- a/crates/ln-dlc-node/src/tests/just_in_time_channel/create.rs +++ b/crates/ln-dlc-node/src/tests/just_in_time_channel/create.rs @@ -341,7 +341,7 @@ pub(crate) async fn send_payment( let coordinator_balance_before = coordinator.get_ldk_balance(); let payee_balance_before = payee.get_ldk_balance(); - let route_hint_hop = coordinator.prepare_payment_with_route_hint(payee.info.pubkey)?; + let route_hint_hop = payee.prepare_payment_with_route_hint(coordinator.info.pubkey)?; let invoice = payee.create_invoice_with_route_hint( Some(invoice_amount_sat), diff --git a/crates/ln-dlc-node/src/tests/mod.rs b/crates/ln-dlc-node/src/tests/mod.rs index 0ee570309..044196c63 100644 --- a/crates/ln-dlc-node/src/tests/mod.rs +++ b/crates/ln-dlc-node/src/tests/mod.rs @@ -462,7 +462,7 @@ async fn wait_for_n_usable_channels( .channel_manager .list_usable_channels() .iter() - .all(|c| c.get_outbound_payment_scid().is_some()); + .all(|c| c.get_inbound_payment_scid().is_some()); Ok((usable_channels_length == channel_count && scids_set).then_some(())) }) diff --git a/mobile/native/src/ln_dlc/mod.rs b/mobile/native/src/ln_dlc/mod.rs index 72a22faea..ebdbb97c5 100644 --- a/mobile/native/src/ln_dlc/mod.rs +++ b/mobile/native/src/ln_dlc/mod.rs @@ -970,36 +970,18 @@ pub fn create_onboarding_invoice(amount_sats: u64, liquidity_option_id: i32) -> } pub fn create_invoice(amount_sats: Option) -> Result { - let runtime = get_or_create_tokio_runtime()?; - - runtime.block_on(async { - let node = NODE.get(); - let client = reqwest_client(); - - let response = client - .post(format!( - "http://{}/api/prepare_regular_payment/{}", - config::get_http_endpoint(), - node.inner.info.pubkey - )) - .send() - .await?; - - if !response.status().is_success() { - let text = response.text().await?; - bail!("Failed to fetch route hint from coordinator for regular payment: {text}") - } - - let final_route_hint_hop: RouteHintHop = response.json().await?; - let final_route_hint_hop = final_route_hint_hop.into(); + let node = NODE.get(); - node.inner.create_invoice_with_route_hint( - amount_sats, - None, - "".to_string(), - final_route_hint_hop, - ) - }) + let final_route_hint_hop = node + .inner + .prepare_payment_with_route_hint(config::get_coordinator_info().pubkey)?; + + node.inner.create_invoice_with_route_hint( + amount_sats, + None, + "".to_string(), + final_route_hint_hop, + ) } pub fn send_payment(payment: SendPayment) -> Result<()> {