Skip to content

rustfmt non-test ln module's not-currently-being-edited files #3763

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

Conversation

TheBlueMatt
Copy link
Collaborator

This rustfmts most of the remaining files in ln that aren't channel{,manager}.rs, outbound_payment.rs and *_tests.rs. It avoids onion_utils since that may get more edits for trampoline, peer_handler.rs (since that's #3725), and chan_utils.rs since that may get more changes for custom commitments.

@ldk-reviews-bot
Copy link

ldk-reviews-bot commented May 1, 2025

I've assigned @valentinewallace 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.

Copy link
Contributor

@carlaKC carlaKC left a comment

Choose a reason for hiding this comment

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

Refactors look reasonable to me, read through all the reformats + verified that they match local diff.

Might be worth dropping the last commit to save trampoline some pain.

Comment on lines 207 to 208
let mac_check =
chacha.variable_time_decrypt(&cyphertext[0..cyphertext.len() - 16], res, hmac);
mac_check.map_err(|()| LightningError {
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpicky non-blocking personal opinion that this looks better without chacha + mac_check:

ChaCha20Poly1305RFC::new(key, &nonce, h)
    .variable_time_decrypt(hmac, res, &cyphertext[cyphertext.len() - 16..])
    .map_err(|()| LightningError {
        err: "Bad MAC".to_owned(),
        action: msgs::ErrorAction::DisconnectPeer { msg: None },
    })

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So first I went and replaced the two &cyphertext[..] with a cyphertext.split_at which is how it should have been to begin with. Sadly, condensing it the way you suggest makes rustfmt push the whole thing onto one line which is kinda hard to read:

        let (data, hmac) = cyphertext.split_at(cyphertext.len() - 16);
        ChaCha20Poly1305RFC::new(key, &nonce, h).variable_time_decrypt(&data, res, hmac).map_err(
            |()| LightningError {
                err: "Bad MAC".to_owned(),
                action: msgs::ErrorAction::DisconnectPeer { msg: None },
            }
        )

so instead I dropped the chacha but kept the hmac_check (which is vaguely nice because it highlights that we're not decrypting, but only checking the MAC):

        let (data, hmac) = cyphertext.split_at(cyphertext.len() - 16);
        let mac_check =
            ChaCha20Poly1305RFC::new(key, &nonce, h).variable_time_decrypt(&data, res, hmac);
        mac_check.map_err(|()| LightningError {
            err: "Bad MAC".to_owned(),
            action: msgs::ErrorAction::DisconnectPeer { msg: None },
        })

);
expect_channel_ready_event(&nodes[0], &nodes[2].node.get_our_node_id());
expect_channel_ready_event(&nodes[2], &nodes[0].node.get_our_node_id());
let as_channel_ready =
Copy link
Contributor

Choose a reason for hiding this comment

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

Changing as_channel_ready from the message that C omits to send to A to the message that A omits to send C seems consistent with naming elsewhere in the codebase (at least the majority of cases) 👌

use bitcoin::hashes::sha256::Hash as Sha256;
use bitcoin::secp256k1::{self, PublicKey, Secp256k1};
use bitcoin::hashes::Hash;
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

@joostjager joostjager May 3, 2025

Choose a reason for hiding this comment

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

That last commit was just a vanilla rustfmt, wasn't it?

I think (...) that wouldn't be a problem when using the fix script #3749 (comment)? Just apply rustfmt to onion_payment.rs for each commit of #3711.

At least then all the new code added in that PR can be rustfmt-optimized immediately and doesn't need to be touched later again potentially.

TheBlueMatt added 11 commits May 2, 2025 20:46
These methods are super trivial to replace with the
`ChannelManager` equivalent, so keeping them around for a while
doesn't give us anything.
This leaves some mess in the tests, but they're mostly encoding
tests that should never fail and are generally quite short.
Via sed:
s/\(\t*\)\(.*\)<Vec<u8>>::from_hex(\(["0-9a-f]*\)).unwrap()/\1let hex = \3;\r\1\2<Vec<u8>>::from_hex(hex).unwrap()/g
@TheBlueMatt TheBlueMatt force-pushed the 2025-05-rustfmt-untouched-ln branch from 27ca228 to 01f50bc Compare May 2, 2025 20:48
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