-
Notifications
You must be signed in to change notification settings - Fork 58
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
Bump MSRV, upgrade dependencies and clippification #906
Conversation
1.63 is the latest version supported by Debian. It's also now almost a year and a half old (August 2023). We start getting way behind on our dependency updates, and sometimes even missing some security updates (nothing which affects us but still..). Asking to support a less than 2.5yo compiler shouldn't be that much to ask, but hey. 1.63 is now a better balance between support for upstream updates and support for a not recklessly new compiler.
Took care of keeping dirs pinned to avoid the dirs license shitshow. See dirs-dev/dirs-sys-rs@e169da7#r111303146 for more.
This gives us bundled SQLite 3.44.0. Notably this patches CVE-2022-35737 but it shouldn't affect us.
It now finally accepts an option as argument.
314971f
to
e478e57
Compare
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.
ACK e478e57.
I just found one possible change to make regarding a weight calculation.
src/spend.rs
Outdated
let weight: u32 = tx_with_change | ||
.weight() | ||
.to_wu() | ||
.checked_sub(base_weight.into()) | ||
.expect("base_weight can't be larger") | ||
.try_into() | ||
.expect("tx size must always fit in u32") | ||
.expect("tx size must always fit in u32"); | ||
// Starting with version 0.31, rust-bitcoin now accounts for the segwit marker when | ||
// serializing transactions with no input. See comment above. | ||
if tx_with_change.input.is_empty() { | ||
weight.saturating_sub(2) | ||
} else { | ||
weight | ||
} |
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.
I think we could alternatively subtract base_tx.weight().to_wu()
instead of base_weight
and then the extra 2 would be cancelled out from both weight values:
diff --git a/src/spend.rs b/src/spend.rs
index a373542..fc71280 100644
--- a/src/spend.rs
+++ b/src/spend.rs
@@ -300,22 +300,15 @@ fn select_coins_for_spend(
let long_term_feerate = FeeRate::from_sat_per_vb(LONG_TERM_FEERATE_VB);
let drain_weights = DrainWeights {
output_weight: {
- let mut tx_with_change = base_tx;
+ let mut tx_with_change = base_tx.clone();
tx_with_change.output.push(change_txo);
- let weight: u32 = tx_with_change
+ tx_with_change
.weight()
.to_wu()
- .checked_sub(base_weight.into())
+ .checked_sub(base_tx.weight().to_wu())
.expect("base_weight can't be larger")
.try_into()
- .expect("tx size must always fit in u32");
- // Starting with version 0.31, rust-bitcoin now accounts for the segwit marker when
- // serializing transactions with no input. See comment above.
- if tx_with_change.input.is_empty() {
- weight.saturating_sub(2)
- } else {
- weight
- }
+ .expect("tx size must always fit in u32")
},
spend_weight: max_input_weight,
};
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.
Good call. Did something similar:
diff --git a/src/spend.rs b/src/spend.rs
index e8e2e10..091839f 100644
--- a/src/spend.rs
+++ b/src/spend.rs
@@ -300,22 +300,18 @@ fn select_coins_for_spend(
let long_term_feerate = FeeRate::from_sat_per_vb(LONG_TERM_FEERATE_VB);
let drain_weights = DrainWeights {
output_weight: {
+ // We don't reuse the above base_weight.since 2 WU may have been substracted from it.
+ // See comment above for details.
+ let nochange_weight = base_tx.weight().to_wu();
let mut tx_with_change = base_tx;
tx_with_change.output.push(change_txo);
- let weight: u32 = tx_with_change
+ tx_with_change
.weight()
.to_wu()
- .checked_sub(base_weight.into())
+ .checked_sub(nochange_weight)
.expect("base_weight can't be larger")
.try_into()
- .expect("tx size must always fit in u32");
- // Starting with version 0.31, rust-bitcoin now accounts for the segwit marker when
- // serializing transactions with no input. See comment above.
- if tx_with_change.input.is_empty() {
- weight.saturating_sub(2)
- } else {
- weight
- }
+ .expect("tx size must always fit in u32")
},
spend_weight: max_input_weight,
};
(Using a different var name to avoid shadowing if ever refactoring this code in the future.)
The most notable change is rust-bitcoin's change in the serialization of transaction with no input. It now accounts for the segwit marker even for those. The base tx weight in coin selection had to be adapted to handle this. See https://gnusha.org/bitcoin-rust/2024-01-04.log for details.
Bump clippy in CI to latest stable.
e478e57
to
0e99136
Compare
reACK 0e99136 -- re-applying jp1ac4's ACK after addressing review |
New years' cleanup!
Our MSRV was becoming too restrictive to keep being able to benefit from the latest releases of our dependencies. Strike a better balance between not requiring a recklessly new compiler and still being able to get upstream bug fixes.
From this update most of our dependencies to their latest point releases. Then upgrade rusqlite, jsonrpc and rust-[bitcoin, miniscript] to their latest major version. Note their is a ton of updates. I've done a minimal due diligence to check what was updated, to what version, what changed, but i can't realistically audit all the code changes this is effectively pulling. I think we need to look into
cargo-crev
.Take the opportunity to apply some clippy cleanups, and bump the version we're using in CI.
See commit messages for details.