Skip to content

Run rustfmt on chain/transaction, chain/chaininterface, max_payment_path_len_tests, and chanmon_update_fail_tests #3783

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 12 commits into
base: main
Choose a base branch
from
Open
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
183 changes: 58 additions & 125 deletions lightning/src/ln/max_payment_path_len_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,16 @@ fn large_payment_metadata() {
// Check that the maximum-size metadata is sendable.
let (mut route_0_1, payment_hash, payment_preimage, payment_secret) =
get_route_and_payment_hash!(&nodes[0], &nodes[1], amt_msat);
let mut recipient_onion_max_md_size = RecipientOnionFields {
let mut max_sized_onion = RecipientOnionFields {
payment_secret: Some(payment_secret),
payment_metadata: Some(payment_metadata.clone()),
custom_tlvs: Vec::new(),
};
let route_params = route_0_1.route_params.clone().unwrap();
let id = PaymentId(payment_hash.0);
nodes[0]
.node
.send_payment(
payment_hash,
recipient_onion_max_md_size.clone(),
PaymentId(payment_hash.0),
route_0_1.route_params.clone().unwrap(),
Retry::Attempts(0),
)
.send_payment(payment_hash, max_sized_onion.clone(), id, route_params, Retry::Attempts(0))
.unwrap();
check_added_monitors!(nodes[0], 1);
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
Expand All @@ -119,35 +115,20 @@ fn large_payment_metadata() {
let mut route_params_0_2 = route_0_2.route_params.clone().unwrap();
route_params_0_2.payment_params.max_path_length = 1;
nodes[0].router.expect_find_route_query(route_params_0_2);

let id = PaymentId(payment_hash_2.0);
let route_params = route_0_2.route_params.clone().unwrap();
let err = nodes[0]
.node
.send_payment(
payment_hash_2,
recipient_onion_max_md_size.clone(),
PaymentId(payment_hash_2.0),
route_0_2.route_params.clone().unwrap(),
Retry::Attempts(0),
)
.send_payment(payment_hash_2, max_sized_onion.clone(), id, route_params, Retry::Attempts(0))
.unwrap_err();
assert_eq!(err, RetryableSendFailure::RouteNotFound);

// If our payment_metadata contains 1 additional byte, we'll fail prior to pathfinding.
let mut recipient_onion_too_large_md = recipient_onion_max_md_size.clone();
recipient_onion_too_large_md.payment_metadata.as_mut().map(|mut md| md.push(42));
let err = nodes[0]
Copy link
Contributor

Choose a reason for hiding this comment

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

For these formatting PRs, I think it is better to keep the formatting strictly separate from any other change. So that reviewers know what to look for in a commit.

This send_payment call is moved down, but as a reviewer I question myself whether it is just formatting or also something that changed functionally. I see it is now called with payment_hash_2 rather than payment_hash.

.node
.send_payment(
payment_hash,
recipient_onion_too_large_md.clone(),
PaymentId(payment_hash.0),
route_0_1.route_params.clone().unwrap(),
Retry::Attempts(0),
)
.unwrap_err();
assert_eq!(err, RetryableSendFailure::OnionPacketSizeExceeded);
let mut too_large_onion = max_sized_onion.clone();
too_large_onion.payment_metadata.as_mut().map(|mut md| md.push(42));

// Confirm that we'll fail to construct an onion packet given this payment_metadata that's too
// large for even a 1-hop path.
// First confirm we'll fail to create the onion packet directly.
let secp_ctx = Secp256k1::signing_only();
route_0_1.paths[0].hops[0].fee_msat = MIN_FINAL_VALUE_ESTIMATE_WITH_OVERPAY;
route_0_1.paths[0].hops[0].cltv_expiry_delta = DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA;
Expand All @@ -156,7 +137,7 @@ fn large_payment_metadata() {
&route_0_1.paths[0],
&test_utils::privkey(42),
MIN_FINAL_VALUE_ESTIMATE_WITH_OVERPAY,
&recipient_onion_too_large_md,
&too_large_onion,
nodes[0].best_block_info().1 + DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA,
&payment_hash,
&None,
Expand All @@ -171,25 +152,28 @@ fn large_payment_metadata() {
_ => panic!(),
}

let route_params = route_0_1.route_params.clone().unwrap();
let err = nodes[0]
.node
.send_payment(payment_hash_2, too_large_onion, id, route_params, Retry::Attempts(0))
.unwrap_err();
assert_eq!(err, RetryableSendFailure::OnionPacketSizeExceeded);

// If we remove enough payment_metadata bytes to allow for 2 hops, we're now able to send to
// nodes[2].
let mut recipient_onion_allows_2_hops = RecipientOnionFields {
let two_hop_metadata = vec![42; max_metadata_len - INTERMED_PAYLOAD_LEN_ESTIMATE];
let mut onion_allowing_2_hops = RecipientOnionFields {
payment_secret: Some(payment_secret_2),
payment_metadata: Some(vec![42; max_metadata_len - INTERMED_PAYLOAD_LEN_ESTIMATE]),
payment_metadata: Some(two_hop_metadata.clone()),
custom_tlvs: Vec::new(),
};
let mut route_params_0_2 = route_0_2.route_params.clone().unwrap();
route_params_0_2.payment_params.max_path_length = 2;
nodes[0].router.expect_find_route_query(route_params_0_2);
let route_params = route_0_2.route_params.unwrap();
nodes[0]
.node
.send_payment(
payment_hash_2,
recipient_onion_allows_2_hops.clone(),
PaymentId(payment_hash_2.0),
route_0_2.route_params.unwrap(),
Retry::Attempts(0),
)
.send_payment(payment_hash_2, onion_allowing_2_hops, id, route_params, Retry::Attempts(0))
.unwrap();
check_added_monitors!(nodes[0], 1);
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
Expand All @@ -198,7 +182,7 @@ fn large_payment_metadata() {
let args =
PassAlongPathArgs::new(&nodes[0], path, amt_msat, payment_hash_2, events.pop().unwrap())
.with_payment_secret(payment_secret_2)
.with_payment_metadata(recipient_onion_allows_2_hops.payment_metadata.unwrap());
.with_payment_metadata(two_hop_metadata);
do_pass_along_path(args);
claim_payment_along_route(ClaimAlongRouteArgs::new(
&nodes[0],
Expand Down Expand Up @@ -277,18 +261,14 @@ fn one_hop_blinded_path_with_custom_tlv() {
- final_payload_len_without_custom_tlv;

// Check that we can send the maximum custom TLV with 1 blinded hop.
let recipient_onion_max_custom_tlv_size = RecipientOnionFields::spontaneous_empty()
let max_sized_onion = RecipientOnionFields::spontaneous_empty()
.with_custom_tlvs(vec![(CUSTOM_TLV_TYPE, vec![42; max_custom_tlv_len])])
.unwrap();
let id = PaymentId(payment_hash.0);
let no_retry = Retry::Attempts(0);
nodes[1]
.node
.send_payment(
payment_hash,
recipient_onion_max_custom_tlv_size.clone(),
PaymentId(payment_hash.0),
route_params.clone(),
Retry::Attempts(0),
)
.send_payment(payment_hash, max_sized_onion.clone(), id, route_params.clone(), no_retry)
Copy link
Contributor

Choose a reason for hiding this comment

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

My opinion remains unchanged that this isn't necessary to reformat.

.unwrap();
check_added_monitors(&nodes[1], 1);

Expand All @@ -298,57 +278,39 @@ fn one_hop_blinded_path_with_custom_tlv() {
let args =
PassAlongPathArgs::new(&nodes[1], path, amt_msat, payment_hash, events.pop().unwrap())
.with_payment_secret(payment_secret)
.with_custom_tlvs(recipient_onion_max_custom_tlv_size.custom_tlvs.clone());
.with_custom_tlvs(max_sized_onion.custom_tlvs.clone());
do_pass_along_path(args);
claim_payment_along_route(
ClaimAlongRouteArgs::new(&nodes[1], &[&[&nodes[2]]], payment_preimage)
.with_custom_tlvs(recipient_onion_max_custom_tlv_size.custom_tlvs.clone()),
.with_custom_tlvs(max_sized_onion.custom_tlvs.clone()),
);

// If 1 byte is added to the custom TLV value, we'll fail to send prior to pathfinding.
let mut recipient_onion_too_large_custom_tlv = recipient_onion_max_custom_tlv_size.clone();
recipient_onion_too_large_custom_tlv.custom_tlvs[0].1.push(42);
let mut too_large_custom_tlv_onion = max_sized_onion.clone();
too_large_custom_tlv_onion.custom_tlvs[0].1.push(42);
let err = nodes[1]
.node
.send_payment(
payment_hash,
recipient_onion_too_large_custom_tlv,
PaymentId(payment_hash.0),
route_params.clone(),
Retry::Attempts(0),
)
.send_payment(payment_hash, too_large_custom_tlv_onion, id, route_params.clone(), no_retry)
.unwrap_err();
assert_eq!(err, RetryableSendFailure::OnionPacketSizeExceeded);

// With the maximum-size custom TLV, our max path length is limited to 1, so attempting to route
// nodes[0] -> nodes[2] will fail.
let err = nodes[0]
.node
.send_payment(
payment_hash,
recipient_onion_max_custom_tlv_size.clone(),
PaymentId(payment_hash.0),
route_params.clone(),
Retry::Attempts(0),
)
.send_payment(payment_hash, max_sized_onion.clone(), id, route_params.clone(), no_retry)
.unwrap_err();
assert_eq!(err, RetryableSendFailure::RouteNotFound);

// If we remove enough custom TLV bytes to allow for 1 intermediate unblinded hop, we're now able
// to send nodes[0] -> nodes[2].
let mut recipient_onion_allows_2_hops = recipient_onion_max_custom_tlv_size.clone();
recipient_onion_allows_2_hops.custom_tlvs[0]
let mut onion_allows_2_hops = max_sized_onion.clone();
onion_allows_2_hops.custom_tlvs[0]
.1
.resize(max_custom_tlv_len - INTERMED_PAYLOAD_LEN_ESTIMATE, 0);
nodes[0]
.node
.send_payment(
payment_hash,
recipient_onion_allows_2_hops.clone(),
PaymentId(payment_hash.0),
route_params.clone(),
Retry::Attempts(0),
)
.send_payment(payment_hash, onion_allows_2_hops.clone(), id, route_params.clone(), no_retry)
.unwrap();
check_added_monitors(&nodes[0], 1);

Expand All @@ -358,11 +320,11 @@ fn one_hop_blinded_path_with_custom_tlv() {
let args =
PassAlongPathArgs::new(&nodes[0], path, amt_msat, payment_hash, events.pop().unwrap())
.with_payment_secret(payment_secret)
.with_custom_tlvs(recipient_onion_allows_2_hops.custom_tlvs.clone());
.with_custom_tlvs(onion_allows_2_hops.custom_tlvs.clone());
do_pass_along_path(args);
claim_payment_along_route(
ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1], &nodes[2]]], payment_preimage)
.with_custom_tlvs(recipient_onion_allows_2_hops.custom_tlvs),
.with_custom_tlvs(onion_allows_2_hops.custom_tlvs),
);
}

Expand Down Expand Up @@ -425,18 +387,14 @@ fn blinded_path_with_custom_tlv() {
- reserved_packet_bytes_without_custom_tlv;

// Check that we can send the maximum custom TLV size with 0 intermediate unblinded hops.
let recipient_onion_max_custom_tlv_size = RecipientOnionFields::spontaneous_empty()
let max_sized_onion = RecipientOnionFields::spontaneous_empty()
.with_custom_tlvs(vec![(CUSTOM_TLV_TYPE, vec![42; max_custom_tlv_len])])
.unwrap();
let no_retry = Retry::Attempts(0);
let id = PaymentId(payment_hash.0);
nodes[1]
.node
.send_payment(
payment_hash,
recipient_onion_max_custom_tlv_size.clone(),
PaymentId(payment_hash.0),
route_params.clone(),
Retry::Attempts(0),
)
.send_payment(payment_hash, max_sized_onion.clone(), id, route_params.clone(), no_retry)
.unwrap();
check_added_monitors(&nodes[1], 1);

Expand All @@ -446,25 +404,19 @@ fn blinded_path_with_custom_tlv() {
let args =
PassAlongPathArgs::new(&nodes[1], path, amt_msat, payment_hash, events.pop().unwrap())
.with_payment_secret(payment_secret)
.with_custom_tlvs(recipient_onion_max_custom_tlv_size.custom_tlvs.clone());
.with_custom_tlvs(max_sized_onion.custom_tlvs.clone());
do_pass_along_path(args);
claim_payment_along_route(
ClaimAlongRouteArgs::new(&nodes[1], &[&[&nodes[2], &nodes[3]]], payment_preimage)
.with_custom_tlvs(recipient_onion_max_custom_tlv_size.custom_tlvs.clone()),
.with_custom_tlvs(max_sized_onion.custom_tlvs.clone()),
);

// If 1 byte is added to the custom TLV value, we'll fail to send prior to pathfinding.
let mut recipient_onion_too_large_custom_tlv = recipient_onion_max_custom_tlv_size.clone();
recipient_onion_too_large_custom_tlv.custom_tlvs[0].1.push(42);
let mut too_large_onion = max_sized_onion.clone();
too_large_onion.custom_tlvs[0].1.push(42);
let err = nodes[1]
.node
.send_payment(
payment_hash,
recipient_onion_too_large_custom_tlv.clone(),
PaymentId(payment_hash.0),
route_params.clone(),
Retry::Attempts(0),
)
.send_payment(payment_hash, too_large_onion.clone(), id, route_params.clone(), no_retry)
.unwrap_err();
assert_eq!(err, RetryableSendFailure::OnionPacketSizeExceeded);

Expand All @@ -477,7 +429,7 @@ fn blinded_path_with_custom_tlv() {
&route.paths[0],
&test_utils::privkey(42),
MIN_FINAL_VALUE_ESTIMATE_WITH_OVERPAY,
&recipient_onion_too_large_custom_tlv,
&too_large_onion,
nodes[0].best_block_info().1 + DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA,
&payment_hash,
&None,
Expand All @@ -496,31 +448,19 @@ fn blinded_path_with_custom_tlv() {
// to route nodes[0] -> nodes[3] will fail.
let err = nodes[0]
.node
.send_payment(
payment_hash,
recipient_onion_max_custom_tlv_size.clone(),
PaymentId(payment_hash.0),
route_params.clone(),
Retry::Attempts(0),
)
.send_payment(payment_hash, max_sized_onion.clone(), id, route_params.clone(), no_retry)
.unwrap_err();
assert_eq!(err, RetryableSendFailure::RouteNotFound);

// If we remove enough custom TLV bytes to allow for 1 intermediate unblinded hop, we're now able
// to send nodes[0] -> nodes[3].
let mut recipient_onion_allows_2_hops = recipient_onion_max_custom_tlv_size.clone();
recipient_onion_allows_2_hops.custom_tlvs[0]
let mut onion_allowing_2_hops = max_sized_onion.clone();
onion_allowing_2_hops.custom_tlvs[0]
.1
.resize(max_custom_tlv_len - INTERMED_PAYLOAD_LEN_ESTIMATE, 0);
nodes[0]
.node
.send_payment(
payment_hash,
recipient_onion_allows_2_hops.clone(),
PaymentId(payment_hash.0),
route_params.clone(),
Retry::Attempts(0),
)
.send_payment(payment_hash, onion_allowing_2_hops.clone(), id, route_params, no_retry)
.unwrap();
check_added_monitors(&nodes[0], 1);

Expand All @@ -530,15 +470,15 @@ fn blinded_path_with_custom_tlv() {
let args =
PassAlongPathArgs::new(&nodes[0], path, amt_msat, payment_hash, events.pop().unwrap())
.with_payment_secret(payment_secret)
.with_custom_tlvs(recipient_onion_allows_2_hops.custom_tlvs.clone());
.with_custom_tlvs(onion_allowing_2_hops.custom_tlvs.clone());
do_pass_along_path(args);
claim_payment_along_route(
ClaimAlongRouteArgs::new(
&nodes[0],
&[&[&nodes[1], &nodes[2], &nodes[3]]],
payment_preimage,
)
.with_custom_tlvs(recipient_onion_allows_2_hops.custom_tlvs),
.with_custom_tlvs(onion_allowing_2_hops.custom_tlvs),
);
}

Expand Down Expand Up @@ -577,17 +517,10 @@ fn bolt12_invoice_too_large_blinded_paths() {

let offer = nodes[1].node.create_offer_builder(None).unwrap().build().unwrap();
let payment_id = PaymentId([1; 32]);
let route_config = RouteParametersConfig::default();
nodes[0]
.node
.pay_for_offer(
&offer,
None,
Some(5000),
None,
payment_id,
Retry::Attempts(0),
RouteParametersConfig::default(),
)
.pay_for_offer(&offer, None, Some(5000), None, payment_id, Retry::Attempts(0), route_config)
.unwrap();
let invreq_om = nodes[0]
.onion_messenger
Expand Down