-
Notifications
You must be signed in to change notification settings - Fork 375
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
Upgrade rust-bitcoin dependency to 0.31 #3063
Upgrade rust-bitcoin dependency to 0.31 #3063
Conversation
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.
Thanks for taking a crack at this! I just skimmed the diff, looking forward to you addressing the remaining issues :). Note that our CI is insistent on each individual commit compiling, so you may end up squashing most of this PR into one commit.
lightning/src/ln/chan_utils.rs
Outdated
@@ -542,6 +545,13 @@ pub struct HTLCOutputInCommitment { | |||
pub transaction_output_index: Option<u32>, | |||
} | |||
|
|||
impl HTLCOutputInCommitment { | |||
/// Returns value of the HTLC. | |||
pub const fn amount(&self) -> Amount { |
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 is a confusing API given an HTLCOutput is for an amount
denominated in msat, but this is rounding to sats.
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.
In the latest version, I named it to_bitcoin_amount()
but I believe there may be better names. Is there some preference?
to_btc_amount()
to_amount()
to_amount_sat()
629ebcb
to
9b2ca1c
Compare
Please let us know when you want some rounds of review by leaving a comment! |
Yes, I will. Thanks! |
a8eee16
to
73d4341
Compare
Codecov ReportAttention: Patch coverage is
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #3063 +/- ##
==========================================
- Coverage 89.90% 89.87% -0.04%
==========================================
Files 117 117
Lines 97105 97134 +29
Branches 97105 97134 +29
==========================================
- Hits 87303 87298 -5
- Misses 7243 7270 +27
- Partials 2559 2566 +7 ☔ View full report in Codecov by Sentry. |
042bc27
to
4aae621
Compare
This is ready for review. I still kept the PR broken into multiple commits that do not compile on their own. This way I can point attention to a few specific changes. I will squash all into one commit after review. Thanks, Matt, for early quick review! |
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.
Did a first pass, mostly looks good to me, just a few comments.
I really like the refactor to use bitcoin::Amount
in more and more places, as it nicely prepares for #2076.
let script = if channel_parameters.channel_type_features().supports_anchors_zero_fee_htlc_tx() { | ||
get_to_countersignatory_with_anchors_redeemscript(&countersignatory_pubkeys.payment_point).to_v0_p2wsh() | ||
} else { | ||
Payload::p2wpkh(&BitcoinPublicKey::new(countersignatory_pubkeys.payment_point)).unwrap().script_pubkey() | ||
ScriptBuf::new_p2wpkh(&Hash160::hash(&countersignatory_pubkeys.payment_point.serialize()).into()) |
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.
Maybe worth to still use bitcoin::key::PublicKey
to be able to use wpubkey_hash
here?
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.
Mmm, I don't know. While the version with bitcoin::key::PublicKey
is a bit more understandable in the intent, it is more verbose and requires an expect()
.
So far I kept it but if you think that it would still be better to use bitcoin::key::PublicKey
, I will change.
Thanks!
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.
Getting rid of an unwrap()
and some verbosity sounds fair and I don't think this reduces clarity that much since intent is clear from new_p2wpkh
.
4aae621
to
32de8fe
Compare
Addressed tnull's comments and rebased. |
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.
Looks good! Just some minor comments.
If @TheBlueMatt and @tnull are happy with the changes, I think this can be squashed :)
let script = if channel_parameters.channel_type_features().supports_anchors_zero_fee_htlc_tx() { | ||
get_to_countersignatory_with_anchors_redeemscript(&countersignatory_pubkeys.payment_point).to_v0_p2wsh() | ||
} else { | ||
Payload::p2wpkh(&BitcoinPublicKey::new(countersignatory_pubkeys.payment_point)).unwrap().script_pubkey() | ||
ScriptBuf::new_p2wpkh(&Hash160::hash(&countersignatory_pubkeys.payment_point.serialize()).into()) |
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.
Getting rid of an unwrap()
and some verbosity sounds fair and I don't think this reduces clarity that much since intent is clear from new_p2wpkh
.
@@ -21,7 +21,8 @@ stdin_fuzz = [] | |||
lightning = { path = "../lightning", features = ["regex", "hashbrown", "_test_utils"] } | |||
lightning-invoice = { path = "../lightning-invoice" } | |||
lightning-rapid-gossip-sync = { path = "../lightning-rapid-gossip-sync" } | |||
bitcoin = { version = "0.30.2", features = ["secp-lowmemory"] } | |||
bech32 = "0.9.1" |
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 believe [email protected]
is also fine for [email protected]
, but I guess we'll bump it with the next PR for [email protected]
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 no 0.10.0 final release (only beta) and it also contains the complete rewrite. So using 0.10 would not help as it would require to rewrite everything in LDK that uses bech32. That's the main reason for sticking to 0.9, so that LDK does not need to rewrite usage of bech32 yet.
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.
Ah I see. Thanks!
32de8fe
to
1daaeda
Compare
1daaeda
to
a8bd4c0
Compare
Addressed @dunxen's comments (thanks!), fixed commit compile check, rebased and finally squashed (otherwise commits would not compile on their own). |
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.
LGTM let's see if CI is happy (besides any unrelated stuff). Then I'll let @tnull and @TheBlueMatt take a final look. Not sure if anything needs to get in before this but I doubt it will create anything more than a few simple 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.
LGTM
Given the size of the changeset, three pairs of eyes can't hurt though, so I'll defer to @TheBlueMatt for the final ACK.
// base size = version size + varint[input count] + input size + varint[output count] + output size + lock time size | ||
// total size = version size + marker + flag + varint[input count] + input size + varint[output count] + output size + lock time size | ||
// weight = 3 * base size + total size = 3 * (4 + 1 + 0 + 1 + 0 + 4) + (4 + 1 + 1 + 1 + 0 + 1 + 0 + 4) = 3 * 10 + 12 = 42 | ||
assert_eq!(tx.weight().to_wu(), 42); |
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 we know where this discrepancy (40 before, now 42) comes from?
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.
rust-bitcoin changed the way how weight was calculated. Probably the previous version was not accurate: rust-bitcoin/rust-bitcoin#2049
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.
Thanks! IMO we should rename to_bitcoin_amount
in a followup, and should also obviously upgrade bech32.
@@ -15,6 +15,12 @@ | |||
#[cfg(not(fuzzing))] | |||
compile_error!("Fuzz targets need cfg=fuzzing"); | |||
|
|||
#[cfg(not(hashes_fuzz))] |
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.
These changes should have been in a separate commit.
@@ -878,8 +878,7 @@ impl SignedRawBolt11Invoice { | |||
|
|||
/// Recovers the public key used for signing the invoice from the recoverable signature. | |||
pub fn recover_payee_pub_key(&self) -> Result<PayeePubKey, secp256k1::Error> { | |||
let hash = Message::from_slice(&self.hash[..]) | |||
.expect("Hash is 32 bytes long, same as MESSAGE_SIZE"); | |||
let hash = Message::from_digest(self.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.
Same here, the old fn still exists, its just deprecated, so we should have fixed it in a separate commit.
/// Converts HTLC's value with millisatoshi precision into [bitcoin::Amount] with satoshi precision. | ||
/// Typically this conversion is needed when transitioning from LN into base-layer Bitcoin, | ||
/// e. g. in commitment transactions. | ||
pub const fn to_bitcoin_amount(&self) -> Amount { |
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'd kinda prefer if we called this satoshi_amount
(its not a to_
because we're not converting the object, and its using satoshi
(or sats
or whatever) improves readability at the callsites (where bitcoin_amount
might imply the amount in whole bitcoins).
Due to the commit compile check, the change comes as one big commit.
Commits do not compile on their own at the momet. I wanted to attract reviewers' attention to a few specific changes, so they have dedicated commits. CommitsUpgrade rust-bitcoin to 0.31*
are relatively uninvolved, so isResolve deprecations
, however the remaining commits bring some changes that I want to point out.At the end, all commits will be squashed into one big.Please let me know what else I forgot and what could be done better and easier for reviewing.
Closes #2745.
Notes
Bech32
v0.31 started to use bech32 v0.10, which is a complete rewrite of the library. This PR keeps using bech32 v0.9.1, it just made it explicit (previously was via rust-bitcoin). Upgrade would require many more changes (
FromBase32
andu5
were removed). Dependency tree will contain both versions of bech32, but they should not be in conflict since v0.31 uses it only internally.Amount type
v0.31 uses
Amount
more often, newly for example inTxOut
's value. Since this field is used quite often in rust-lightning, this PR accommodates to it by changing some occurrrences of usingu64
for amount of satoshi intoAmount
. I did not try to change all such cases; I usually set the boundary on public interfaces.In tests, I used all existing calculations in
u64
, converted toAmount
only at the end.Transaction weight
Calculation of transaction weight in v0.31 was corrected and that broke some tests.
Most notable change is in
Fix test_tx_change_edge
commit.PSBT
Psbt::extract_tx()
newly checks for using too high a fee rate but requires prevouts. Substituted byPsbt::extract_tx_unchecked_fee_rate()
which behaves the same asPsbt::extract_tx()
in v0.30.Broken teststransaction_utils / test_tx_change_edgeError message
Due to corrected weight calculation of transactions in v0.31, the test had to be adjusted to reflect that.
lightning-block-syncError message
Bug in hex-conservative in error message of parsing hash types from string. PR #88 should fix it.Fixed in hex-conservative v0.1.2
FuzzError message
Dependencies secp256k1 and bitcoin_hashes newly need dedicated flags to enable fuzzing,
cfg=secp256k1_fuzz
andcfg=hashes_fuzz
.