|
| 1 | +use crate::ln::channelmanager::{PaymentId, RecipientOnionFields, Retry}; |
| 2 | +use crate::ln::functional_test_utils::*; |
| 3 | +use crate::ln::msgs::{accountable_from_bool, ChannelMessageHandler, ExperimentalAccountable}; |
| 4 | +use crate::routing::router::{PaymentParameters, RouteParameters}; |
| 5 | + |
| 6 | +fn test_accountable_forwarding_with_override( |
| 7 | + override_accountable: ExperimentalAccountable, expected_forwarded: ExperimentalAccountable, |
| 8 | +) { |
| 9 | + let chanmon_cfgs = create_chanmon_cfgs(3); |
| 10 | + let node_cfgs = create_node_cfgs(3, &chanmon_cfgs); |
| 11 | + let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, None, None]); |
| 12 | + let nodes = create_network(3, &node_cfgs, &node_chanmgrs); |
| 13 | + |
| 14 | + let _chan_ab = create_announced_chan_between_nodes(&nodes, 0, 1); |
| 15 | + let _chan_bc = create_announced_chan_between_nodes(&nodes, 1, 2); |
| 16 | + |
| 17 | + let (payment_preimage, payment_hash, payment_secret) = get_payment_preimage_hash!(nodes[2]); |
| 18 | + let route_params = RouteParameters::from_payment_params_and_value( |
| 19 | + PaymentParameters::from_node_id(nodes[2].node.get_our_node_id(), TEST_FINAL_CLTV), |
| 20 | + 100_000, |
| 21 | + ); |
| 22 | + let onion_fields = RecipientOnionFields::secret_only(payment_secret); |
| 23 | + let payment_id = PaymentId(payment_hash.0); |
| 24 | + nodes[0] |
| 25 | + .node |
| 26 | + .send_payment(payment_hash, onion_fields, payment_id, route_params, Retry::Attempts(0)) |
| 27 | + .unwrap(); |
| 28 | + check_added_monitors!(nodes[0], 1); |
| 29 | + |
| 30 | + let updates_ab = get_htlc_update_msgs(&nodes[0], &nodes[1].node.get_our_node_id()); |
| 31 | + assert_eq!(updates_ab.update_add_htlcs.len(), 1); |
| 32 | + let mut htlc_ab = updates_ab.update_add_htlcs[0].clone(); |
| 33 | + |
| 34 | + // Override accountable value if requested |
| 35 | + if let Some(override_value) = override_accountable { |
| 36 | + htlc_ab.accountable = Some(override_value); |
| 37 | + } |
| 38 | + |
| 39 | + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &htlc_ab); |
| 40 | + do_commitment_signed_dance(&nodes[1], &nodes[0], &updates_ab.commitment_signed, false, false); |
| 41 | + expect_and_process_pending_htlcs(&nodes[1], false); |
| 42 | + check_added_monitors!(nodes[1], 1); |
| 43 | + |
| 44 | + let updates_bc = get_htlc_update_msgs(&nodes[1], &nodes[2].node.get_our_node_id()); |
| 45 | + assert_eq!(updates_bc.update_add_htlcs.len(), 1); |
| 46 | + let htlc_bc = &updates_bc.update_add_htlcs[0]; |
| 47 | + assert_eq!( |
| 48 | + htlc_bc.accountable, expected_forwarded, |
| 49 | + "B -> C should have accountable = {:?}", |
| 50 | + expected_forwarded |
| 51 | + ); |
| 52 | + |
| 53 | + nodes[2].node.handle_update_add_htlc(nodes[1].node.get_our_node_id(), htlc_bc); |
| 54 | + do_commitment_signed_dance(&nodes[2], &nodes[1], &updates_bc.commitment_signed, false, false); |
| 55 | + expect_and_process_pending_htlcs(&nodes[2], false); |
| 56 | + check_added_monitors!(nodes[2], 0); |
| 57 | + expect_payment_claimable!(nodes[2], payment_hash, payment_secret, 100_000); |
| 58 | + claim_payment(&nodes[0], &[&nodes[1], &nodes[2]], payment_preimage); |
| 59 | +} |
| 60 | + |
| 61 | +#[test] |
| 62 | +fn test_accountable_signal() { |
| 63 | + // Tests forwarding of accountable signal for various incoming signal values. |
| 64 | + test_accountable_forwarding_with_override(None, accountable_from_bool(false)); |
| 65 | + test_accountable_forwarding_with_override(Some(7), accountable_from_bool(true)); |
| 66 | + test_accountable_forwarding_with_override(Some(3), accountable_from_bool(false)); |
| 67 | +} |
0 commit comments