Skip to content

Run rustfmt on payment_tests and functional_tests and split up the latter #3751

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 18 commits into
base: main
Choose a base branch
from

Conversation

TheBlueMatt
Copy link
Collaborator

functional_tests' time has come, and there's some easy batches of tests to move into separate files. Even at the end its still 10k LoC, but that's better than the 14K it started as (let alone how long it'd be if it were naively rustfmt'd).

`funtional_tests.rs` has gotten incredibly huge over the years, so
here we move some channel reserve tests into a new file.
`funtional_tests.rs` has gotten incredibly huge over the years, so
here we move some further channel reserve tests into a new file.

We do so separately from the previous commit to ensure git
identifies the changes as move-only.
`funtional_tests.rs` has gotten incredibly huge over the years, so
here we move some simple HTLC unit tests into a new file.
`funtional_tests.rs` has gotten incredibly huge over the years, so
here we move all the channel fee-related tests out to their own
file.
@ldk-reviews-bot
Copy link

ldk-reviews-bot commented Apr 28, 2025

👋 Thanks for assigning @joostjager as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

In general we shouldn't have tests lying around that are useless as
its dead code and may break due to harmless protocol changes. Here,
we drop a few useless tests.
@TheBlueMatt TheBlueMatt force-pushed the 2025-04-rustfmt-tests-1 branch from 293c6af to 820cb58 Compare April 28, 2025 14:54
@wpaulino wpaulino requested review from joostjager and removed request for wpaulino April 28, 2025 20:27
Copy link
Contributor

@joostjager joostjager left a comment

Choose a reason for hiding this comment

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

First of all, I’m incredibly impressed by your ability to stay focused and produce a change set like this. Maybe you used some refactoring tooling or search/replace, but even so, it's impressive. As a reviewer, I’m quite sure I have done a worse job. This kind of diff is hard to stay attentive to, and I haven’t verified every single repeated change in detail.

Secondly, given the potential for merge conflicts, it's probably best not to leave this PR open longer than necessary.

I understand why you want these refactors before applying rustfmt, but I think it’s important to acknowledge that many of these changes are a matter of personal preference rather than necessity. Some of them might even reduce readability, depending on who you ask.

There’s also some risk involved. As mentioned, this kind of work demands a lot of attention from both the author and reviewers. While the impact is lower for tests, I would be hesitant to apply a similar approach to non-test code. Fixing formatting issues in the normal flow of PRs feels much safer.

All that said, this work is done now, and despite the subjective aspects, I believe this PR is a net positive change. Still, it reinforces my opinion that for the rest of the codebase, we should move forward with #3749.

let params = route.route_params.clone().unwrap();
let onion = RecipientOnionFields::spontaneous_empty();
let retry = Retry::Attempts(0);
nodes[0].node.send_spontaneous_payment(preimage, onion, payment_id_0, params, retry).unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

Whether extractions into short var names is an improvement or not, is subjective. Especially with an IDE that whispers argument names, I prefer not to have the indirection through these short vars.

I am totally fine with what it was:

image

Copy link
Contributor

Choose a reason for hiding this comment

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

Would agree with this, in some cases there's a loss of information in the new var name (e.g. removing _msat suffix, secret vs payment_secret) which doesn't seem worth it. It also makes it less clear that the variable isn't used elsewhere.

let third_persister;
let third_new_chain_monitor;
let persist_1;
let chain_1;
Copy link
Contributor

Choose a reason for hiding this comment

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

This might be considered loss of information / readability. It think it is valid to have a preference for more vertical layout instead.

let secret = Some(payment_secret);
let path = &[&nodes[1]];
pass_along_path(&nodes[0], path, amt_msat, payment_hash, secret, event, true, Some(preimage));
claim_payment_along_route(ClaimAlongRouteArgs::new(&nodes[0], &[path], preimage));
Copy link
Contributor

Choose a reason for hiding this comment

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

For this type PR, an alternative commit structure would be to first 'rustfmt' and then fix problems in a later commit. That way as a reviewer it's possible to see how the formatting was improved by looking at the diff.

For this review, I kept a local 'naively' rustfmt'ed copy on the side to glance at occassionally.


let (temp_chan_id, tx, funding_output) =
create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 1_000_000, 42);
create_funding_transaction(&nodes[0], &node_b_id, 1_000_000, 42);
Copy link
Contributor

Choose a reason for hiding this comment

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

Mixing node numbers and letters isn't ideal I think. node_0_id etc would have been consistent.

@@ -505,3 +509,433 @@ pub fn channel_reserve_in_flight_removes() {
claim_payment(&nodes[1], &[&nodes[0]], payment_preimage_4);
claim_payment(&nodes[0], &[&nodes[1]], payment_preimage_3);
}

#[xtest(feature = "_externalize_tests")]
Copy link
Contributor

Choose a reason for hiding this comment

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

Commit msg typo, funtional_tests

assert!(nodes[0].node.create_channel(node_b_id, channel_value_satoshis, push_msat, 42, None, None).is_ok()); //Create a valid channel
let node0_to_1_send_open_channel = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, node_b_id);
assert!(node0_to_1_send_open_channel.channel_reserve_satoshis>=node0_to_1_send_open_channel.common_fields.dust_limit_satoshis);
nodes[0].node.create_channel(node_b_id, 100_000, 0, 42, None, None).unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

Explain in the commit message why it is dead code?

@@ -62,7 +62,7 @@ pub fn test_async_inbound_update_fee() {
*feerate_lock += 20;
}
nodes[0].node.timer_tick_occurred();
check_added_monitors!(nodes[0], 1);
check_added_monitors(&nodes[0], 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

It's nice to de-macro, but doing it in a separate PR would've been fine too. Just pre-formatting is a lot already.

@ldk-reviews-bot
Copy link

👋 The first review has been submitted!

Do you think this PR is ready for a second reviewer? If so, click here to assign a second reviewer.

@ldk-reviews-bot
Copy link

✅ Added second reviewer: @valentinewallace

@valentinewallace
Copy link
Contributor

Needs rebase since #3700 landed

let params = route.route_params.clone().unwrap();
let onion = RecipientOnionFields::spontaneous_empty();
let retry = Retry::Attempts(0);
nodes[0].node.send_spontaneous_payment(preimage, onion, payment_id_0, params, retry).unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

Would agree with this, in some cases there's a loss of information in the new var name (e.g. removing _msat suffix, secret vs payment_secret) which doesn't seem worth it. It also makes it less clear that the variable isn't used elsewhere.

assert_eq!(unusable_chan_err , APIError::ChannelUnavailable {
err: format!("Channel with id {} for the passed counterparty node_id {} is still opening.",
temp_chan_id, node_c_id) });
let chan_id = nodes[1].node.create_channel(node_c_id, 100_000, 0, 42, None, None).unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

Prefer s/chan_id/temp_id to make it clearer what's going on

Comment on lines -10050 to +10488
*nodes[0].connect_style.borrow_mut() = ConnectStyle::BestBlockFirstSkippingBlocks;

let node_a_id = nodes[0].node.get_our_node_id();
let node_b_id = nodes[1].node.get_our_node_id();
let node_c_id = nodes[2].node.get_our_node_id();

*nodes[0].connect_style.borrow_mut() = ConnectStyle::BestBlockFirstSkippingBlocks;

let node_c_id = node_c_id;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: unnecessary diff and declared node_c_id twice

Comment on lines 1494 to 1496
fn commit_tx_fee_msat(feerate: u32, num_htlcs: u64, channel_type_features: &ChannelTypeFeatures) -> u64 {
(commitment_tx_base_weight(channel_type_features) + num_htlcs * COMMITMENT_TX_WEIGHT_PER_HTLC) * feerate as u64 / 1000 * 1000
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this belongs in the commit that adds this method to functional_test_utils

assert!(nodes[0].node.create_channel(node_b_id, channel_value_satoshis, push_msat, 42, None, None).is_ok()); //Create a valid channel
let node0_to_1_send_open_channel = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, node_b_id);
assert!(node0_to_1_send_open_channel.channel_reserve_satoshis>=node0_to_1_send_open_channel.common_fields.dust_limit_satoshis);
nodes[0].node.create_channel(node_b_id, 100_000, 0, 42, None, None).unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

This and the below get_event_msg call need a comment now for what they're testing

Comment on lines +32 to +38
use crate::ln::channel::{
get_holder_selected_channel_reserve_satoshis, Channel, InboundV1Channel, OutboundV1Channel,
COINBASE_MATURITY,
};
use crate::ln::channel::{
ChannelError, DISCONNECT_PEER_AWAITING_RESPONSE_TICKS, MIN_CHAN_DUST_LIMIT_SATOSHIS,
};
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: combine imports here and above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants