-
Notifications
You must be signed in to change notification settings - Fork 368
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
rustfmt
: Run on util/*
(2/2)
#3323
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3323 +/- ##
==========================================
- Coverage 89.62% 89.56% -0.07%
==========================================
Files 127 127
Lines 103517 104124 +607
Branches 103517 104124 +607
==========================================
+ Hits 92780 93257 +477
- Misses 8041 8116 +75
- Partials 2696 2751 +55 ☔ View full report in Codecov by Sentry. |
6c4dd83
to
9b991df
Compare
Ugh, can we split this? 42 commits in one PR is just a lot... |
Alright, happy to if you prefer (although at least half of these commits are one-line diffs). Now split out ~the first half of commits to #3324. |
60ae0af
to
e2dcdc7
Compare
Rebased after #3327 landed. |
e2dcdc7
to
bc122e3
Compare
Rebased after #3324 landed. |
bc122e3
to
572f48c
Compare
Rebased to resolve minor conflicts. |
572f48c
to
449a0d6
Compare
Rebased once more to resolve minor conflicts. Any additional comments here after we landed the split-out commits in #3324, @TheBlueMatt ? |
.. we pull out `Mutex` field initialization into dedicated variables as they might otherwise land on the same line when formatting, which might lead to lockorder violation false-positives when compiled with the `backtrace` feature.
449a0d6
to
b909a7a
Compare
Rebased once more to resolve minor conflicts. |
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.
Some initial comments. Maybe could have been split across PRs.
($last_type: expr, $type: expr, $fieldty: tt) => { | ||
if let Some(t) = $last_type { | ||
#[allow(unused_comparisons)] // Note that $type may be 0 making the following comparison always false | ||
#[allow(unused_comparisons)] | ||
// Note that $type may be 0 making the following comparison always false |
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.
This should go above the allow
, no?
$crate::_get_varint_length_prefixed_tlv_length!( | ||
$len, | ||
$type, | ||
$crate::util::ser::WithoutLength(&$field), |
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.
Can this be pulled out into a var?
$crate::_get_varint_length_prefixed_tlv_length!( | ||
$len, | ||
$type, | ||
$field.map(|f| $encoding(f)), |
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.
Same.
#[allow(unused_comparisons)] // Note that $type may be 0 making the second comparison always false | ||
let invalid_order = ($last_seen_type.is_none() || $last_seen_type.unwrap() < $type) && $typ.0 > $type; | ||
#[allow(unused_comparisons)] | ||
// Note that $type may be 0 making the second comparison always false |
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.
Same
#[allow(unused_comparisons)] // Note that $type may be 0 making the second comparison always false | ||
let invalid_order = ($last_seen_type.is_none() || $last_seen_type.unwrap() < $type) && $typ.0 > $type; | ||
#[allow(unused_comparisons)] | ||
// Note that $type may be 0 making the second comparison always false |
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.
Same
).unwrap()[..]) { | ||
} else { panic!(); } | ||
if let Err(DecodeError::InvalidValue) = tlv_reader( | ||
&<Vec<u8>>::from_hex(concat!("0100", "0304deadbeef", "0208deadbeef1badbeef")).unwrap() |
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.
Some of these (across these tests) could be cleaned up a good bit if the vec+slice were pulled out or the tlv_reader
return value were pulled out.
do_test!(concat!("01", "08", "0100000000000000"), Some(72057594037927936), None, None, None); | ||
do_test!(concat!("02", "08", "0000000000000226"), None, Some((0 << 30) | (0 << 5) | (550 << 0)), None, None); | ||
do_test!( | ||
concat!("01", "08", "0100000000000000"), |
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.
Same here.
} | ||
|
||
fn sign_counterparty_htlc_transaction(&self, htlc_tx: &Transaction, input: usize, amount: u64, per_commitment_point: &PublicKey, htlc: &HTLCOutputInCommitment, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, ()> { | ||
Ok(EcdsaChannelSigner::sign_holder_htlc_transaction( |
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.
Can this be less verbose if we use self.inner.sign_holder_htlc_transaction
?
weight_with_change += (VarInt(tx.output.len() as u64 + 1).size() | ||
- VarInt(tx.output.len() as u64).size()) as i64 | ||
* 4; | ||
// When calculating weight, add two for the flag bytes | ||
let change_value: i64 = (input_value - output_value).to_sat() as i64 - weight_with_change * feerate_sat_per_1000_weight as i64 / 1000; | ||
let change_value: i64 = (input_value - output_value).to_sat() as i64 | ||
- weight_with_change * feerate_sat_per_1000_weight as i64 / 1000; | ||
if change_value >= dust_value.to_sat() as i64 { | ||
change_output.value = Amount::from_sat(change_value as u64); | ||
tx.output.push(change_output); | ||
Ok(weight_with_change as u64) | ||
} else if (input_value - output_value).to_sat() as i64 - (starting_weight as i64) * feerate_sat_per_1000_weight as i64 / 1000 < 0 { | ||
} else if (input_value - output_value).to_sat() as i64 | ||
- (starting_weight as i64) * feerate_sat_per_1000_weight as i64 / 1000 | ||
< 0 |
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.
Could probably use some new variables here.
version: Version::TWO, | ||
lock_time: LockTime::ZERO, | ||
input: Vec::new(), | ||
output: vec![TxOut { script_pubkey: ScriptBuf::new(), value: Amount::from_sat(1000) }], | ||
}; | ||
assert!(maybe_add_change_output( | ||
&mut tx, | ||
Amount::from_sat(21_000_000_0000_0001), | ||
0, | ||
253, | ||
ScriptBuf::new() |
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.
Do these want new variables (similarly below)?
This is PR 2/2, based on #3324.
The diff is a bit larger for this one, but AFAICT the changes look mostly reasonable (besides the oddity commented below).
FWIW, I had a look at currently open inflight PRs and the conflicts should be minimal if I'm not overlooking something.