+ fn do_create_invoice_min_final_cltv_delta(with_custom_delta: bool) {
+ let chanmon_cfgs = create_chanmon_cfgs(2);
+ let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
+ let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
+ let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
+ let custom_min_final_cltv_expiry_delta = Some(50);
+
+ let invoice = crate::utils::create_invoice_from_channelmanager_and_duration_since_epoch(
+ nodes[1].node, nodes[1].keys_manager, nodes[1].logger, Currency::BitcoinTestnet,
+ Some(10_000), "".into(), Duration::from_secs(1234567), 3600,
+ if with_custom_delta { custom_min_final_cltv_expiry_delta } else { None },
+ ).unwrap();
+ assert_eq!(invoice.min_final_cltv_expiry_delta(), if with_custom_delta {
+ custom_min_final_cltv_expiry_delta.unwrap() + 3 /* Buffer */} else { MIN_FINAL_CLTV_EXPIRY_DELTA } as u64);
+ }
+
+ #[test]
+ fn test_create_invoice_custom_min_final_cltv_delta() {
+ do_create_invoice_min_final_cltv_delta(true);
+ do_create_invoice_min_final_cltv_delta(false);
+ }
+
+ #[test]
+ fn create_invoice_min_final_cltv_delta_equals_htlc_fail_buffer() {
+ let chanmon_cfgs = create_chanmon_cfgs(2);
+ let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
+ let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
+ let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
+ let custom_min_final_cltv_expiry_delta = Some(21);
+
+ let invoice = crate::utils::create_invoice_from_channelmanager_and_duration_since_epoch(
+ nodes[1].node, nodes[1].keys_manager, nodes[1].logger, Currency::BitcoinTestnet,
+ Some(10_000), "".into(), Duration::from_secs(1234567), 3600,
+ custom_min_final_cltv_expiry_delta,
+ ).unwrap();
+ assert_eq!(invoice.min_final_cltv_expiry_delta(), MIN_FINAL_CLTV_EXPIRY_DELTA as u64);
+ }
+
+ #[test]
+ fn test_create_invoice_with_description_hash() {
+ let chanmon_cfgs = create_chanmon_cfgs(2);
+ let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
+ let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
+ let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
+ let description_hash = crate::Sha256(Hash::hash("Testing description_hash".as_bytes()));
+ let invoice = crate::utils::create_invoice_from_channelmanager_with_description_hash_and_duration_since_epoch(
+ nodes[1].node, nodes[1].keys_manager, nodes[1].logger, Currency::BitcoinTestnet,
+ Some(10_000), description_hash, Duration::from_secs(1234567), 3600, None,
+ ).unwrap();
+ assert_eq!(invoice.amount_pico_btc(), Some(100_000));
+ assert_eq!(invoice.min_final_cltv_expiry_delta(), MIN_FINAL_CLTV_EXPIRY_DELTA as u64);
+ assert_eq!(invoice.description(), InvoiceDescription::Hash(&crate::Sha256(Sha256::hash("Testing description_hash".as_bytes()))));
+ }
+
+ #[test]
+ fn test_create_invoice_from_channelmanager_and_duration_since_epoch_with_payment_hash() {
+ let chanmon_cfgs = create_chanmon_cfgs(2);
+ let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
+ let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
+ let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
+ let payment_hash = PaymentHash([0; 32]);
+ let invoice = crate::utils::create_invoice_from_channelmanager_and_duration_since_epoch_with_payment_hash(
+ nodes[1].node, nodes[1].keys_manager, nodes[1].logger, Currency::BitcoinTestnet,
+ Some(10_000), "test".to_string(), Duration::from_secs(1234567), 3600,
+ payment_hash, None,
+ ).unwrap();
+ assert_eq!(invoice.amount_pico_btc(), Some(100_000));
+ assert_eq!(invoice.min_final_cltv_expiry_delta(), MIN_FINAL_CLTV_EXPIRY_DELTA as u64);
+ assert_eq!(invoice.description(), InvoiceDescription::Direct(&Description("test".to_string())));
+ assert_eq!(invoice.payment_hash(), &sha256::Hash::from_slice(&payment_hash.0[..]).unwrap());
+ }
+
+ #[test]
+ fn test_hints_has_only_public_confd_channels() {
+ let chanmon_cfgs = create_chanmon_cfgs(2);
+ let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
+ let mut config = test_default_channel_config();
+ config.channel_handshake_config.minimum_depth = 1;
+ let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[Some(config), Some(config)]);
+ let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
+
+ // Create a private channel with lots of capacity and a lower value public channel (without
+ // confirming the funding tx yet).
+ let unannounced_scid = create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 0);
+ let conf_tx = create_chan_between_nodes_with_value_init(&nodes[0], &nodes[1], 10_000, 0);
+
+ // Before the channel is available, we should include the unannounced_scid.
+ let mut scid_aliases = HashSet::new();
+ scid_aliases.insert(unannounced_scid.0.short_channel_id_alias.unwrap());
+ match_invoice_routes(Some(5000), &nodes[1], scid_aliases.clone());
+
+ // However after we mine the funding tx and exchange channel_ready messages for the public
+ // channel we'll immediately switch to including it as a route hint, even though it isn't
+ // yet announced.
+ let pub_channel_scid = mine_transaction(&nodes[0], &conf_tx);
+ let node_a_pub_channel_ready = get_event_msg!(nodes[0], MessageSendEvent::SendChannelReady, nodes[1].node.get_our_node_id());
+ nodes[1].node.handle_channel_ready(&nodes[0].node.get_our_node_id(), &node_a_pub_channel_ready);
+
+ assert_eq!(mine_transaction(&nodes[1], &conf_tx), pub_channel_scid);
+ let events = nodes[1].node.get_and_clear_pending_msg_events();
+ assert_eq!(events.len(), 2);
+ if let MessageSendEvent::SendChannelReady { msg, .. } = &events[0] {
+ nodes[0].node.handle_channel_ready(&nodes[1].node.get_our_node_id(), msg);
+ } else { panic!(); }
+ if let MessageSendEvent::SendChannelUpdate { msg, .. } = &events[1] {
+ nodes[0].node.handle_channel_update(&nodes[1].node.get_our_node_id(), msg);
+ } else { panic!(); }
+
+ nodes[1].node.handle_channel_update(&nodes[0].node.get_our_node_id(), &get_event_msg!(nodes[0], MessageSendEvent::SendChannelUpdate, nodes[1].node.get_our_node_id()));
+
+ expect_channel_ready_event(&nodes[0], &nodes[1].node.get_our_node_id());
+ expect_channel_ready_event(&nodes[1], &nodes[0].node.get_our_node_id());
+
+ scid_aliases.clear();
+ scid_aliases.insert(node_a_pub_channel_ready.short_channel_id_alias.unwrap());
+ match_invoice_routes(Some(5000), &nodes[1], scid_aliases.clone());
+ // This also applies even if the amount is more than the payment amount, to ensure users
+ // dont screw up their privacy.
+ match_invoice_routes(Some(50_000_000), &nodes[1], scid_aliases.clone());
+
+ // The same remains true until the channel has 7 confirmations, at which point we include
+ // no hints.
+ connect_blocks(&nodes[1], 5);
+ match_invoice_routes(Some(5000), &nodes[1], scid_aliases.clone());
+ connect_blocks(&nodes[1], 1);
+ get_event_msg!(nodes[1], MessageSendEvent::SendAnnouncementSignatures, nodes[0].node.get_our_node_id());
+ match_invoice_routes(Some(5000), &nodes[1], HashSet::new());
+ }
+