Merge pull request #1694 from jurvis/jurvis/2022-08-move-scorer-from-router
[rust-lightning] / lightning-invoice / src / payment.rs
index 0d99041ad9e854207dc802f8a96b187d8ac3995f..21d7def4a51e9feadac7b4e6c7488b5714f98409 100644 (file)
@@ -676,7 +676,7 @@ where
 
                match event {
                        Event::PaymentPathFailed {
-                               payment_id, payment_hash, rejected_by_dest, path, short_channel_id, retry, ..
+                               payment_id, payment_hash, payment_failed_permanently, path, short_channel_id, retry, ..
                        } => {
                                if let Some(short_channel_id) = short_channel_id {
                                        let path = path.iter().collect::<Vec<_>>();
@@ -685,7 +685,7 @@ where
 
                                if payment_id.is_none() {
                                        log_trace!(self.logger, "Payment {} has no id; not retrying", log_bytes!(payment_hash.0));
-                               } else if *rejected_by_dest {
+                               } else if *payment_failed_permanently {
                                        log_trace!(self.logger, "Payment {} rejected by destination; not retrying", log_bytes!(payment_hash.0));
                                        self.payer.abandon_payment(payment_id.unwrap());
                                } else if retry.is_none() {
@@ -764,7 +764,8 @@ mod tests {
        use utils::{ScorerAccountingForInFlightHtlcs, create_invoice_from_channelmanager_and_duration_since_epoch};
        use bitcoin_hashes::sha256::Hash as Sha256;
        use lightning::ln::PaymentPreimage;
-       use lightning::ln::features::{ChannelFeatures, NodeFeatures, InitFeatures};
+       use lightning::ln::channelmanager;
+       use lightning::ln::features::{ChannelFeatures, NodeFeatures};
        use lightning::ln::functional_test_utils::*;
        use lightning::ln::msgs::{ChannelMessageHandler, ErrorAction, LightningError};
        use lightning::routing::gossip::{EffectiveCapacity, NodeId};
@@ -899,7 +900,7 @@ mod tests {
                        payment_id,
                        payment_hash,
                        network_update: None,
-                       rejected_by_dest: false,
+                       payment_failed_permanently: false,
                        all_paths_failed: false,
                        path: TestRouter::path_for_value(final_value_msat),
                        short_channel_id: None,
@@ -962,7 +963,7 @@ mod tests {
                        payment_id,
                        payment_hash,
                        network_update: None,
-                       rejected_by_dest: false,
+                       payment_failed_permanently: false,
                        all_paths_failed: false,
                        path: TestRouter::path_for_value(final_value_msat),
                        short_channel_id: None,
@@ -1008,7 +1009,7 @@ mod tests {
                        payment_id,
                        payment_hash: PaymentHash(invoice.payment_hash().clone().into_inner()),
                        network_update: None,
-                       rejected_by_dest: false,
+                       payment_failed_permanently: false,
                        all_paths_failed: true,
                        path: TestRouter::path_for_value(final_value_msat),
                        short_channel_id: None,
@@ -1022,7 +1023,7 @@ mod tests {
                        payment_id,
                        payment_hash: PaymentHash(invoice.payment_hash().clone().into_inner()),
                        network_update: None,
-                       rejected_by_dest: false,
+                       payment_failed_permanently: false,
                        all_paths_failed: false,
                        path: TestRouter::path_for_value(final_value_msat / 2),
                        short_channel_id: None,
@@ -1067,7 +1068,7 @@ mod tests {
                        payment_id,
                        payment_hash: PaymentHash(invoice.payment_hash().clone().into_inner()),
                        network_update: None,
-                       rejected_by_dest: false,
+                       payment_failed_permanently: false,
                        all_paths_failed: true,
                        path: TestRouter::path_for_value(final_value_msat),
                        short_channel_id: None,
@@ -1106,7 +1107,7 @@ mod tests {
                        payment_id,
                        payment_hash: PaymentHash(invoice.payment_hash().clone().into_inner()),
                        network_update: None,
-                       rejected_by_dest: false,
+                       payment_failed_permanently: false,
                        all_paths_failed: false,
                        path: vec![],
                        short_channel_id: None,
@@ -1165,7 +1166,7 @@ mod tests {
                        payment_id,
                        payment_hash: PaymentHash(invoice.payment_hash().clone().into_inner()),
                        network_update: None,
-                       rejected_by_dest: false,
+                       payment_failed_permanently: false,
                        all_paths_failed: false,
                        path: vec![],
                        short_channel_id: None,
@@ -1201,7 +1202,7 @@ mod tests {
                        payment_id,
                        payment_hash: PaymentHash(invoice.payment_hash().clone().into_inner()),
                        network_update: None,
-                       rejected_by_dest: false,
+                       payment_failed_permanently: false,
                        all_paths_failed: false,
                        path: TestRouter::path_for_value(final_value_msat / 2),
                        short_channel_id: None,
@@ -1234,7 +1235,7 @@ mod tests {
                        payment_id,
                        payment_hash: PaymentHash(invoice.payment_hash().clone().into_inner()),
                        network_update: None,
-                       rejected_by_dest: true,
+                       payment_failed_permanently: true,
                        all_paths_failed: false,
                        path: vec![],
                        short_channel_id: None,
@@ -1282,7 +1283,7 @@ mod tests {
                        payment_id,
                        payment_hash,
                        network_update: None,
-                       rejected_by_dest: false,
+                       payment_failed_permanently: false,
                        all_paths_failed: false,
                        path: vec![],
                        short_channel_id: None,
@@ -1412,7 +1413,7 @@ mod tests {
                        payment_id,
                        payment_hash,
                        network_update: None,
-                       rejected_by_dest: false,
+                       payment_failed_permanently: false,
                        all_paths_failed: false,
                        path: vec![],
                        short_channel_id: None,
@@ -1458,7 +1459,7 @@ mod tests {
                        payment_id,
                        payment_hash,
                        network_update: None,
-                       rejected_by_dest: false,
+                       payment_failed_permanently: false,
                        all_paths_failed: false,
                        path,
                        short_channel_id,
@@ -1644,7 +1645,7 @@ mod tests {
                        payment_id,
                        payment_hash,
                        network_update: None,
-                       rejected_by_dest: false,
+                       payment_failed_permanently: false,
                        all_paths_failed: false,
                        path: TestRouter::path_for_value(final_value_msat),
                        short_channel_id: None,
@@ -1656,7 +1657,7 @@ mod tests {
                        payment_id,
                        payment_hash,
                        network_update: None,
-                       rejected_by_dest: false,
+                       payment_failed_permanently: false,
                        all_paths_failed: false,
                        path: TestRouter::path_for_value(final_value_msat / 2),
                        short_channel_id: None,
@@ -2162,24 +2163,24 @@ mod tests {
                let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None, None]);
                let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
 
-               create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 0, InitFeatures::known(), InitFeatures::known());
-               create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 0, InitFeatures::known(), InitFeatures::known());
+               create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 0, channelmanager::provided_init_features(), channelmanager::provided_init_features());
+               create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 0, channelmanager::provided_init_features(), channelmanager::provided_init_features());
                let chans = nodes[0].node.list_usable_channels();
                let mut route = Route {
                        paths: vec![
                                vec![RouteHop {
                                        pubkey: nodes[1].node.get_our_node_id(),
-                                       node_features: NodeFeatures::known(),
+                                       node_features: channelmanager::provided_node_features(),
                                        short_channel_id: chans[0].short_channel_id.unwrap(),
-                                       channel_features: ChannelFeatures::known(),
+                                       channel_features: channelmanager::provided_channel_features(),
                                        fee_msat: 10_000,
                                        cltv_expiry_delta: 100,
                                }],
                                vec![RouteHop {
                                        pubkey: nodes[1].node.get_our_node_id(),
-                                       node_features: NodeFeatures::known(),
+                                       node_features: channelmanager::provided_node_features(),
                                        short_channel_id: chans[1].short_channel_id.unwrap(),
-                                       channel_features: ChannelFeatures::known(),
+                                       channel_features: channelmanager::provided_channel_features(),
                                        fee_msat: 100_000_001, // Our default max-HTLC-value is 10% of the channel value, which this is one more than
                                        cltv_expiry_delta: 100,
                                }],
@@ -2213,16 +2214,16 @@ mod tests {
                let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None, None]);
                let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
 
-               create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 0, InitFeatures::known(), InitFeatures::known());
-               create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 0, InitFeatures::known(), InitFeatures::known());
+               create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 0, channelmanager::provided_init_features(), channelmanager::provided_init_features());
+               create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 0, channelmanager::provided_init_features(), channelmanager::provided_init_features());
                let chans = nodes[0].node.list_usable_channels();
                let mut route = Route {
                        paths: vec![
                                vec![RouteHop {
                                        pubkey: nodes[1].node.get_our_node_id(),
-                                       node_features: NodeFeatures::known(),
+                                       node_features: channelmanager::provided_node_features(),
                                        short_channel_id: chans[0].short_channel_id.unwrap(),
-                                       channel_features: ChannelFeatures::known(),
+                                       channel_features: channelmanager::provided_channel_features(),
                                        fee_msat: 100_000_001, // Our default max-HTLC-value is 10% of the channel value, which this is one more than
                                        cltv_expiry_delta: 100,
                                }],
@@ -2271,38 +2272,38 @@ mod tests {
                let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, None, None]);
                let nodes = create_network(3, &node_cfgs, &node_chanmgrs);
 
-               let chan_1_scid = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 0, InitFeatures::known(), InitFeatures::known()).0.contents.short_channel_id;
-               let chan_2_scid = create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 0, InitFeatures::known(), InitFeatures::known()).0.contents.short_channel_id;
+               let chan_1_scid = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 0, channelmanager::provided_init_features(), channelmanager::provided_init_features()).0.contents.short_channel_id;
+               let chan_2_scid = create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 0, channelmanager::provided_init_features(), channelmanager::provided_init_features()).0.contents.short_channel_id;
 
                let mut route = Route {
                        paths: vec![
                                vec![RouteHop {
                                        pubkey: nodes[1].node.get_our_node_id(),
-                                       node_features: NodeFeatures::known(),
+                                       node_features: channelmanager::provided_node_features(),
                                        short_channel_id: chan_1_scid,
-                                       channel_features: ChannelFeatures::known(),
+                                       channel_features: channelmanager::provided_channel_features(),
                                        fee_msat: 0,
                                        cltv_expiry_delta: 100,
                                }, RouteHop {
                                        pubkey: nodes[2].node.get_our_node_id(),
-                                       node_features: NodeFeatures::known(),
+                                       node_features: channelmanager::provided_node_features(),
                                        short_channel_id: chan_2_scid,
-                                       channel_features: ChannelFeatures::known(),
+                                       channel_features: channelmanager::provided_channel_features(),
                                        fee_msat: 100_000_000,
                                        cltv_expiry_delta: 100,
                                }],
                                vec![RouteHop {
                                        pubkey: nodes[1].node.get_our_node_id(),
-                                       node_features: NodeFeatures::known(),
+                                       node_features: channelmanager::provided_node_features(),
                                        short_channel_id: chan_1_scid,
-                                       channel_features: ChannelFeatures::known(),
+                                       channel_features: channelmanager::provided_channel_features(),
                                        fee_msat: 0,
                                        cltv_expiry_delta: 100,
                                }, RouteHop {
                                        pubkey: nodes[2].node.get_our_node_id(),
-                                       node_features: NodeFeatures::known(),
+                                       node_features: channelmanager::provided_node_features(),
                                        short_channel_id: chan_2_scid,
-                                       channel_features: ChannelFeatures::known(),
+                                       channel_features: channelmanager::provided_channel_features(),
                                        fee_msat: 100_000_000,
                                        cltv_expiry_delta: 100,
                                }]
@@ -2392,8 +2393,8 @@ mod tests {
                // treated this as "HTLC complete" and dropped the retry counter, causing us to retry again
                // if the final HTLC failed.
                expected_events.borrow_mut().push_back(&|ev: &Event| {
-                       if let Event::PaymentPathFailed { rejected_by_dest, all_paths_failed, .. } = ev {
-                               assert!(!rejected_by_dest);
+                       if let Event::PaymentPathFailed { payment_failed_permanently, all_paths_failed, .. } = ev {
+                               assert!(!payment_failed_permanently);
                                assert!(all_paths_failed);
                        } else { panic!("Unexpected event"); }
                });
@@ -2410,8 +2411,8 @@ mod tests {
                commitment_signed_dance!(nodes[0], nodes[1], &bs_fail_update.commitment_signed, false, true);
 
                expected_events.borrow_mut().push_back(&|ev: &Event| {
-                       if let Event::PaymentPathFailed { rejected_by_dest, all_paths_failed, .. } = ev {
-                               assert!(!rejected_by_dest);
+                       if let Event::PaymentPathFailed { payment_failed_permanently, all_paths_failed, .. } = ev {
+                               assert!(!payment_failed_permanently);
                                assert!(all_paths_failed);
                        } else { panic!("Unexpected event"); }
                });