Skip to content

Commit 641f242

Browse files
committed
Correct source_node_id and channel_id in PaymentForwarded event
1 parent f77700a commit 641f242

File tree

7 files changed

+40
-46
lines changed

7 files changed

+40
-46
lines changed

lightning/src/ln/chanmon_update_fail_tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,7 +1102,7 @@ fn test_monitor_update_fail_reestablish() {
11021102
assert!(updates.update_fee.is_none());
11031103
assert_eq!(updates.update_fulfill_htlcs.len(), 1);
11041104
nodes[1].node.handle_update_fulfill_htlc(&nodes[2].node.get_our_node_id(), &updates.update_fulfill_htlcs[0]);
1105-
expect_payment_forwarded!(nodes[1], chan_1.2, Some(1000), false);
1105+
expect_payment_forwarded!(nodes[1], nodes[0], chan_1.2, Some(1000), false);
11061106
check_added_monitors!(nodes[1], 1);
11071107
assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
11081108
commitment_signed_dance!(nodes[1], nodes[2], updates.commitment_signed, false);
@@ -2087,7 +2087,7 @@ fn test_fail_htlc_on_broadcast_after_claim() {
20872087
nodes[1].node.handle_update_fulfill_htlc(&nodes[2].node.get_our_node_id(), &cs_updates.update_fulfill_htlcs[0]);
20882088
let bs_updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id());
20892089
check_added_monitors!(nodes[1], 1);
2090-
expect_payment_forwarded!(nodes[1], chan_id_1, Some(1000), false);
2090+
expect_payment_forwarded!(nodes[1], nodes[0], chan_id_1, Some(1000), false);
20912091

20922092
mine_transaction(&nodes[1], &bs_txn[0]);
20932093
check_closed_event!(nodes[1], 1, ClosureReason::CommitmentTxConfirmed);
@@ -2468,7 +2468,7 @@ fn do_test_reconnect_dup_htlc_claims(htlc_status: HTLCStatusAtDupClaim, second_f
24682468
assert_eq!(fulfill_msg, cs_updates.update_fulfill_htlcs[0]);
24692469
}
24702470
nodes[1].node.handle_update_fulfill_htlc(&nodes[2].node.get_our_node_id(), &fulfill_msg);
2471-
expect_payment_forwarded!(nodes[1], chan_id_1, Some(1000), false);
2471+
expect_payment_forwarded!(nodes[1], nodes[0], chan_id_1, Some(1000), false);
24722472
check_added_monitors!(nodes[1], 1);
24732473

24742474
let mut bs_updates = None;

lightning/src/ln/channelmanager.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4278,7 +4278,6 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
42784278
// update to. Instead, we simply document in `PaymentForwarded` that this
42794279
// can happen.
42804280
}
4281-
mem::drop(channel_state_lock);
42824281
if let ClaimFundsFromHop::MonitorUpdateFail(pk, err, _) = res {
42834282
let result: Result<(), _> = Err(err);
42844283
let _ = handle_error!(self, result, pk);
@@ -4292,15 +4291,14 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
42924291

42934292
let mut pending_events = self.pending_events.lock().unwrap();
42944293

4295-
let source_node_id = self.get_our_node_id();
4296-
42974294
let channel_id = prev_outpoint.to_channel_id();
4298-
let chan_ab_id = [54, 1, 27, 147, 208, 68, 174, 120, 153, 166, 147, 131, 196, 197, 137, 125, 20, 169, 146, 130, 47, 96, 90, 106, 226, 118, 1, 231, 93, 113, 103, 164];
4299-
let chan_bc_id = [62, 94, 18, 107, 70, 218, 72, 107, 73, 188, 156, 196, 17, 42, 11, 32, 206, 143, 17, 229, 106, 81, 201, 215, 188, 141, 176, 146, 55, 122, 100, 36];
4300-
// Given 3 nodes A, B, and C, if C is claiming the HTLC with B, channel_id is of A<-->B
4301-
// Check line 5076 of functional_tests.rs
4302-
assert_eq!(chan_ab_id, channel_id);
4303-
println!("prev_outpoint_channel_id: {:?}", channel_id);
4295+
let channel = match channel_state_lock.by_id.entry(channel_id) {
4296+
hash_map::Entry::Occupied(chan) => chan,
4297+
hash_map::Entry::Vacant(_) => {
4298+
panic!("Channel doesn't exist")
4299+
}
4300+
};
4301+
let source_node_id = channel.get().get_counterparty_node_id();
43044302

43054303
pending_events.push(events::Event::PaymentForwarded {
43064304
source_node_id,
@@ -4310,6 +4308,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
43104308
});
43114309
}
43124310
}
4311+
mem::drop(channel_state_lock);
43134312
},
43144313
}
43154314
}

lightning/src/ln/functional_test_utils.rs

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,13 +1328,13 @@ macro_rules! expect_payment_path_successful {
13281328
}
13291329

13301330
macro_rules! expect_payment_forwarded {
1331-
($node: expr, $channel_id: expr, $expected_fee: expr, $upstream_force_closed: expr) => {
1331+
($node: expr, $source_node: expr, $channel_id: expr, $expected_fee: expr, $upstream_force_closed: expr) => {
13321332
let events = $node.node.get_and_clear_pending_events();
13331333
assert_eq!(events.len(), 1);
13341334
match events[0] {
13351335
Event::PaymentForwarded { source_node_id, channel_id, fee_earned_msat, claim_from_onchain_tx } => {
1336-
assert_eq!(source_node_id, $node.node.get_our_node_id());
1337-
// assert_eq!(channel_id, $channel_id);
1336+
assert_eq!(source_node_id, $source_node.node.get_our_node_id());
1337+
assert_eq!(channel_id, $channel_id);
13381338
assert_eq!(fee_earned_msat, $expected_fee);
13391339
assert_eq!(claim_from_onchain_tx, $upstream_force_closed);
13401340
},
@@ -1575,12 +1575,11 @@ pub fn do_claim_payment_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>,
15751575
}
15761576
}
15771577
macro_rules! mid_update_fulfill_dance {
1578-
($node: expr, $prev_node: expr, $next_channel_id: expr, $new_msgs: expr) => {
1578+
($node: expr, $prev_node: expr, $next_node: expr, $next_channel_id: expr, $new_msgs: expr) => {
15791579
{
1580-
// TODO channel_id is not correct. Causes tests to fail.
15811580
$node.node.handle_update_fulfill_htlc(&$prev_node.node.get_our_node_id(), &next_msgs.as_ref().unwrap().0);
15821581
let fee = $node.node.channel_state.lock().unwrap().by_id.get(&next_msgs.as_ref().unwrap().0.channel_id).unwrap().config.forwarding_fee_base_msat;
1583-
expect_payment_forwarded!($node, $next_channel_id, Some(fee as u64), false);
1582+
expect_payment_forwarded!($node, $next_node, $next_channel_id, Some(fee as u64), false);
15841583
expected_total_fee_msat += fee as u64;
15851584
check_added_monitors!($node, 1);
15861585
let new_next_msgs = if $new_msgs {
@@ -1599,23 +1598,23 @@ pub fn do_claim_payment_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>,
15991598
}
16001599
}
16011600

1602-
// [1, 2, 3, 4, 5, 6]
1603-
// prev_node = 6
1604-
// len = 6
1605-
// [6, 5, 4, 3, 2, 1] (1 = 5) (need to get node 4 => idx = 1 => need to get index 3 => len-1-idx-1
1606-
// [6, 5, 4, 3, 2, 1] (2 = 4) (need to get node 3 => idx = 2 => need to get index 2 => len-1-idx-1
1607-
// [6, 5, 4, 3, 2, 1] (3 = 3) (need to get node 3 => idx = 3 => len-1-idx => need to index 1 => len-1-idx-1
16081601
let mut prev_node = expected_route.last().unwrap();
1609-
let mut prev_channel_id = match prev_node.node.list_usable_channels().iter().find(|&x| x.counterparty.node_id == expected_next_node) {
1610-
Some(channel) => channel.channel_id,
1611-
None => panic!("Coudn't find channel")
1612-
};
1613-
16141602
for (idx, node) in expected_route.iter().rev().enumerate().skip(1) {
16151603
assert_eq!(expected_next_node, node.node.get_our_node_id());
16161604
let update_next_msgs = !skip_last || idx != expected_route.len() - 1;
16171605
if next_msgs.is_some() {
1618-
mid_update_fulfill_dance!(node, prev_node, prev_channel_id, update_next_msgs);
1606+
// Since we are traversing in reverse, next_node is actually the previous node
1607+
let next_node: &Node;
1608+
if idx == expected_route.len() - 1 {
1609+
next_node = origin_node;
1610+
} else {
1611+
next_node = expected_route[idx - 1];
1612+
}
1613+
let next_channel_id = match node.node.list_usable_channels().iter().find(|&x| x.counterparty.node_id == next_node.node.get_our_node_id()) {
1614+
Some(channel) => channel.channel_id,
1615+
None => panic!("Uh oh! Coudn't find the channel")
1616+
};
1617+
mid_update_fulfill_dance!(node, prev_node, next_node, next_channel_id, update_next_msgs);
16191618
} else {
16201619
assert!(!update_next_msgs);
16211620
assert!(node.node.get_and_clear_pending_msg_events().is_empty());
@@ -1624,10 +1623,6 @@ pub fn do_claim_payment_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>,
16241623
assert_eq!(expected_next_node, origin_node.node.get_our_node_id());
16251624
}
16261625

1627-
prev_channel_id = match node.node.list_usable_channels().iter().find(|&x| x.counterparty.node_id == prev_node.node.get_our_node_id()) {
1628-
Some(channel) => channel.channel_id,
1629-
None => panic!("Couldn't find channel")
1630-
};
16311626
prev_node = node;
16321627
}
16331628

lightning/src/ln/functional_tests.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2684,8 +2684,8 @@ fn test_htlc_on_chain_success() {
26842684
Event::ChannelClosed { reason: ClosureReason::CommitmentTxConfirmed, .. } => {}
26852685
_ => panic!("Unexpected event"),
26862686
}
2687-
let node_id = nodes[1].node.get_our_node_id();
2688-
let chan_id = chan_2.2;
2687+
let node_id = nodes[0].node.get_our_node_id();
2688+
let chan_id = chan_1.2;
26892689
match forwarded_events[1] {
26902690
Event::PaymentForwarded { source_node_id, channel_id, fee_earned_msat, claim_from_onchain_tx } => {
26912691
assert_eq!(source_node_id, node_id);
@@ -5125,7 +5125,7 @@ fn test_onchain_to_onchain_claim() {
51255125
}
51265126
match events[1] {
51275127
Event::PaymentForwarded { source_node_id, channel_id, fee_earned_msat, claim_from_onchain_tx } => {
5128-
assert_eq!(source_node_id, nodes[1].node.get_our_node_id());
5128+
assert_eq!(source_node_id, nodes[0].node.get_our_node_id());
51295129
assert_eq!(channel_id, chan_1.2);
51305130
assert_eq!(fee_earned_msat, Some(1000));
51315131
assert_eq!(claim_from_onchain_tx, true);
@@ -5293,7 +5293,7 @@ fn test_duplicate_payment_hash_one_failure_one_success() {
52935293
// Note that the fee paid is effectively double as the HTLC value (including the nodes[1] fee
52945294
// and nodes[2] fee) is rounded down and then claimed in full.
52955295
mine_transaction(&nodes[1], &htlc_success_txn[0]);
5296-
expect_payment_forwarded!(nodes[1], chan_1.2 ,Some(196*2), true);
5296+
expect_payment_forwarded!(nodes[1], nodes[0], chan_1.2 ,Some(196*2), true);
52975297
let updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id());
52985298
assert!(updates.update_add_htlcs.is_empty());
52995299
assert!(updates.update_fail_htlcs.is_empty());
@@ -8871,7 +8871,7 @@ fn do_test_onchain_htlc_settlement_after_close(broadcast_alice: bool, go_onchain
88718871
assert_eq!(carol_updates.update_fulfill_htlcs.len(), 1);
88728872

88738873
nodes[1].node.handle_update_fulfill_htlc(&nodes[2].node.get_our_node_id(), &carol_updates.update_fulfill_htlcs[0]);
8874-
expect_payment_forwarded!(nodes[1], chan_ab.2, if go_onchain_before_fulfill || force_closing_node == 1 { None } else { Some(1000) }, false);
8874+
expect_payment_forwarded!(nodes[1], nodes[0], chan_ab.2, if go_onchain_before_fulfill || force_closing_node == 1 { None } else { Some(1000) }, false);
88758875
// If Alice broadcasted but Bob doesn't know yet, here he prepares to tell her about the preimage.
88768876
if !go_onchain_before_fulfill && broadcast_alice {
88778877
let events = nodes[1].node.get_and_clear_pending_msg_events();
@@ -8979,9 +8979,9 @@ fn do_test_onchain_htlc_settlement_after_close(broadcast_alice: bool, go_onchain
89798979

89808980
#[test]
89818981
fn test_onchain_htlc_settlement_after_close() {
8982-
// do_test_onchain_htlc_settlement_after_close(true, true);
8983-
// do_test_onchain_htlc_settlement_after_close(false, true); // Technically redundant, but may as well
8984-
// do_test_onchain_htlc_settlement_after_close(true, false);
8982+
do_test_onchain_htlc_settlement_after_close(true, true);
8983+
do_test_onchain_htlc_settlement_after_close(false, true); // Technically redundant, but may as well
8984+
do_test_onchain_htlc_settlement_after_close(true, false);
89858985
do_test_onchain_htlc_settlement_after_close(false, false);
89868986
}
89878987

lightning/src/ln/payment_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ fn do_retry_with_no_persist(confirm_before_reload: bool) {
495495
let bs_htlc_claim_txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);
496496
assert_eq!(bs_htlc_claim_txn.len(), 1);
497497
check_spends!(bs_htlc_claim_txn[0], as_commitment_tx);
498-
expect_payment_forwarded!(nodes[1], chan_id, None, false);
498+
expect_payment_forwarded!(nodes[1], nodes[0], chan_id, None, false);
499499

500500
if !confirm_before_reload {
501501
mine_transaction(&nodes[0], &as_commitment_tx);

lightning/src/ln/reorg_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ fn do_test_onchain_htlc_reorg(local_commitment: bool, claim: bool) {
138138
// ChannelManager only polls chain::Watch::release_pending_monitor_events when we
139139
// probe it for events, so we probe non-message events here (which should just be the
140140
// PaymentForwarded event).
141-
expect_payment_forwarded!(nodes[1], chan_1.2, Some(1000), true);
141+
expect_payment_forwarded!(nodes[1], nodes[0], chan_1.2, Some(1000), true);
142142
} else {
143143
// Confirm the timeout tx and check that we fail the HTLC backwards
144144
let block = Block {

lightning/src/ln/shutdown_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ fn updates_shutdown_wait() {
110110
assert!(updates.update_fee.is_none());
111111
assert_eq!(updates.update_fulfill_htlcs.len(), 1);
112112
nodes[1].node.handle_update_fulfill_htlc(&nodes[2].node.get_our_node_id(), &updates.update_fulfill_htlcs[0]);
113-
expect_payment_forwarded!(nodes[1], chan_1.2, Some(1000), false);
113+
expect_payment_forwarded!(nodes[1], nodes[0], chan_1.2, Some(1000), false);
114114
check_added_monitors!(nodes[1], 1);
115115
let updates_2 = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id());
116116
commitment_signed_dance!(nodes[1], nodes[2], updates.commitment_signed, false);
@@ -279,7 +279,7 @@ fn do_test_shutdown_rebroadcast(recv_count: u8) {
279279
assert!(updates.update_fee.is_none());
280280
assert_eq!(updates.update_fulfill_htlcs.len(), 1);
281281
nodes[1].node.handle_update_fulfill_htlc(&nodes[2].node.get_our_node_id(), &updates.update_fulfill_htlcs[0]);
282-
expect_payment_forwarded!(nodes[1], chan_1.2, Some(1000), false);
282+
expect_payment_forwarded!(nodes[1], nodes[0], chan_1.2, Some(1000), false);
283283
check_added_monitors!(nodes[1], 1);
284284
let updates_2 = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id());
285285
commitment_signed_dance!(nodes[1], nodes[2], updates.commitment_signed, false);

0 commit comments

Comments
 (0)