Skip to content

Split out receive_htlcs from the forwarding pipeline #3973

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 57 additions & 41 deletions lightning/src/ln/onion_route_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1173,17 +1173,21 @@ fn test_onion_failure() {
|_| {},
|| {
nodes[1].node.process_pending_update_add_htlcs();
for (_, pending_forwards) in nodes[1].node.forward_htlcs.lock().unwrap().iter_mut() {
for f in pending_forwards.iter_mut() {
match f {
&mut HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo {
ref mut forward_info,
..
}) => forward_info.outgoing_cltv_value -= 1,
_ => {},
}
assert_eq!(nodes[1].node.forward_htlcs.lock().unwrap().len(), 1);
if let Some((_, pending_forwards)) =
nodes[1].node.forward_htlcs.lock().unwrap().iter_mut().next()
{
assert_eq!(pending_forwards.len(), 1);
match pending_forwards.get_mut(0).unwrap() {
Comment on lines +1176 to +1181
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This repeated pattern really looks like it could be in a test util function or macro.

&mut HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo {
ref mut forward_info,
..
}) => forward_info.outgoing_cltv_value -= 1,
_ => panic!("Unexpected HTLCForwardInfo"),
}
}
} else {
panic!("Expected pending forwards!");
};
},
true,
Some(LocalHTLCFailureReason::FinalIncorrectCLTVExpiry),
Expand All @@ -1203,17 +1207,21 @@ fn test_onion_failure() {
|| {
nodes[1].node.process_pending_update_add_htlcs();
// violate amt_to_forward > msg.amount_msat
for (_, pending_forwards) in nodes[1].node.forward_htlcs.lock().unwrap().iter_mut() {
for f in pending_forwards.iter_mut() {
match f {
&mut HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo {
ref mut forward_info,
..
}) => forward_info.outgoing_amt_msat -= 1,
_ => {},
}
assert_eq!(nodes[1].node.forward_htlcs.lock().unwrap().len(), 1);
if let Some((_, pending_forwards)) =
nodes[1].node.forward_htlcs.lock().unwrap().iter_mut().next()
{
assert_eq!(pending_forwards.len(), 1);
match pending_forwards.get_mut(0).unwrap() {
&mut HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo {
ref mut forward_info,
..
}) => forward_info.outgoing_amt_msat -= 1,
_ => panic!("Unexpected HTLCForwardInfo"),
}
}
} else {
panic!("Expected pending forwards!");
};
},
true,
Some(LocalHTLCFailureReason::FinalIncorrectHTLCAmount),
Expand Down Expand Up @@ -1553,16 +1561,21 @@ fn test_overshoot_final_cltv() {
commitment_signed_dance!(nodes[1], nodes[0], &update_0.commitment_signed, false, true);

assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
for (_, pending_forwards) in nodes[1].node.forward_htlcs.lock().unwrap().iter_mut() {
for f in pending_forwards.iter_mut() {
match f {
&mut HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo {
ref mut forward_info, ..
}) => forward_info.outgoing_cltv_value += 1,
_ => {},
}
nodes[1].node.process_pending_update_add_htlcs();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this line gets removed in a later commit? It doesn't seem to belong in this commit.

assert_eq!(nodes[1].node.forward_htlcs.lock().unwrap().len(), 1);
if let Some((_, pending_forwards)) =
nodes[1].node.forward_htlcs.lock().unwrap().iter_mut().next()
{
assert_eq!(pending_forwards.len(), 1);
match pending_forwards.get_mut(0).unwrap() {
&mut HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo { ref mut forward_info, .. }) => {
forward_info.outgoing_cltv_value += 1
},
_ => panic!("Unexpected HTLCForwardInfo"),
}
}
} else {
panic!("Expected pending forwards!");
};
expect_and_process_pending_htlcs(&nodes[1], false);

check_added_monitors!(&nodes[1], 1);
Expand Down Expand Up @@ -2614,19 +2627,22 @@ fn test_phantom_final_incorrect_cltv_expiry() {
nodes[1].node.process_pending_update_add_htlcs();

// Modify the payload so the phantom hop's HMAC is bogus.
for (_, pending_forwards) in nodes[1].node.forward_htlcs.lock().unwrap().iter_mut() {
for f in pending_forwards.iter_mut() {
match f {
&mut HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo {
forward_info: PendingHTLCInfo { ref mut outgoing_cltv_value, .. },
..
}) => {
*outgoing_cltv_value -= 1;
},
_ => panic!("Unexpected forward"),
}
if let Some((_, pending_forwards)) =
nodes[1].node.forward_htlcs.lock().unwrap().iter_mut().next()
{
assert_eq!(pending_forwards.len(), 1);
match pending_forwards.get_mut(0).unwrap() {
&mut HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo {
forward_info: PendingHTLCInfo { ref mut outgoing_cltv_value, .. },
..
}) => {
*outgoing_cltv_value -= 1;
},
_ => panic!("Unexpected HTLCForwardInfo"),
}
}
} else {
panic!("Expected pending forwards!");
};
nodes[1].node.process_pending_htlc_forwards();
expect_htlc_failure_conditions(
nodes[1].node.get_and_clear_pending_events(),
Expand Down
68 changes: 39 additions & 29 deletions lightning/src/ln/payment_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,24 +636,30 @@ fn test_reject_mpp_keysend_htlc_mismatching_secret() {
nodes[3].node.process_pending_update_add_htlcs();

assert!(nodes[3].node.get_and_clear_pending_msg_events().is_empty());
for (_, pending_forwards) in nodes[3].node.forward_htlcs.lock().unwrap().iter_mut() {
for f in pending_forwards.iter_mut() {
match f {
&mut HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo {
ref mut forward_info, ..
}) => match forward_info.routing {
assert_eq!(nodes[3].node.forward_htlcs.lock().unwrap().len(), 1);
if let Some((_, pending_forwards)) =
nodes[3].node.forward_htlcs.lock().unwrap().iter_mut().next()
{
assert_eq!(pending_forwards.len(), 1);
match pending_forwards.get_mut(0).unwrap() {
&mut HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo { ref mut forward_info, .. }) => {
match forward_info.routing {
PendingHTLCRouting::ReceiveKeysend { ref mut payment_data, .. } => {
*payment_data = Some(msgs::FinalOnionHopData {
payment_secret: PaymentSecret([42; 32]),
total_msat: amount * 2,
});
},
_ => panic!("Expected PendingHTLCRouting::ReceiveKeysend"),
},
_ => {},
}
}
},
_ => {
panic!("Unexpected HTLCForwardInfo");
},
}
}
} else {
panic!("Expected pending receive");
};
nodes[3].node.process_pending_htlc_forwards();

// Pay along nodes[2]
Expand Down Expand Up @@ -685,26 +691,30 @@ fn test_reject_mpp_keysend_htlc_mismatching_secret() {
nodes[3].node.process_pending_update_add_htlcs();

assert!(nodes[3].node.get_and_clear_pending_msg_events().is_empty());
for (_, pending_forwards) in nodes[3].node.forward_htlcs.lock().unwrap().iter_mut() {
for f in pending_forwards.iter_mut() {
match f {
&mut HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo {
ref mut forward_info, ..
}) => {
match forward_info.routing {
PendingHTLCRouting::ReceiveKeysend { ref mut payment_data, .. } => {
*payment_data = Some(msgs::FinalOnionHopData {
payment_secret: PaymentSecret([43; 32]), // Doesn't match the secret used above
total_msat: amount * 2,
});
},
_ => panic!("Expected PendingHTLCRouting::ReceiveKeysend"),
}
},
_ => {},
}
assert_eq!(nodes[3].node.forward_htlcs.lock().unwrap().len(), 1);
if let Some((_, pending_forwards)) =
nodes[3].node.forward_htlcs.lock().unwrap().iter_mut().next()
{
assert_eq!(pending_forwards.len(), 1);
match pending_forwards.get_mut(0).unwrap() {
&mut HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo { ref mut forward_info, .. }) => {
match forward_info.routing {
PendingHTLCRouting::ReceiveKeysend { ref mut payment_data, .. } => {
*payment_data = Some(msgs::FinalOnionHopData {
payment_secret: PaymentSecret([43; 32]), // Doesn't match the secret used above
total_msat: amount * 2,
});
},
_ => panic!("Expected PendingHTLCRouting::ReceiveKeysend"),
}
},
_ => {
panic!("Unexpected HTLCForwardInfo");
},
}
}
} else {
panic!("Expected pending receive");
};
nodes[3].node.process_pending_htlc_forwards();
let fail_type = HTLCHandlingFailureType::Receive { payment_hash };
expect_and_process_pending_htlcs_and_htlc_handling_failed(&nodes[3], &[fail_type]);
Expand Down