Half-ass some CLTV fixes for real channel creation
[rust-lightning] / src / ln / router.rs
index 9e3272c13e260dc565eb2e6fe6935e674e6bbcaf..ad7ae675117f935561979b1ff97277dde314b48f 100644 (file)
@@ -21,7 +21,7 @@ pub struct RouteHop {
        /// The fee taken on this hop. For the last hop, this should be the full value of the payment.
        pub fee_msat: u64,
        /// The CLTV delta added for this hop. For the last hop, this should be the full CLTV value
-       /// expected at the destination, NOT a delta.
+       /// expected at the destination, in excess of the current block height.
        pub cltv_expiry_delta: u32,
 }
 
@@ -403,7 +403,18 @@ impl Router {
                let mut first_hop_targets = HashMap::with_capacity(if first_hops.is_some() { first_hops.as_ref().unwrap().len() } else { 0 });
                if let Some(hops) = first_hops {
                        for chan in hops {
-                               first_hop_targets.insert(chan.remote_network_id, chan.short_channel_id.expect("first_hops should be filled in with usable channels, not pending ones"));
+                               let short_channel_id = chan.short_channel_id.expect("first_hops should be filled in with usable channels, not pending ones");
+                               if chan.remote_network_id == *target {
+                                       return Ok(Route {
+                                               hops: vec![RouteHop {
+                                                       pubkey: chan.remote_network_id,
+                                                       short_channel_id,
+                                                       fee_msat: final_value_msat,
+                                                       cltv_expiry_delta: final_cltv,
+                                               }],
+                                       });
+                               }
+                               first_hop_targets.insert(chan.remote_network_id, short_channel_id);
                        }
                        if first_hop_targets.is_empty() {
                                return Err(HandleError{err: "Cannot route when there are no outbound routes away from us", action: None});