units: Deprecate from_witness_data_size and from_non_witness_data_size#4915
units: Deprecate from_witness_data_size and from_non_witness_data_size#4915apoelstra merged 3 commits intorust-bitcoin:masterfrom
from_witness_data_size and from_non_witness_data_size#4915Conversation
0ffdf46 to
23e2d73
Compare
from_witness_data_size and from_non_witness_data_sizefrom_witness_data_size and from_non_witness_data_size
| } | ||
|
|
||
| /// Constructs a new [`Weight`] from witness size. | ||
| pub const fn from_witness_data_size(witness_size: u64) -> Self { Weight::from_wu(witness_size) } |
There was a problem hiding this comment.
This is exposed in 0.32.7 so it would be worth a deprecation warning? Same with the other function.
There was a problem hiding this comment.
Yeah mate, we should deprecate then backport the deprecation to 0.32.x
If you deprecate here I'll do the backport.
There was a problem hiding this comment.
my bad, thought the next release was gonna be the 1.0 one so this wouldn't be in there (but we'd still need to backport). Ill update this later this afternoon when I have a sec
There was a problem hiding this comment.
The plan is to have a final RC release with all the deprecated stuff in there and then drop the 1.0 without it.
23e2d73 to
740a60e
Compare
from_witness_data_size and from_non_witness_data_sizefrom_witness_data_size and from_non_witness_data_size
| /// # Panics | ||
| /// | ||
| /// If the conversion from virtual bytes overflows. | ||
| #[deprecated(since = "TBD", note = "use `from_vb` or `from_vb_unchecked` instead")] |
There was a problem hiding this comment.
Not sure if it's enough to just add the doc update here, but since it's already exposed, i didn't want to break it
There was a problem hiding this comment.
Yep looks good to me. I'd just delete the unit test though.
There was a problem hiding this comment.
since the constructors are still there, shouldn't we leave the tests and remove them all together when we clean out the deprecated code?
740a60e to
ebbfdcc
Compare
|
While looking into #5054, found that these constructors were causing the daily fuzz cron job to fail, so removing them from the fuzz target |
|
In cacf1b3 The commit log says 'deprecate ...' but then two public functions have their return types changed. This is a breaking change and needs to be done in a separate patch please. I"d actually prefer to see it in a different PR. In this PR we could just throw and allow-deprecated attribute on the call sites in |
|
@tcharding the two functions that had their return types changed aren't public: and I just added the deprecated tag to the public ones, and for |
|
I believe these are public because they are defined as part of the |
|
ah you're totally right. Is it ok if i use: #![allow(deprecated_in_future)] // For `from_non_witness_data_size` and `from_witness_data_size`at the top of internal_macros::define_extension_trait! {
/// Extension functionality for the [`OutPoint`] type.
pub trait OutPointExt impl for OutPoint {
/// Constructs a new [`OutPoint`].
#[inline]
#[deprecated(since = "TBD", note = "use struct initialization syntax instead")]
#[allow(clippy::new-ret-no-self)]
fn new(txid: Txid, vout: u32) -> Self { OutPoint { txid, vout } }
/// Checks if an `OutPoint` is "null".
#[inline]
#[deprecated(since = "TBD", note = "use `outpoint == OutPoint::COINBASE_PREVOUT` instead")]
fn is_null(&self) -> bool { *self == OutPoint::COINBASE_PREVOUT }
}
}gets expanded to (note the missing #[cfg_attr(docsrs, doc(notable_trait))]
#[doc = " Extension functionality for the [`OutPoint`] type."]
pub trait OutPointExt: sealed::Sealed {
#[doc = " Constructs a new [`OutPoint`]."]
fn new(txid: Txid, vout: u32) -> Self;
#[doc = " Checks if an `OutPoint` is \"null\"."]
fn is_null(&self) -> bool;
}
impl OutPointExt for OutPoint {
#[doc = " Constructs a new [`OutPoint`]."]
fn new(txid: Txid, vout: u32) -> Self {
OutPoint { txid, vout }
}
#[doc = " Checks if an `OutPoint` is \"null\"."]
fn is_null(&self) -> bool {
*self == OutPoint::COINBASE_PREVOUT
}
}I put the macro into an LLM, which got me to a point to where it was adding the missing attributes to the functions, but then it broke a bunch of stuff because I'm starting to understand why you guys hate macros now, and I'm quickly approaching that point too lol |
|
ah I'm sorry mate, yeah deprecating doesn't work in macros. Let me think again tomorrow with fresh eyes. |
Oof, now you catch something important and obvious that I totally missed. |
|
Its good to have a crew huh. Seems the only constant is that us humans make mistakes constantly. |
|
My suggestion would be to use Sorry to burden you with such thoroughness. @apoelstra may want to override me and just update this PR title/description himself to something sane. |
|
My suggestion would be to backport the deprecation to 0.32.x and then just delete it in 0.33.x. This is a bit mean to users and is a faster deprecation than we'd prefer but these are fairly obscure methods and our extension-trait thing is causing us problems with doing a full deprecation cycle. |
|
Let's go! |
|
Did you mean delete them or just change the return value like originally attempted here? |
Deprecation in trait methods is painful and these two weight constructors are now defined in `TxInExt`. In rust-bitcoin#4915 we deprecate `Weight::from_non_witness_data_size` and `Weight::from_witness_data_size` in favour of `Weight::from_vb` and `Weight::from_wu` respectively but doing so messes with the APIs of these to `TxIn` methods because the return value changes from `Weight` to `Option<Weight>`. Deprecate the functions here so we can either break the API in 0.33 or delete the functions entirely.
|
Done in #5082, the question above needs addressing please to ensure the deprecation message is sensible. |
Deprecation in trait methods is painful and these two weight constructors are now defined in `TxInExt`. In rust-bitcoin#4915 we deprecate `Weight::from_non_witness_data_size` and `Weight::from_witness_data_size` in favour of `Weight::from_vb` and `Weight::from_wu` respectively but doing so messes with the APIs of these to `TxIn` methods because the return value changes from `Weight` to `Option<Weight>`. Deprecate the functions here so we can either break the API in 0.33 or delete the functions entirely. Note this only does the stuff from 4915 in `bitcoin` not in `units`.
|
Hmmm. So, we don't have good replacements for these methods (you can sorta use So I think "changing the signature" is the right way to go. Now that I look at I think the correct thing to do here, annoyingly, is to deprecate and rename, and change the signature of the renamed function. Then we can backport both the deprecation and the rename. We may want to move to an issue to discuss the new names. |
|
Is there anything wrong with the current names? Just to be clear we are talking about If its all this hard why don't we just break the API, change the return value (exactly like what is done here) and call it a day. My main grievance, and why I originally brought it up, is that all this is hidden inside a PR titled 'units: Deprecate ...'. |
|
Hmmm, yeah, maybe we should just break it. No, the existing names are fine. The only reason to rename would be to change the API in a non-breaking way.
Yeah, ok, agreed. @shinghim can you remove this change (you'll have to stick an explicit While we're at it lets do |
cd2e679 to
c7b3f78
Compare
These were causing the daily fuzz cron job to fail
c7b3f78 to
0cd384d
Compare
|
sorry was out traveling, but I'm following now. Updated to use non-deprecated functions and just |
|
I just remembered that there used to be a bot that commented on the PR if it changed the public api. Did we get rid of it? I'm not at my computer so I can't check right now, but I don't want to forget and thought maybe one of you guys knew off the top of your head |
|
There is a CI job that fails if a PR changes the API without updating the API text files (units only). We got rid of the bot. |
Weight::from_non_witness_data_size has an overflow bug. These methods duplicate the functionality of
Weight::from_vbandWeight::from_wu, respectively. Furthermore, they are less discoverable than the methods they duplicate, so they will be removed in this PR.Related discussion in #4847