Merge pull request #2924 from tnull/2024-03-add-user-channel-id-to-payment-forwarded
authorvalentinewallace <valentinewallace@users.noreply.github.com>
Wed, 20 Mar 2024 14:27:16 +0000 (10:27 -0400)
committerGitHub <noreply@github.com>
Wed, 20 Mar 2024 14:27:16 +0000 (10:27 -0400)
Expose `{prev,next}_user_channel_id` fields in `PaymentForwarded`

1  2 
lightning/src/ln/channelmanager.rs
lightning/src/ln/functional_test_utils.rs

Simple merge
index cb310ec95398a38309840a3177966102da3eeebb,0c8909b56850d670874297da23b299b93a3490ad..5840fead943049a6ac2a26eb4e784253ad3bcffb
@@@ -2227,22 -2226,14 +2227,22 @@@ macro_rules! expect_payment_path_succes
  pub fn expect_payment_forwarded<CM: AChannelManager, H: NodeHolder<CM=CM>>(
        event: Event, node: &H, prev_node: &H, next_node: &H, expected_fee: Option<u64>,
        expected_extra_fees_msat: Option<u64>, upstream_force_closed: bool,
 -      downstream_force_closed: bool
 -) {
 +      downstream_force_closed: bool, allow_1_msat_fee_overpay: bool,
 +) -> Option<u64> {
        match event {
                Event::PaymentForwarded {
-                       total_fee_earned_msat, prev_channel_id, claim_from_onchain_tx, next_channel_id,
-                       outbound_amount_forwarded_msat: _, skimmed_fee_msat
+                       prev_channel_id, next_channel_id, prev_user_channel_id, next_user_channel_id,
+                       total_fee_earned_msat, skimmed_fee_msat, claim_from_onchain_tx, ..
                } => {
 -                      assert_eq!(total_fee_earned_msat, expected_fee);
 +                      if allow_1_msat_fee_overpay {
 +                              // Aggregating fees for blinded paths may result in a rounding error, causing slight
 +                              // overpayment in fees.
 +                              let actual_fee = total_fee_earned_msat.unwrap();
 +                              let expected_fee = expected_fee.unwrap();
 +                              assert!(actual_fee == expected_fee || actual_fee == expected_fee + 1);
 +                      } else {
 +                              assert_eq!(total_fee_earned_msat, expected_fee);
 +                      }
  
                        // Check that the (knowingly) withheld amount is always less or equal to the expected
                        // overpaid amount.
                        // We check for force closures since a force closed channel is removed from the
                        // node's channel list
                        if !downstream_force_closed {
-                               assert!(node.node().list_channels().iter().any(|x| x.counterparty.node_id == next_node.node().get_our_node_id() && x.channel_id == next_channel_id.unwrap()));
+                               // As documented, `next_user_channel_id` will only be `Some` if we didn't settle via an
+                               // onchain transaction, just as the `total_fee_earned_msat` field. Rather than
+                               // introducing yet another variable, we use the latter's state as a flag to detect
+                               // this and only check if it's `Some`.
+                               if total_fee_earned_msat.is_none() {
+                                       assert!(node.node().list_channels().iter().any(|x|
+                                               x.counterparty.node_id == next_node.node().get_our_node_id() &&
+                                               x.channel_id == next_channel_id.unwrap()
+                                       ));
+                               } else {
+                                       assert!(node.node().list_channels().iter().any(|x|
+                                               x.counterparty.node_id == next_node.node().get_our_node_id() &&
+                                               x.channel_id == next_channel_id.unwrap() &&
+                                               x.user_channel_id == next_user_channel_id.unwrap()
+                                       ));
+                               }
                        }
                        assert_eq!(claim_from_onchain_tx, downstream_force_closed);
 +                      total_fee_earned_msat
                },
                _ => panic!("Unexpected event"),
        }