-
Notifications
You must be signed in to change notification settings - Fork 403
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
base: main
Are you sure you want to change the base?
rustfmt
non-test ln
module's not-currently-being-edited files
#3763
Conversation
I've assigned @valentinewallace as a reviewer! |
There was a problem hiding this 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.
let mac_check = | ||
chacha.variable_time_decrypt(&cyphertext[0..cyphertext.len() - 16], res, hmac); | ||
mac_check.map_err(|()| LightningError { |
There was a problem hiding this comment.
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 },
})
There was a problem hiding this comment.
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 = |
There was a problem hiding this comment.
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) 👌
lightning/src/ln/onion_payment.rs
Outdated
use bitcoin::hashes::sha256::Hash as Sha256; | ||
use bitcoin::secp256k1::{self, PublicKey, Secp256k1}; | ||
use bitcoin::hashes::Hash; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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.
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
27ca228
to
01f50bc
Compare
This
rustfmt
s most of the remaining files inln
that aren'tchannel{,manager}.rs
,outbound_payment.rs
and*_tests.rs
. It avoidsonion_utils
since that may get more edits for trampoline,peer_handler.rs
(since that's #3725), andchan_utils.rs
since that may get more changes for custom commitments.